anton-afanasyev updated this revision to Diff 205297. anton-afanasyev marked 2 inline comments as done. anton-afanasyev added a comment.
Updated 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/lib/Parse/ParseAST.cpp clang/test/Driver/check-time-trace-sections.cpp clang/test/Driver/check-time-trace-sections.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-sections.py =================================================================== --- /dev/null +++ clang/test/Driver/check-time-trace-sections.py @@ -0,0 +1,20 @@ +#!/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) + +events = json.loads(sys.stdin.read())["traceEvents"] +codegens = filter(lambda x: x["name"] == "CodeGen Function", events) +frontends = filter(lambda x: x["name"] == "Frontend", events) + +if not len(frontends) == 1: + sys.exit("There should be exactly one Frontend section!") + +frontend = frontends[0] + +if not all([is_inside(codegen, frontend) for codegen in codegens]): + sys.exit("Not all CodeGen sections are inside Frontend section!") Index: clang/test/Driver/check-time-trace-sections.cpp =================================================================== --- /dev/null +++ clang/test/Driver/check-time-trace-sections.cpp @@ -0,0 +1,7 @@ +// REQUIRES: shell +// RUN: %clangxx -S -ftime-trace -mllvm --time-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); } Index: clang/lib/Parse/ParseAST.cpp =================================================================== --- clang/lib/Parse/ParseAST.cpp +++ clang/lib/Parse/ParseAST.cpp @@ -150,8 +150,11 @@ // after the pragma, there won't be any tokens or a Lexer. bool HaveLexer = S.getPreprocessor().getCurrentLexer(); + // Start "Frontend" section finishing inside clang::HandleTranslationUnit() + if (llvm::timeTraceProfilerEnabled()) + llvm::timeTraceProfilerBegin("Frontend", StringRef("")); + if (HaveLexer) { - llvm::TimeTraceScope TimeScope("Frontend", StringRef("")); P.Initialize(); Parser::DeclGroupPtrTy ADecl; for (bool AtEOF = P.ParseFirstTopLevelDecl(ADecl); !AtEOF; 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" @@ -246,6 +247,10 @@ IRGenFinished = true; } + // Finish "Frontend" section starting inside clang::ParseAST() + if (llvm::timeTraceProfilerEnabled()) + llvm::timeTraceProfilerEnd(); + // Silently ignore if we weren't initialized for some reason. if (!getModule()) return;
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-sections.py =================================================================== --- /dev/null +++ clang/test/Driver/check-time-trace-sections.py @@ -0,0 +1,20 @@ +#!/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) + +events = json.loads(sys.stdin.read())["traceEvents"] +codegens = filter(lambda x: x["name"] == "CodeGen Function", events) +frontends = filter(lambda x: x["name"] == "Frontend", events) + +if not len(frontends) == 1: + sys.exit("There should be exactly one Frontend section!") + +frontend = frontends[0] + +if not all([is_inside(codegen, frontend) for codegen in codegens]): + sys.exit("Not all CodeGen sections are inside Frontend section!") Index: clang/test/Driver/check-time-trace-sections.cpp =================================================================== --- /dev/null +++ clang/test/Driver/check-time-trace-sections.cpp @@ -0,0 +1,7 @@ +// REQUIRES: shell +// RUN: %clangxx -S -ftime-trace -mllvm --time-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); } Index: clang/lib/Parse/ParseAST.cpp =================================================================== --- clang/lib/Parse/ParseAST.cpp +++ clang/lib/Parse/ParseAST.cpp @@ -150,8 +150,11 @@ // after the pragma, there won't be any tokens or a Lexer. bool HaveLexer = S.getPreprocessor().getCurrentLexer(); + // Start "Frontend" section finishing inside clang::HandleTranslationUnit() + if (llvm::timeTraceProfilerEnabled()) + llvm::timeTraceProfilerBegin("Frontend", StringRef("")); + if (HaveLexer) { - llvm::TimeTraceScope TimeScope("Frontend", StringRef("")); P.Initialize(); Parser::DeclGroupPtrTy ADecl; for (bool AtEOF = P.ParseFirstTopLevelDecl(ADecl); !AtEOF; 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" @@ -246,6 +247,10 @@ IRGenFinished = true; } + // Finish "Frontend" section starting inside clang::ParseAST() + if (llvm::timeTraceProfilerEnabled()) + llvm::timeTraceProfilerEnd(); + // Silently ignore if we weren't initialized for some reason. if (!getModule()) return;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits