5
5
#include < vector>
6
6
#include < x86intrin.h> // for __rdtsc() CPU time step counter
7
7
8
- #include " ngcore_api.hpp" // for NGCORE_API
9
8
#include " logging.hpp" // for logger
9
+ #include " ngcore_api.hpp" // for NGCORE_API
10
+ #include " utils.hpp"
10
11
11
12
namespace ngcore
12
13
{
@@ -15,15 +16,11 @@ namespace ngcore
15
16
class PajeTrace
16
17
{
17
18
public:
18
- typedef std::chrono::system_clock TClock;
19
- // typedef TClock::time_point TTimePoint;
20
- typedef size_t TTimePoint;
19
+ using TClock = std::chrono::system_clock;
21
20
22
21
protected:
23
22
std::shared_ptr<spdlog::logger> logger = GetLogger(" PajeTrace" );
24
23
private:
25
- friend class TraceDisabler ;
26
-
27
24
NGCORE_API static size_t max_tracefile_size;
28
25
static bool trace_thread_counter;
29
26
static bool trace_threads;
@@ -104,32 +101,32 @@ namespace ngcore
104
101
std::vector<TimerEvent> timer_events;
105
102
std::vector<std::vector<ThreadLink> > links;
106
103
107
- TTimePoint GetTime ()
108
- {
109
- // return TClock::now();
110
- return TTimePoint (__rdtsc ());
111
- }
112
-
113
104
public:
114
105
NGCORE_API void StopTracing ();
115
106
107
+ PajeTrace () = delete ;
108
+ PajeTrace (const PajeTrace &) = delete ;
109
+ PajeTrace (PajeTrace &&) = delete ;
116
110
PajeTrace (int anthreads, std::string aname = " " );
117
111
~PajeTrace ();
118
112
113
+ void operator =(const PajeTrace &) = delete ;
114
+ void operator =(PajeTrace &&) = delete ;
115
+
119
116
void StartTimer (int timer_id)
120
117
{
121
118
if (!tracing_enabled) return ;
122
119
if (unlikely (timer_events.size () == max_num_events_per_thread))
123
120
StopTracing ();
124
- timer_events.push_back (TimerEvent{timer_id, GetTime (), true });
121
+ timer_events.push_back (TimerEvent{timer_id, GetTimeCounter (), true });
125
122
}
126
123
127
124
void StopTimer (int timer_id)
128
125
{
129
126
if (!tracing_enabled) return ;
130
127
if (unlikely (timer_events.size () == max_num_events_per_thread))
131
128
StopTracing ();
132
- timer_events.push_back (TimerEvent{timer_id, GetTime (), false });
129
+ timer_events.push_back (TimerEvent{timer_id, GetTimeCounter (), false });
133
130
}
134
131
135
132
NETGEN_INLINE int StartTask (int thread_id, int id, int id_type = Task::ID_NONE, int additional_value = -1 )
@@ -139,15 +136,15 @@ namespace ngcore
139
136
if (unlikely (tasks[thread_id].size () == max_num_events_per_thread))
140
137
StopTracing ();
141
138
int task_num = tasks[thread_id].size ();
142
- tasks[thread_id].push_back ( Task{thread_id, id, id_type, additional_value, GetTime ()} );
139
+ tasks[thread_id].push_back ( Task{thread_id, id, id_type, additional_value, GetTimeCounter ()} );
143
140
return task_num;
144
141
}
145
142
146
143
void StopTask (int thread_id, int task_num)
147
144
{
148
145
if (!trace_threads && !trace_thread_counter) return ;
149
146
if (task_num>=0 )
150
- tasks[thread_id][task_num].stop_time = GetTime ();
147
+ tasks[thread_id][task_num].stop_time = GetTimeCounter ();
151
148
}
152
149
153
150
void SetTask (int thread_id, int task_num, int additional_value) {
@@ -161,55 +158,34 @@ namespace ngcore
161
158
if (!tracing_enabled) return ;
162
159
if (jobs.size () == max_num_events_per_thread)
163
160
StopTracing ();
164
- jobs.push_back ( Job{job_id, &type, GetTime ()} );
161
+ jobs.push_back ( Job{job_id, &type, GetTimeCounter ()} );
165
162
}
166
163
167
164
void StopJob ()
168
165
{
169
166
if (tracing_enabled)
170
- jobs.back ().stop_time = GetTime ();
167
+ jobs.back ().stop_time = GetTimeCounter ();
171
168
}
172
169
173
170
void StartLink (int thread_id, int key)
174
171
{
175
172
if (!tracing_enabled) return ;
176
173
if (links[thread_id].size () == max_num_events_per_thread)
177
174
StopTracing ();
178
- links[thread_id].push_back ( ThreadLink{thread_id, key, GetTime (), true } );
175
+ links[thread_id].push_back ( ThreadLink{thread_id, key, GetTimeCounter (), true } );
179
176
}
180
177
181
178
void StopLink (int thread_id, int key)
182
179
{
183
180
if (!tracing_enabled) return ;
184
181
if (links[thread_id].size () == max_num_events_per_thread)
185
182
StopTracing ();
186
- links[thread_id].push_back ( ThreadLink{thread_id, key, GetTime (), false } );
183
+ links[thread_id].push_back ( ThreadLink{thread_id, key, GetTimeCounter (), false } );
187
184
}
188
185
189
- void Write ( std::string filename );
190
-
191
- };
186
+ void Write ( const std::string & filename );
192
187
193
- class TraceDisabler
194
- {
195
- bool trace_thread_counter;
196
- bool trace_threads;
197
-
198
- public:
199
- TraceDisabler ()
200
- {
201
- trace_thread_counter = PajeTrace::trace_thread_counter;
202
- PajeTrace::trace_thread_counter = false ;
203
- trace_threads = PajeTrace::trace_threads;
204
- PajeTrace::trace_threads = false ;
205
- }
206
-
207
- ~TraceDisabler ()
208
- {
209
- PajeTrace::trace_thread_counter = trace_thread_counter;
210
- PajeTrace::trace_threads = trace_threads;
211
- }
212
188
};
213
- }
189
+ } // namespace ngcore
214
190
215
191
#endif // NETGEN_CORE_PAJE_TRACE_HPP
0 commit comments