This is an archive of the discontinued LLVM Phabricator instance.

[memprof] Extend llvm-profdata to display MemProf profile summaries.
ClosedPublic

Authored by snehasish on Nov 19 2021, 2:14 PM.

Details

Summary

This commit adds initial support to llvm-profdata to read and print
summaries of raw memprof profiles.
Summary of changes:

  • Refactor shared defs to MemProfData.inc
  • Extend show_main to display memprof profile summaries.
  • Add a simple raw memprof profile reader.
  • Add a couple of tests to tools/llvm-profdata.

Diff Detail

Event Timeline

snehasish created this revision.Nov 19 2021, 2:14 PM
snehasish requested review of this revision.Nov 19 2021, 2:14 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptNov 19 2021, 2:14 PM
Herald added subscribers: llvm-commits, Restricted Project. · View Herald Transcript
snehasish updated this revision to Diff 388642.Nov 19 2021, 3:13 PM

Add a couple of sentences to the tests to clarify expectations.

Probably better to split out the refactor patch and commit it separately as NFC.

snehasish updated this revision to Diff 389013.Nov 22 2021, 1:08 PM

Add headers to address undefined uint64_t on Windows build.

Probably better to split out the refactor patch and commit it separately as NFC.

I tried it out and decided against it for the following reasons:

  • IMO we should introduce both shared .inc files in a single commit.
  • If I move both refactored inc files into a separate commit, to keep it NFC the file in include/llvm/ProfileData will be unused.

Finally, since the size of the refactored out content isn't large (<50 LOC) I'd like to keep this as is unless you have a strong opinion.

PTAL, thanks!

davidxl added inline comments.Nov 22 2021, 1:30 PM
llvm/lib/ProfileData/RawMemProfReader.cpp
34

This assumes one Header in the profile, but it is possible to have multiple raw profiles concatenated in the same file?

75

Add checks to Headers here?

snehasish updated this revision to Diff 389031.Nov 22 2021, 1:35 PM

Move the header sanity checks into the loop.

snehasish marked an inline comment as done.Nov 22 2021, 1:40 PM
snehasish added inline comments.
llvm/lib/ProfileData/RawMemProfReader.cpp
34

This is just a helper which reads some data from 1 raw profile. Start only needs to point to the beginning of a header (see usage in RawMemProfReader::printSummary). Is there anything you recommend to make this usage clearer?

davidxl added inline comments.Nov 22 2021, 1:53 PM
llvm/lib/ProfileData/RawMemProfReader.cpp
34

I misunderstood - I thought this interface is used to compute the 'combined' summary.

Do we have a need to have the later? For instance, for printSummary, is it helpful to just print out the combined data to the user instead of printing out multiple 'summaries'? Intuitively, summary means the later.

snehasish updated this revision to Diff 389063.Nov 22 2021, 4:14 PM
  • Clarify summary function.
  • Use llvm::memprof namespace in the MemProfData.inc header.
  • Rename memprof enum in llvm-profdata.cpp to avoid conflict with namespace.
snehasish added inline comments.Nov 22 2021, 4:18 PM
llvm/lib/ProfileData/RawMemProfReader.cpp
34

I renamed the function to printSummaries and added comments to clarify what it does. For now this is just used to test the raw format reader. I don't think there is much value in the combined summary apart from sanity checking - the indexed format conversion step will have to merge the raw profiles prior to processing. At that point I can enhance the printed out summary if it helps us in testing. Wdyt?

davidxl accepted this revision.Nov 22 2021, 4:49 PM

lgtm

This revision is now accepted and ready to land.Nov 22 2021, 4:49 PM
snehasish updated this revision to Diff 389612.Nov 24 2021, 2:07 PM

Update MemProfData.inc.

  • Add a header guard
  • Do not use c typedef-style struct decl (MSVC build fails when included in a cpp file)
  • Use appropriate pragmas for packing - clang+gcc vs msvc.

Thanks for the review David, I've fixed some issues with the Windows build. I'll wait till next week to push this after ensuring CI is green + any comments from @tejohnson.

tejohnson accepted this revision.Nov 25 2021, 7:45 AM

lgtm with a couple of minor comments below (please ignore until after the holiday weekend, forgot to finalize these comments yesterday).

llvm/include/llvm/ProfileData/MemProfData.inc
48

Nit: we're using a combo of coding styles in this file. I.e. underscore separated names (a la sanitizer runtime) in this struct and lower camel case in the SegmentEntry struct (buildId). Looks like InstrProfData.inc in this directory uses the LLVM coding style of upper camel case - perhaps that should be done here too for consistency?

llvm/test/tools/llvm-profdata/memprof-multi.test
36

Is this just dumb luck? Doesn't really matter since you have saved the profile, but might if we ever need to regenerate the profile as described above.

snehasish updated this revision to Diff 390517.Nov 29 2021, 4:08 PM
  • Use consistent style for MemProfData.inc
  • Update an llvm-profdata error message to mention --memory.
snehasish marked an inline comment as done.Nov 29 2021, 4:14 PM

PTAL, thanks!

llvm/test/tools/llvm-profdata/memprof-multi.test
36

It is deterministic in behaviour if thats what you were implying. I'll take a closer look once I add symbolization support to llvm-profdata.

davidxl accepted this revision.Nov 29 2021, 4:38 PM

lgtm.

llvm/include/llvm/ProfileData/MemProfData.inc
25

It would be ideal to have the macro defined in a common header, but it is probably difficult because the .inc file is for both llvm and runtime.

snehasish added inline comments.Nov 30 2021, 10:46 AM
llvm/include/llvm/ProfileData/MemProfData.inc
25

Yes, there are no headers shared between LLVM and compiler-rt so it would have to be duplicated. Since memprof is the only place where this is used I will leave it in the shared .inc files as is.