This is an archive of the discontinued LLVM Phabricator instance.

Add profile summary support for sample profile
ClosedPublic

Authored by eraman on Feb 11 2016, 4:59 PM.

Details

Summary

This adds profile summary to the sample profile file. This is similar to the changes to the instrumentation based profile. For sample profile, I treat a program line as the unit of summary computation.

Diff Detail

Repository
rL LLVM

Event Timeline

eraman updated this revision to Diff 47754.Feb 11 2016, 4:59 PM
eraman retitled this revision from to Add profile summary support for sample profile.
eraman updated this object.
eraman added a subscriber: llvm-commits.
davidxl edited edge metadata.Feb 15 2016, 4:20 PM

Can you upload the patch with more context lines?

eraman updated this revision to Diff 48087.Feb 16 2016, 11:11 AM
eraman edited edge metadata.

Added summary support to GCC format and the diff now has more context.

dnovillo edited edge metadata.Feb 16 2016, 11:20 AM

I just started looking at this. Some early feedback so we can discuss whether my idea makes sense. Mostly, I'm thinking we want to support summary data in text profiles for testing and debugging. Does that make sense to you?

include/llvm/ProfileData/SampleProfReader.h
139 ↗(On Diff #48087)

Well, this is always exactly one for sampling profiles. There's always one count per line.

lib/ProfileData/SampleProfReader.cpp
792 ↗(On Diff #48087)

s/aftter/after/

I would prefer to see a text version of the summary profile. This is invaluable for generating test cases and general debugging.

lib/ProfileData/SampleProfWriter.cpp
126 ↗(On Diff #48087)

One blank line above, please.

eraman added inline comments.Feb 16 2016, 12:28 PM
include/llvm/ProfileData/SampleProfReader.h
139 ↗(On Diff #48087)

I use count to mean samples. The fields of ProfileSummary are named *Counts and in the context of sample profiles, I use those fields to represent samples. Thus, MaxBlockCount contains the max among samples on any given line.

lib/ProfileData/SampleProfReader.cpp
792 ↗(On Diff #48087)

The reason why I decided to compute the summary after reading is that it made generating test cases easy. If it is part of the header, either we need to make it optional (and compute it while reading) or write the summary to the profile file.

One thing I want to point out is that I'll add support to llvm-profdata to generate summaries for sample profile after this change. At present, it does generate summaries for instrumented profile, but that also needs to be cleaned up since it uses a different set of cutoffs.

dnovillo requested changes to this revision.Feb 17 2016, 6:14 AM
dnovillo edited edge metadata.
dnovillo added inline comments.
include/llvm/ProfileData/SampleProfReader.h
139 ↗(On Diff #48087)

Ah, yes, that makes sense. Thanks.

lib/ProfileData/ProfileSummary.cpp
20 ↗(On Diff #48087)

Could you add a comment describing these cutoffs and a general idea of what the numbers are and mean?

lib/ProfileData/SampleProfReader.cpp
403 ↗(On Diff #48087)

I'm wondering if we don't want to do something similar to what we do for instrumented profiles here. We could make up a fake summary for older versions of the profile.

Right now, you should be seeing test failures for older binary profiles. Are you not?

792 ↗(On Diff #48087)

OK, thanks. That sounds fine.

Still need to s/aftter/after/ in the comment.

This revision now requires changes to proceed.Feb 17 2016, 6:14 AM
eraman marked 2 inline comments as done.Feb 17 2016, 4:11 PM

I had refactored the ProfileSummary class and made InstrProfSummary as a derived patch. I have merged in that change and added a SampleProfSummary as a new class and avoided the need to use InstrProf specific terms here.

lib/ProfileData/ProfileSummary.cpp
20 ↗(On Diff #48087)

I've added a comment here. Let me know if you want anything more specific.

lib/ProfileData/SampleProfReader.cpp
403 ↗(On Diff #48087)

In the case of instrumented profile, summary is available only for indexed format. If we read an older version of the profile, the summary is computed after reading the profile.

There was only one test case that had a binary format directly checked in and I have fixed that test case.

eraman updated this revision to Diff 48258.Feb 17 2016, 4:12 PM
eraman edited edge metadata.

Address Diego's comments and rebase.

dnovillo accepted this revision.Feb 18 2016, 9:52 AM
dnovillo edited edge metadata.

Thanks for the new feature! LGTM with one minor nit.

include/llvm/ProfileData/SampleProfReader.h
299 ↗(On Diff #48258)

As a matter of consistency, let's keep the naming to SampleProfile instead of SampleProf. I know it's not really "consistent" because instruction profiles use InstrProf, but at least we make it consistent within the sample profiler :)

This revision is now accepted and ready to land.Feb 18 2016, 9:52 AM
This revision was automatically updated to reflect the committed changes.