Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
TimingTrace.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Debug_TimingTrace_h_
5#define _Stroika_Foundation_Debug_TimingTrace_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
10#include "Stroika/Foundation/Execution/WhenTimeExceeded.h"
11
12/**
13 * \file
14 *
15 * \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
16 *
17 */
18
19namespace Stroika::Foundation::Debug {
20
21 /**
22 * Simple utility to print debug trace timing values for procedures (or contexts).
23 *
24 * \par Example Usage
25 * \code
26 * {
27 * TimingTrace ttrc;
28 * do_some_call();
29 * }
30 * \endcode
31 * \code
32 * OUTPUT IN TRACELOG:
33 * (timeTaken=3.4 seconds)
34 * \endcode
35 *
36 * \par Example Usage
37 * \code
38 * {
39 * TraceContextBumper ctx{"do_some_call"};
40 * TimingTrace ttrc;
41 * do_some_call();
42 * }
43 * \endcode
44 * \code
45 * OUTPUT IN TRACELOG:
46 * <do_some_call>
47 * (timeTaken=3.4 seconds)
48 * </do_some_call>
49 * \endcode
50 *
51 * \note This implementation should mostly disappear when qStroika_Foundation_Debug_DefaultTracingOn is disabled (and so the DbgTrace() calls wouldn't do anything)
52 * To do something like this when when qStroika_Foundation_Debug_DefaultTracingOn is off, see the base class WhenTimeExceeded
53 *
54 * \note Aliases Performance Trace, PerformanceTrace
55 */
57#if qStroika_Foundation_Debug_DefaultTracingOn
59#endif
60 {
61 public:
62 TimingTrace (Time::DurationSeconds warnIfLongerThan = 0s);
63 TimingTrace (const char* label, Time::DurationSeconds warnIfLongerThan = 0s);
64 TimingTrace (const wchar_t* label, Time::DurationSeconds warnIfLongerThan = 0s);
65 TimingTrace (const Characters::String& label, Time::DurationSeconds warnIfLongerThan = 0s);
66
67 public:
68 /**
69 * Optionally suppress logging for a given timing context; for example, if trying to trace failed fetches, call .Suppress() on success and then
70 * you only see log entries for the timing of failed fetches.
71 */
72 nonvirtual void Suppress ();
73
74#if qStroika_Foundation_Debug_DefaultTracingOn
75 private:
76 bool fShowIfTimeExceeded_{true};
77#endif
78 };
79
80}
81
82/*
83 ********************************************************************************
84 ***************************** Implementation Details ***************************
85 ********************************************************************************
86 */
87#include "TimingTrace.inl"
88
89#endif /*_Stroika_Foundation_Debug_TimingTrace_h_*/
chrono::duration< double > DurationSeconds
chrono::duration<double> - a time span (length of time) measured in seconds, but high precision.
Definition Realtime.h:57
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201