This is an archive of the discontinued LLVM Phabricator instance.

[Driver] Allow to collect `-save-stats` data to a file specified in the environment variable.
ClosedPublic

Authored by vsapsai on Feb 28 2023, 9:59 AM.

Details

Summary

Using two environment variables CC_PRINT_INTERNAL_STAT and
CC_PRINT_INTERNAL_STAT_FILE to work like CC_PRINT_PROC_STAT.

The purpose of the change is to allow collecting the internal stats
without modifying the build scripts. Write all stats to a single file
to simplify aggregating the data.

Diff Detail

Event Timeline

vsapsai created this revision.Feb 28 2023, 9:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 28 2023, 9:59 AM
Herald added a subscriber: ributzka. · View Herald Transcript
vsapsai requested review of this revision.Feb 28 2023, 9:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 28 2023, 9:59 AM
ahatanak added inline comments.Feb 28 2023, 2:44 PM
clang/lib/Frontend/CompilerInstance.cpp
1093

OF_Append is necessary when the results are written to a single file specified via CC_PRINT_INTERNAL_STAT_FILE, but do we want this change for users passing -save-stats to the command line?

vsapsai planned changes to this revision.Mar 1 2023, 1:31 PM
vsapsai added inline comments.
clang/lib/Frontend/CompilerInstance.cpp
1093

For implicit modules appending seems to be correct and desirable as we store information about all CompilerInstance and not only for the last one. But as llvm-test-suite https://github.com/llvm/llvm-test-suite/blob/main/litsupport/modules/stats.py doesn't expect appended stats, I'll look into doing it only for environment-driven stats collection.

vsapsai updated this revision to Diff 501709.Mar 1 2023, 5:43 PM

Append to stats file when using CC_PRINT_INTERNAL_STAT and for LTO when reusing the same stats file.

ahatanak added inline comments.Mar 7 2023, 1:51 PM
clang/test/Driver/save-stats.c
26

Doesn't this require stats-file-append to be supported by the plugin just like stats-file is supported?

https://github.com/llvm/llvm-project/blob/main/llvm/tools/gold/gold-plugin.cpp#L309

ahatanak added inline comments.Mar 7 2023, 1:58 PM
clang/test/Driver/save-stats.c
26

Do we want to pass stats-file-append in tools::addLTOOptions?

vsapsai added inline comments.Mar 8 2023, 1:08 PM
clang/test/Driver/save-stats.c
26

You are right with the gold-plugin. I think I'll drop any changes for LTO now because that's not my purpose and I don't want to change emission of stats for something I don't work on. Also I believe it creates discrepancies for different linker plugins and I really don't want to introduce this inconsistency.

vsapsai updated this revision to Diff 503488.Mar 8 2023, 1:10 PM

Don't touch LTO pipeline to avoid breaking existing workflows.

Adding folks involved with LTO. The problem is that stats emitted during the first round of compilation are likely to be overwritten by stats emitted during [Thin]LTO itself. Not touching it now to preserve the existing behavior. But wanted to inform you about this shortcoming in case it is important for you to fix.

Original change adding -save-stats for LTO is D45531.

This revision is now accepted and ready to land.Mar 13 2023, 9:05 AM

Thanks for the review!

This revision was landed with ongoing or failed builds.Mar 16 2023, 11:58 AM
This revision was automatically updated to reflect the committed changes.