This is an archive of the discontinued LLVM Phabricator instance.

Add --hot-func-list to llvm-profdata show for sample profiles
ClosedPublic

Authored by weihe on Jun 13 2020, 3:53 PM.

Details

Summary

Add the --hot-func-list feature to llvm-profdata show for sample profiles. This feature prints a list of hot functions whose max sample count are above the 99% threshold, with their numbers of total samples, total samples percentage, max samples, entry samples, and their function names.

Diff Detail

Event Timeline

weihe created this revision.Jun 13 2020, 3:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 13 2020, 3:53 PM
hoyFB added a reviewer: wmi.Jun 13 2020, 4:23 PM
weihe edited the summary of this revision. (Show Details)Jun 15 2020, 7:08 AM
weihe added reviewers: hoyFB, wenlei.
wmi added a comment.Jun 15 2020, 10:21 AM

Thanks for adding the feature.

llvm/tools/llvm-profdata/llvm-profdata.cpp
1032–1048

Please make it a member function of FunctionSamples so it can be used elsewhere.

The max count can either be in inlinee or in itself. Your comment explicitly says that and it is good. Just the name getInlineeMaxCount is a little misleading. Perhaps use another name like getMaxCountInside?

1058

Uses a const variable instead of a raw number.

1092–1127

Can you wrap the output part in a function? I feel it can be useful as well for Instr profile. It is also better to be flexible about which metric is used to decide whether the function is hot (currently it is MaxCount). That could be different between PGO and SampleFDO.

weihe marked 3 inline comments as done.Jun 15 2020, 11:20 AM
weihe added inline comments.
llvm/tools/llvm-profdata/llvm-profdata.cpp
1032–1048

Sounds good! I'll move and rename it. Thank you for your suggestions.

1058

Yeah, I'll change it. Thanks you!

1092–1127

Thank you for the suggestions! I would like to ask the following questions to make sure I understand them correctly:

For wrapping the output part into a function, is this function supposed to be reusable for other output format or only for the current format?

For making the metric flexible, is the purpose to make the showHotFunctionList() reusable for PGO? I'm asking this question because this function is currently coupled with FunctionSample objects and interfaces that may not work with other types of profiles.

Thanks!

wmi added inline comments.Jun 15 2020, 5:06 PM
llvm/tools/llvm-profdata/llvm-profdata.cpp
1092–1127

It is to make the output part usable for PGO profile. I see that showHotFunctionList is coupled with FunctionSample, but after you decide which functions to output based on Function Sample, the output content and format are independent from profile kind and can be shared with PGO.

weihe marked an inline comment as done.Jun 16 2020, 11:38 AM
weihe added inline comments.
llvm/tools/llvm-profdata/llvm-profdata.cpp
1092–1127

Thank you for the clarification! I'm working on it now.

weihe updated this revision to Diff 271258.Jun 16 2020, 6:53 PM
weihe edited the summary of this revision. (Show Details)

Moved getInlineeMaxCount() to be FunctionSamples' member and wrapped printing code into a separate function.

The original static function getInlineeMaxCount() has been moved to be FunctionSamples::getMaxCountInside(). The output code in the original showHotFunctionList() has been wrapped into a separate function dumpHotFunctionList().

weihe marked an inline comment as done.Jun 16 2020, 7:01 PM
weihe added inline comments.
llvm/tools/llvm-profdata/llvm-profdata.cpp
1092–1127

Hello, I moved the output code into a function dumpHotFunctionList() in the current revision. I tried to make it more flexible by allowing callers to determine column titles and column offsets. But the attributes to print out is still hard-coded in this function. There needs to be some changes if PGO would like to reuse this code. Please let me know if you have any suggestions.

weihe marked 4 inline comments as done.Jun 18 2020, 4:31 PM
wmi accepted this revision.Jun 19 2020, 10:54 AM

LGTM. Thanks.

This revision is now accepted and ready to land.Jun 19 2020, 10:54 AM

@weihe thanks for working on this, I just committed this change on your behalf.

This revision was automatically updated to reflect the committed changes.

This is causing an Asan failure (see for example: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/17880).
I have reverted it for now. Thanks!

This is causing an Asan failure (see for example: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/17880).
I have reverted it for now. Thanks!

Thanks for the heads up. We'll fix and resubmit later.

llvm/tools/llvm-profdata/llvm-profdata.cpp
1054

ColNum isn't modified in the function, no need to pass by reference.

1141

ColumnOffset needs 4 slots too, otherwise dumpHotFunctionList will access out-of-bound. I think this is what's causing the asan failure.