Skip to content

Commit a38f090

Browse files
committed
stack: Change Signature.CreatedBy to be a stack
This is a stack when the race detector is enabled. It's somewhat inconvenient when used normally, but on the other hand it makes verification if one was present more clear.
1 parent 45137ab commit a38f090

11 files changed

Lines changed: 159 additions & 75 deletions

File tree

internal/htmlstack/data.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/htmlstack/goroutines.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ document.addEventListener("DOMContentLoaded", ready);
214214
</h1>
215215
{{if $e.Locked}} <span class="locked">[locked]</span>
216216
{{- end -}}
217-
{{- if $e.CreatedBy.Func.Complete}} <span class="created">Created by: {{template "RenderCall" $e.CreatedBy}}</span>
217+
{{- if $e.CreatedBy.Calls}} <span class="created">Created by: {{template "RenderCall" index $e.CreatedBy.Calls 0}}</span>
218218
{{- end -}}
219219
{{template "RenderCalls" $e.Signature.Stack}}
220220
{{- end -}}

internal/htmlstack/htmlstack_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,27 @@ func TestSymbol(t *testing.T) {
241241
}
242242
}
243243

244+
func TestRace(t *testing.T) {
245+
t.Parallel()
246+
data := internaltest.PanicOutputs()["race"]
247+
c, err := stack.ParseDump(bytes.NewReader(data), ioutil.Discard, true)
248+
if err != nil {
249+
t.Fatal(err)
250+
}
251+
if c != nil {
252+
t.Fatal("unexpected context")
253+
}
254+
/*
255+
if c.Goroutines != nil {
256+
t.Fatal("unexpected context")
257+
}
258+
buckets := stack.Aggregate(c.Goroutines, stack.AnyPointer)
259+
if err := Write(ioutil.Discard, buckets, false, false); err != nil {
260+
t.Fatal(err)
261+
}
262+
*/
263+
}
264+
244265
func BenchmarkWrite(b *testing.B) {
245266
b.ReportAllocs()
246267
c, err := stack.ParseDump(bytes.NewReader(internaltest.StaticPanicwebOutput()), ioutil.Discard, true)

internal/ui.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ func (pf pathFormat) formatCall(c *stack.Call) string {
6060
}
6161

6262
func (pf pathFormat) createdByString(s *stack.Signature) string {
63-
if s.CreatedBy.Func.DirName == "" {
63+
if len(s.CreatedBy.Calls) == 0 {
6464
return ""
6565
}
66-
return s.CreatedBy.Func.DirName + "." + s.CreatedBy.Func.Name + " @ " + pf.formatCall(&s.CreatedBy)
66+
return s.CreatedBy.Calls[0].Func.DirName + "." + s.CreatedBy.Calls[0].Func.Name + " @ " + pf.formatCall(&s.CreatedBy.Calls[0])
6767
}
6868

6969
// calcLengths returns the maximum length of the source lines and package names.

internal/ui_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ func TestBucketHeader(t *testing.T) {
6262
b := &stack.Bucket{
6363
Signature: stack.Signature{
6464
State: "chan receive",
65-
CreatedBy: newCallLocal(
66-
"main.mainImpl", stack.Args{}, "/home/user/go/src/github.com/foo/bar/baz.go", 74),
65+
CreatedBy: stack.Stack{
66+
Calls: []stack.Call{
67+
newCallLocal("main.mainImpl", stack.Args{}, "/home/user/go/src/github.com/foo/bar/baz.go", 74),
68+
},
69+
},
6770
SleepMax: 6,
6871
SleepMin: 2,
6972
},

stack/bucket_test.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,15 @@ func TestAggregateExactMatching(t *testing.T) {
9696
{
9797
Signature: Signature{
9898
State: "chan receive",
99-
CreatedBy: newCall(
100-
"main.mainImpl",
101-
Args{},
102-
"/gopath/src/github.com/maruel/panicparse/stack/stack.go",
103-
74),
99+
CreatedBy: Stack{
100+
Calls: []Call{
101+
newCall(
102+
"main.mainImpl",
103+
Args{},
104+
"/gopath/src/github.com/maruel/panicparse/stack/stack.go",
105+
74),
106+
},
107+
},
104108
Stack: Stack{
105109
Calls: []Call{
106110
newCall(

stack/context.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ func (s *scanningState) scan(line string) (string, error) {
479479
return "", nil
480480

481481
case gotCreated:
482-
if found, err := parseFile(&cur.CreatedBy, trimmed); err != nil {
482+
if found, err := parseFile(&cur.CreatedBy.Calls[0], trimmed); err != nil {
483483
return "", err
484484
} else if !found {
485485
return "", fmt.Errorf("expected a file after a created line, got: %q", trimmed)
@@ -489,7 +489,9 @@ func (s *scanningState) scan(line string) (string, error) {
489489

490490
case gotFileFunc:
491491
if match := reCreated.FindStringSubmatch(trimmed); match != nil {
492-
if err := cur.CreatedBy.Func.Init(match[1]); err != nil {
492+
cur.CreatedBy.Calls = make([]Call, 1)
493+
if err := cur.CreatedBy.Calls[0].Func.Init(match[1]); err != nil {
494+
cur.CreatedBy.Calls = nil
493495
return "", err
494496
}
495497
s.state = gotCreated
@@ -534,7 +536,9 @@ func (s *scanningState) scan(line string) (string, error) {
534536
return "", nil
535537
}
536538
if match := reCreated.FindStringSubmatch(trimmed); match != nil {
537-
if err := cur.CreatedBy.Func.Init(match[1]); err != nil {
539+
cur.CreatedBy.Calls = make([]Call, 1)
540+
if err := cur.CreatedBy.Calls[0].Func.Init(match[1]); err != nil {
541+
cur.CreatedBy.Calls = nil
538542
return "", err
539543
}
540544
s.state = gotCreated

0 commit comments

Comments
 (0)