DriveWorks SDK Reference
5.16.65 Release
For Test and Development only

Trace.hpp
Go to the documentation of this file.
1
2//
3// Notice
4// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES
5// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
6// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT,
7// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8//
9// NVIDIA CORPORATION & AFFILIATES assumes no responsibility for the consequences of use of such
10// information or for any infringement of patents or other rights of third parties that may
11// result from its use. No license is granted by implication or otherwise under any patent
12// or patent rights of NVIDIA CORPORATION & AFFILIATES. No third party distribution is allowed unless
13// expressly authorized by NVIDIA. Details are subject to change without notice.
14// This code supersedes and replaces all information previously supplied.
15// NVIDIA CORPORATION & AFFILIATES products are not authorized for use as critical
16// components in life support devices or systems without express written approval of
17// NVIDIA CORPORATION & AFFILIATES.
18//
19// SPDX-FileCopyrightText: Copyright (c) 2016-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
20// SPDX-License-Identifier: LicenseRef-NvidiaProprietary
21//
22// NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
23// property and proprietary rights in and to this material, related
24// documentation and any modifications thereto. Any use, reproduction,
25// disclosure or distribution of this material and related documentation
26// without an express license agreement from NVIDIA CORPORATION or
27// its affiliates is strictly prohibited.
28//
30
31#ifndef DWTRACE_TRACE_HPP_
32#define DWTRACE_TRACE_HPP_
33
34// Trace Public header file
36
37namespace dw
38{
39namespace trace
40{
41static constexpr char8_t const* DW_TRACE_STR_TAG{"[TRACE]: "};
42static constexpr uint64_t DW_TRACE_CHAN_MASK_NONE{0};
43static constexpr uint64_t DW_TRACE_CHAN_ENABLE_ALL{(0xFFFFFFFF)};
44// coverity[autosar_cpp14_a8_5_2_violation] FP: nvbugs/3904083
45static const auto DW_TRACE_CHAN_MASK = [](uint32_t const idx) { return (1U << idx); };
46
54static constexpr size_t DW_TRACE_MAX_CUDA_EVENTS{425};
55
62
66static constexpr uint32_t DW_TRACE_FLUSH_INTERVAL_DEFAULT{5500};
67
72static constexpr uint32_t DW_TRACE_MAX_FILE_SIZE_MB{8192};
73
79{
80 // Enable tracing.
81 bool enabled = false;
82 // File path where Trace*.txt will be stored if fileBackend is enabled.
84 // DWTrace supports total 32 channels. Following mask allows to enable/
85 // disable specific channels.
86 uint64_t channelMask = 0;
87 // Enable filebased backend. For this backend post processing
88 // script dwTrace.py is needed to infer results.
89 bool fileBackendEnabled = false;
90 // Max file size of generated filebackend based dwtrace.
91 // After this file limit reached log rotation will start.
92 uint32_t maxFileSizeMB = 0;
93 // Enable network socket backend. For this backend post processing
95 // customer's ipAddr
97 // customer's serverPort
98 uint16_t serverPort = 0;
99 // Enable NVTx backend.
100 bool nvtxBackendEnabled = false;
101 // Global tracing level, any trace which has level greater than this
102 // level will be ignored.
104 // Number of frames after which flusing to backend will be called.
105 uint32_t flushInterval = 0;
106 // Enable ftrace backend.
108 // Enable memory usage trace
109 bool memTraceEnabled = false;
110 // Enable memory usage trace outside of STARTUP channel
111 bool fullMemUsage = false;
112 // Enable disk io usage(read/write bytes, io delay total) trace. Disk IO operation
113 // mainly happens when running application after boot. After that data is cached(Depends upon OS and System memory)
114 // For now this info will be dumped for STARTUP channels BEGIN/END, as it is expected that major IO operation happens during program init phase.
115 bool diskIOStatsEnabled = false;
116 // Start time of roadrunner
118 // Create Cuda Events
119 bool createCudaEvents = true;
120
121 TracerConfig() = default;
122 TracerConfig(bool const enabledFlag, char8_t const* const fileLoc, uint64_t const chanMask,
123 bool const fileBackendFlag, uint32_t const fileSize, bool const networkBackendFlag, char8_t const* const ipAddress,
124 uint16_t const portNum, bool const nvtxBackendFlag, uint32_t const traceLevel,
125 uint32_t const flushEpoch, bool const ftraceFlag, bool const memTraceFlag, bool const fullMemUse, bool const diskIOStats,
126 char8_t const* const start = nullptr, bool const& createCudaEventsFlag = true)
127 : enabled(enabledFlag), filePath(fileLoc), channelMask(chanMask), fileBackendEnabled(fileBackendFlag), maxFileSizeMB(fileSize), networkBackendEnabled(networkBackendFlag), ipAddr(ipAddress), serverPort(portNum), nvtxBackendEnabled(nvtxBackendFlag), tracingLevel(static_cast<Level>(traceLevel)), flushInterval((flushEpoch > DW_TRACE_MAX_NUM_EVENTS_PER_CHAN) ? DW_TRACE_MAX_NUM_EVENTS_PER_CHAN : flushEpoch), ftraceBackendEnabled(ftraceFlag), memTraceEnabled(memTraceFlag), fullMemUsage(fullMemUse), diskIOStatsEnabled(diskIOStats), startTime(start), createCudaEvents(createCudaEventsFlag)
128 {
129 }
130};
131} // namespace trace
132} // namespace dw
133
134// Supports up to 5 layers of Concatenation
135#ifdef DW_USE_TRACE
136#include <dwtrace/dw/trace/core/TraceImpl.hpp>
137#include <dwtrace/dw/trace/wrapper/TraceWrapper.hpp>
138
139namespace dw
140{
141namespace trace
142{
143#define DW_TRACE_GET_MACRO_2(_1, _2, NAME, ...) NAME
144#define DW_TRACE_GET_MACRO_5(_1, _2, _3, _4, _5, NAME, ...) NAME
145
146#define DW_TRACE_TAG(...) \
147 dw::trace::dwtFixedString_t(DW_TRACE_GET_MACRO_5(__VA_ARGS__, DW_TRACE_TAG5, DW_TRACE_TAG4, DW_TRACE_TAG3, DW_TRACE_TAG2, DW_TRACE_TAG1)(__VA_ARGS__))
148#define DW_TRACE_TAG1(STR1) (STR1)
149#define DW_TRACE_TAG2(STR1, STR2) (STR1 "@" STR2)
150#define DW_TRACE_TAG3(STR1, STR2, STR3) (STR1 ":" STR2 "@" STR3)
151#define DW_TRACE_TAG4(STR1, STR2, STR3, STR4) (STR1 ":" STR2 ":" STR3 "@" STR4)
152#define DW_TRACE_TAG5(STR1, STR2, STR3, STR4, STR5) (STR1 ":" STR2 ":" STR3 ":" STR4 "@" STR5)
153
154#define DW_TRACE_PAYLOAD(...) \
155 DW_TRACE_GET_MACRO_2(__VA_ARGS__, DW_TRACE_PAYLOAD2, DW_TRACE_PAYLOAD1) \
156 (__VA_ARGS__)
157#define DW_TRACE_PAYLOAD1(STR1) dw::trace::singlePayload(STR1)
158static inline dwtFixedString_t singlePayload(char8_t const* const str1)
159{
160 dwtFixedString_t const str{str1};
161 return str;
162}
163static inline dwtFixedString_t singlePayload(int32_t const i)
164{
165 dwtFixedString_t str{};
166 str += i;
167 return str;
168}
169
170#define DW_TRACE_PAYLOAD2(STR1, STR2) dw::trace::joinPayloadChars(STR1, STR2)
171static inline dwtFixedString_t joinPayloadChars(char8_t const* const str1, char8_t const* const str2)
172{
173 dwtFixedString_t str{str1};
174 str += "@";
175 str += str2;
176 return str;
177}
178
179// Avoid shadow declaration for nested tracing with unique variables
180#define DW_CONCAT_(x, y) x##y
181#define DW_CONCAT(x, y) DW_CONCAT_(x, y)
182#define DW_UNIQUE_VAR(name) DW_CONCAT(name, __LINE__)
183
190#define DW_TRACE_ENABLE(chan_mask, level) dw::trace::dwTraceEnable(chan_mask, level)
191
196#define DW_TRACE_DISABLE(chan_mask) dw::trace::dwTraceDisable(chan_mask)
197
201#define DW_TRACE_ENABLE_ALL() dw::trace::dwTraceEnableAll()
202
210#define DW_TRACE_MARK(...) dw::trace::dwTraceMark(__VA_ARGS__)
211
220#define DW_TRACE_BEGIN(...) dw::trace::dwTraceBegin(__VA_ARGS__)
221
230#define DW_TRACE_END(...) dw::trace::dwTraceEnd(__VA_ARGS__)
231
241#define DW_TRACE_ASYNC_BEGIN(...) dw::trace::dwTraceAsyncBegin(__VA_ARGS__)
242
250#define DW_TRACE_ASYNC_END(...) dw::trace::dwTraceAsyncEnd(__VA_ARGS__)
251
261#define DW_TRACE_CUDA_BEGIN(...) dw::trace::dwTraceCudaBegin(__VA_ARGS__)
262
271#define DW_TRACE_CUDA_END(...) dw::trace::dwTraceCudaEnd(__VA_ARGS__)
272
282#define DW_TRACE_CUDA_BEGIN_ASYNC(...) DW_TRACE_CUDA_BEGIN(__VA_ARGS__)
283
292#define DW_TRACE_CUDA_RECORD_ASYNC(...) dw::trace::dwTraceCudaRecordAsync(__VA_ARGS__)
293
310#define DW_TRACE_CUDA_COLLECT_ASYNC(...) dw::trace::dwTraceCudaCollectAsync(__VA_ARGS__)
311
324#define DW_TRACE_CUDA_COLLECT_ALL() dw::trace::dwTraceCudaCollectAll()
325
334#define DW_TRACE_CORE_INIT(...) dw::trace::dwTraceCoreInit(__VA_ARGS__)
335
342#define DW_TRACE_INIT(...) \
343 if (!dw::trace::isDWTracingEnabled()) \
344 { \
345 dw::trace::dwTraceCoreInit(__VA_ARGS__); \
346 dw::trace::dwTraceWrapperInit(__VA_ARGS__); \
347 }
348
352#define DW_TRACE_RESET(...) \
353 dw::trace::dwTraceReset(__VA_ARGS__); \
354 if (!dw::trace::isDWTracingEnabled()) \
355 { \
356 dw::trace::dwTraceWrapperDeinit(__VA_ARGS__); \
357 }
358
362#define DW_TRACE_RESET_WRAPPER(...) \
363 dw::trace::dwTraceWrapperReset(__VA_ARGS__);
364
365#define DW_TRACE_BIND_OUTPUT(...) dw::trace::dwTraceBindOutput(__VA_ARGS__)
366
367#define DW_TRACE_REGISTER_CB(...) dw::trace::dwTraceRegisterCallback(__VA_ARGS__)
374#define DW_TRACE_FLUSH(isForce) dw::trace::dwTraceFlush(isForce)
375
386#define DW_TRACE_SCOPE(...) \
387 dw::trace::CpuScopeTraceEvent DW_UNIQUE_VAR(cpuTraceEvent_){__VA_ARGS__}; \
388 if (dw::trace::isDWTracingEnabled()) \
389 { \
390 dw::trace::dwTraceBegin(__VA_ARGS__); \
391 }
392
404#define DW_TRACE_CUDA_SCOPE(...) \
405 dw::trace::CudaScopeTraceEvent DW_UNIQUE_VAR(cudaTraceEvent_){false, __VA_ARGS__}; \
406 if (dw::trace::isDWTracingEnabled()) \
407 { \
408 dw::trace::dwTraceCudaBegin(__VA_ARGS__); \
409 }
410
422#define DW_TRACE_CUDA_SCOPE_ASYNC(...) \
423 dw::trace::CudaScopeTraceEvent DW_UNIQUE_VAR(cudaTraceEvent_){true, __VA_ARGS__}; \
424 if (dw::trace::isDWTracingEnabled()) \
425 { \
426 dw::trace::dwTraceCudaBegin(__VA_ARGS__); \
427 }
428
435#ifdef __QNX__
436#define DW_TRACE_BOOT_PROFILER(msg) dw::trace::dwTraceBootProfiler(msg)
437#else
438#define DW_TRACE_BOOT_PROFILER(msg)
439#endif
440
441} // namespace trace
442} // namespace dw
443
444#else
445
446namespace dw
447{
448namespace trace
449{
450#define DW_TRACE_TAG(...)
451#define DW_TRACE_PAYLOAD(...)
452#define DW_TRACE_INIT(...)
453#define DW_TRACE_ENABLED(chan_mask, level)
454#define DW_TRACE_DISABLED(chan_mask)
455#define DW_TRACE_BIND_OUTPUT(...)
456#define DW_TRACE_REGISTER_CB(...)
457#define DW_UNIQUE_VAR(name)
458#define DW_TRACE_MARK(...)
459#define DW_TRACE_BEGIN(...)
460#define DW_TRACE_END(...)
461#define DW_TRACE_SCOPE(...)
462#define DW_TRACE_ASYNC_BEGIN(...)
463#define DW_TRACE_ASYNC_END(...)
464#define DW_TRACE_FLUSH(isForce)
465#define DW_TRACE_CUDA_BEGIN(...)
466#define DW_TRACE_CUDA_END(...)
467#define DW_TRACE_CUDA_BEGIN_ASYNC(...)
468#define DW_TRACE_CUDA_RECORD_ASYNC(...)
469#define DW_TRACE_CUDA_COLLECT_ASYNC(...)
470#define DW_TRACE_CUDA_SCOPE(...)
471#define DW_TRACE_CUDA_SCOPE_ASYNC(...)
472#define DW_TRACE_BOOT_PROFILER(msg)
473
474} // namespace trace
475} // namespace dw
476#endif
477
478namespace dw
479{
480namespace trace
481{
482
483// advertise performance impact of cudaEventBlockingSync (true = use it)
485{
486#ifdef VIBRANTE
487 return true; // Tegra
488#else
489 return false; // x86
490#endif
491}
492
494{
495 return dw::trace::isBlockingSyncPreferred() ? static_cast<uint32_t>(cudaEventBlockingSync) : static_cast<uint32_t>(0U);
496}
497
498} // namespace trace
499} // namespace dw
500
501#endif // DWTRACE_TRACE_HPP_
Level
Tracing can be controlled through tracing levels.
Definition: TraceTypes.hpp:114
static constexpr uint64_t DW_TRACE_CHAN_ENABLE_ALL
Definition: Trace.hpp:43
static constexpr uint64_t DW_TRACE_CHAN_MASK_NONE
Definition: Trace.hpp:42
static constexpr uint32_t DW_TRACE_FLUSH_INTERVAL_DEFAULT
Default number of channel traces before flush.
Definition: Trace.hpp:66
static constexpr Level DW_TRACE_LEVEL_DEFAULT
If not sure about tracing level at the time of using DWTrace API, then use default trace level.
Definition: Trace.hpp:61
uint32_t getPreferredBlockingFlags()
Definition: Trace.hpp:493
static constexpr size_t DW_TRACE_MAX_CUDA_EVENTS
Cuda events are required for measuring execution time on GPU/DLA.
Definition: Trace.hpp:54
static constexpr uint32_t DW_TRACE_MAX_NUM_EVENTS_PER_CHAN
Definition: TraceTypes.hpp:48
dw::core::FixedString< DW_TRACE_MAX_TAG_SIZE > dwtFixedString_t
Definition: TraceTypes.hpp:54
bool isBlockingSyncPreferred()
Definition: Trace.hpp:484
dw::core::FixedString< 384 > dwtStringFilepath_t
Definition: TraceTypes.hpp:55
static constexpr char8_t const * DW_TRACE_STR_TAG
Definition: Trace.hpp:41
static constexpr uint32_t DW_TRACE_MAX_FILE_SIZE_MB
Default Max file size of generate DWTrace in MBs.
Definition: Trace.hpp:72
dw::core::FixedString< 16 > dwtStringIPAddr_t
Definition: TraceTypes.hpp:56
static const auto DW_TRACE_CHAN_MASK
Definition: Trace.hpp:45
DWTrace initialisation and configuration structure.
Definition: Trace.hpp:79
uint32_t maxFileSizeMB
Definition: Trace.hpp:92
TracerConfig(bool const enabledFlag, char8_t const *const fileLoc, uint64_t const chanMask, bool const fileBackendFlag, uint32_t const fileSize, bool const networkBackendFlag, char8_t const *const ipAddress, uint16_t const portNum, bool const nvtxBackendFlag, uint32_t const traceLevel, uint32_t const flushEpoch, bool const ftraceFlag, bool const memTraceFlag, bool const fullMemUse, bool const diskIOStats, char8_t const *const start=nullptr, bool const &createCudaEventsFlag=true)
Definition: Trace.hpp:122
dwtStringIPAddr_t ipAddr
Definition: Trace.hpp:96
dwtStringFilepath_t filePath
Definition: Trace.hpp:83
uint32_t flushInterval
Definition: Trace.hpp:105
uint64_t channelMask
Definition: Trace.hpp:86
dwtFixedString_t startTime
Definition: Trace.hpp:117