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,2026 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXPERFORMANCE_H
22 #define FXPERFORMANCE_H
23 
24 namespace FX {
25 
26 
27 // Performance measurement counter
28 class FXAPI FXCounter {
29 private:
30  const FXchar *const name;
31  volatile FXlong minticks;
32  volatile FXlong maxticks;
33  volatile FXlong totticks;
34  volatile FXlong counter;
35 public:
36  FXCounter(const FXchar *const nm);
37  void tally(FXlong ticks);
38  ~FXCounter();
39  };
40 
41 
42 // Measure performance of code in scope
43 template<FXCounter& counter>
45 private:
46  volatile FXlong ticks;
47 public:
49  ~FXPerformanceCounter(){counter.tally(FXThread::ticks()-ticks);}
50  };
51 
52 
53 
54 // Invoke counter if enabled
55 #if defined(PERFORMANCE_LOGGING)
56 #define PERFORMANCE_RECORDER(counter) FXCounter perf##counter(#counter)
57 #define PERFORMANCE_COUNTER(counter) FXPerformanceCounter< perf##counter > measure##counter
58 #else
59 #define PERFORMANCE_RECORDER(counter)
60 #define PERFORMANCE_COUNTER(counter)
61 #endif
62 
63 }
64 
65 #endif
Definition: FX4Splitter.h:28
Definition: FXPerformance.h:28
static FXTime ticks()
Return time in processor ticks.
Definition: FXPerformance.h:44

Copyright © 1997-2026 Jeroen van der Zijp