Contur 2
Educational OS kernel simulator
Loading...
Searching...
No Matches
trace_scope.h
Go to the documentation of this file.
1
3
4#pragma once
5
6#include <string_view>
7
9
10namespace contur {
11
13 class TraceScope final
14 {
15 public:
20 TraceScope(ITracer &tracer, std::string_view subsystem, std::string_view operation)
21 : tracer_(tracer)
22 , active_(true)
23 {
24 tracer_.pushScope(subsystem, operation);
25 }
26
29 {
30 if (active_)
31 {
32 tracer_.popScope();
33 }
34 }
35
37 TraceScope(const TraceScope &) = delete;
38
40 TraceScope &operator=(const TraceScope &) = delete;
42 TraceScope(TraceScope &&) = delete;
43
46
47 private:
49 bool active_;
50 };
51
52} // namespace contur
53
54#ifdef CONTUR_TRACE_ENABLED
55#define CONTUR_TRACE_SCOPE(tracer, subsystem, operation) \
56 ::contur::TraceScope contur_trace_scope_##__LINE__((tracer), (subsystem), (operation))
57#define CONTUR_TRACE_BLOCK(code) \
58 do \
59 { \
60 code \
61 } while (0)
62#define CONTUR_TRACE_L(tracer, level, subsystem, operation, details) \
63 (tracer).trace( \
64 ::contur::makeTraceEvent( \
65 (tracer).clock().now(), (subsystem), (operation), (details), (tracer).currentDepth(), (level) \
66 ) \
67 )
68#define CONTUR_TRACE(tracer, subsystem, operation, details) \
69 CONTUR_TRACE_L((tracer), ::contur::TraceLevel::Info, (subsystem), (operation), (details))
70#else
71#define CONTUR_TRACE_SCOPE(tracer, subsystem, operation) ((void)0)
72#define CONTUR_TRACE_BLOCK(code) ((void)0)
73#define CONTUR_TRACE_L(tracer, level, subsystem, operation, details) ((void)0)
74#define CONTUR_TRACE(tracer, subsystem, operation, details) ((void)0)
75#endif
Tracer interface used by kernel subsystems.
Definition i_tracer.h:17
TraceScope & operator=(const TraceScope &)=delete
Copy assignment is disabled.
TraceScope(ITracer &tracer, std::string_view subsystem, std::string_view operation)
Constructs a nested tracing scope.
Definition trace_scope.h:20
~TraceScope()
Destroys scope and pops nesting level.
Definition trace_scope.h:28
TraceScope(TraceScope &&)=delete
Move construction is disabled.
TraceScope(const TraceScope &)=delete
Copy construction is disabled.
TraceScope & operator=(TraceScope &&)=delete
Move assignment is disabled.
Tracer interface for hierarchical event tracing.
Definition block.h:15