LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 41969 - -ftime-trace Frontend timer misses Codegen Function for template functions
Summary: -ftime-trace Frontend timer misses Codegen Function for template functions
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: -New Bugs (show other bugs)
Version: trunk
Hardware: PC All
: P enhancement
Assignee: Anton Afanasyev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-05-21 09:31 PDT by Russell Gallop
Modified: 2019-09-05 02:17 PDT (History)
5 users (show)

See Also:
Fixed By Commit(s):


Attachments
Screenshot of chrome://tracing (8.07 KB, image/png)
2019-05-21 09:31 PDT, Russell Gallop
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Russell Gallop 2019-05-21 09:31:55 PDT
Created attachment 21982 [details]
Screenshot of chrome://tracing

Clang "CodeGen Function" timers from -ftime-trace for some functions falls outside of the "Frontend" timer and thus between Frontend and Backend (see attached screenshot). I think this should be counted under Frontend. In the original motivating example the time between "Frontend" and "Backend" was 11% of the overall execution time so fairly significant.

e.g. at r361164
# Apply patch to trace ALL durations however small (to allow small reproducible)
diff --git a/llvm/lib/Support/TimeProfiler.cpp b/llvm/lib/Support/TimeProfiler.cpp
index bc234081564..f63847a8a28 100644
--- a/llvm/lib/Support/TimeProfiler.cpp
+++ b/llvm/lib/Support/TimeProfiler.cpp
@@ -65,8 +65,8 @@ struct TimeTraceProfiler {
     E.Duration = steady_clock::now() - E.Start;

     // Only include sections longer than TimeTraceGranularity msec.
-    if (duration_cast<microseconds>(E.Duration).count() > TimeTraceGranularity)
-      Entries.emplace_back(E);
+    //if (duration_cast<microseconds>(E.Duration).count() > TimeTraceGranularity)
+    Entries.emplace_back(E);

     // Track total time taken by each "name", but only the topmost levels of
     // them; e.g. if there's a template instantiation that instantiates other

$ cat test.cpp
template <typename T> void foo(T) {}
void bar() { foo(0); }
$ clang -c -ftime-trace test.cpp
# test.json now has CodeGen Function for foo<int> between "Frontend" and "Backend"
{
    "traceEvents": [
      ...
        {
            "args": {
                "detail": ""
            },
            "dur": 1451,
            "name": "Frontend",
            "ph": "X",
            "pid": 1,
            "tid": 0,
            "ts": 3722
        },
        {
            "args": {
                "detail": "foo<int>"
            },
            "dur": 66,
            "name": "CodeGen Function",
            "ph": "X",
            "pid": 1,
            "tid": 0,
            "ts": 5177
        },
...
        {
            "args": {
                "detail": ""
            },
            "dur": 2866,
            "name": "Backend",
            "ph": "X",
            "pid": 1,
            "tid": 0,
            "ts": 5287
        },
...
}
Comment 1 Anton Afanasyev 2019-06-14 03:48:10 PDT
Here is a review for fix: https://reviews.llvm.org/D63325
I've added second Frontend time trace entry for HandleTranslateUnit() codegen function.
Comment 2 Russell Gallop 2019-09-05 02:17:47 PDT
Fixed in r369308.