HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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.store(m.myCount);
35  myPeak.store(m.myPeak);
36  myIncrements.store(m.myIncrements);
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 
53  UT_Counter &operator+=(int v)
54  {
55  myPeak.maximum(myCount.add(v));
56  if (v > 0)
57  myIncrements.add(v);
58  return *this;
59  }
60  UT_Counter &operator-=(int v) { return operator+=(-v); }
61  UT_Counter &operator++(int) { return operator+=(1); }
62  UT_Counter &operator--(int) { return operator+=(-1); }
63  void reset() { myCount.store(0,
65  exint peak() const { return myPeak.load(); }
66  exint count() const { return myCount.load(); }
67  exint increments() const { return myIncrements.load(); }
68 
69 private:
70  SYS_AtomicCounter myCount;
71  SYS_AtomicCounter myPeak;
72  SYS_AtomicCounter myIncrements;
73  const char *myMessage;
74 };
75 
76 #else // UT_DEBUG
77 
78 #include <SYS/SYS_Types.h>
79 // When no debugging is on, we'll make a dummy class. Hopefully, the compiler
80 // will optimize this right out.
82 public:
83  UT_Counter(const char *) {}
85 
86  UT_Counter &operator+=(int) { return *this; }
87  UT_Counter &operator++(int) { return *this; }
88  UT_Counter &operator-=(int) { return *this; }
89  UT_Counter &operator--(int) { return *this; }
90  void reset() { }
91  exint peak() const { return 0; }
92  exint count() const { return 0; }
93  exint increments() const { return 0; }
94 };
95 
96 #endif // UT_DEBUG
97 #endif
UT_Counter(const char *)
Definition: UT_Counter.h:83
void itoa_pretty(int64 val)
exint peak() const
Definition: UT_Counter.h:91
const GLdouble * v
Definition: glcorearb.h:836
#define UT_API
Definition: UT_API.h:12
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:109
exint count() const
Definition: UT_Counter.h:92
exint increments() const
Definition: UT_Counter.h:93
UT_Counter & operator-=(int)
Definition: UT_Counter.h:88
UT_Counter & operator++(int)
Definition: UT_Counter.h:87
Any reordering the compiler or hardware chooses to do is okay.
UT_Counter & operator--(int)
Definition: UT_Counter.h:89
GLint GLsizei count
Definition: glcorearb.h:404
UT_Counter & operator+=(int)
Definition: UT_Counter.h:86
void reset()
Definition: UT_Counter.h:90