[clang] [llvm] [TimeProfiler][Clang] Add zstd-compressed time-trace output support (PR #228627)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-aarch64-sve2-vla-2stage` running on `arm-bbot-clang-aarch64-sve2-vla-2stage` while building `clang,llvm` at step 12 "ninja check 2". Full details are available at: https://lab.llvm.org/buildbot/#/builders/199/builds/11306 Here is the relevant piece of the build log for the reference ``` Step 12 (ninja check 2) failure: stage 2 checked (failure) TEST 'AddressSanitizer-Unit :: ./Asan-aarch64-inline-Dynamic-Test/34/49' FAILED Script(shard): -- GTEST_OUTPUT=json:/home/buildbot/workspace/clang-aarch64-sve2-vla-2stage/stage2/runtimes/runtimes-bins/compiler-rt/lib/asan/tests/AARCH64LinuxDynamicConfig/./Asan-aarch64-inline-Dynamic-Test-AddressSanitizer-Unit-1694680-34-49.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=49 GTEST_SHARD_INDEX=34 /home/buildbot/workspace/clang-aarch64-sve2-vla-2stage/stage2/runtimes/runtimes-bins/compiler-rt/lib/asan/tests/AARCH64LinuxDynamicConfig/./Asan-aarch64-inline-Dynamic-Test -- Script: -- /home/buildbot/workspace/clang-aarch64-sve2-vla-2stage/stage2/runtimes/runtimes-bins/compiler-rt/lib/asan/tests/AARCH64LinuxDynamicConfig/./Asan-aarch64-inline-Dynamic-Test --gtest_filter=AddressSanitizer.ManyThreadsTest -- /home/buildbot/workspace/clang-aarch64-sve2-vla-2stage/llvm/compiler-rt/lib/asan/tests/asan_test.cpp:379: Failure Expected equality of these values: 0 pthread_create(&t[i], 0, ManyThreadsWorker, (void*)i) Which is: 11 /home/buildbot/workspace/clang-aarch64-sve2-vla-2stage/llvm/compiler-rt/lib/asan/tests/asan_test.cpp:379 Expected equality of these values: 0 pthread_create(&t[i], 0, ManyThreadsWorker, (void*)i) Which is: 11 ``` https://github.com/llvm/llvm-project/pull/228627 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [TimeProfiler][Clang] Add zstd-compressed time-trace output support (PR #228627)
https://github.com/chandlerc closed https://github.com/llvm/llvm-project/pull/228627 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [TimeProfiler][Clang] Add zstd-compressed time-trace output support (PR #228627)
https://github.com/chandlerc auto_merge_enabled https://github.com/llvm/llvm-project/pull/228627 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [TimeProfiler][Clang] Add zstd-compressed time-trace output support (PR #228627)
https://github.com/chandlerc updated
https://github.com/llvm/llvm-project/pull/228627
>From 2765dc14d832440ecb0ede141a64d3a1460ec088 Mon Sep 17 00:00:00 2001
From: Chandler Carruth
Date: Fri, 2 Oct 2026 18:06:45 +
Subject: [PATCH 1/4] [TimeProfiler][Clang] Add zstd-compressed time-trace
output support
Time trace JSON files can become very large (tens of megabytes) when profiling
with fine granularity (-ftime-trace-granularity=0) or verbose output
(-ftime-trace-verbose), while compressing by ~20x with zstd.
Add support for writing zstd-compressed time-trace output directly using LLVM's
existing llvm::compression facilities:
- Extend llvm::timeTraceProfilerInitialize and llvm::timeTraceProfilerWrite to
support DebugCompressionType and infer zstd compression from .zst/.zstd file
extensions via llvm::inferTimeTraceCompressionFromPath.
- Add -ftime-trace-compress and -ftime-trace-compress= driver and
CC1 options to explicitly control compression regardless of output filename.
- Update default output filename inference when -ftime-trace is used without an
explicit filename so compressed traces use a .json.zst extension.
Assisted-by: Antigravity with Gemini
---
.../clang/Basic/DiagnosticDriverKinds.td | 2 +
.../include/clang/Frontend/FrontendOptions.h | 5 ++
clang/include/clang/Options/Options.td| 11 +++
clang/lib/Driver/Driver.cpp | 18 -
clang/lib/Driver/ToolChains/Clang.cpp | 26 +++
clang/lib/Frontend/CompilerInvocation.cpp | 5 ++
clang/test/Driver/compress-zstd.c | 4 +
clang/test/Driver/ftime-trace.cpp | 11 ++-
clang/tools/driver/cc1_main.cpp | 7 +-
llvm/include/llvm/Support/TimeProfiler.h | 12 ++-
llvm/lib/Support/TimeProfiler.cpp | 74 +--
llvm/unittests/Support/TimeProfilerTest.cpp | 28 +++
12 files changed, 185 insertions(+), 18 deletions(-)
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index df6ff0c2cf399f..369fbef8d0c858 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -564,6 +564,8 @@ def warn_incompatible_sysroot : Warning<"using sysroot for
'%0' but targeting '%
InGroup>;
def warn_debug_compression_unavailable : Warning<"cannot compress debug
sections (%0 not enabled)">,
InGroup>;
+def err_drv_time_trace_compression_unavailable
+: Error<"cannot compress time trace (%0 not enabled)">;
def warn_drv_disabling_vptr_no_rtti_default : Warning<
"implicitly disabling vptr sanitizer because rtti wasn't enabled">,
InGroup;
diff --git a/clang/include/clang/Frontend/FrontendOptions.h
b/clang/include/clang/Frontend/FrontendOptions.h
index b85cf4c0078628..701c8d75fe61f8 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -16,6 +16,7 @@
#include "clang/Serialization/ModuleFileExtension.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/Support/Compression.h"
#include "llvm/Support/MemoryBuffer.h"
#include
#include
@@ -543,6 +544,10 @@ class FrontendOptions {
LLVM_PREFERRED_TYPE(bool)
unsigned TimeTraceVerbose : 1;
+ /// Compression format for -ftime-trace output.
+ llvm::DebugCompressionType TimeTraceCompress =
+ llvm::DebugCompressionType::None;
+
/// Path which stores the output files for -ftime-trace
std::string TimeTracePath;
diff --git a/clang/include/clang/Options/Options.td
b/clang/include/clang/Options/Options.td
index 60ae84cb0af5c7..1d867223b9b68b 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -4822,6 +4822,17 @@ def ftime_trace_verbose : Joined<["-"],
"ftime-trace-verbose">, Group,
HelpText<"Make time trace capture verbose event details (e.g. source
filenames). This can increase the size of the output by 2-3 times">,
Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
MarshallingInfoFlag>;
+def ftime_trace_compress_EQ : Joined<["-"], "ftime-trace-compress=">,
Group,
+ HelpText<"Compress -ftime-trace output with the specified algorithm">,
+ Values<"none,zstd">,
+ NormalizedValuesScope<"llvm::DebugCompressionType">,
+ NormalizedValues<["None", "Zstd"]>,
+ Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
+ MarshallingInfoEnum, "None">;
+def ftime_trace_compress : Flag<["-"], "ftime-trace-compress">, Group,
+ Alias, AliasArgs<["zstd"]>,
+ HelpText<"Alias for -ftime-trace-compress=zstd">,
+ Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>;
def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, Group,
HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory
which will contain the JSON file">,
Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index
[clang] [llvm] [TimeProfiler][Clang] Add zstd-compressed time-trace output support (PR #228627)
https://github.com/chandlerc edited https://github.com/llvm/llvm-project/pull/228627 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [TimeProfiler][Clang] Add zstd-compressed time-trace output support (PR #228627)
@@ -425,26 +440,68 @@ void llvm::timeTraceProfilerFinishThread() {
void llvm::timeTraceProfilerWrite(raw_pwrite_stream &OS) {
assert(TimeTraceProfilerInstance != nullptr &&
"Profiler object can't be null");
- TimeTraceProfilerInstance->write(OS);
+ TimeTraceCompression CompressType =
+ TimeTraceProfilerInstance->TimeTraceCompress;
+ if (CompressType != TimeTraceCompression::Zstd) {
+TimeTraceProfilerInstance->write(OS);
+return;
+ }
+
+ compression::Format F = compression::Format::Zstd;
+ if (const char *Reason = compression::getReasonIfUnsupported(F))
+report_fatal_error(Reason);
+
+ SmallVector Uncompressed;
+ {
+raw_svector_ostream UncompressedOS(Uncompressed);
+TimeTraceProfilerInstance->write(UncompressedOS);
+ }
+ SmallVector Compressed;
+ compression::compress(
+ compression::Params(F),
+ ArrayRef(reinterpret_cast(Uncompressed.data()),
+ Uncompressed.size()),
+ Compressed);
+ OS.write(reinterpret_cast(Compressed.data()),
+ Compressed.size());
}
Error llvm::timeTraceProfilerWrite(StringRef PreferredFileName,
StringRef FallbackFileName) {
assert(TimeTraceProfilerInstance != nullptr &&
"Profiler object can't be null");
+ TimeTraceCompression CompressType =
+ TimeTraceProfilerInstance->TimeTraceCompress;
std::string Path = PreferredFileName.str();
if (Path.empty()) {
Path = FallbackFileName == "-" ? "out" : FallbackFileName.str();
Path += TimeTraceFileExtension;
+if (CompressType == TimeTraceCompression::Zstd)
+ Path += ".zst";
+ } else if (CompressType == TimeTraceCompression::Infer) {
+CompressType = inferTimeTraceCompressionFromPath(Path);
+ }
+
+ if (CompressType == TimeTraceCompression::Zstd) {
+if (const char *Reason =
+compression::getReasonIfUnsupported(compression::Format::Zstd))
+ return createStringError(inconvertibleErrorCode(), Reason);
}
std::error_code EC;
- raw_fd_ostream OS(Path, EC, sys::fs::OF_TextWithCRLF);
+ sys::fs::OpenFlags Flags = CompressType == TimeTraceCompression::Zstd
+ ? sys::fs::OF_None
+ : sys::fs::OF_TextWithCRLF;
+ raw_fd_ostream OS(Path, EC, Flags);
if (EC)
return createStringError(EC, "Could not open " + Path);
+ TimeTraceCompression SavedCompress =
+ TimeTraceProfilerInstance->TimeTraceCompress;
+ TimeTraceProfilerInstance->TimeTraceCompress = CompressType;
chandlerc wrote:
Yeah. I'll send a follow-up PR to try and simplify the API here.
https://github.com/llvm/llvm-project/pull/228627
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [TimeProfiler][Clang] Add zstd-compressed time-trace output support (PR #228627)
@@ -7344,6 +7346,32 @@ void Clang::ConstructJob(Compilation &C, const JobAction
&JA,
CmdArgs.push_back(Args.MakeArgString("-ftime-trace=" + Twine(Name)));
Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_granularity_EQ);
Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_verbose);
+llvm::TimeTraceCompression Compress = llvm::TimeTraceCompression::Infer;
+if (const Arg *CompressArg =
+Args.getLastArg(options::OPT_ftime_trace_compress_EQ)) {
+ StringRef Value = CompressArg->getValue();
+ if (Value == "none")
+Compress = llvm::TimeTraceCompression::None;
+ else if (Value == "zstd")
+Compress = llvm::TimeTraceCompression::Zstd;
+ else if (Value == "infer")
+Compress = llvm::TimeTraceCompression::Infer;
+ else
+D.Diag(diag::err_drv_unsupported_option_argument)
+<< CompressArg->getSpelling() << Value;
+}
+if (Compress == llvm::TimeTraceCompression::Infer)
+ Compress = llvm::inferTimeTraceCompressionFromPath(Name);
+if (Compress == llvm::TimeTraceCompression::Zstd) {
+ if (llvm::compression::zstd::isAvailable())
+CmdArgs.push_back("-ftime-trace-compress=zstd");
+ else
+D.Diag(diag::err_drv_time_trace_compression_unavailable) << "zstd";
chandlerc wrote:
Good point, done and simplified accordingly.
https://github.com/llvm/llvm-project/pull/228627
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [TimeProfiler][Clang] Add zstd-compressed time-trace output support (PR #228627)
https://github.com/chandlerc commented: Thanks, merging! https://github.com/llvm/llvm-project/pull/228627 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [TimeProfiler][Clang] Add zstd-compressed time-trace output support (PR #228627)
https://github.com/chandlerc updated
https://github.com/llvm/llvm-project/pull/228627
>From 2765dc14d832440ecb0ede141a64d3a1460ec088 Mon Sep 17 00:00:00 2001
From: Chandler Carruth
Date: Fri, 2 Oct 2026 18:06:45 +
Subject: [PATCH 1/4] [TimeProfiler][Clang] Add zstd-compressed time-trace
output support
Time trace JSON files can become very large (tens of megabytes) when profiling
with fine granularity (-ftime-trace-granularity=0) or verbose output
(-ftime-trace-verbose), while compressing by ~20x with zstd.
Add support for writing zstd-compressed time-trace output directly using LLVM's
existing llvm::compression facilities:
- Extend llvm::timeTraceProfilerInitialize and llvm::timeTraceProfilerWrite to
support DebugCompressionType and infer zstd compression from .zst/.zstd file
extensions via llvm::inferTimeTraceCompressionFromPath.
- Add -ftime-trace-compress and -ftime-trace-compress= driver and
CC1 options to explicitly control compression regardless of output filename.
- Update default output filename inference when -ftime-trace is used without an
explicit filename so compressed traces use a .json.zst extension.
Assisted-by: Antigravity with Gemini
---
.../clang/Basic/DiagnosticDriverKinds.td | 2 +
.../include/clang/Frontend/FrontendOptions.h | 5 ++
clang/include/clang/Options/Options.td| 11 +++
clang/lib/Driver/Driver.cpp | 18 -
clang/lib/Driver/ToolChains/Clang.cpp | 26 +++
clang/lib/Frontend/CompilerInvocation.cpp | 5 ++
clang/test/Driver/compress-zstd.c | 4 +
clang/test/Driver/ftime-trace.cpp | 11 ++-
clang/tools/driver/cc1_main.cpp | 7 +-
llvm/include/llvm/Support/TimeProfiler.h | 12 ++-
llvm/lib/Support/TimeProfiler.cpp | 74 +--
llvm/unittests/Support/TimeProfilerTest.cpp | 28 +++
12 files changed, 185 insertions(+), 18 deletions(-)
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index df6ff0c2cf399f..369fbef8d0c858 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -564,6 +564,8 @@ def warn_incompatible_sysroot : Warning<"using sysroot for
'%0' but targeting '%
InGroup>;
def warn_debug_compression_unavailable : Warning<"cannot compress debug
sections (%0 not enabled)">,
InGroup>;
+def err_drv_time_trace_compression_unavailable
+: Error<"cannot compress time trace (%0 not enabled)">;
def warn_drv_disabling_vptr_no_rtti_default : Warning<
"implicitly disabling vptr sanitizer because rtti wasn't enabled">,
InGroup;
diff --git a/clang/include/clang/Frontend/FrontendOptions.h
b/clang/include/clang/Frontend/FrontendOptions.h
index b85cf4c0078628..701c8d75fe61f8 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -16,6 +16,7 @@
#include "clang/Serialization/ModuleFileExtension.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/Support/Compression.h"
#include "llvm/Support/MemoryBuffer.h"
#include
#include
@@ -543,6 +544,10 @@ class FrontendOptions {
LLVM_PREFERRED_TYPE(bool)
unsigned TimeTraceVerbose : 1;
+ /// Compression format for -ftime-trace output.
+ llvm::DebugCompressionType TimeTraceCompress =
+ llvm::DebugCompressionType::None;
+
/// Path which stores the output files for -ftime-trace
std::string TimeTracePath;
diff --git a/clang/include/clang/Options/Options.td
b/clang/include/clang/Options/Options.td
index 60ae84cb0af5c7..1d867223b9b68b 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -4822,6 +4822,17 @@ def ftime_trace_verbose : Joined<["-"],
"ftime-trace-verbose">, Group,
HelpText<"Make time trace capture verbose event details (e.g. source
filenames). This can increase the size of the output by 2-3 times">,
Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
MarshallingInfoFlag>;
+def ftime_trace_compress_EQ : Joined<["-"], "ftime-trace-compress=">,
Group,
+ HelpText<"Compress -ftime-trace output with the specified algorithm">,
+ Values<"none,zstd">,
+ NormalizedValuesScope<"llvm::DebugCompressionType">,
+ NormalizedValues<["None", "Zstd"]>,
+ Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
+ MarshallingInfoEnum, "None">;
+def ftime_trace_compress : Flag<["-"], "ftime-trace-compress">, Group,
+ Alias, AliasArgs<["zstd"]>,
+ HelpText<"Alias for -ftime-trace-compress=zstd">,
+ Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>;
def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, Group,
HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory
which will contain the JSON file">,
Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index
[clang] [llvm] [TimeProfiler][Clang] Add zstd-compressed time-trace output support (PR #228627)
@@ -425,26 +439,68 @@ void llvm::timeTraceProfilerFinishThread() {
void llvm::timeTraceProfilerWrite(raw_pwrite_stream &OS) {
assert(TimeTraceProfilerInstance != nullptr &&
"Profiler object can't be null");
- TimeTraceProfilerInstance->write(OS);
+ DebugCompressionType CompressType =
+ TimeTraceProfilerInstance->TimeTraceCompress;
+ if (CompressType == DebugCompressionType::None) {
+TimeTraceProfilerInstance->write(OS);
+return;
+ }
+
+ compression::Format F = compression::formatFor(CompressType);
+ if (const char *Reason = compression::getReasonIfUnsupported(F))
+report_fatal_error(Reason);
+
+ SmallVector Uncompressed;
+ {
+raw_svector_ostream UncompressedOS(Uncompressed);
+TimeTraceProfilerInstance->write(UncompressedOS);
+ }
+ SmallVector Compressed;
+ compression::compress(
+ compression::Params(F),
+ ArrayRef(reinterpret_cast(Uncompressed.data()),
+ Uncompressed.size()),
+ Compressed);
+ OS.write(reinterpret_cast(Compressed.data()),
+ Compressed.size());
}
Error llvm::timeTraceProfilerWrite(StringRef PreferredFileName,
StringRef FallbackFileName) {
assert(TimeTraceProfilerInstance != nullptr &&
"Profiler object can't be null");
+ DebugCompressionType CompressType =
+ TimeTraceProfilerInstance->TimeTraceCompress;
std::string Path = PreferredFileName.str();
if (Path.empty()) {
Path = FallbackFileName == "-" ? "out" : FallbackFileName.str();
Path += TimeTraceFileExtension;
+if (CompressType == DebugCompressionType::Zstd)
+ Path += ".zst";
+ } else if (CompressType == DebugCompressionType::None) {
+CompressType = inferTimeTraceCompressionFromPath(Path);
chandlerc wrote:
Yeah, introduced `llvm::TimeTraceCompression` and added `infer` to
`-ftime-trace-compress=`. Seems a bit cleaner this way too.
https://github.com/llvm/llvm-project/pull/228627
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [TimeProfiler][Clang] Add zstd-compressed time-trace output support (PR #228627)
@@ -4822,6 +4822,17 @@ def ftime_trace_verbose : Joined<["-"], "ftime-trace-verbose">, Group, HelpText<"Make time trace capture verbose event details (e.g. source filenames). This can increase the size of the output by 2-3 times">, Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>, MarshallingInfoFlag>; +def ftime_trace_compress_EQ : Joined<["-"], "ftime-trace-compress=">, Group, + HelpText<"Compress -ftime-trace output with the specified algorithm">, + Values<"none,zstd">, + NormalizedValuesScope<"llvm::DebugCompressionType">, + NormalizedValues<["None", "Zstd"]>, + Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>, + MarshallingInfoEnum, "None">; +def ftime_trace_compress : Flag<["-"], "ftime-trace-compress">, Group, chandlerc wrote: Removed. https://github.com/llvm/llvm-project/pull/228627 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [TimeProfiler][Clang] Add zstd-compressed time-trace output support (PR #228627)
https://github.com/chandlerc updated
https://github.com/llvm/llvm-project/pull/228627
>From 2765dc14d832440ecb0ede141a64d3a1460ec088 Mon Sep 17 00:00:00 2001
From: Chandler Carruth
Date: Fri, 2 Oct 2026 18:06:45 +
Subject: [PATCH 1/3] [TimeProfiler][Clang] Add zstd-compressed time-trace
output support
Time trace JSON files can become very large (tens of megabytes) when profiling
with fine granularity (-ftime-trace-granularity=0) or verbose output
(-ftime-trace-verbose), while compressing by ~20x with zstd.
Add support for writing zstd-compressed time-trace output directly using LLVM's
existing llvm::compression facilities:
- Extend llvm::timeTraceProfilerInitialize and llvm::timeTraceProfilerWrite to
support DebugCompressionType and infer zstd compression from .zst/.zstd file
extensions via llvm::inferTimeTraceCompressionFromPath.
- Add -ftime-trace-compress and -ftime-trace-compress= driver and
CC1 options to explicitly control compression regardless of output filename.
- Update default output filename inference when -ftime-trace is used without an
explicit filename so compressed traces use a .json.zst extension.
Assisted-by: Antigravity with Gemini
---
.../clang/Basic/DiagnosticDriverKinds.td | 2 +
.../include/clang/Frontend/FrontendOptions.h | 5 ++
clang/include/clang/Options/Options.td| 11 +++
clang/lib/Driver/Driver.cpp | 18 -
clang/lib/Driver/ToolChains/Clang.cpp | 26 +++
clang/lib/Frontend/CompilerInvocation.cpp | 5 ++
clang/test/Driver/compress-zstd.c | 4 +
clang/test/Driver/ftime-trace.cpp | 11 ++-
clang/tools/driver/cc1_main.cpp | 7 +-
llvm/include/llvm/Support/TimeProfiler.h | 12 ++-
llvm/lib/Support/TimeProfiler.cpp | 74 +--
llvm/unittests/Support/TimeProfilerTest.cpp | 28 +++
12 files changed, 185 insertions(+), 18 deletions(-)
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index df6ff0c2cf399..369fbef8d0c85 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -564,6 +564,8 @@ def warn_incompatible_sysroot : Warning<"using sysroot for
'%0' but targeting '%
InGroup>;
def warn_debug_compression_unavailable : Warning<"cannot compress debug
sections (%0 not enabled)">,
InGroup>;
+def err_drv_time_trace_compression_unavailable
+: Error<"cannot compress time trace (%0 not enabled)">;
def warn_drv_disabling_vptr_no_rtti_default : Warning<
"implicitly disabling vptr sanitizer because rtti wasn't enabled">,
InGroup;
diff --git a/clang/include/clang/Frontend/FrontendOptions.h
b/clang/include/clang/Frontend/FrontendOptions.h
index b85cf4c007862..701c8d75fe61f 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -16,6 +16,7 @@
#include "clang/Serialization/ModuleFileExtension.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/Support/Compression.h"
#include "llvm/Support/MemoryBuffer.h"
#include
#include
@@ -543,6 +544,10 @@ class FrontendOptions {
LLVM_PREFERRED_TYPE(bool)
unsigned TimeTraceVerbose : 1;
+ /// Compression format for -ftime-trace output.
+ llvm::DebugCompressionType TimeTraceCompress =
+ llvm::DebugCompressionType::None;
+
/// Path which stores the output files for -ftime-trace
std::string TimeTracePath;
diff --git a/clang/include/clang/Options/Options.td
b/clang/include/clang/Options/Options.td
index 60ae84cb0af5c..1d867223b9b68 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -4822,6 +4822,17 @@ def ftime_trace_verbose : Joined<["-"],
"ftime-trace-verbose">, Group,
HelpText<"Make time trace capture verbose event details (e.g. source
filenames). This can increase the size of the output by 2-3 times">,
Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
MarshallingInfoFlag>;
+def ftime_trace_compress_EQ : Joined<["-"], "ftime-trace-compress=">,
Group,
+ HelpText<"Compress -ftime-trace output with the specified algorithm">,
+ Values<"none,zstd">,
+ NormalizedValuesScope<"llvm::DebugCompressionType">,
+ NormalizedValues<["None", "Zstd"]>,
+ Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
+ MarshallingInfoEnum, "None">;
+def ftime_trace_compress : Flag<["-"], "ftime-trace-compress">, Group,
+ Alias, AliasArgs<["zstd"]>,
+ HelpText<"Alias for -ftime-trace-compress=zstd">,
+ Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>;
def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, Group,
HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory
which will contain the JSON file">,
Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index
[clang] [llvm] [TimeProfiler][Clang] Add zstd-compressed time-trace output support (PR #228627)
@@ -7344,6 +7346,28 @@ void Clang::ConstructJob(Compilation &C, const JobAction
&JA,
CmdArgs.push_back(Args.MakeArgString("-ftime-trace=" + Twine(Name)));
Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_granularity_EQ);
Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_verbose);
+if (const Arg *CompressArg =
+Args.getLastArg(options::OPT_ftime_trace_compress_EQ)) {
+ StringRef Value = CompressArg->getValue();
+ if (Value == "none") {
+// Explicit -ftime-trace-compress=none disables compression even if the
+// filename has a .zst/.zstd extension.
chandlerc wrote:
The main use case for `-ftime-trace-compress=none` is overriding an earlier
`-ftime-trace-compress` (or `-ftime-trace-compress=zstd`) flag on the command
line (e.g., from build-system default `CXXFLAGS`). Because
`-ftime-trace-compress` is an alias for `-ftime-trace-compress=zstd`,
`getLastArg(OPT_ftime_trace_compress_EQ)` matches both.
If someone also uses `-ftime-trace-compress=none` to override a
build-system-hardcoded `-ftime-trace=foo.json.zst` path, emitting a warning
would break under `-Werror` and make that override harder to use. I've updated
the comment here to clarify that the primary purpose is overriding earlier
flags (and added a driver test case for `-ftime-trace -ftime-trace-compress
-ftime-trace-compress=none`).
https://github.com/llvm/llvm-project/pull/228627
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [TimeProfiler][Clang] Add zstd-compressed time-trace output support (PR #228627)
@@ -437,14 +474,35 @@ Error llvm::timeTraceProfilerWrite(StringRef
PreferredFileName,
if (Path.empty()) {
Path = FallbackFileName == "-" ? "out" : FallbackFileName.str();
Path += TimeTraceFileExtension;
+if (TimeTraceProfilerInstance->TimeTraceCompress ==
chandlerc wrote:
Done — switched to your suggested `if (Path.empty()) ... else if (CompressType
== DebugCompressionType::None)` structure, which is much clearer!
And yes, not mutating a non-empty `PreferredFileName` when `CompressType ==
Zstd` is WAI: if a caller or user explicitly specifies an output file path
(e.g., `-ftime-trace=custom.out`), we write to the exact path they requested
rather than silently renaming it, and only append `.zst` when synthesizing a
default filename.
https://github.com/llvm/llvm-project/pull/228627
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [TimeProfiler][Clang] Add zstd-compressed time-trace output support (PR #228627)
https://github.com/chandlerc updated
https://github.com/llvm/llvm-project/pull/228627
>From 2765dc14d832440ecb0ede141a64d3a1460ec088 Mon Sep 17 00:00:00 2001
From: Chandler Carruth
Date: Fri, 2 Oct 2026 18:06:45 +
Subject: [PATCH 1/2] [TimeProfiler][Clang] Add zstd-compressed time-trace
output support
Time trace JSON files can become very large (tens of megabytes) when profiling
with fine granularity (-ftime-trace-granularity=0) or verbose output
(-ftime-trace-verbose), while compressing by ~20x with zstd.
Add support for writing zstd-compressed time-trace output directly using LLVM's
existing llvm::compression facilities:
- Extend llvm::timeTraceProfilerInitialize and llvm::timeTraceProfilerWrite to
support DebugCompressionType and infer zstd compression from .zst/.zstd file
extensions via llvm::inferTimeTraceCompressionFromPath.
- Add -ftime-trace-compress and -ftime-trace-compress= driver and
CC1 options to explicitly control compression regardless of output filename.
- Update default output filename inference when -ftime-trace is used without an
explicit filename so compressed traces use a .json.zst extension.
Assisted-by: Antigravity with Gemini
---
.../clang/Basic/DiagnosticDriverKinds.td | 2 +
.../include/clang/Frontend/FrontendOptions.h | 5 ++
clang/include/clang/Options/Options.td| 11 +++
clang/lib/Driver/Driver.cpp | 18 -
clang/lib/Driver/ToolChains/Clang.cpp | 26 +++
clang/lib/Frontend/CompilerInvocation.cpp | 5 ++
clang/test/Driver/compress-zstd.c | 4 +
clang/test/Driver/ftime-trace.cpp | 11 ++-
clang/tools/driver/cc1_main.cpp | 7 +-
llvm/include/llvm/Support/TimeProfiler.h | 12 ++-
llvm/lib/Support/TimeProfiler.cpp | 74 +--
llvm/unittests/Support/TimeProfilerTest.cpp | 28 +++
12 files changed, 185 insertions(+), 18 deletions(-)
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index df6ff0c2cf399..369fbef8d0c85 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -564,6 +564,8 @@ def warn_incompatible_sysroot : Warning<"using sysroot for
'%0' but targeting '%
InGroup>;
def warn_debug_compression_unavailable : Warning<"cannot compress debug
sections (%0 not enabled)">,
InGroup>;
+def err_drv_time_trace_compression_unavailable
+: Error<"cannot compress time trace (%0 not enabled)">;
def warn_drv_disabling_vptr_no_rtti_default : Warning<
"implicitly disabling vptr sanitizer because rtti wasn't enabled">,
InGroup;
diff --git a/clang/include/clang/Frontend/FrontendOptions.h
b/clang/include/clang/Frontend/FrontendOptions.h
index b85cf4c007862..701c8d75fe61f 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -16,6 +16,7 @@
#include "clang/Serialization/ModuleFileExtension.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/Support/Compression.h"
#include "llvm/Support/MemoryBuffer.h"
#include
#include
@@ -543,6 +544,10 @@ class FrontendOptions {
LLVM_PREFERRED_TYPE(bool)
unsigned TimeTraceVerbose : 1;
+ /// Compression format for -ftime-trace output.
+ llvm::DebugCompressionType TimeTraceCompress =
+ llvm::DebugCompressionType::None;
+
/// Path which stores the output files for -ftime-trace
std::string TimeTracePath;
diff --git a/clang/include/clang/Options/Options.td
b/clang/include/clang/Options/Options.td
index 60ae84cb0af5c..1d867223b9b68 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -4822,6 +4822,17 @@ def ftime_trace_verbose : Joined<["-"],
"ftime-trace-verbose">, Group,
HelpText<"Make time trace capture verbose event details (e.g. source
filenames). This can increase the size of the output by 2-3 times">,
Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
MarshallingInfoFlag>;
+def ftime_trace_compress_EQ : Joined<["-"], "ftime-trace-compress=">,
Group,
+ HelpText<"Compress -ftime-trace output with the specified algorithm">,
+ Values<"none,zstd">,
+ NormalizedValuesScope<"llvm::DebugCompressionType">,
+ NormalizedValues<["None", "Zstd"]>,
+ Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
+ MarshallingInfoEnum, "None">;
+def ftime_trace_compress : Flag<["-"], "ftime-trace-compress">, Group,
+ Alias, AliasArgs<["zstd"]>,
+ HelpText<"Alias for -ftime-trace-compress=zstd">,
+ Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>;
def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, Group,
HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory
which will contain the JSON file">,
Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index
[clang] [llvm] [TimeProfiler][Clang] Add zstd-compressed time-trace output support (PR #228627)
@@ -7344,6 +7346,28 @@ void Clang::ConstructJob(Compilation &C, const JobAction
&JA,
CmdArgs.push_back(Args.MakeArgString("-ftime-trace=" + Twine(Name)));
Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_granularity_EQ);
Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_verbose);
+if (const Arg *CompressArg =
+Args.getLastArg(options::OPT_ftime_trace_compress_EQ)) {
+ StringRef Value = CompressArg->getValue();
+ if (Value == "none") {
+// Explicit -ftime-trace-compress=none disables compression even if the
+// filename has a .zst/.zstd extension.
alinas wrote:
Nit: does it make sense to have a warning diagnostic when inferPath returns
zstd?
I'm not clear what would be a use case for the mismatch -- when the path
argument cannot be updated and needs to be overwritten by
`-ftime-trace-compress=none`?
https://github.com/llvm/llvm-project/pull/228627
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [TimeProfiler][Clang] Add zstd-compressed time-trace output support (PR #228627)
@@ -437,14 +474,35 @@ Error llvm::timeTraceProfilerWrite(StringRef
PreferredFileName,
if (Path.empty()) {
Path = FallbackFileName == "-" ? "out" : FallbackFileName.str();
Path += TimeTraceFileExtension;
+if (TimeTraceProfilerInstance->TimeTraceCompress ==
alinas wrote:
I find this section confusing, because it makes it look like you could update
CompressType when the path is empty and I *think* that shouldn't happen?
Does the following make sense:
```
DebugCompressionType CompressType =
TimeTraceProfilerInstance->TimeTraceCompress;
if (Path.empty()) {
Path = FallbackFileName == "-" ? "out" : FallbackFileName.str();
Path += TimeTraceFileExtension;
if (CompressType == DebugCompressionType::Zstd)
Path += ".zst";
} else if (CompressType == DebugCompressionType::None) {
CompressType = inferTimeTraceCompressionFromPath(Path);
}
if (CompressType != DebugCompressionType::None) {
[...]
```
https://github.com/llvm/llvm-project/pull/228627
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [TimeProfiler][Clang] Add zstd-compressed time-trace output support (PR #228627)
@@ -437,14 +474,35 @@ Error llvm::timeTraceProfilerWrite(StringRef
PreferredFileName,
if (Path.empty()) {
Path = FallbackFileName == "-" ? "out" : FallbackFileName.str();
Path += TimeTraceFileExtension;
+if (TimeTraceProfilerInstance->TimeTraceCompress ==
alinas wrote:
Hmm, is could be possible the given path does not have a .zst(d) extension, but
the compression is specified as zstd, in which case the path is not currently
updated. I'm assuming that's WAI.
https://github.com/llvm/llvm-project/pull/228627
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [TimeProfiler][Clang] Add zstd-compressed time-trace output support (PR #228627)
https://github.com/chandlerc updated
https://github.com/llvm/llvm-project/pull/228627
>From 2765dc14d832440ecb0ede141a64d3a1460ec088 Mon Sep 17 00:00:00 2001
From: Chandler Carruth
Date: Fri, 2 Oct 2026 18:06:45 +
Subject: [PATCH] [TimeProfiler][Clang] Add zstd-compressed time-trace output
support
Time trace JSON files can become very large (tens of megabytes) when profiling
with fine granularity (-ftime-trace-granularity=0) or verbose output
(-ftime-trace-verbose), while compressing by ~20x with zstd.
Add support for writing zstd-compressed time-trace output directly using LLVM's
existing llvm::compression facilities:
- Extend llvm::timeTraceProfilerInitialize and llvm::timeTraceProfilerWrite to
support DebugCompressionType and infer zstd compression from .zst/.zstd file
extensions via llvm::inferTimeTraceCompressionFromPath.
- Add -ftime-trace-compress and -ftime-trace-compress= driver and
CC1 options to explicitly control compression regardless of output filename.
- Update default output filename inference when -ftime-trace is used without an
explicit filename so compressed traces use a .json.zst extension.
Assisted-by: Antigravity with Gemini
---
.../clang/Basic/DiagnosticDriverKinds.td | 2 +
.../include/clang/Frontend/FrontendOptions.h | 5 ++
clang/include/clang/Options/Options.td| 11 +++
clang/lib/Driver/Driver.cpp | 18 -
clang/lib/Driver/ToolChains/Clang.cpp | 26 +++
clang/lib/Frontend/CompilerInvocation.cpp | 5 ++
clang/test/Driver/compress-zstd.c | 4 +
clang/test/Driver/ftime-trace.cpp | 11 ++-
clang/tools/driver/cc1_main.cpp | 7 +-
llvm/include/llvm/Support/TimeProfiler.h | 12 ++-
llvm/lib/Support/TimeProfiler.cpp | 74 +--
llvm/unittests/Support/TimeProfilerTest.cpp | 28 +++
12 files changed, 185 insertions(+), 18 deletions(-)
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index df6ff0c2cf399f6..369fbef8d0c858a 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -564,6 +564,8 @@ def warn_incompatible_sysroot : Warning<"using sysroot for
'%0' but targeting '%
InGroup>;
def warn_debug_compression_unavailable : Warning<"cannot compress debug
sections (%0 not enabled)">,
InGroup>;
+def err_drv_time_trace_compression_unavailable
+: Error<"cannot compress time trace (%0 not enabled)">;
def warn_drv_disabling_vptr_no_rtti_default : Warning<
"implicitly disabling vptr sanitizer because rtti wasn't enabled">,
InGroup;
diff --git a/clang/include/clang/Frontend/FrontendOptions.h
b/clang/include/clang/Frontend/FrontendOptions.h
index b85cf4c0078628a..701c8d75fe61f8e 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -16,6 +16,7 @@
#include "clang/Serialization/ModuleFileExtension.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/Support/Compression.h"
#include "llvm/Support/MemoryBuffer.h"
#include
#include
@@ -543,6 +544,10 @@ class FrontendOptions {
LLVM_PREFERRED_TYPE(bool)
unsigned TimeTraceVerbose : 1;
+ /// Compression format for -ftime-trace output.
+ llvm::DebugCompressionType TimeTraceCompress =
+ llvm::DebugCompressionType::None;
+
/// Path which stores the output files for -ftime-trace
std::string TimeTracePath;
diff --git a/clang/include/clang/Options/Options.td
b/clang/include/clang/Options/Options.td
index 60ae84cb0af5c7b..1d867223b9b68bf 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -4822,6 +4822,17 @@ def ftime_trace_verbose : Joined<["-"],
"ftime-trace-verbose">, Group,
HelpText<"Make time trace capture verbose event details (e.g. source
filenames). This can increase the size of the output by 2-3 times">,
Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
MarshallingInfoFlag>;
+def ftime_trace_compress_EQ : Joined<["-"], "ftime-trace-compress=">,
Group,
+ HelpText<"Compress -ftime-trace output with the specified algorithm">,
+ Values<"none,zstd">,
+ NormalizedValuesScope<"llvm::DebugCompressionType">,
+ NormalizedValues<["None", "Zstd"]>,
+ Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
+ MarshallingInfoEnum, "None">;
+def ftime_trace_compress : Flag<["-"], "ftime-trace-compress">, Group,
+ Alias, AliasArgs<["zstd"]>,
+ HelpText<"Alias for -ftime-trace-compress=zstd">,
+ Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>;
def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, Group,
HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory
which will contain the JSON file">,
Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index
[clang] [llvm] [TimeProfiler][Clang] Add zstd-compressed time-trace output support (PR #228627)
llvmorg-github-actions[bot] wrote: @llvm/pr-subscribers-clang-driver Author: Chandler Carruth (chandlerc) Changes Time trace JSON files can become very large (tens of megabytes) when profiling with fine granularity (-ftime-trace-granularity=0) or verbose output (-ftime-trace-verbose), while compressing by ~20x with zstd. Add support for writing zstd-compressed time-trace output directly using LLVM's existing llvm::compression facilities: - Extend llvm::timeTraceProfilerInitialize and llvm::timeTraceProfilerWrite to support DebugCompressionType and infer zstd compression from .zst/.zstd file extensions via llvm::inferTimeTraceCompressionFromPath. - Add -ftime-trace-compress and -ftime-trace-compress=driver and CC1 options to explicitly control compression regardless of output filename. - Update default output filename inference when -ftime-trace is used without an explicit filename so compressed traces use a .json.zst extension. Assisted-by: Antigravity with Gemini --- Patch is 20.35 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/228627.diff 12 Files Affected: - (modified) clang/include/clang/Basic/DiagnosticDriverKinds.td (+2) - (modified) clang/include/clang/Frontend/FrontendOptions.h (+5) - (modified) clang/include/clang/Options/Options.td (+11) - (modified) clang/lib/Driver/Driver.cpp (+14-4) - (modified) clang/lib/Driver/ToolChains/Clang.cpp (+26) - (modified) clang/lib/Frontend/CompilerInvocation.cpp (+5) - (modified) clang/test/Driver/compress-zstd.c (+4) - (modified) clang/test/Driver/ftime-trace.cpp (+10-1) - (modified) clang/tools/driver/cc1_main.cpp (+5-2) - (modified) llvm/include/llvm/Support/TimeProfiler.h (+10-3) - (modified) llvm/lib/Support/TimeProfiler.cpp (+66-8) - (modified) llvm/unittests/Support/TimeProfilerTest.cpp (+28) ``diff diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index df6ff0c2cf399f6..369fbef8d0c858a 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -564,6 +564,8 @@ def warn_incompatible_sysroot : Warning<"using sysroot for '%0' but targeting '% InGroup>; def warn_debug_compression_unavailable : Warning<"cannot compress debug sections (%0 not enabled)">, InGroup>; +def err_drv_time_trace_compression_unavailable +: Error<"cannot compress time trace (%0 not enabled)">; def warn_drv_disabling_vptr_no_rtti_default : Warning< "implicitly disabling vptr sanitizer because rtti wasn't enabled">, InGroup; diff --git a/clang/include/clang/Frontend/FrontendOptions.h b/clang/include/clang/Frontend/FrontendOptions.h index b85cf4c0078628a..701c8d75fe61f8e 100644 --- a/clang/include/clang/Frontend/FrontendOptions.h +++ b/clang/include/clang/Frontend/FrontendOptions.h @@ -16,6 +16,7 @@ #include "clang/Serialization/ModuleFileExtension.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Compiler.h" +#include "llvm/Support/Compression.h" #include "llvm/Support/MemoryBuffer.h" #include #include @@ -543,6 +544,10 @@ class FrontendOptions { LLVM_PREFERRED_TYPE(bool) unsigned TimeTraceVerbose : 1; + /// Compression format for -ftime-trace output. + llvm::DebugCompressionType TimeTraceCompress = + llvm::DebugCompressionType::None; + /// Path which stores the output files for -ftime-trace std::string TimeTracePath; diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td index 60ae84cb0af5c7b..1d867223b9b68bf 100644 --- a/clang/include/clang/Options/Options.td +++ b/clang/include/clang/Options/Options.td @@ -4822,6 +4822,17 @@ def ftime_trace_verbose : Joined<["-"], "ftime-trace-verbose">, Group, HelpText<"Make time trace capture verbose event details (e.g. source filenames). This can increase the size of the output by 2-3 times">, Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>, MarshallingInfoFlag>; +def ftime_trace_compress_EQ : Joined<["-"], "ftime-trace-compress=">, Group, + HelpText<"Compress -ftime-trace output with the specified algorithm">, + Values<"none,zstd">, + NormalizedValuesScope<"llvm::DebugCompressionType">, + NormalizedValues<["None", "Zstd"]>, + Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>, + MarshallingInfoEnum, "None">; +def ftime_trace_compress : Flag<["-"], "ftime-trace-compress">, Group, + Alias, AliasArgs<["zstd"]>, + HelpText<"Alias for -ftime-trace-compress=zstd">, + Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>; def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, Group, HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory which will contain the JSON file">, Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>, diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 7649941a68b1ccc..79ad73d45825c5f 100644 ---
[clang] [llvm] [TimeProfiler][Clang] Add zstd-compressed time-trace output support (PR #228627)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff origin/main HEAD --extensions c,cpp,h -- clang/include/clang/Frontend/FrontendOptions.h clang/lib/Driver/Driver.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Frontend/CompilerInvocation.cpp clang/test/Driver/compress-zstd.c clang/test/Driver/ftime-trace.cpp clang/tools/driver/cc1_main.cpp llvm/include/llvm/Support/TimeProfiler.h llvm/lib/Support/TimeProfiler.cpp llvm/unittests/Support/TimeProfilerTest.cpp --diff_from_common_commit `` :warning: The reproduction instructions above might return results for more than one PR in a stack if you are using a stacked PR workflow. You can limit the results by changing `origin/main` to the base branch/commit you want to compare against. :warning: View the diff from clang-format here. ``diff diff --git a/llvm/include/llvm/Support/TimeProfiler.h b/llvm/include/llvm/Support/TimeProfiler.h index 417918cb1..014379de6 100644 --- a/llvm/include/llvm/Support/TimeProfiler.h +++ b/llvm/include/llvm/Support/TimeProfiler.h @@ -116,8 +116,7 @@ struct TimeTraceProfilerEntry; /// Infer the time trace compression format from \p Path based on its file /// extension (.zst/.zstd -> Zstd, otherwise None). -LLVM_ABI DebugCompressionType -inferTimeTraceCompressionFromPath(StringRef Path); +LLVM_ABI DebugCompressionType inferTimeTraceCompressionFromPath(StringRef Path); /// Initialize the time trace profiler. /// This sets up the global \p TimeTraceProfilerInstance `` https://github.com/llvm/llvm-project/pull/228627 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [TimeProfiler][Clang] Add zstd-compressed time-trace output support (PR #228627)
https://github.com/chandlerc created
https://github.com/llvm/llvm-project/pull/228627
Time trace JSON files can become very large (tens of megabytes) when profiling
with fine granularity (-ftime-trace-granularity=0) or verbose output
(-ftime-trace-verbose), while compressing by ~20x with zstd.
Add support for writing zstd-compressed time-trace output directly using LLVM's
existing llvm::compression facilities:
- Extend llvm::timeTraceProfilerInitialize and llvm::timeTraceProfilerWrite to
support DebugCompressionType and infer zstd compression from .zst/.zstd file
extensions via llvm::inferTimeTraceCompressionFromPath.
- Add -ftime-trace-compress and -ftime-trace-compress= driver and
CC1 options to explicitly control compression regardless of output filename.
- Update default output filename inference when -ftime-trace is used without an
explicit filename so compressed traces use a .json.zst extension.
Assisted-by: Antigravity with Gemini
>From ec262e8571bec9cea1e5d2aeeaf2ba4c7c55066c Mon Sep 17 00:00:00 2001
From: Chandler Carruth
Date: Fri, 2 Oct 2026 18:06:45 +
Subject: [PATCH] [TimeProfiler][Clang] Add zstd-compressed time-trace output
support
Time trace JSON files can become very large (tens of megabytes) when profiling
with fine granularity (-ftime-trace-granularity=0) or verbose output
(-ftime-trace-verbose), while compressing by ~20x with zstd.
Add support for writing zstd-compressed time-trace output directly using LLVM's
existing llvm::compression facilities:
- Extend llvm::timeTraceProfilerInitialize and llvm::timeTraceProfilerWrite to
support DebugCompressionType and infer zstd compression from .zst/.zstd file
extensions via llvm::inferTimeTraceCompressionFromPath.
- Add -ftime-trace-compress and -ftime-trace-compress= driver and
CC1 options to explicitly control compression regardless of output filename.
- Update default output filename inference when -ftime-trace is used without an
explicit filename so compressed traces use a .json.zst extension.
Assisted-by: Antigravity with Gemini
---
.../clang/Basic/DiagnosticDriverKinds.td | 2 +
.../include/clang/Frontend/FrontendOptions.h | 5 ++
clang/include/clang/Options/Options.td| 11 +++
clang/lib/Driver/Driver.cpp | 18 -
clang/lib/Driver/ToolChains/Clang.cpp | 26 +++
clang/lib/Frontend/CompilerInvocation.cpp | 5 ++
clang/test/Driver/compress-zstd.c | 4 +
clang/test/Driver/ftime-trace.cpp | 11 ++-
clang/tools/driver/cc1_main.cpp | 7 +-
llvm/include/llvm/Support/TimeProfiler.h | 13 +++-
llvm/lib/Support/TimeProfiler.cpp | 74 +--
llvm/unittests/Support/TimeProfilerTest.cpp | 28 +++
12 files changed, 186 insertions(+), 18 deletions(-)
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index df6ff0c2cf399..369fbef8d0c85 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -564,6 +564,8 @@ def warn_incompatible_sysroot : Warning<"using sysroot for
'%0' but targeting '%
InGroup>;
def warn_debug_compression_unavailable : Warning<"cannot compress debug
sections (%0 not enabled)">,
InGroup>;
+def err_drv_time_trace_compression_unavailable
+: Error<"cannot compress time trace (%0 not enabled)">;
def warn_drv_disabling_vptr_no_rtti_default : Warning<
"implicitly disabling vptr sanitizer because rtti wasn't enabled">,
InGroup;
diff --git a/clang/include/clang/Frontend/FrontendOptions.h
b/clang/include/clang/Frontend/FrontendOptions.h
index b85cf4c007862..701c8d75fe61f 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -16,6 +16,7 @@
#include "clang/Serialization/ModuleFileExtension.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/Support/Compression.h"
#include "llvm/Support/MemoryBuffer.h"
#include
#include
@@ -543,6 +544,10 @@ class FrontendOptions {
LLVM_PREFERRED_TYPE(bool)
unsigned TimeTraceVerbose : 1;
+ /// Compression format for -ftime-trace output.
+ llvm::DebugCompressionType TimeTraceCompress =
+ llvm::DebugCompressionType::None;
+
/// Path which stores the output files for -ftime-trace
std::string TimeTracePath;
diff --git a/clang/include/clang/Options/Options.td
b/clang/include/clang/Options/Options.td
index 60ae84cb0af5c..1d867223b9b68 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -4822,6 +4822,17 @@ def ftime_trace_verbose : Joined<["-"],
"ftime-trace-verbose">, Group,
HelpText<"Make time trace capture verbose event details (e.g. source
filenames). This can increase the size of the output by 2-3 times">,
Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
MarshallingInfoFlag>;
+def ftime_trace_compress_EQ :
