Skip to content

Conversation

@dc03-work
Copy link
Contributor

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.

gcov.cc Outdated
Comment on lines 153 to 154
if (absl::GetFlag(FLAGS_gcov_version) == 2 ||
absl::GetFlag(FLAGS_gcov_version) == 3) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (absl::GetFlag(FLAGS_gcov_version) == 2 ||
absl::GetFlag(FLAGS_gcov_version) == 3) {
if (absl::GetFlag(FLAGS_gcov_version) >= 2) {

gcov.cc Outdated
Comment on lines 234 to 235
if (absl::GetFlag(FLAGS_gcov_version) == 2 ||
absl::GetFlag(FLAGS_gcov_version) == 3) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (absl::GetFlag(FLAGS_gcov_version) == 2 ||
absl::GetFlag(FLAGS_gcov_version) == 3) {
if (absl::GetFlag(FLAGS_gcov_version) >= 2) {

#include "llvm/ProfileData/SampleProf.h"
#include "llvm/ProfileData/ProfileCommon.h"

// sizeof(gcov_unsigned_t)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid dragging any llvm files into create_gcov build?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am using the LLVM files to calculate the histogram information in the same manner as create_llvm_prof - removing them would require duplicating a fair bit of logic from the LLVM side.

@erozenfeld
Copy link
Contributor

@dc03-work I saw that you made some changes to your GCC patch. Does that require corresponding changes in this PR?

@dc03-work
Copy link
Contributor Author

@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.

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.
@dc03-work
Copy link
Contributor Author

@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?

@dc03-work
Copy link
Contributor Author

@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.

hubot pushed a commit to gcc-mirror/gcc that referenced this pull request Dec 23, 2025
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 <[email protected]>

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants