Skip to content
This repository has been archived by the owner on Jul 19, 2023. It is now read-only.

Add query subcommand to profilecli for downloading pprof from phlare #475

Merged
merged 3 commits into from
Jan 17, 2023

Conversation

simonswine
Copy link
Collaborator

@simonswine simonswine commented Jan 11, 2023

This adds a query subcommand to download pprof from phlare using profilecli.

This is on top of #474

Usage:

$ profilecli query merge --from now-5m --output pprof=my.pprof

$ profilecli query merge --from now-5m --profile-type memory:alloc_space:bytes:space:bytes
&googlev1.Profile{
  SampleType: []*googlev1.ValueType{
    &googlev1.ValueType{
      Type: 1,
      Unit: 2,
    },
  },

[...]
  DropFrames:    0,
  KeepFrames:    0,
  TimeNanos:     1673453999823000000,
  DurationNanos: 300000000000,
  PeriodType:    &googlev1.ValueType{
    Type:          434,
    Unit:          2,
  },
  Period:            524288,
  Comment:           []int64(nil),
  DefaultSampleType: 1,
}

@simonswine simonswine changed the title 20230111 profilecli query Add query subcommand to profilecli for downloading pprof from phlare Jan 11, 2023
@simonswine simonswine force-pushed the 20230111_profilecli_query branch from 6c4a88b to db9adaf Compare January 11, 2023 16:45
Usage:

```
$ profilecli query merge --from now-5m --output pprof=my.pprof

$ profilecli query merge --from now-5m --profile-type memory:alloc_space:bytes:space:bytes
&googlev1.Profile{
  SampleType: []*googlev1.ValueType{
    &googlev1.ValueType{
      Type: 1,
      Unit: 2,
    },
  },

[...]
  DropFrames:    0,
  KeepFrames:    0,
  TimeNanos:     1673453999823000000,
  DurationNanos: 300000000000,
  PeriodType:    &googlev1.ValueType{
    Type:          434,
    Unit:          2,
  },
  Period:            524288,
  Comment:           []int64(nil),
  DefaultSampleType: 1,
}
```
Previous output is available with --output=raw
@simonswine simonswine force-pushed the 20230111_profilecli_query branch from 39220f8 to 72a274b Compare January 12, 2023 09:35
@simonswine simonswine marked this pull request as ready for review January 12, 2023 09:35
return errors.Wrap(err, "failed to marshal protobuf")
}

err = os.WriteFile(filePath, buf, 0644)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should gzip it here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes pprof should be gziped

Copy link
Collaborator

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM if you can add the gzip.

This will also change the behaviour, when create a pprof file, it will
fail when the file already exists.
@cyriltovena cyriltovena enabled auto-merge (squash) January 17, 2023 13:17
@cyriltovena cyriltovena merged commit 2f03659 into grafana:main Jan 17, 2023
simonswine added a commit to simonswine/pyroscope that referenced this pull request Jun 30, 2023
…rafana/phlare#475)

* Add query subcommand to download pprof from phlare

Usage:

```
$ profilecli query merge --from now-5m --output pprof=my.pprof

$ profilecli query merge --from now-5m --profile-type memory:alloc_space:bytes:space:bytes
&googlev1.Profile{
  SampleType: []*googlev1.ValueType{
    &googlev1.ValueType{
      Type: 1,
      Unit: 2,
    },
  },

[...]
  DropFrames:    0,
  KeepFrames:    0,
  TimeNanos:     1673453999823000000,
  DurationNanos: 300000000000,
  PeriodType:    &googlev1.ValueType{
    Type:          434,
    Unit:          2,
  },
  Period:            524288,
  Comment:           []int64(nil),
  DefaultSampleType: 1,
}
```

* Use parsed profile output for console by default

Previous output is available with --output=raw

* Implement gzip compression for pprof file

This will also change the behaviour, when create a pprof file, it will
fail when the file already exists.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants