[PATCH] D128048: Add a new clang option "-ftime-trace-path"

dongjunduo via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 17 06:07:40 PDT 2022


dongjunduo created this revision.
Herald added a project: All.
dongjunduo requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

The time profiler traces the stages during the clang compile 
process. Each compiling stage of a single source file 
corresponds to a separately .json file which holds its 
time tracing data. However, the .json files are stored in the 
same path/directory as its corresponding stage's '-o' option.
For example, if we compile the "demo.cc" to "demo.o" with option
"-o /tmp/demo.o", the time trace data file path is "/tmp/demo.json".

A typical c++ project can contain multiple source files in different 
path, but all the json files' paths can be a mess.

The option "-ftime-trace-path" allows you to specify where the json 
files should be stored. This allows the users to place the time trace 
data files of interest in the desired location for further data analysis.

Usage:

  clang/clang++ -ftime-trace -ftime-trace-path=/path-you-want/ ...


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128048

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/tools/driver/cc1_main.cpp


Index: clang/tools/driver/cc1_main.cpp
===================================================================
--- clang/tools/driver/cc1_main.cpp
+++ clang/tools/driver/cc1_main.cpp
@@ -254,8 +254,9 @@
   llvm::TimerGroup::clearAll();
 
   if (llvm::timeTraceProfilerEnabled()) {
-    SmallString<128> Path(Clang->getFrontendOpts().OutputFile);
-    llvm::sys::path::replace_extension(Path, "json");
+    SmallString<128> Path(Clang->getFrontendOpts().TimeTracePath);
+    Path.append(llvm::sys::path::filename(Clang->getFrontendOpts().OutputFile));
+    Path.append(".json");
     if (auto profilerOutput = Clang->createOutputFile(
             Path.str(), /*Binary=*/false, /*RemoveFileOnSignal=*/false,
             /*useTemporary=*/false)) {
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6183,6 +6183,7 @@
   Args.AddLastArg(CmdArgs, options::OPT_ftime_report_EQ);
   Args.AddLastArg(CmdArgs, options::OPT_ftime_trace);
   Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_granularity_EQ);
+  Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_path);
   Args.AddLastArg(CmdArgs, options::OPT_ftrapv);
   Args.AddLastArg(CmdArgs, options::OPT_malign_double);
   Args.AddLastArg(CmdArgs, options::OPT_fno_temp_file);
Index: clang/include/clang/Frontend/FrontendOptions.h
===================================================================
--- clang/include/clang/Frontend/FrontendOptions.h
+++ clang/include/clang/Frontend/FrontendOptions.h
@@ -499,6 +499,9 @@
   /// Minimum time granularity (in microseconds) traced by time profiler.
   unsigned TimeTraceGranularity;
 
+  /// Path which stores the output files of time profiler.
+  std::string TimeTracePath;
+
 public:
   FrontendOptions()
       : DisableFree(false), RelocatablePCH(false), ShowHelp(false),
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2828,6 +2828,10 @@
   HelpText<"Minimum time granularity (in microseconds) traced by time profiler">,
   Flags<[CC1Option, CoreOption]>,
   MarshallingInfoInt<FrontendOpts<"TimeTraceGranularity">, "500u">;
+def ftime_trace_path : Joined<["-"], "ftime-trace-path=">, Group<f_Group>,
+  HelpText<"Path which stores the output files of time profiler">,
+  Flags<[CC1Option, CoreOption]>,
+  MarshallingInfoString<FrontendOpts<"TimeTracePath">>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group<f_Group>,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group<f_Group>,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128048.437867.patch
Type: text/x-patch
Size: 2761 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220617/64cbe397/attachment.bin>


More information about the cfe-commits mailing list