Add profile summary information to GCOV#251
Conversation
gcov.cc
Outdated
| if (absl::GetFlag(FLAGS_gcov_version) == 2 || | ||
| absl::GetFlag(FLAGS_gcov_version) == 3) { |
There was a problem hiding this comment.
| if (absl::GetFlag(FLAGS_gcov_version) == 2 || | |
| absl::GetFlag(FLAGS_gcov_version) == 3) { | |
| if (absl::GetFlag(FLAGS_gcov_version) >= 2) { |
gcov.cc
Outdated
| if (absl::GetFlag(FLAGS_gcov_version) == 2 || | ||
| absl::GetFlag(FLAGS_gcov_version) == 3) { |
There was a problem hiding this comment.
| if (absl::GetFlag(FLAGS_gcov_version) == 2 || | |
| absl::GetFlag(FLAGS_gcov_version) == 3) { | |
| if (absl::GetFlag(FLAGS_gcov_version) >= 2) { |
|
@dc03-work I saw that you made some changes to your GCC patch. Does that require corresponding changes in this PR? |
No, but I will be rewriting the histogram calculation as a set of standalone routines. |
72fa47a to
9627fd2
Compare
|
@erozenfeld Hi, I have implemented the calculation as a standalone visitor and verified that it produces the same values as LLVM's implementation. Does this look OK now? |
|
@erozenfeld Similar to #244, the GCC patch corresponding to this has landed as r16-6349-gdbe8e0efb7b029. Can we please land this if there are no immediate issues as well? This is also required for the AutoFDO flow to work. |
This patch aims to implement summary support in auto-profile, similar to LLVM. The summary information stores various information about the profile being read such as the number of functions, the maximum sample count, the total number of samples and so on. It also adds a section called the "detailed summary" which contains a histogram-based calculation of the minimum execution count for a sample needed to belong to a specific percentile of samples. This is used to decide the hot count threshold (which can be controlled with a command line parameter). The default is any sample belonging to the 99th percentile being marked as hot. This patch requires the changes from google/autofdo#251 to work correctly. Signed-off-by: Dhruv Chawla <dhruvc@nvidia.com> gcc/ChangeLog: * auto-profile.cc (struct summary_info): New struct. (summary_info::read): New function. (summary_info::get_threshold_count): Likewise. (function_instance::read_function_instance): Read afdo_profile_info->sum_max directly from summary info. (autofdo_source_profile::read): Set afdo_hot_bb_threshold from param_hot_bb_count_ws_permille. (read_profile): Call summary_info->read. (end_auto_profile): Free afdo_summary_info. * gcov-io.h (GCOV_TAG_AFDO_SUMMARY): New define.
erozenfeld
left a comment
There was a problem hiding this comment.
Looks good, just a couple of minor suggestions.
profile_reader.cc
Outdated
| for (unsigned i = 0; i < num; i++) { | ||
| gcov_read_unsigned(); // Cutoff | ||
| gcov_read_counter(); // Min count | ||
| gcov_read_counter(); // Num cutoffs |
There was a problem hiding this comment.
Should the comment say
// Num counts
?
profile_writer.cc
Outdated
|
|
||
| ProfileSummaryInformation info = ProfileSummaryComputer::Compute( | ||
| *symbol_map_, {std::begin(ProfileSummaryInformation::default_cutoffs), | ||
| std::end(ProfileSummaryInformation::default_cutoffs)}); |
There was a problem hiding this comment.
The call to ProfileSummaryComputer::Compute can be moved to under
if (absl::GetFlag(FLAGS_gcov_version) >= 3)
check below.
snehasish
left a comment
There was a problem hiding this comment.
Is it possible to add a test for this?
@snehasish I've added the test case. I tried to make it work with the existing binaries / perf data in |
summary_calculation_test.cc
Outdated
| }; | ||
| symbol_map.AddSourceCount("boo", boo_stack3, 150, 2); | ||
|
|
||
| ProfileSummaryInformation info = ProfileSummaryComputer::Compute( |
There was a problem hiding this comment.
Can we test the summary reading and writing by serializing it to a simple profile and then reading it back in?
There was a problem hiding this comment.
Sure, I will add that.
snehasish
left a comment
There was a problem hiding this comment.
lgtm, just a couple of optional suggestions. Let me know when you are ready to merge.
profile_writer.h
Outdated
| StringIndexMap *map_; | ||
| }; | ||
|
|
||
| class ProfileSummaryInformation { |
There was a problem hiding this comment.
If everything is public maybe this is better off as a struct?
summary_calculation_test.cc
Outdated
|
|
||
| // Make sure the summary that was written out is the same as that which is | ||
| // read back in. | ||
| EXPECT_EQ(info_1.total_count_, info_2->total_count_); |
There was a problem hiding this comment.
If you define operator== for ProfileSummaryInformation and DetailedSummary then I think you can simplify all of these expectations to just EXPECT_THAT(info_1, Eq(info_2)).
This patch adds supports for writing out profile summaries and histogram-based percentile information for samples to the GCOV profile, in a similar manner to how this information is written out for LLVM profiles. It also bumps the GCOV version to 3.
35b9b9b to
b9e980d
Compare
|
Addressed comments and rebased on master. Feel free to merge :) Thanks for the reviews! |
|
|
||
| // Write out the GCOV_TAG_AFDO_SUMMARY section. | ||
| if (absl::GetFlag(FLAGS_gcov_version) >= 3) { | ||
| assert(summary != nullptr); |
There was a problem hiding this comment.
Looks like I accidentally left an assert in here from the first commit that doesn't work anymore. I think it didn't fail to compile because the assert get preprocessed out - the summary variable doesn't exist anywhere anymore.
I forgot to remove this assert as it was not compiled in Release mode.
I forgot to remove this assert as it was not compiled in Release mode.
This patch adds supports for writing out profile summaries and histogram-based percentile information for samples to the GCOV profile, in a similar manner to how this information is written out for LLVM profiles. It also bumps the GCOV version to 3. This is part of the work to add support for the same to GCC.