Skip to content

Commit

Permalink
main.go: Reset buffer to correctly report length (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
brancz authored May 22, 2023
1 parent 15a2e22 commit e98268b
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 438 deletions.
19 changes: 11 additions & 8 deletions cmd/parca-debuginfo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func run(kongCtx *kong.Context, flags flags) error {
grpcUploadClient := parcadebuginfo.NewGrpcUploadClient(debuginfoClient)

srcDst := map[string]io.WriteSeeker{}
uploads := []uploadInfo{}
uploads := []*uploadInfo{}

if flags.Upload.NoExtract {
for _, path := range flags.Upload.Paths {
Expand All @@ -131,15 +131,14 @@ func run(kongCtx *kong.Context, flags flags) error {
return fmt.Errorf("stat file: %w", err)
}

uploads = append(uploads, uploadInfo{
uploads = append(uploads, &uploadInfo{
buildID: buildID,
path: path,
reader: f,
size: fi.Size(),
})
}
} else {
buffers := []*flexbuf.Buffer{}
for _, path := range flags.Upload.Paths {
ef, err := elf.Open(path)
if err != nil {
Expand All @@ -155,13 +154,11 @@ func run(kongCtx *kong.Context, flags flags) error {
buf := &flexbuf.Buffer{}
srcDst[path] = buf

uploads = append(uploads, uploadInfo{
uploads = append(uploads, &uploadInfo{
buildID: buildID,
path: path,
reader: buf,
size: int64(buf.Len()),
})
buffers = append(buffers, buf)
}

if len(srcDst) == 0 {
Expand All @@ -171,8 +168,14 @@ func run(kongCtx *kong.Context, flags flags) error {
if err := extractor.ExtractAll(ctx, srcDst); err != nil {
return fmt.Errorf("failed to extract debug information: %w", err)
}
for _, buf := range buffers {
for _, upload := range uploads {
buf, ok := upload.reader.(*flexbuf.Buffer)
if !ok {
return fmt.Errorf("failed to cast reader to flexbuf.Buffer, something went terribly wrong as this should be the only type used")
}

buf.SeekStart()
upload.size = int64(buf.Len())
}
}

Expand All @@ -187,7 +190,7 @@ func run(kongCtx *kong.Context, flags flags) error {
}

if flags.Upload.NoInitiate {
fmt.Fprintf(os.Stdout, "Not initiating upload of %q with Build ID %q as requested, but would have requested that next.\n", upload.path, upload.buildID)
fmt.Fprintf(os.Stdout, "Not initiating upload of %q with Build ID %q as requested, but would have requested that next, because: %s\n", upload.path, upload.buildID, shouldInitiate.Reason)
continue
}

Expand Down
43 changes: 21 additions & 22 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ require (
github.com/go-kit/log v0.2.1
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/oklog/run v1.1.0
github.com/parca-dev/parca v0.14.1-0.20221212171405-85937bf44f5d
github.com/parca-dev/parca-agent v0.10.2-0.20221212164511-777aacdd7420
github.com/parca-dev/parca v0.15.0
github.com/parca-dev/parca-agent v0.12.1-0.20230216133018-8dd5ccaeef0f
github.com/prometheus/client_golang v1.14.0
github.com/rzajac/flexbuf v0.14.0
google.golang.org/grpc v1.51.0
google.golang.org/grpc v1.53.0
)

require (
cloud.google.com/go v0.105.0 // indirect
cloud.google.com/go/compute v1.13.0 // indirect
cloud.google.com/go/compute/metadata v0.2.1 // indirect
cloud.google.com/go v0.107.0 // indirect
cloud.google.com/go/compute v1.15.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v0.8.0 // indirect
cloud.google.com/go/storage v1.28.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.1.0 // indirect
Expand All @@ -42,7 +42,7 @@ require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/clbanning/mxj v1.8.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/efficientgo/core v1.0.0-rc.0.0.20221201130417-ba593f67d2a4 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/goburrow/cache v0.1.4 // indirect
Expand All @@ -52,18 +52,18 @@ require (
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/pprof v0.0.0-20221203041831-ce31453925ec // indirect
github.com/google/pprof v0.0.0-20230131232505-5a9e8f65f08f // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.14.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.15.12 // indirect
github.com/klauspost/compress v1.15.15 // indirect
github.com/klauspost/cpuid/v2 v2.1.1 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/minio-go/v7 v7.0.45 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
Expand All @@ -77,28 +77,27 @@ require (
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/rogpeppe/go-internal v1.6.1 // indirect
github.com/prometheus/common v0.39.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/rs/xid v1.4.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/sony/gobreaker v0.5.0 // indirect
github.com/tencentyun/cos-go-sdk-v5 v0.7.40 // indirect
github.com/thanos-io/objstore v0.0.0-20221207004404-2e4c6638339a // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel v1.11.1 // indirect
go.opentelemetry.io/otel/trace v1.11.1 // indirect
go.opentelemetry.io/otel v1.11.2 // indirect
go.opentelemetry.io/otel/trace v1.11.2 // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/net v0.2.0 // indirect
golang.org/x/oauth2 v0.2.0 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/oauth2 v0.4.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/time v0.1.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.6.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.103.0 // indirect
google.golang.org/api v0.104.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading

0 comments on commit e98268b

Please sign in to comment.