[llvm] [NFC][Support] Add an include file for time profiler helpers for tools (PR #152416)

Min-Yih Hsu via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 8 13:56:04 PDT 2025


================
@@ -0,0 +1,62 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines command line options and helper class for tools that want
+// to use time trace profiling. It is intended for inclusion in a tool's .cpp
+// file.
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_TIMEROFILER_TOOL_INC
+#define LLVM_SUPPORT_TIMEROFILER_TOOL_INC
+
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/TimeProfiler.h"
+
+static llvm::cl::opt<bool> TimeTrace("time-trace",
+                                     llvm::cl::desc("Record time trace"));
+
+static llvm::cl::opt<unsigned> TimeTraceGranularity(
+    "time-trace-granularity",
+    llvm::cl::desc(
+        "Minimum time granularity (in microseconds) traced by time profiler"),
+    llvm::cl::init(500), llvm::cl::Hidden);
+
+static llvm::cl::opt<std::string>
+    TimeTraceFile("time-trace-file",
+                  llvm::cl::desc("Specify time trace file destination"),
+                  llvm::cl::value_desc("filename"));
+
+namespace {
+
+/// The TimeTraceProfilerRAII is a helper class to initialize and write the time
+/// trace profile, intended for use in various tools.
+class TimeTraceProfilerRAII {
+private:
+  llvm::StringRef OutputFilename;
+
+public:
+  TimeTraceProfilerRAII(llvm::StringRef ProgramName,
+                        llvm::StringRef OutputFilename)
----------------
mshockwave wrote:

should we be consistent with `timeTraceProfilerWrite`'s API description and use `FallbackFilename`?

https://github.com/llvm/llvm-project/pull/152416


More information about the llvm-commits mailing list