C++ TargetRTS
Loading...
Searching...
No Matches
RTTracer.h
1/*******************************************************************************
2 * Licensed Materials - Property of HCL
3 * (c) Copyright HCL Technologies Ltd. 2025. All Rights Reserved.
4 *******************************************************************************/
5#ifndef __RTTracer_h__
6#define __RTTracer_h__ included
7
8#include <fstream>
9#include <string>
10#include <RTJsonResult.h>
11#include <RTStreamBuffer.h>
12#if RTUseCPP11
13#include <chrono>
14#endif
15
16class RTActor;
17class RTMessage;
18class RTProtocol;
19
20class RTTracer: public RTStreamBuffer {
21public:
25 static RTS_INLINE void flushTrace(void);
26
30 static RTS_INLINE bool isEnabled(void);
31
39 static void setEnabled(bool);
40
45 static bool configure(const char* configFile = nullptr);
46
50 static RTS_INLINE bool isConfigured(void);
51
55 static RTS_INLINE void note(const char* text);
56
61 Initialize, // Synchronous initialization of parts
62 Send, // Asynchronous send of a message
63 Invoke, // Synchronous invoke of a message (explicit reply)
64 InvokeWithoutReply, // Synchronous invoke of a message (implicit reply)
65 Reply, // Synchronous reply of a message
66 Pause, // Pause tracing
67 Flush // Flush the trace file
68 };
69
70#if RTUseCPP11
74 typedef std::chrono::system_clock::time_point TraceTime;
75#endif
76
80 struct TraceInfo {
81 const RTActor* sender;
82 const RTProtocol* fromPort;
83 int fromIndex;
84#if RTUseCPP11
85 TraceTime t2;
86#endif
87
88 TraceInfo();
89 };
90
91protected:
92 enum {
93 TIME1 = 0x10, // 0001 0000
94 TIME2 = 0x20, // 0010 0000
95 TIME3 = 0x40, // 0100 0000
96 TIME_ABSOLUTE = 0x80, // 1000 0000
97 PRECISION_MASK = 0x0F, // 0000 1111
98 PRECISION_NANO = 0x09, // 0000 1001
99 PRECISION_MICRO = 0x06, // 0000 0110
100 PRECISION_MILLI = 0x03 // 0000 0011
101 };
102 static bool _enabled;
103 static RTJsonResult jsonConfig;
104 static bool _configured;
105 static std::string _applicationName; // Name of traced application
106 static std::string _traceFileName; // Name of generated trace file
107 static bool _overwriteFile;
108
109#if RTUseCPP11
110 static TraceTime _start;
111 static int _timestamps;
112 void printTimestamp(const TraceTime& timestamp);
113#endif
114
115 std::string _traceFile;
116 std::ofstream _file;
117
118 RTTracer(void);
119 ~RTTracer(void);
120
121 static RTTracer& instance();
122
123 static std::string initTraceFile(void);
124
125 static void getSenderInfo(const RTMessage*, TraceInfo*);
126
127 static RTS_INLINE void traceMS(const RTMessage*, TraceEventKind traceEventKind, const TraceInfo* = nullptr);
128
129 void traceMessage(const RTMessage*, TraceEventKind traceEventKind, const TraceInfo*);
130 void traceNote(const char* text);
131 void traceNote_nolock(const char* text);
132 int flush(void) override;
133
134 friend class RTActor;
135 friend class RTMessage;
136 friend class RTProtocol;
137};
138
139#define TRACE_TIME1 "time1_send"
140#define TRACE_TIME2 "time2_receive"
141#define TRACE_TIME3 "time3_handle"
142
143#if RTS_INLINES
144#include <RTTracer.inl>
145#endif
146
147#endif
An instance of this class represents a capsule instance.
Definition: RTActor.h:44
Represents the result of parsing a JSON string.
Definition: RTJsonResult.h:30
Represents a message used for communication between capsule instances.
Definition: RTMessage.h:33
Represents a general capsule port typed by a protocol which determines the set of events that can be ...
Definition: RTProtocol.h:50
Definition: RTStreamBuffer.h:22
Definition: RTTracer.h:20
std::chrono::system_clock::time_point TraceTime
Type for storing trace timestamps.
Definition: RTTracer.h:74
static bool isConfigured(void)
Check if tracing has been configured.
Definition: RTTracer.inl:20
static void note(const char *text)
Write a note to the trace.
Definition: RTTracer.inl:36
static bool configure(const char *configFile=nullptr)
Configure RTTracer and tracing preferences.
static void flushTrace(void)
Flush buffered trace messages to file.
Definition: RTTracer.inl:12
static bool isEnabled(void)
Check if tracing is enabled.
Definition: RTTracer.inl:16
TraceEventKind
Types of trace events supported.
Definition: RTTracer.h:60
static void setEnabled(bool)
Enable or disable tracing to file.
int flush(void) override
Flushes the data written to the buffer.
Structure with additional info passed to traceMessage call.
Definition: RTTracer.h:80