Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3704efb

Browse files
cooppCooper Partingithub-actions[bot]
authored
Implement -ftime-trace-granularity option to set time granularity value for the time profiler (microsoft#6381)
This commit adds a new optional -ftime-trace-granularity option that is already implemented in llvm-project. This change is a surgical port of an existing feature from the upstream llvm-project repo into the DXC codebase. The following commits in the llvm-project repo were copied and followed for this change. Clean cherry picks were not possible due to the differences in repos like change of file locations and other dependant changes made in the repo. *** Adds the granularity configuration setting *** 'Time profiler: small fixes and optimizations' Commit: 26536728591d5fdac373ef535ae122b873f73292 *** Wires up the commandline option -ftime-trace-granularity to the TraceProfiler code *** '[Support] Fix -ftime-trace-granularity option' Commit: 4fdcabf259c4ab94654e6cd5d95d0e0313159c70 Fixes microsoft#6372 --------- Signed-off-by: Cooper Partin <[email protected]> Co-authored-by: Cooper Partin <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 359b3e9 commit 3704efb

File tree

9 files changed

+43
-6
lines changed

9 files changed

+43
-6
lines changed

include/dxc/Support/HLSLOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ class DxcOpts {
235235
bool NewInlining = false; // OPT_fnew_inlining_behavior
236236
bool TimeReport = false; // OPT_ftime_report
237237
std::string TimeTrace = ""; // OPT_ftime_trace[EQ]
238+
unsigned TimeTraceGranularity = 500; // OPT_ftime_trace_granularity_EQ
238239
bool VerifyDiagnostics = false; // OPT_verify
239240

240241
// Optimization pass enables, disables and selects

include/dxc/Support/HLSLOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ def ftime_trace : Flag<["-"], "ftime-trace">,
189189
def ftime_trace_EQ : Joined<["-"], "ftime-trace=">,
190190
Group<hlslcomp_Group>, Flags<[CoreOption]>,
191191
HelpText<"Print hierchial time tracing to file">;
192+
def ftime_trace_granularity_EQ : Joined<["-"], "ftime-trace-granularity=">,
193+
Group<hlslcomp_Group>, Flags<[CoreOption]>,
194+
HelpText<"Minimum time granularity (in microseconds) traced by time profiler">;
192195

193196
def verify : Joined<["-"], "verify">,
194197
Group<hlslcomp_Group>, Flags<[CoreOption, DriverOption]>,

include/llvm/Support/TimeProfiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extern TimeTraceProfiler *TimeTraceProfilerInstance;
2121
/// Initialize the time trace profiler.
2222
/// This sets up the global \p TimeTraceProfilerInstance
2323
/// variable to be the profiler instance.
24-
void timeTraceProfilerInitialize();
24+
void timeTraceProfilerInitialize(unsigned TimeTraceGranularity);
2525

2626
/// Cleanup the time trace profiler, if it was initialized.
2727
void timeTraceProfilerCleanup();

lib/DxcSupport/HLSLOptions.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,16 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude,
824824
opts.VerifyDiagnostics = Args.hasFlag(OPT_verify, OPT_INVALID, false);
825825
if (Args.hasArg(OPT_ftime_trace_EQ))
826826
opts.TimeTrace = Args.getLastArgValue(OPT_ftime_trace_EQ);
827+
if (Arg *A = Args.getLastArg(OPT_ftime_trace_granularity_EQ)) {
828+
if (llvm::StringRef(A->getValue())
829+
.getAsInteger(10, opts.TimeTraceGranularity)) {
830+
opts.TimeTraceGranularity = 500;
831+
errors << "Warning: Invalid value for -ftime-trace-granularity option "
832+
"specified, defaulting to "
833+
<< opts.TimeTraceGranularity << " microseconds.";
834+
}
835+
}
836+
827837
opts.EnablePayloadQualifiers =
828838
Args.hasFlag(OPT_enable_payload_qualifiers, OPT_INVALID,
829839
DXIL::CompareVersions(Major, Minor, 6, 7) >= 0);

lib/Support/TimeProfiler.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ struct TimeTraceProfiler {
7777
auto &E = Stack.back();
7878
E.Duration = steady_clock::now() - E.Start;
7979

80-
// Only include sections longer than 500us.
81-
if (duration_cast<microseconds>(E.Duration).count() > 500)
80+
// Only include sections longer than TimeTraceGranularity msec.
81+
if (duration_cast<microseconds>(E.Duration).count() > TimeTraceGranularity)
8282
Entries.emplace_back(E);
8383

8484
// Track total time taken by each "name", but only the topmost levels of
@@ -146,12 +146,16 @@ struct TimeTraceProfiler {
146146
std::unordered_map<std::string, DurationType> TotalPerName;
147147
std::unordered_map<std::string, size_t> CountPerName;
148148
time_point<steady_clock> StartTime;
149+
150+
// Minimum time granularity (in microseconds)
151+
unsigned TimeTraceGranularity;
149152
};
150153

151-
void timeTraceProfilerInitialize() {
154+
void timeTraceProfilerInitialize(unsigned TimeTraceGranularity) {
152155
assert(TimeTraceProfilerInstance == nullptr &&
153156
"Profiler should not be initialized");
154157
TimeTraceProfilerInstance = new TimeTraceProfiler();
158+
TimeTraceProfilerInstance->TimeTraceGranularity = TimeTraceGranularity;
155159
}
156160

157161
void timeTraceProfilerCleanup() {

tools/clang/include/clang/Frontend/CodeGenOptions.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ CODEGENOPT(StrictEnums , 1, 0) ///< Optimize based on strict enum definiti
132132
CODEGENOPT(TimePasses , 1, 0) ///< Set when -ftime-report is enabled.
133133
CODEGENOPT(TimeTrace , 1, 0) ///< HLSL Change:
134134
///< Set when -ftime-trace is enabled.
135+
VALUE_CODEGENOPT(TimeTraceGranularity, 32, 500) ///< HLSL Change:
136+
///< Set when -ftime_trace_granularity is set.
135137
CODEGENOPT(UnitAtATime , 1, 1) ///< Unused. For mirroring GCC optimization
136138
///< selection.
137139
CODEGENOPT(UnrollLoops , 1, 0) ///< Control whether loops are unrolled.

tools/clang/include/clang/Frontend/FrontendOptions.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,11 @@ class FrontendOptions {
254254
/// \brief File name of the file that will provide record layouts
255255
/// (in the format produced by -fdump-record-layouts).
256256
std::string OverrideRecordLayoutsFile;
257-
257+
258+
/// If given, the minimum time granularity (in microseconds) traced by
259+
/// time profiler is set to this value.
260+
unsigned TimeTraceGranularity;
261+
258262
public:
259263
FrontendOptions() :
260264
DisableFree(false), RelocatablePCH(false), ShowHelp(false),
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %dxc -E main -T vs_6_0 %s -ftime-trace -ftime-trace-granularity=99999 | FileCheck %s
2+
// RUN: %dxc -E main -T vs_6_0 %s -ftime-trace=%t.json -ftime-trace-granularity=99999
3+
// RUN: cat %t.json | FileCheck %s
4+
5+
// This test runs both stdout and file output paths.
6+
// Validate that we do not output named stats
7+
// but still continue to output the Totals
8+
// versions of them which is expected.
9+
// CHECK: { "traceEvents": [
10+
// CHECK-NOT: "name":"Frontend"
11+
// CHECK: "name":"Total Frontend"
12+
13+
void main() {}

tools/clang/tools/dxcompiler/dxcompilerobj.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1805,7 +1805,7 @@ HRESULT DxcCompilerAdapter::WrapCompile(
18051805
dxcutil::ReadOptsAndValidate(mainArgs, opts, pOutputStream,
18061806
&pOperationResult, finished);
18071807
if (!opts.TimeTrace.empty())
1808-
llvm::timeTraceProfilerInitialize();
1808+
llvm::timeTraceProfilerInitialize(opts.TimeTraceGranularity);
18091809
if (finished) {
18101810
IFT(pOperationResult->QueryInterface(ppResult));
18111811
return S_OK;

0 commit comments

Comments
 (0)