Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Trace.h File Reference
#include "Stroika/Foundation/StroikaPreComp.h"
#include <array>
#include <span>
#include <thread>
#include "Stroika/Foundation/Common/Common.h"
#include "Stroika/Foundation/Debug/CompileTimeFlagChecker.h"
#include "Stroika/Foundation/Time/Realtime.h"
#include "Trace.inl"

Go to the source code of this file.

Classes

class  Stroika::Foundation::Debug::TraceContextBumper
 
class  Stroika::Foundation::Debug::TraceContextSuppressor
 

Namespaces

namespace  Stroika::Foundation
 
namespace  Stroika::Foundation::Characters
 

Macros

#define qStroika_Foundation_Debug_TraceToFile   0
 
#define qStroika_Foundation_Debug_ShowThreadIndex   1
 if true, emit a much shorter thread ID, making - I suspect (testing) for terser and clearer tracelogs. Only downside is that you must find first occurrence of that index to find real threadId, and use that in waits, etc.
 
#define Stroika_Foundation_Debug_OptionalizeTraceArgs(...)
 
#define DbgTrace   _NoOp_
 

Functions

wstring Stroika::Foundation::Debug::GetDbgTraceThreadName (thread::id threadID)
 

Detailed Description

Note
Code-Status: Beta

Definition in file Trace.h.

Macro Definition Documentation

◆ qStroika_Foundation_Debug_TraceToFile

#define qStroika_Foundation_Debug_TraceToFile   0

If qStroika_Foundation_Debug_TraceToFile is set true, then DbgTrace () and other Trace calls all go both to the usual debugger output screen, and to an auto-generated logfile.

This can be handy for building a version of code to hand to customers with an irreproducible bug to get a detailed report of what happened. Its also handy for embedded or timing sensative programs where capturing the log of exactly what happened is helpful.

Definition at line 45 of file Trace.h.

◆ qStroika_Foundation_Debug_ShowThreadIndex

#define qStroika_Foundation_Debug_ShowThreadIndex   1

if true, emit a much shorter thread ID, making - I suspect (testing) for terser and clearer tracelogs. Only downside is that you must find first occurrence of that index to find real threadId, and use that in waits, etc.

This is defined as a #define, so you can turn it off when building Stroika. I'm unsure if the showing of thread indexes helps readability of the tracelog, but I think it does.

This is somewhat helpful on windows, but much more so on 64-bit linux with very long fairly random looking thread ids.

Definition at line 83 of file Trace.h.

◆ Stroika_Foundation_Debug_OptionalizeTraceArgs

#define Stroika_Foundation_Debug_OptionalizeTraceArgs (   ...)

This is meant to be used with the 2+ argument Debug::TraceContextBumper constructor (_f format string), to optionally suppress side-effects of trace arguments when tracing is disabled (at compile time).

Note
this may still be useful in Stroika v3 and later, but was mostly useful in before, switching to use of variadic templates, since now the compiler can see the variadic and format parameters are unused for anything, so probably is able to optimize them away.

Definition at line 270 of file Trace.h.

◆ DbgTrace

#define DbgTrace   _NoOp_

This function either does NOTHING (trying to not even evaluate its arguments) or does a printf style PRINT function by delegating to @'EmitTraceMessage'. Which of these two behaviors you see is conditioned on @'qStroika_Foundation_Debug_DefaultTracingOn'

Note
Not Cancelation Point - and uses noexcept So you can call this freely without worrying about Throw (ThreadAbortException) etc (though beware of passing arguments to DbgTrace() which may be cancelation points)
- DbgTrace can take either printf style format strings, or _f format strings.
Example Usage
auto url = IO::Network::URI{"http://www.sophists.com"};
DbgTrace ("u = {}"_f, url); // output "u = 'http://www.sophists.com'"
#define DbgTrace
Definition Trace.h:309

template <typename CHAR_T, typename... Args> nonvirtual void DbgTrace (Characters::FormatString<CHAR_T> fmt, Args&&... args) noexcept { or some such try { Stroika::Foundation::Debug::Private_::Emitter::Get ().EmitTraceMessage (fmt.get (), Common::StdCompat::make_wformat_args (args...)); } catch (...) { } } but only after 'd' stage development so I can lose C-style FMT string overloads...

Definition at line 309 of file Trace.h.

Function Documentation

◆ GetDbgTraceThreadName()

wstring Stroika::Foundation::Debug::GetDbgTraceThreadName ( thread::id  threadID)

Just for debugging purposes, get the name displayed in the trace log for the given thread-id.

Definition at line 619 of file Trace.cpp.