[Timers] Ideas for truncating the output of -ftime-report (and -ftime-report-json) (original) (raw)

In clang, the output of -ftime-report and -ftime-report-json is somewhat large; for a hello world program built with -O3, -ftime-report outputs ~30K and -ftime-report-json outputs ~62K:

$ bin/clang++ -o /dev/null -ftime-report-json ~/hello.cpp -O3 2>&1 | wc -m
62302
$ bin/clang++ -o /dev/null -ftime-report-json ~/hello.cpp -O3 2>&1 | wc -m
62302

This is quite large, and I’ve been thinking of ways to reduce the output. One PR that I have been working on ([Timers] Add a flag to set a minimum timer value for printing by alanzhao1 · Pull Request #139306 · llvm/llvm-project · GitHub) adds a flag that sets a minimum value a timer must have before it gets printed. However, @hansw2000 pointed out in a comment that an alternative would be to set a flag that only prints the top X timers. What do other folks in the LLVM community think?

cc: @rnk @aeubanks @MaskRay

+1 for filtering by top N times. Because in many cases I wouldn’t know the most suitable minimum time, especially in a multi-user environment where the CPU workload might fluctuate a lot, and the compilation time might vary by a large margin even when you’re running the same command.

Can you explain the issues caused by the size of the files?
For example, would using jq or similar tool after the fact to filter out irrelevant data points be an option for you?