3#ifndef CESIUM_OVERRIDE_TRACING
7#ifndef CESIUM_TRACING_ENABLED
8#define CESIUM_TRACING_ENABLED 0
11#if !CESIUM_TRACING_ENABLED
13#define CESIUM_TRACE_INIT(filename)
14#define CESIUM_TRACE_SHUTDOWN()
15#define CESIUM_TRACE(name)
16#define CESIUM_TRACE_BEGIN(name)
17#define CESIUM_TRACE_END(name)
18#define CESIUM_TRACE_BEGIN_IN_TRACK(name)
19#define CESIUM_TRACE_END_IN_TRACK(name)
20#define CESIUM_TRACE_DECLARE_TRACK_SET(id, name)
21#define CESIUM_TRACE_USE_TRACK_SET(id)
22#define CESIUM_TRACE_LAMBDA_CAPTURE_TRACK() tracingTrack = false
23#define CESIUM_TRACE_USE_CAPTURED_TRACK()
36#define TRACE_NAME_AUX1(A, B) A##B
37#define TRACE_NAME_AUX2(A, B) TRACE_NAME_AUX1(A, B)
45#define CESIUM_TRACE_INIT(filename) \
46 CesiumUtility::CesiumImpl::Tracer::instance().startTracing(filename)
51#define CESIUM_TRACE_SHUTDOWN() \
52 CesiumUtility::CesiumImpl::Tracer::instance().endTracing()
64#define CESIUM_TRACE(name) \
65 CesiumUtility::CesiumImpl::ScopedTrace TRACE_NAME_AUX2( \
100#define CESIUM_TRACE_BEGIN(name) \
101 CesiumUtility::CesiumImpl::Tracer::instance().writeAsyncEventBegin(name)
112#define CESIUM_TRACE_END(name) \
113 CesiumUtility::CesiumImpl::Tracer::instance().writeAsyncEventEnd(name)
125#define CESIUM_TRACE_BEGIN_IN_TRACK(name) \
126 if (CesiumUtility::CesiumImpl::TrackReference::current() != nullptr) { \
127 CESIUM_TRACE_BEGIN(name); \
140#define CESIUM_TRACE_END_IN_TRACK(name) \
141 if (CesiumUtility::CesiumImpl::TrackReference::current() != nullptr) { \
142 CESIUM_TRACE_END(name); \
159#define CESIUM_TRACE_DECLARE_TRACK_SET(id, name) \
160 CesiumUtility::CesiumImpl::TrackSet id { name }
173#define CESIUM_TRACE_USE_TRACK_SET(id) \
174 CesiumUtility::CesiumImpl::TrackReference TRACE_NAME_AUX2( \
175 cesiumTraceEnlistTrack, \
187#define CESIUM_TRACE_LAMBDA_CAPTURE_TRACK() \
188 tracingTrack = CesiumUtility::CesiumImpl::LambdaCaptureTrack()
197#define CESIUM_TRACE_USE_CAPTURED_TRACK() \
198 CESIUM_TRACE_USE_TRACK_SET(tracingTrack)
201namespace CesiumImpl {
210 std::thread::id threadID;
217 static Tracer& instance();
221 void startTracing(
const std::string& filePath =
"trace.json");
224 void writeCompleteEvent(
const Trace& trace);
225 void writeAsyncEventBegin(
const char* name, int64_t
id);
226 void writeAsyncEventBegin(
const char* name);
227 void writeAsyncEventEnd(
const char* name, int64_t
id);
228 void writeAsyncEventEnd(
const char* name);
230 int64_t allocateTrackID();
235 int64_t getCurrentThreadTrackID()
const;
236 void writeAsyncEvent(
237 const char* category,
242 std::ofstream _output;
245 std::atomic<int64_t> _lastAllocatedID;
250 explicit ScopedTrace(
const std::string& message);
255 ScopedTrace(
const ScopedTrace& rhs) =
delete;
256 ScopedTrace(ScopedTrace&& rhs) =
delete;
257 ScopedTrace& operator=(
const ScopedTrace& rhs) =
delete;
258 ScopedTrace& operator=(ScopedTrace&& rhs) =
delete;
262 std::chrono::steady_clock::time_point _startTime;
263 std::thread::id _threadId;
269 explicit TrackSet(
const char* name);
272 size_t acquireTrack();
273 void addReference(
size_t trackIndex)
noexcept;
274 void releaseReference(
size_t trackIndex)
noexcept;
276 int64_t getTracingID(
size_t trackIndex)
noexcept;
278 TrackSet(TrackSet&& rhs)
noexcept;
279 TrackSet& operator=(TrackSet&& rhs)
noexcept;
283 Track(int64_t id_,
bool inUse_)
284 : id(id_), referenceCount(0), inUse(inUse_) {}
287 int32_t referenceCount;
292 std::vector<Track> tracks;
296class LambdaCaptureTrack {
298 LambdaCaptureTrack();
299 LambdaCaptureTrack(LambdaCaptureTrack&& rhs)
noexcept;
300 LambdaCaptureTrack(
const LambdaCaptureTrack& rhs)
noexcept;
301 ~LambdaCaptureTrack();
302 LambdaCaptureTrack& operator=(
const LambdaCaptureTrack& rhs)
noexcept;
303 LambdaCaptureTrack& operator=(LambdaCaptureTrack&& rhs)
noexcept;
309 friend class TrackReference;
315class TrackReference {
317 static TrackReference* current();
319 TrackReference(TrackSet& set)
noexcept;
320 TrackReference(TrackSet& set,
size_t index)
noexcept;
321 TrackReference(
const LambdaCaptureTrack& lambdaCapture)
noexcept;
322 ~TrackReference() noexcept;
324 operator
bool() const noexcept;
325 int64_t getTracingID() const noexcept;
327 TrackReference(const TrackReference& rhs) = delete;
328 TrackReference(TrackReference&& rhs) = delete;
329 TrackReference& operator=(const TrackReference& rhs) = delete;
330 TrackReference& operator=(TrackReference&& rhs) = delete;
333 void enlistCurrentThread();
334 void dismissCurrentThread();
339 static thread_local
std::vector<TrackReference*> _threadEnlistedTracks;
341 friend class LambdaCaptureTrack;
Utility classes for Cesium.