Skip to content

Commit

Permalink
Fix not working on new Go versions
Browse files Browse the repository at this point in the history
  • Loading branch information
spowelljr committed Nov 7, 2023
1 parent a6814bc commit 18bf2b6
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 48 deletions.
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module github.com/google/slowjam
go 1.20

require (
github.com/golang/protobuf v1.5.2
github.com/maruel/panicparse v1.6.2
github.com/golang/protobuf v1.5.3
github.com/maruel/panicparse/v2 v2.3.1
github.com/spf13/pflag v1.0.5
google.golang.org/protobuf v1.28.1
k8s.io/klog/v2 v2.80.1
google.golang.org/protobuf v1.31.0
k8s.io/klog/v2 v2.110.1
)

require github.com/go-logr/logr v1.2.0 // indirect
require github.com/go-logr/logr v1.3.0 // indirect
35 changes: 17 additions & 18 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
github.com/go-logr/logr v1.2.0 h1:QK40JKJyMdUDz+h+xvCsru/bJhvG0UxvePV0ufL/AcE=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/maruel/panicparse v1.6.2 h1:tZuGQTlbOY5jCprrWMJTikREqKPn+UAKdR4CHSpj834=
github.com/maruel/panicparse v1.6.2/go.mod h1:uoxI4w9gJL6XahaYPMq/z9uadrdr1SyHuQwV2q80Mm0=
github.com/maruel/panicparse/v2 v2.1.1/go.mod h1:AeTWdCE4lcq8OKsLb6cHSj1RWHVSnV9HBCk7sKLF4Jg=
github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/maruel/panicparse/v2 v2.3.1 h1:NtJavmbMn0DyzmmSStE8yUsmPZrZmudPH7kplxBinOA=
github.com/maruel/panicparse/v2 v2.3.1/go.mod h1:s3UmQB9Fm/n7n/prcD2xBGDkwXD6y2LeZnhbEXvs9Dg=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
k8s.io/klog/v2 v2.80.1 h1:atnLQ121W371wYYFawwYx1aEY2eUfs4l3J72wtgAwV4=
k8s.io/klog/v2 v2.80.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
k8s.io/klog/v2 v2.110.1 h1:U/Af64HJf7FcwMcXyKm2RPM22WZzyR7OSpYj5tg3cL0=
k8s.io/klog/v2 v2.110.1/go.mod h1:YGtd1984u+GgbuZ7e08/yBuAfKLSO0+uR1Fhi6ExXjo=
12 changes: 6 additions & 6 deletions pkg/pprof/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func processSamples(samples []*stackparse.StackSample, st map[string]int64, igno
locs := []uint64{}

for _, g := range s.Context.Goroutines {
if ig[g.CreatedBy.Func.PkgDotName()] {
if len(g.CreatedBy.Calls) != 0 && ig[stackparse.PkgDotName(g.CreatedBy.Calls[0].Func)] {
continue
}

Expand All @@ -99,14 +99,14 @@ func processSamples(samples []*stackparse.StackSample, st map[string]int64, igno
}

f := &Function{
Id: uint64(ix(ftable, c.Func.Raw)),
Name: ix(st, c.Func.PkgDotName()),
SystemName: ix(st, c.Func.PkgDotName()),
Filename: ix(st, c.SrcPath),
Id: uint64(ix(ftable, c.Func.Complete)),
Name: ix(st, stackparse.PkgDotName(c.Func)),
SystemName: ix(st, stackparse.PkgDotName(c.Func)),
Filename: ix(st, c.RemoteSrcPath),
}

l := &Location{
Id: uint64(ix(ltable, fmt.Sprintf("%s:%d", c.SrcPath, c.Line))),
Id: uint64(ix(ltable, fmt.Sprintf("%s:%d", c.RemoteSrcPath, c.Line))),
Line: []*Line{
{FunctionId: f.Id, Line: int64(c.Line)},
},
Expand Down
13 changes: 9 additions & 4 deletions pkg/stackparse/stackparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@ package stackparse
import (
"bufio"
"bytes"
"fmt"
"io"
"os"
"strconv"
"strings"
"time"

"github.com/maruel/panicparse/stack"
"github.com/maruel/panicparse/v2/stack"
)

// StackSample represents a single Go stack at a point in time.
type StackSample struct {
Time time.Time
Context *stack.Context
Context *stack.Snapshot
}

// Read parses a stack log input.
Expand Down Expand Up @@ -62,8 +63,8 @@ func Read(r io.Reader) ([]*StackSample, error) {
if strings.HasPrefix(scanner.Text(), "-") {
inStack = false

ctx, err := stack.ParseDump(sd, os.Stdout, false)
if err != nil {
ctx, _, err := stack.ScanSnapshot(sd, os.Stdout, &stack.Opts{})
if err != nil && err != io.EOF {
return samples, err
}

Expand All @@ -82,3 +83,7 @@ func Read(r io.Reader) ([]*StackSample, error) {

return samples, nil
}

func PkgDotName(f stack.Func) string {
return fmt.Sprintf("%s.%s", f.DirName, f.Name)
}
16 changes: 8 additions & 8 deletions pkg/stackparse/timeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"strings"
"time"

"github.com/maruel/panicparse/stack"
"github.com/maruel/panicparse/v2/stack"
"k8s.io/klog/v2"
)

Expand Down Expand Up @@ -154,7 +154,7 @@ func CreateTimeline(samples []*StackSample, ignoreCreators []string, goroutines
tl.Samples++

for _, g := range s.Context.Goroutines {
if ig[g.CreatedBy.Func.PkgDotName()] {
if len(g.CreatedBy.Calls) != 0 && ig[PkgDotName(g.CreatedBy.Calls[0].Func)] {
continue
}

Expand All @@ -177,8 +177,8 @@ func CreateTimeline(samples []*StackSample, ignoreCreators []string, goroutines

thisCall := &Call{
StartDelta: s.Time.Sub(tl.Start),
Name: c.Func.PkgDotName(),
Package: c.Func.PkgName(),
Name: PkgDotName(c.Func),
Package: c.Func.DirName,
Args: c.Args,
lastSeen: s.Time,
Samples: 1,
Expand Down Expand Up @@ -208,7 +208,7 @@ func CreateTimeline(samples []*StackSample, ignoreCreators []string, goroutines

lc := calls[len(calls)-1]
// Existing call with the same name or short sample size
if lc.Name == c.Func.PkgDotName() && lc.EndDelta == 0 && (lc.Samples < 3 || SameArgs(lc.Args, c.Args)) {
if lc.Name == PkgDotName(c.Func) && lc.EndDelta == 0 && (lc.Samples < 3 || SameArgs(lc.Args, c.Args)) {
lc.Samples++
lc.lastSeen = s.Time

Expand Down Expand Up @@ -241,15 +241,15 @@ func CreateTimeline(samples []*StackSample, ignoreCreators []string, goroutines
}

func InternalCall(c stack.Call) bool {
if c.Func.PkgName() == "syscall" {
if c.Func.DirName == "syscall" {
return true
}

if c.Func.IsExported() {
if c.Func.IsExported {
return false
}

if c.IsStdlib || strings.Contains(c.SrcPath, "/go/src/") {
if strings.Contains(c.RemoteSrcPath, "/go/src/") {
return true
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/text/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ func Tree(tl *stackparse.Timeline) string {

for _, gid := range gor {
g := tl.Goroutines[gid]
sb.WriteString(fmt.Sprintf("goroutine %d (%s)\n", gid, g.Signature.CreatedByString(true)))
funcName := ""
if len(g.Signature.CreatedBy.Calls) != 0 {
call := g.Signature.CreatedBy.Calls[0]
funcName = fmt.Sprintf("%s @ %s:%d", stackparse.PkgDotName(call.Func), call.RemoteSrcPath, call.Line)
}
sb.WriteString(fmt.Sprintf("goroutine %d (%s)\n", gid, funcName))

for i, l := range g.Layers {
for _, c := range l.Calls {
Expand Down
10 changes: 4 additions & 6 deletions pkg/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

"github.com/google/slowjam/pkg/stackparse"
"github.com/google/slowjam/third_party/colornames"
"github.com/maruel/panicparse/stack"
"github.com/maruel/panicparse/v2/stack"
)

var ganttTemplate = `
Expand Down Expand Up @@ -153,12 +153,10 @@ func sorted(grs map[int]*stackparse.GoroutineTimeline) []*stackparse.GoroutineTi
}

func creator(s *stack.Signature) string {
c := s.CreatedBy.Func.PkgDotName()
if c == "" {
c = "main"
if len(s.CreatedBy.Calls) == 0 {
return "main"
}

return c
return stackparse.PkgDotName(s.CreatedBy.Calls[0].Func)
}

func height(ls []*stackparse.Layer) string {
Expand Down

0 comments on commit 18bf2b6

Please sign in to comment.