-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ft: Filter by function
functionality added to ProfileView
#2062
Changes from 5 commits
416223e
3c5974f
957b1da
ad1ff51
5b4dc58
3098803
b477a5a
dde4dd7
1685937
f1fc0b1
98aeb77
4b4f82f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import ( | |
"bytes" | ||
"context" | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
||
"github.com/go-kit/log" | ||
|
@@ -142,9 +143,33 @@ func (q *ColumnQueryAPI) Query(ctx context.Context, req *pb.QueryRequest) (*pb.Q | |
return nil, err | ||
} | ||
|
||
if req.FilterQuery != nil { | ||
p = filterProfileData(p, *req.FilterQuery) | ||
} | ||
|
||
return q.renderReport(ctx, p, req.GetReportType()) | ||
} | ||
|
||
func filterProfileData(p *profile.Profile, filterQuery string) *profile.Profile { | ||
filteredSamples := []*profile.SymbolizedSample{} | ||
for _, s := range p.Samples { | ||
var lines []profile.LocationLine | ||
for _, loc := range s.Locations { | ||
lines = append(lines, loc.Lines...) | ||
} | ||
for _, l := range lines { | ||
if l.Function != nil && strings.Contains(strings.ToLower(l.Function.Name), strings.ToLower(filterQuery)) { | ||
filteredSamples = append(filteredSamples, s) | ||
break | ||
} | ||
} | ||
} | ||
return &profile.Profile{ | ||
Samples: filteredSamples, | ||
Meta: p.Meta, | ||
} | ||
} | ||
|
||
func (q *ColumnQueryAPI) renderReport(ctx context.Context, p *profile.Profile, typ pb.QueryRequest_ReportType) (*pb.QueryResponse, error) { | ||
ctx, span := q.tracer.Start(ctx, "renderReport") | ||
span.SetAttributes(attribute.String("reportType", typ.String())) | ||
|
@@ -196,6 +221,7 @@ func (q *ColumnQueryAPI) renderReport(ctx context.Context, p *profile.Profile, t | |
Report: &pb.QueryResponse_Top{Top: top}, | ||
}, nil | ||
case pb.QueryRequest_REPORT_TYPE_CALLGRAPH: | ||
fmt.Println("callgraph") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. debugging leftover I assume? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, yes, my bad. |
||
callgraph, err := GenerateCallgraph(ctx, p) | ||
if err != nil { | ||
return nil, status.Errorf(codes.Internal, "failed to generate callgraph: %v", err.Error()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to copy here. I would suggest the inside of this loop should be extracted to a separate function that's just called
keepSample
and if it returns true, then we append tofilteredSamples
. All thekeepSample
function then does is loop over all lines of all locations and on the first match it returnstrue
and otherwise if no location line contained the search string, then it returns false.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done