|
11 | 11 | //
|
12 | 12 | //===----------------------------------------------------------------------===//
|
13 | 13 |
|
| 14 | +#include "llvm/ADT/ScopeExit.h" |
14 | 15 | #include "llvm/ADT/Statistic.h"
|
15 | 16 | #include "llvm/Bitcode/BitcodeReader.h"
|
16 | 17 | #include "llvm/Bitcode/BitcodeWriter.h"
|
|
31 | 32 | #include "llvm/Support/Path.h"
|
32 | 33 | #include "llvm/Support/TargetSelect.h"
|
33 | 34 | #include "llvm/Support/Threading.h"
|
| 35 | +#include "llvm/Support/TimeProfiler.h" |
34 | 36 | #include "llvm/Support/raw_ostream.h"
|
35 | 37 | #include "llvm/TargetParser/Host.h"
|
36 | 38 | #include <list>
|
@@ -220,6 +222,10 @@ namespace options {
|
220 | 222 | static std::string cs_profile_path;
|
221 | 223 | static bool cs_pgo_gen = false;
|
222 | 224 |
|
| 225 | + // Time trace options. |
| 226 | + static std::string time_trace_file; |
| 227 | + static unsigned time_trace_granularity = 500; |
| 228 | + |
223 | 229 | static void process_plugin_option(const char *opt_)
|
224 | 230 | {
|
225 | 231 | if (opt_ == nullptr)
|
@@ -308,6 +314,14 @@ namespace options {
|
308 | 314 | RemarksFormat = std::string(opt);
|
309 | 315 | } else if (opt.consume_front("stats-file=")) {
|
310 | 316 | stats_file = std::string(opt);
|
| 317 | + } else if (opt.consume_front("time-trace=")) { |
| 318 | + time_trace_file = std::string(opt); |
| 319 | + } else if (opt.consume_front("time-trace-granularity=")) { |
| 320 | + unsigned Granularity; |
| 321 | + if (opt.getAsInteger(10, Granularity)) |
| 322 | + message(LDPL_FATAL, "Invalid time trace granularity: %s", opt); |
| 323 | + else |
| 324 | + time_trace_granularity = Granularity; |
311 | 325 | } else {
|
312 | 326 | // Save this option to pass to the code generator.
|
313 | 327 | // ParseCommandLineOptions() expects argv[0] to be program name. Lazily
|
@@ -953,6 +967,10 @@ static std::unique_ptr<LTO> createLTO(IndexWriteCallback OnIndexWrite,
|
953 | 967 | Conf.HasWholeProgramVisibility = options::whole_program_visibility;
|
954 | 968 |
|
955 | 969 | Conf.StatsFile = options::stats_file;
|
| 970 | + |
| 971 | + Conf.TimeTraceEnabled = !options::time_trace_file.empty(); |
| 972 | + Conf.TimeTraceGranularity = options::time_trace_granularity; |
| 973 | + |
956 | 974 | return std::make_unique<LTO>(std::move(Conf), Backend,
|
957 | 975 | options::ParallelCodeGenParallelismLevel);
|
958 | 976 | }
|
@@ -1113,6 +1131,19 @@ static ld_plugin_status allSymbolsReadHook() {
|
1113 | 1131 | if (unsigned NumOpts = options::extra.size())
|
1114 | 1132 | cl::ParseCommandLineOptions(NumOpts, &options::extra[0]);
|
1115 | 1133 |
|
| 1134 | + // Initialize time trace profiler |
| 1135 | + if (!options::time_trace_file.empty()) |
| 1136 | + llvm::timeTraceProfilerInitialize(options::time_trace_granularity, |
| 1137 | + options::extra.size() ? options::extra[0] |
| 1138 | + : "LLVMgold"); |
| 1139 | + auto FinalizeTimeTrace = llvm::make_scope_exit([&]() { |
| 1140 | + if (!llvm::timeTraceProfilerEnabled()) |
| 1141 | + return; |
| 1142 | + assert(!options::time_trace_file.empty()); |
| 1143 | + check(llvm::timeTraceProfilerWrite(options::time_trace_file, output_name)); |
| 1144 | + llvm::timeTraceProfilerCleanup(); |
| 1145 | + }); |
| 1146 | + |
1116 | 1147 | std::vector<std::pair<SmallString<128>, bool>> Files = runLTO();
|
1117 | 1148 |
|
1118 | 1149 | if (options::TheOutputType == options::OT_DISABLE ||
|
|
0 commit comments