Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXPerformance.h
1 /********************************************************************************
2 * *
3 * P e r f o r m a n c e C o u n t e r *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2009,2024 by Jeroen van der Zijp. All Rights Reserved. *
7 ********************************************************************************/
8 #ifndef FXPERFORMANCE_H
9 #define FXPERFORMANCE_H
10 
11 namespace FX {
12 
13 
14 // Performance measurement counter
15 class FXAPI FXCounter {
16 private:
17  const FXchar *const name;
18  volatile FXlong minticks;
19  volatile FXlong maxticks;
20  volatile FXlong totticks;
21  volatile FXlong counter;
22 public:
23  FXCounter(const FXchar *const nm);
24  void tally(FXlong ticks);
25  ~FXCounter();
26  };
27 
28 
29 // Measure performance of code in scope
30 template<FXCounter& counter>
32 private:
33  volatile FXlong ticks;
34 public:
36  ~FXPerformanceCounter(){counter.tally(FXThread::ticks()-ticks);}
37  };
38 
39 
40 
41 // Invoke counter if enabled
42 #if defined(PERFORMANCE_LOGGING)
43 #define PERFORMANCE_RECORDER(counter) FXCounter perf##counter(#counter)
44 #define PERFORMANCE_COUNTER(counter) FXPerformanceCounter< perf##counter > measure##counter
45 #else
46 #define PERFORMANCE_RECORDER(counter)
47 #define PERFORMANCE_COUNTER(counter)
48 #endif
49 
50 }
51 
52 #endif
Definition: FX4Splitter.h:28
Definition: FXPerformance.h:15
static FXTime ticks()
Return time in processor ticks.
Definition: FXPerformance.h:31

Copyright © 1997-2022 Jeroen van der Zijp