Skip to content

Commit

Permalink
refactor: renaming commands to
Browse files Browse the repository at this point in the history
  • Loading branch information
alsoba13 committed Oct 15, 2024
1 parent 27533b4 commit 0f1d49a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
18 changes: 9 additions & 9 deletions cmd/profilecli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func main() {
blocksQueryCmd := blocksCmd.Command("query", "Query on local/remote blocks.")
blocksQuerySeriesCmd := blocksQueryCmd.Command("series", "Request series labels on local/remote blocks.")
blocksQuerySeriesParams := addBlocksQuerySeriesParams(blocksQuerySeriesCmd)
blocksQueryMergeCmd := blocksQueryCmd.Command("merge", "Request merged profile on local/remote block.")
blocksQueryMergeParams := addBlocksQueryMergeParams(blocksQueryMergeCmd)
blocksQueryProfileCmd := blocksQueryCmd.Command("profile", "Request merged profile on local/remote block.").Alias("merge")
blocksQueryProfileParams := addBlocksQueryProfileParams(blocksQueryProfileCmd)

parquetCmd := adminCmd.Command("parquet", "Operate on a Parquet file.")
parquetInspectCmd := parquetCmd.Command("inspect", "Inspect a parquet file's structure.")
Expand All @@ -71,9 +71,9 @@ func main() {
tsdbSeriesFiles := tsdbSeriesCmd.Arg("file", "tsdb file path").Required().ExistingFiles()

queryCmd := app.Command("query", "Query profile store.")
queryMergeCmd := queryCmd.Command("merge", "Request merged profile.")
queryMergeOutput := queryMergeCmd.Flag("output", "How to output the result, examples: console, raw, pprof=./my.pprof").Default("console").String()
queryMergeParams := addQueryMergeParams(queryMergeCmd)
queryProfileCmd := queryCmd.Command("profile", "Request merged profile.").Alias("merge")
queryProfileOutput := queryProfileCmd.Flag("output", "How to output the result, examples: console, raw, pprof=./my.pprof").Default("console").String()
queryProfileParams := addQueryProfileParams(queryProfileCmd)
queryGoPGOCmd := queryCmd.Command("go-pgo", "Request profile for Go PGO.")
queryGoPGOOutput := queryGoPGOCmd.Flag("output", "How to output the result, examples: console, raw, pprof=./my.pprof").Default("pprof=./default.pgo").String()
queryGoPGOParams := addQueryGoPGOParams(queryGoPGOCmd)
Expand Down Expand Up @@ -125,8 +125,8 @@ func main() {
os.Exit(checkError(err))
}
}
case queryMergeCmd.FullCommand():
if err := queryMerge(ctx, queryMergeParams, *queryMergeOutput); err != nil {
case queryProfileCmd.FullCommand():
if err := queryProfile(ctx, queryProfileParams, *queryProfileOutput); err != nil {
os.Exit(checkError(err))
}
case queryGoPGOCmd.FullCommand():
Expand All @@ -142,8 +142,8 @@ func main() {
if err := blocksQuerySeries(ctx, blocksQuerySeriesParams); err != nil {
os.Exit(checkError(err))
}
case blocksQueryMergeCmd.FullCommand():
if err := blocksQueryMerge(ctx, blocksQueryMergeParams); err != nil {
case blocksQueryProfileCmd.FullCommand():
if err := blocksQueryProfile(ctx, blocksQueryProfileParams); err != nil {
os.Exit(checkError(err))
}

Expand Down
12 changes: 6 additions & 6 deletions cmd/profilecli/query-blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type blocksQueryParams struct {
Query string
}

type blocksQueryMergeParams struct {
type blocksQueryProfileParams struct {
*blocksQueryParams
Output string
ProfileType string
Expand All @@ -49,8 +49,8 @@ func addBlocksQueryParams(queryCmd commander) *blocksQueryParams {
return params
}

func addBlocksQueryMergeParams(queryCmd commander) *blocksQueryMergeParams {
params := new(blocksQueryMergeParams)
func addBlocksQueryProfileParams(queryCmd commander) *blocksQueryProfileParams {
params := new(blocksQueryProfileParams)
params.blocksQueryParams = addBlocksQueryParams(queryCmd)
queryCmd.Flag("output", "How to output the result, examples: console, raw, pprof=./my.pprof").Default("console").StringVar(&params.Output)
queryCmd.Flag("profile-type", "Profile type to query.").Default("process_cpu:cpu:nanoseconds:cpu:nanoseconds").StringVar(&params.ProfileType)
Expand All @@ -65,12 +65,12 @@ func addBlocksQuerySeriesParams(queryCmd commander) *blocksQuerySeriesParams {
return params
}

func blocksQueryMerge(ctx context.Context, params *blocksQueryMergeParams) error {
level.Info(logger).Log("msg", "blocks query merge", "blockIds", fmt.Sprintf("%v", params.BlockIds), "path",
func blocksQueryProfile(ctx context.Context, params *blocksQueryProfileParams) error {
level.Info(logger).Log("msg", "blocks query profile", "blockIds", fmt.Sprintf("%v", params.BlockIds), "path",
cfg.blocks.path, "bucketName", params.BucketName, "tenantId", params.TenantID, "query", params.Query, "type", params.ProfileType)

if len(params.BlockIds) > 1 {
return errors.New("query merge is limited to a single block")
return errors.New("query profile is limited to a single block")
}

profileType, err := model.ParseProfileTypeSelector(params.ProfileType)
Expand Down
12 changes: 6 additions & 6 deletions cmd/profilecli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,21 @@ func addQueryParams(queryCmd commander) *queryParams {
return params
}

type queryMergeParams struct {
type queryProfileParams struct {
*queryParams
ProfileType string
StacktraceSelector []string
}

func addQueryMergeParams(queryCmd commander) *queryMergeParams {
params := new(queryMergeParams)
func addQueryProfileParams(queryCmd commander) *queryProfileParams {
params := new(queryProfileParams)
params.queryParams = addQueryParams(queryCmd)
queryCmd.Flag("profile-type", "Profile type to query.").Default("process_cpu:cpu:nanoseconds:cpu:nanoseconds").StringVar(&params.ProfileType)
queryCmd.Flag("stacktrace-selector", "Only query locations with those symbols. Provide multiple times starting with the root").StringsVar(&params.StacktraceSelector)
return params
}

func queryMerge(ctx context.Context, params *queryMergeParams, outputFlag string) (err error) {
func queryProfile(ctx context.Context, params *queryProfileParams, outputFlag string) (err error) {
from, to, err := params.parseFromTo()
if err != nil {
return err
Expand Down Expand Up @@ -145,14 +145,14 @@ func selectMergeProfile(ctx context.Context, client *phlareClient, outputFlag st
}

type queryGoPGOParams struct {
*queryMergeParams
*queryProfileParams
KeepLocations uint32
AggregateCallees bool
}

func addQueryGoPGOParams(queryCmd commander) *queryGoPGOParams {
params := new(queryGoPGOParams)
params.queryMergeParams = addQueryMergeParams(queryCmd)
params.queryProfileParams = addQueryProfileParams(queryCmd)
queryCmd.Flag("keep-locations", "Number of leaf locations to keep.").Default("5").Uint32Var(&params.KeepLocations)
queryCmd.Flag("aggregate-callees", "Aggregate samples for the same callee by ignoring the line numbers in the leaf locations.").Default("true").BoolVar(&params.AggregateCallees)
return params
Expand Down
12 changes: 6 additions & 6 deletions docs/sources/view-and-analyze-profile-data/profile-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,27 +224,27 @@ You can narrow the results down with the `--query` flag. See `profilecli help qu
### Reading a raw profile from a Pyroscope server
You can use the `profilecli query merge` command to retrieve a merged (aggregated) profile from a Pyroscope server.
You can use the `profilecli query profile` command to retrieve a merged (aggregated) profile from a Pyroscope server.
The command merges all samples found in the profile store for the specified query and time range.
By default it looks for samples within the last hour, though this can be controlled with the `--from` and `--to` flags. The source data can be narrowed down with the `--query` flag in the same way as with the `series` command.
#### Query merge steps
#### Query profile steps
1. Specify optional flags.
- You can provide a label selector using the `--query` flag, for example, `--query='{service_name="my_application_name"}'`.
- You can provide a custom time range using the `--from` and `--to` flags, for example, `--from="now-3h" --to="now"`.
- You can specify the profile type via the `--profile-type` flag. The available profile types are listed in the output of the `profilecli query series` command.
2. Construct and execute the Query Merge command.
2. Construct and execute the Query Profile command.
- Here's a basic command template:
```bash
export PROFILECLI_URL=<pyroscope_server_url>
export PROFILECLI_USERNAME=<username>
export PROFILECLI_PASSWORD=<password>
profilecli query merge \
profilecli query profile \
--profile-type=<profile_type> \
--query='{<label_name>="<label_value>"' \
--from="<from>" --to="<to>"
Expand All @@ -256,7 +256,7 @@ By default it looks for samples within the last hour, though this can be control
export PROFILECLI_USERNAME=my_username
export PROFILECLI_PASSWORD=my_password
profilecli query merge \
profilecli query profile \
--profile-type=memory:inuse_space:bytes:space:bytes \
--query='{service_name="my_application_name"}' \
--from="now-1h" --to="now"
Expand All @@ -278,7 +278,7 @@ By default it looks for samples within the last hour, though this can be control
### Exporting a profile for Go PGO

You can use the `profilecli query go-pgo` command to retrieve an aggregated profile from a Pyroscope server for use with Go PGO.
Profiles retrieved with `profilecli query merge` include all samples found in the profile store, resulting in a large profile size.
Profiles retrieved with `profilecli query profile` include all samples found in the profile store, resulting in a large profile size.
The profile size may cause issues with network transfer and slow down the PGO process.
In contrast, profiles retrieved with `profilecli query go-pgo` include only the information used in Go PGO, making them significantly smaller and more efficient to handle.
By default, it looks for samples within the last hour, though this can be controlled with the `--from` and `--to` flags. The source data can be narrowed down with the `--query` flag in the same way as with the `query` command.
Expand Down

0 comments on commit 0f1d49a

Please sign in to comment.