This is an archive of the discontinued LLVM Phabricator instance.

[Driver] Print process statistics report on CC_PRINT_PROC_STAT env variable.
ClosedPublic

Authored by vvereschaka on Feb 19 2021, 2:54 PM.

Details

Summary

Added supporting CC_PRINT_PROC_STAT and CC_PRINT_PROC_STAT_FILE environment variables to trigger clang driver reporting the process statistics into specified file (alternate for -fproc-stat-report option).

Diff Detail

Event Timeline

vvereschaka requested review of this revision.Feb 19 2021, 2:54 PM
vvereschaka created this revision.

@sepavloff would you add more persons in additional to the reviewers?

Updated diff in according of the Lint/clang-format recommendations.

sepavloff added inline comments.
clang/include/clang/Driver/Driver.h
210

Strictly speaking it is driver that dumps performance report, not frontend.

Fixed comment.

vvereschaka marked an inline comment as done.Feb 22 2021, 2:55 PM
vvereschaka added inline comments.
clang/include/clang/Driver/Driver.h
210

Thanks, I have updated the comment accordingly.

vvereschaka marked an inline comment as done.Feb 22 2021, 2:56 PM
aganea added inline comments.Feb 22 2021, 2:59 PM
clang/lib/Driver/Driver.cpp
1107

Please remove, getLastArg already claims all arguments for this option.

4031

I think the code below is safe-explanatory, I don't think you need this comment, it doesn't add much value.

4050

The previous behavior was printing both the output and the CSV file when specifying -fproc-stat-report -fproc-stat-report=file.csv, now it would only emit the CSV, is that intended? @sepavloff what do you think?

clang/test/Driver/cc-print-proc-stat.c
1

Could you please expand a bit the test to entirely cover all the codepaths above?

Thank you @aganea

Updated diff:

  • removed ClaimAllArgs for OPT_fproc_stat_report_EQ (used in getLastArg);
  • used const char* instead of std::string for CCPrintStatReportFilename;
  • removed unnecessary comment
vvereschaka added inline comments.Feb 23 2021, 4:26 PM
clang/lib/Driver/Driver.cpp
4050

now it would only emit the CSV, is that intended?

yes, I thought in that way. I dоn't think that usage of both options at the same time was specially designed. I don't see a reasonable usage case for that for now actually, but I could be wrong. @sepavloff ?

sepavloff added inline comments.Feb 24 2021, 6:30 AM
clang/lib/Driver/Driver.cpp
4050

now it would only emit the CSV, is that intended?

yes, I thought in that way. I dоn't think that usage of both options at the same time was specially designed. I don't see a reasonable usage case for that for now actually, but I could be wrong. @sepavloff ?

The previous behavior (printing both the output and the CSV file) was not intentional, it was the implementation peculiarity. I don't see real use case for both outputs.

Thanks for the update @vvereschaka ! Just a few minor things and it should be good to go.
Also please use git diff -U99999 next time to add context to the patch.

clang/docs/UsersManual.rst
783

I think this should read "In this case statistics are printed.." Would you mind changing this as well?

799

Do you think it would be possible to rephrase a bit to avoid the repetition of CC_PRINT_PROC_STAT_FILE? Perhaps also explicitate that CC_PRINT_PROC_STAT is for "enabling the feature and logging to stdout"; while CC_PRINT_PROC_STAT_FILE only "redirects the log to a file".

clang/lib/Driver/Driver.cpp
1108

Remove this too, hasArg claims all arguments.

4039

Suggestion: I find if (!CCPrintStatReportFilename) more intutive, more compact and easier to read, but that's my personal preference. There are arguments both ways probably, up to you.

Updated diff:

  • rewording the doc part
  • removed ClaimAllArgs for OPT_fproc_stat_report
  • updated if statement for CCPrintStatReportFilename
vvereschaka added inline comments.Feb 25 2021, 1:38 PM
clang/docs/UsersManual.rst
799

Yes, sure. Here is updated and extended version of the doc part.

clang/lib/Driver/Driver.cpp
4039

I have updated it in according of you suggestion. It is ok for me too.

aganea accepted this revision.Feb 26 2021, 5:35 AM

LGTM, just a few minor things:

clang/docs/UsersManual.rst
798

"enables the feature, the report goes to the stdout in the human readable format."

800

"the process statistics to the given file in the CSV format"

804

Would you be able to merge this paragraph with the following one please? It could be something like:

"These environment variables are handy when you need to request the statistics report without changing your build scripts or alter the existing set of compiler options. Note that -fproc-stat-report take precedence over CC_PRINT_PROC_STAT and CC_PRINT_PROC_STAT_FILE."

This revision is now accepted and ready to land.Feb 26 2021, 5:35 AM

Updated diff:

  • updated doc parts

@aganea thanks a lot for your suggestions for doc improvements. I have updated it accordingly.