This is an archive of the discontinued LLVM Phabricator instance.

[llvm-profdata] Add --output-format option
ClosedPublic

Authored by ellis on Oct 3 2022, 9:44 PM.

Details

Summary

Add --output-format option for the llvm-profdata show command to select the type of output. The existing --text flag is used to emit text encoded profiles. To avoid confusion, --output-format=text-encoding indicates that the output will be profiles encoded in the text format, and --output-format=text indicates the default text output that doesn't necessarily represent a profile.
--output-format=json is an alias for --json and --output-format=yaml will be used in D134770.

Diff Detail

Event Timeline

ellis created this revision.Oct 3 2022, 9:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 3 2022, 9:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 3 2022, 9:58 PM
MaskRay added inline comments.Oct 4 2022, 10:13 PM
llvm/tools/llvm-profdata/llvm-profdata.cpp
60

Should this be OutputFormat instead? Then you can use a different name for the variable...

  1. the CommandLine documentation file needs to be updated.
  2. what is the use case of splitting text and text-encoding?
  1. Please also add test cases.
llvm/tools/llvm-profdata/llvm-profdata.cpp
2742

fix typo "test-encoding'

ellis added a comment.Oct 5 2022, 9:14 AM
  1. what is the use case of splitting text and text-encoding?

The existing --text option for the show command is used to emit the profile in the text-encoded format. I thought it would be confusing use --output-format=text to mean this, since I would expect this to mean "print normal text output". So I decided on the following flags:

  • --output-format=text
    • The show command will print text that is useful to the user
  • --output-format=text-encoding
    • Will emit the profile in the text-encoded format without additional output. This is identical to the --text flag.

I know this is a bit weird. So I'm wondering if it's better to leave the --text flag alone and only have --output-format=<json|yaml>. Let me know what you think!

llvm/tools/llvm-profdata/llvm-profdata.cpp
60

I thought the name OutputFormat would be confusing because one might think it had the meaning of ProfileFormat above. ProfileFormat specifies which profile format we should output, while ShowOutputFormat only specifies the output for the show command. We don't currently have YAML or JSON profile formats.

ellis updated this revision to Diff 465797.Oct 6 2022, 11:15 AM

Don't add text and text-encoding to output-format type.

ellis added a comment.Oct 6 2022, 11:18 AM

I decided to just stick with --output-format=<json|yaml> and removed changes to the --text option to make things cleaner.

phosek accepted this revision.Oct 6 2022, 12:42 PM

LGTM

This revision is now accepted and ready to land.Oct 6 2022, 12:42 PM
ellis updated this revision to Diff 466102.Oct 7 2022, 9:46 AM

Sorry, forgot to run clang-format

This revision was landed with ongoing or failed builds.Oct 7 2022, 9:47 AM
This revision was automatically updated to reflect the committed changes.
wenlei added inline comments.Oct 7 2022, 10:03 AM
llvm/tools/llvm-profdata/llvm-profdata.cpp
60

OutputFormat is indeed confusing. Before you make show output format selectable, output format has one to one mapping with profile format, so output format and profile format were interchangeable.. And we have this line:

cl::opt<ProfileFormat> OutputFormat

We tried to hold an invariant -- all file outputs are valid profile, non-profile output are all for stdout (users can redirect to file). Can we try to hold that invariant still? Can we disambiguate them by variable names as well as switch name? i.e. --show-format for show command, and --output-format for merge command. If you separate them in difference space, --show-format=text and --output-format=text could also co-exist if needed.

ellis added inline comments.Oct 7 2022, 10:34 AM
llvm/tools/llvm-profdata/llvm-profdata.cpp
60

I like your idea of --show-format. I've put up D135467 to rename the flag.