Skip to content

Commit 0169ee5

Browse files
authored
Add stacktrace selectors to query merge (#3412)
1 parent a5aebf6 commit 0169ee5

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

cmd/profilecli/query.go

+25-8
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,15 @@ func addQueryParams(queryCmd commander) *queryParams {
108108

109109
type queryMergeParams struct {
110110
*queryParams
111-
ProfileType string
111+
ProfileType string
112+
StacktraceSelector []string
112113
}
113114

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

@@ -124,13 +126,28 @@ func queryMerge(ctx context.Context, params *queryMergeParams, outputFlag string
124126
return err
125127
}
126128
level.Info(logger).Log("msg", "query aggregated profile from profile store", "url", params.URL, "from", from, "to", to, "query", params.Query, "type", params.ProfileType)
127-
return selectMergeProfile(ctx, params.phlareClient, outputFlag,
128-
&querierv1.SelectMergeProfileRequest{
129-
ProfileTypeID: params.ProfileType,
130-
Start: from.UnixMilli(),
131-
End: to.UnixMilli(),
132-
LabelSelector: params.Query,
133-
})
129+
130+
req := &querierv1.SelectMergeProfileRequest{
131+
ProfileTypeID: params.ProfileType,
132+
Start: from.UnixMilli(),
133+
End: to.UnixMilli(),
134+
LabelSelector: params.Query,
135+
}
136+
137+
if len(params.StacktraceSelector) > 0 {
138+
locations := make([]*typesv1.Location, 0, len(params.StacktraceSelector))
139+
for _, cs := range params.StacktraceSelector {
140+
locations = append(locations, &typesv1.Location{
141+
Name: cs,
142+
})
143+
}
144+
req.StackTraceSelector = &typesv1.StackTraceSelector{
145+
CallSite: locations,
146+
}
147+
level.Info(logger).Log("msg", "selecting with stackstrace selector", "call-site", fmt.Sprintf("%#+v", params.StacktraceSelector))
148+
}
149+
150+
return selectMergeProfile(ctx, params.phlareClient, outputFlag, req)
134151
}
135152

136153
func selectMergeProfile(ctx context.Context, client *phlareClient, outputFlag string, req *querierv1.SelectMergeProfileRequest) error {

0 commit comments

Comments
 (0)