HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Counter.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_Counter.h ( UT Library, C++)
7  *
8  * COMMENTS: Class to keep track of records and print out the data at the
9  * end of a render. You simply have to declare a static printer
10  * in the file you want the printing to occur in. The destructor
11  * will cause the stat to be printed.
12  */
13 
14 #ifndef __UT_Counter__
15 #define __UT_Counter__
16 
17 #include "UT_API.h"
18 
19 #ifdef UT_DEBUG
20 
21 #include <stdio.h>
22 #include <SYS/SYS_AtomicInt.h>
23 #include "UT_String.h"
24 
25 class UT_API UT_Counter {
26 public:
27  explicit UT_Counter(const char *msg)
28  {
29  myMessage = msg;
30  }
31  UT_Counter(const UT_Counter &m)
32  {
33  myMessage = m.myMessage;
34  myCount.relaxedStore(m.myCount.relaxedLoad());
35  myPeak.relaxedStore(m.myPeak.relaxedLoad());
36  myIncrements.relaxedStore(m.myIncrements.relaxedLoad());
37  }
38 
39  ~UT_Counter()
40  {
41  if (myPeak.load() > 0)
42  {
43  UT_String count, peak, incs;
44  count.itoa_pretty(myCount.load());
45  peak.itoa_pretty(myPeak.load());
46  incs.itoa_pretty(myIncrements.load());
47  printf("%s: %s [%s peak, %s increments]\n",
48  myMessage, count.buffer(), peak.buffer(), incs.buffer());
49  fflush(stdout);
50  }
51  }
52 
54  {
55  myPeak.maximum(v);
56  myCount.maximum(v);
57  return *this;
58  }
59  UT_Counter &operator+=(int v)
60  {
61  myPeak.maximum(myCount.add(v));
62  if (v > 0)
63  myIncrements.add(v);
64  return *this;
65  }
66  UT_Counter &operator-=(int v) { return operator+=(-v); }
67  UT_Counter &operator++(int) { return operator+=(1); }
68  UT_Counter &operator--(int) { return operator+=(-1); }
69  void reset() { myCount.store(0,
71  exint peak() const { return myPeak.load(); }
72  exint count() const { return myCount.load(); }
73  exint increments() const { return myIncrements.load(); }
74 
75 private:
76  SYS_AtomicCounter myCount;
77  SYS_AtomicCounter myPeak;
78  SYS_AtomicCounter myIncrements;
79  const char *myMessage;
80 };
81 
82 #else // UT_DEBUG
83 
84 #include <SYS/SYS_Types.h>
85 // When no debugging is on, we'll make a dummy class. Hopefully, the compiler
86 // will optimize this right out.
88 public:
89  UT_Counter(const char *) {}
91 
92  UT_Counter &max(exint) { return *this; }
93  UT_Counter &operator+=(int) { return *this; }
94  UT_Counter &operator++(int) { return *this; }
95  UT_Counter &operator-=(int) { return *this; }
96  UT_Counter &operator--(int) { return *this; }
97  void reset() { }
98  exint peak() const { return 0; }
99  exint count() const { return 0; }
100  exint increments() const { return 0; }
101 };
102 
103 #endif // UT_DEBUG
104 #endif
UT_Counter(const char *)
Definition: UT_Counter.h:89
void itoa_pretty(int64 val)
exint peak() const
Definition: UT_Counter.h:98
const GLdouble * v
Definition: glcorearb.h:836
#define UT_API
Definition: UT_API.h:13
UT_Counter & max(exint)
Definition: UT_Counter.h:92
bool load(UT_IStream &is)
Load string from stream. Use is.eof() to check eof status.
const char * buffer() const
Definition: UT_String.h:503
int64 exint
Definition: SYS_Types.h:116
const std::enable_if<!VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:133
exint count() const
Definition: UT_Counter.h:99
exint increments() const
Definition: UT_Counter.h:100
UT_Counter & operator-=(int)
Definition: UT_Counter.h:95
UT_Counter & operator++(int)
Definition: UT_Counter.h:94
Any reordering the compiler or hardware chooses to do is okay.
UT_Counter & operator--(int)
Definition: UT_Counter.h:96
GLint GLsizei count
Definition: glcorearb.h:404
UT_Counter & operator+=(int)
Definition: UT_Counter.h:93
void reset()
Definition: UT_Counter.h:97