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 "UT_String.h"
22 #include <SYS/SYS_AtomicInt.h>
23 #include <stdio.h>
24 
25 class UT_API UT_Counter
26 {
27 public:
28  explicit UT_Counter(const char *msg)
29  {
30  myMessage = msg;
31  }
32 
33  ~UT_Counter()
34  {
35  if (myPeak.load() > 0)
36  {
37  UT_String count, peak, incs;
38  count.itoaPretty(myCount.load());
39  peak.itoaPretty(myPeak.load());
40  incs.itoaPretty(myIncrements.load());
41  printf("%s: %s [%s peak, %s increments]\n",
42  myMessage, count.buffer(), peak.buffer(), incs.buffer());
43  fflush(stdout);
44  }
45  }
46 
47  UT_Counter(const UT_Counter &m)
48  {
49  myMessage = m.myMessage;
50  myCount.relaxedStore(m.myCount.relaxedLoad());
51  myPeak.relaxedStore(m.myPeak.relaxedLoad());
52  myIncrements.relaxedStore(m.myIncrements.relaxedLoad());
53  }
55  {
56  if (this == &m)
57  return *this;
58  myMessage = m.myMessage;
59  myCount.relaxedStore(m.myCount.relaxedLoad());
60  myPeak.relaxedStore(m.myPeak.relaxedLoad());
61  myIncrements.relaxedStore(m.myIncrements.relaxedLoad());
62  return *this;
63  }
64 
66  {
67  myPeak.maximum(v);
68  myCount.maximum(v);
69  return *this;
70  }
71  UT_Counter &operator+=(int v)
72  {
73  myPeak.maximum(myCount.add(v));
74  if (v > 0)
75  myIncrements.add(v);
76  return *this;
77  }
78  UT_Counter &operator-=(int v) { return operator+=(-v); }
79 
80  UT_Counter &operator++() { return operator+=(1); }
81  UT_Counter &operator--() { return operator+=(-1); }
82 
83  SYS_DEPRECATED_REPLACE(22.0, prefix increment operator)
84  UT_Counter &operator++(int) { return operator+=(1); }
85 
86  SYS_DEPRECATED_REPLACE(22.0, prefix decrement operator)
87  UT_Counter &operator--(int) { return operator+=(-1); }
88 
89  void reset() { myCount.store(0,
91  exint peak() const { return myPeak.load(); }
92  exint count() const { return myCount.load(); }
93  exint increments() const { return myIncrements.load(); }
94 
95 private:
96  SYS_AtomicCounter myCount;
97  SYS_AtomicCounter myPeak;
98  SYS_AtomicCounter myIncrements;
99  const char *myMessage;
100 };
101 
102 #else // UT_DEBUG
103 
104 #include <SYS/SYS_Types.h>
105 
106 // When no debugging is on, we'll make a dummy class. Hopefully, the compiler
107 // will optimize this right out.
109 {
110 public:
111  UT_Counter(const char *) {}
113 
114  UT_Counter(const UT_Counter &m) = default;
115  UT_Counter &operator=(const UT_Counter &m) = default;
116 
117  UT_Counter &max(exint) { return *this; }
118  UT_Counter &operator+=(int) { return *this; }
119  UT_Counter &operator++() { return *this; }
120  UT_Counter &operator++(int) { return *this; }
121  UT_Counter &operator-=(int) { return *this; }
122  UT_Counter &operator--() { return *this; }
123  UT_Counter &operator--(int) { return *this; }
124  void reset() { }
125  exint peak() const { return 0; }
126  exint count() const { return 0; }
127  exint increments() const { return 0; }
128 };
129 
130 #endif // UT_DEBUG
131 #endif
UT_Counter(const char *)
Definition: UT_Counter.h:111
exint peak() const
Definition: UT_Counter.h:125
const GLdouble * v
Definition: glcorearb.h:837
auto printf(const S &fmt, const T &...args) -> int
Definition: printf.h:670
int64 exint
Definition: SYS_Types.h:125
UT_Counter & operator++()
Definition: UT_Counter.h:119
#define UT_API
Definition: UT_API.h:14
UT_Counter & max(exint)
Definition: UT_Counter.h:117
void itoaPretty(int64 val)
bool load(UT_IStream &is)
Load string from stream. Use is.eof() to check eof status.
#define SYS_DEPRECATED_REPLACE(__V__, __R__)
UT_Counter & operator--()
Definition: UT_Counter.h:122
const char * buffer() const
Definition: UT_String.h:525
GLboolean reset
Definition: glad.h:5138
OIIO_FORCEINLINE const vint4 & operator+=(vint4 &a, const vint4 &b)
Definition: simd.h:4512
exint count() const
Definition: UT_Counter.h:126
constexpr SYS_MemoryOrder SYS_MEMORY_ORDER_RELAXED
Any reordering the compiler or hardware chooses to do is okay.
exint increments() const
Definition: UT_Counter.h:127
UT_Counter & operator-=(int)
Definition: UT_Counter.h:121
UT_Counter & operator++(int)
Definition: UT_Counter.h:120
UT_Counter & operator--(int)
Definition: UT_Counter.h:123
UT_Counter & operator+=(int)
Definition: UT_Counter.h:118
LeafData & operator=(const LeafData &)=delete
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
OIIO_FORCEINLINE const vint4 & operator-=(vint4 &a, const vint4 &b)
Definition: simd.h:4539
void reset()
Definition: UT_Counter.h:124