Bug 92396 - -ftime-trace support
Summary: -ftime-trace support
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: other (show other bugs)
Version: 10.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL: https://gcc.gnu.org/pipermail/gcc-pat...
Keywords: patch
Depends on:
Blocks:
 
Reported: 2019-11-06 13:28 UTC by Trass3r
Modified: 2026-05-10 18:59 UTC (History)
19 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-11-07 00:00:00


Attachments
Time trace prototype (2.05 KB, application/mbox)
2020-07-28 12:11 UTC, Martin Liška
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Trass3r 2019-11-06 13:28:47 UTC
Would be nice if gcc also supported clang's -ftime-trace option for optimizing compile times:
https://www.snsystems.com/technology/tech-blog/clang-time-trace-feature
Comment 1 Drea Pinski 2019-11-06 19:27:44 UTC
-ftime-report gets you some of that information.  But this information is only really useful for the compiler developer.
Comment 2 Eric Gallager 2019-11-07 05:46:55 UTC
(In reply to Andrew Pinski from comment #1)
> -ftime-report gets you some of that information.  But this information is
> only really useful for the compiler developer.

Since GCC already can output json for other stuff (diagnostics, I think?), it should be possible to combine the -ftime-report option with the json subsystems to get the -ftime-trace option described...
Comment 3 Martin Liška 2019-11-07 12:45:55 UTC
Yes, I think we can do something similar to what clang does.
I can work on that next stage1.
Comment 4 Trass3r 2019-11-07 13:26:07 UTC
Nice! Btw the traces can be viewed independently of the browser using https://www.speedscope.app.
Comment 5 Martin Liška 2020-07-28 12:11:16 UTC
Created attachment 48943 [details]
Time trace prototype

So I've just created a prototype patch, but I don't see it much useful:
https://gist.github.com/marxin/dc4354696bc5bd76cdc1d2ecaa4ab060

The main problem is that in case of tree/RTL passes, we run each pass for each function. Which makes the report full of thin lines.
Thoughts?
Comment 6 Alexander Monakov 2020-07-28 13:27:47 UTC
Raw data from timevars is not suitable to make a useful-for-users -ftime-trace report. The point of -ftime-trace is to present the person using the compiler with a breakdown on the level of their source files, functions, template instantiations, i.e. something they understand and can change. No need to show users any sort of breakdown by individual GIMPLE/RTL passes: as far as they are concerned it's one complex "code generation" phase they cannot substantially change.

The original blog post by Aras Pranckevičius explains this well, contrasting against GCC's and LLVM's -ftime-report: https://aras-p.info/blog/2019/01/12/Investigating-compile-times-and-Clang-ftime-report/ (and part 2: https://aras-p.info/blog/2019/01/16/time-trace-timeline-flame-chart-profiler-for-Clang/ ).

GCC simply doesn't measure time on the relevant "axes": we don't split preprocessing time by included files, nor do we split template instantiation time in the C++ frontend by template.
Comment 7 Martin Liška 2020-07-29 07:21:53 UTC
Thank you Alexander for the pointer. I've just read the article and I must confirm that compiler uses demand for something that we can't currently support easily. I'm leaving that unassigned.
Comment 8 jeremycong 2020-08-05 16:43:59 UTC
Anecdotally, this would be an amazing feature to have. Since enabling time tracing in clang, I've been able to improve build times significantly for a project that uses templates, but with the GCC time report information, I can't seem to get GCC build times improved to the same degree. I definitely don't think this feature is strictly useful for only the compiler developer.
Comment 9 Jakub Jelinek 2021-04-27 11:38:23 UTC
GCC 11.1 has been released, retargeting bugs to GCC 11.2.
Comment 10 Jules Pénuchot 2021-10-15 14:47:45 UTC
I've been writing a compile-time benchmarking and analysis tool (https://github.com/JPenuchot/ctbench) to study the impact of C++ metaprogramming techniques on compile-times. Clang's time-trace features allows me to break the measurements down to every major compiler pass and get a better understanding of what's happening under the hood.

I'd be really happy if GCC provided similar profiling tools and draw conclusions that aren't valid just for Clang.
Comment 11 Barry Revzin 2022-03-29 16:47:32 UTC
+1 to supporting this. gcc's existing -ftime-report is useful for being able to make statements like "gcc 11 is substantially more efficient at constraint satisfaction than gcc 10 was" (nice job, folks!) but it isn't very useful for being able to answer questions like "this translation unit takes 90 seconds to compile, how can I improve that?" Clang's -ftime-trace, on the other hand, gives me granular data per function -- which can help me determine what the hot spots are, etc.
Comment 12 AK 2022-08-12 23:56:56 UTC
I was building a giant file that takes around 100 minutes. The -ftime-report gave nothing useful to find out hotspots. It is also not clear what we are reporting here as there is no documentation for it in man gcc. The %ages don't add up to 100 and that makes it confusing.

I'm wondering if making this task a GSoC project will get more attention?
Comment 13 Eric Gallager 2026-05-10 18:59:44 UTC
Heli Shah has submitted a patch for this here:
https://gcc.gnu.org/pipermail/gcc-patches/2026-May/715621.html