HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BRAY_Stats.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: BRAY_Stats.h (BRAY Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __BRAY_Stats__
12 #define __BRAY_Stats__
13 
14 #include "BRAY_API.h"
15 #include "BRAY_Types.h"
16 #include <UT/UT_UniquePtr.h>
17 #include <UT/UT_Rect.h>
18 #include <UT/UT_NonCopyable.h>
19 #include <UT/UT_StringHolder.h>
20 #include <UT/UT_JSONValue.h>
21 
22 class BRAY_StatsImpl;
23 class BRAY_Renderer;
24 
25 namespace BRAY
26 {
27 
30 {
31 public:
32  Stats(const BRAY_Renderer &renderer);
33  ~Stats();
34 
35  enum Key
36  {
37  // System information
38  USERNAME, // User name
39  HOSTNAME, // Host name
40  KARMA_VERSION, // Karma version
41  SYSTEM_THREADS, // Thread count
42  SYSTEM_CPU_BRAND, // CPU brand
43  SYSTEM_CPU_ARCHITECTURE,// CPU architecture
44  SYSTEM_MEMORY, // Current system memory usage
45  SYSTEM_TIME, // Current system times
46  SYSTEM_RESOURCE_USAGE, // Current system resource usage
47 
48  // Global render state
49  ENGINE, // Rendering engine (cpu or xpu)
50  XPU_DEVICE_COUNT, // XPU device count
51 
52  RENDER_SETTINGS, // JSON string of all global render settings
53 
54  RENDER_CAMERA, // Path to render camera
55  DICING_CAMERA, // Path to dicing camera
56  RESOLUTION, // Image resoution
57 
58  WORLD_TO_CAMERA, // World to camera transform
59  WORLD_TO_SCREEN, // World to screen transform
60  WORLD_TO_NDC, // World to NDC transform
61  WORLD_TO_RASTER, // World to raster space transform
62 
63  CAMERA_NEAR_FAR, // Camera near/far clipping planes
64 
65  AOV_BUFFERS, // AOV Buffer dictionary
66  AOV_RASTER_MEMORY, // Current/Peak memory used by rasters
67 
68  // Texture information
69  UNIFIED_CACHE, // Unified cache information
70  TEXTURE_ERROR_FILES, // List of bad texture paths
71  TEXTURE_CONVERSIONS, // Textures converted interanally
72 
73  RAT_STATS, // Number of .rat textures
74  RAT_DISK_CACHE, // RAT file disk cache performance
75  RAT_DISK_CACHE_ERRORS, // RAT file disk cache conversions
76 
77  OIIO_STATS, // OIIO texture stats
78  OIIO_STATS_STRING, // OIIO stats string (direct from OIIO)
79 
80  PTEX_STATS, // Ptex texture stats
81 
82  // USD information
83  OBJECT_COUNTS, // Object counts in the scene
84  GEOMETRY_COUNTS, // Geometry prim counts in the scene
85  LIGHT_TYPES, // Counts for different light types
86  PRIMVAR_CACHE, // Information about primvar cache
87 
88  // Rendering state information
89  PERCENT_COMPLETE, // Percent complete (0-1)
90  RENDER_STAGE, // Stage of rendering (inactive, loading, etc.)
91  RENDER_STAGE_LABEL, // Stage of rendering (inactive, loading, etc.)
92  LOAD_TIME, // Time to load scene
93  LOAD_MEMORY, // Memory after load
94  TTFP, // Time to first pixel
95  FILTER_ERRORS, // Errors in pixel/image filters (denoisers)
96 
97  // Karma CPU
98  SHADER_CALLS, // Number of shader calls
99  SHADER_NODES, // Number of shader graph nodes
100  RAY_COUNTS, // Primary, indirect, occlusion, etc.
101  TIMINGS, // Breakdown of time
102 
103  // Karma XPU
104  XPU_COMPILES, // XPU compile information
105 
106  STOCHASTIC_DEPTH, // Depth of stochastic transparency
107  RAY_DEPTHS, // Distribution of ray-depths
108  RAY_DEPTHS_PERCENTAGE, // Distribution of ray-depths
109  RAY_BATCH_EFFICIENCY, // Batch efficiency
110 
111  // Checkpointing
112  CHECKPOINT_STATS, // Checkpoint stats
113 
114  // Render progress
115  ACTIVE_BUCKETS, // Active buckets list
116 
117  // Annoatations (backward compatibility)
118  PROGRESS_ANNOTATION, // Progress
119  STATS_ANNOTATION, // XPU Stats
120 
121  MAX_KEYS // Sentinal
122  };
123 
125  {
126  DEVICE_LABEL, // Label for the device
127  DEVICE_TYPE, // Type of device (gpu, embree)
128  DEVICE_STATUS, // Device status
129  DEVICE_ERROR, // Device error message
130  DEVICE_MEMORY, // Breakdown of memory
131  DEVICE_SAMPLES, // Number of samples processed by device
132  DEVICE_CONTRIB, // Contribution of device
133 
134  DEVICE_MAX_KEYS // Sentinal
135  };
136 
138  : public UT_NonCopyable
139  {
140  Value(BRAY_StatsImpl &stats, Key key);
141  Value(BRAY_StatsImpl &stats, DeviceKey key, int device);
142  ~Value();
143 
144  SYS_SAFE_BOOL operator bool() const
145  {
146  return myValue.getType() != UT_JSONValue::JSON_NULL;
147  }
148 
149  const UT_JSONValue &get() const { return myValue; }
150  const UT_JSONValue &operator->() const { return myValue; }
151  const UT_JSONValue &operator*() const { return myValue; }
152 
153  const UT_StringHolder &key() const;
154  UT_StringHolder asString() const;
155  private:
156  const UT_JSONValue &myValue;
157  BRAY_StatsImpl &myStats;
158  int myDevice;
159  Key myKey;
160  DeviceKey myDeviceKey;
161  };
162 
163  static const UT_StringHolder &keyName(Key key);
164  static const UT_StringHolder &deviceKeyName(DeviceKey key);
165 
166  /// Lightweight method to get the render stage
167  BRAY_RenderStage renderStage() const;
168  /// Lightweight method to get the percent complete (between 0 and 100)
169  fpreal percentComplete() const;
170 
171  /// Get the value of the stat
172  Value get(Key key) const
173  { return Value(*myImpl, key); }
174 
175  /// Get the value of the device stat
176  Value get(DeviceKey key, int device) const
177  { return Value(*myImpl, key, device); }
178 
179  /// After XPU devices are initialized, call this method to configure the
180  /// stats.
181  void initDevices();
182 
183  /// Clear for next render
184  void clear();
185 
186  /// @{
187  /// @private - methods used by the renderer to update stats during rendering
189  void setPercentDone(fpreal v);
190  void setTTFP(fpreal v);
191  void setProgressAnnotation(const UT_StringHolder &s);
192  void setStatsAnnotation(const UT_StringHolder &s);
193  void setAnnotations(const UT_StringHolder &progress_annotation,
194  const UT_StringHolder &stats_annotation);
195  void startBucket(const UT_DimRect &bounds, int pass);
196  void endBucket();
197 
198  struct AutoBucket
199  {
200  AutoBucket(Stats &stats, const UT_DimRect &bounds, int pass)
201  : myStats(stats)
202  {
203  myStats.startBucket(bounds, pass);
204  }
206  {
207  myStats.endBucket();
208  }
210  };
211  /// @}
212 
213 private:
215 };
216 
217 } // End namespace
218 
219 #endif
220 
const UT_JSONValue & operator*() const
Definition: BRAY_Stats.h:151
const GLdouble * v
Definition: glcorearb.h:837
GLdouble s
Definition: glad.h:3009
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
BRAY_RenderStage
Definition: BRAY_Types.h:555
#define SYS_SAFE_BOOL
Definition: SYS_Compiler.h:55
AutoBucket(Stats &stats, const UT_DimRect &bounds, int pass)
Definition: BRAY_Stats.h:200
fpreal64 fpreal
Definition: SYS_Types.h:277
#define BRAY_API
Definition: BRAY_API.h:12
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
const UT_JSONValue & operator->() const
Definition: BRAY_Stats.h:150