]> granicus.if.org Git - clang/commitdiff
[Support][Time profiler] Make FE codegen blocks to be inside frontend blocks
authorAnton Afanasyev <anton.a.afanasyev@gmail.com>
Mon, 19 Aug 2019 22:58:26 +0000 (22:58 +0000)
committerAnton Afanasyev <anton.a.afanasyev@gmail.com>
Mon, 19 Aug 2019 22:58:26 +0000 (22:58 +0000)
Summary:
Add `Frontend` time trace entry to `HandleTranslationUnit()` function.
Add test to check all codegen blocks are inside frontend blocks.
Also, change `--time-trace-granularity` option a bit to make sure very small
time blocks are outputed to json-file when using `--time-trace-granularity=0`.

This fixes http://llvm.org/pr41969

Reviewers: russell.gallop, lebedev.ri, thakis

Reviewed By: russell.gallop

Subscribers: vsapsai, aras-p, lebedev.ri, hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D63325

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@369308 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenAction.cpp
test/Driver/check-time-trace-sections.cpp [new file with mode: 0644]
test/Driver/check-time-trace-sections.py [new file with mode: 0644]

index ab568a765a4a48711f974f1c0d210f5c7c893ec5..2356f84c05d183713750a2199c96df4838500eec 100644 (file)
@@ -38,6 +38,7 @@
 #include "llvm/Pass.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/SourceMgr.h"
+#include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/ToolOutputFile.h"
 #include "llvm/Support/YAMLTraits.h"
@@ -229,6 +230,7 @@ namespace clang {
 
     void HandleTranslationUnit(ASTContext &C) override {
       {
+        llvm::TimeTraceScope TimeScope("Frontend", StringRef(""));
         PrettyStackTraceString CrashInfo("Per-file LLVM IR generation");
         if (FrontendTimesIsEnabled) {
           LLVMIRGenerationRefCount += 1;
diff --git a/test/Driver/check-time-trace-sections.cpp b/test/Driver/check-time-trace-sections.cpp
new file mode 100644 (file)
index 0000000..4d1c0fd
--- /dev/null
@@ -0,0 +1,7 @@
+// REQUIRES: shell
+// RUN: %clangxx -S -ftime-trace -ftime-trace-granularity=0 -o %T/check-time-trace-sections %s
+// RUN: cat %T/check-time-trace-sections.json | %python %S/check-time-trace-sections.py
+
+template <typename T>
+void foo(T) {}
+void bar() { foo(0); }
diff --git a/test/Driver/check-time-trace-sections.py b/test/Driver/check-time-trace-sections.py
new file mode 100644 (file)
index 0000000..e807dae
--- /dev/null
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+
+import json, sys
+
+def is_inside(range1, range2):
+    a = range1["ts"]; b = a + range1["dur"]
+    c = range2["ts"]; d = c + range2["dur"]
+    return (a >= c and a <= d) and (b >= c and b <= d)
+
+def is_before(range1, range2):
+    b = range1["ts"] + range1["dur"]; c = range2["ts"]
+    return b <= c
+
+events = json.loads(sys.stdin.read())["traceEvents"]
+codegens = filter(lambda x: x["name"] == "CodeGen Function", events)
+frontends = filter(lambda x: x["name"] == "Frontend", events)
+backends = filter(lambda x: x["name"] == "Backend", events)
+
+if not all([any([is_inside(codegen, frontend) for frontend in frontends])
+                        for codegen in codegens]):
+    sys.exit("Not all CodeGen sections are inside any Frontend section!")
+
+if not all([all([is_before(frontend, backend) for frontend in frontends])
+                        for backend in backends]):
+    sys.exit("Not all Frontend section are before all Backend sections!")