[PATCH] D63325: [Support][Time profiler] Make FE codegen blocks to be inside frontend blocks

Anton Afanasyev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 14 03:44:40 PDT 2019


anton-afanasyev updated this revision to Diff 204738.
anton-afanasyev added a comment.

Small fix


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63325/new/

https://reviews.llvm.org/D63325

Files:
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/Driver/check-time-trace-blocks.cpp
  clang/test/Driver/check-time-trace-blocks.py
  llvm/lib/Support/TimeProfiler.cpp


Index: llvm/lib/Support/TimeProfiler.cpp
===================================================================
--- llvm/lib/Support/TimeProfiler.cpp
+++ llvm/lib/Support/TimeProfiler.cpp
@@ -65,7 +65,7 @@
     E.Duration = steady_clock::now() - E.Start;
 
     // Only include sections longer than TimeTraceGranularity msec.
-    if (duration_cast<microseconds>(E.Duration).count() > TimeTraceGranularity)
+    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
Index: clang/test/Driver/check-time-trace-blocks.py
===================================================================
--- /dev/null
+++ clang/test/Driver/check-time-trace-blocks.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+
+import json, sys
+
+events = json.loads(sys.stdin.read())["traceEvents"]
+codegens = filter(lambda x: x["name"] == "CodeGen Function", events)
+frontends = filter(lambda x: x["name"] == "Frontend", events)
+
+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)
+
+if not all([any([is_inside(codegen, frontend) for frontend in frontends])
+            for codegen in codegens]):
+    sys.exit("Not all CodeGen blocks are inside any of Frontend blocks!")
Index: clang/test/Driver/check-time-trace-blocks.cpp
===================================================================
--- /dev/null
+++ clang/test/Driver/check-time-trace-blocks.cpp
@@ -0,0 +1,7 @@
+// REQUIRES: shell
+// RUN: %clangxx -S -ftime-trace -mllvm --time-trace-granularity=0 -o %T/check-time-trace-blocks %s
+// RUN: cat %T/check-time-trace-blocks.json | %python %S/check-time-trace-blocks.py
+
+template <typename T>
+void foo(T) {}
+void bar() { foo(0); }
Index: clang/lib/CodeGen/CodeGenAction.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -37,6 +37,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"
@@ -228,6 +229,7 @@
 
     void HandleTranslationUnit(ASTContext &C) override {
       {
+        llvm::TimeTraceScope TimeScope("Frontend", StringRef(""));
         PrettyStackTraceString CrashInfo("Per-file LLVM IR generation");
         if (FrontendTimesIsEnabled) {
           LLVMIRGenerationRefCount += 1;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63325.204738.patch
Type: text/x-patch
Size: 2649 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190614/c2b20b97/attachment-0001.bin>


More information about the cfe-commits mailing list