20 #if !defined(__MITSUBA_CORE_STATISTICS_H_)
21 #define __MITSUBA_CORE_STATISTICS_H_
39 #define PROGRESS_MSG_SIZE 56
49 #define NUM_COUNTERS 128 // Must be a power of 2
52 #define NUM_COUNTERS_MASK (NUM_COUNTERS-1)
64 #if (defined(_WIN32) && !defined(_WIN64)) || (defined(__POWERPC__) && !defined(_LP64))
65 #define MTS_32BIT_COUNTERS 1
74 #if MTS_32BIT_COUNTERS == 1
105 StatsCounter(
const std::string &category,
const std::string &name,
113 #if defined(MTS_NO_STATISTICS)
116 #elif defined(_MSC_VER) && defined(_WIN64)
118 _InterlockedExchangeAdd64(reinterpret_cast<__int64 volatile *>(&m_value[offset].value), 1);
119 return m_value[offset].value;
120 #elif defined(_MSC_VER) && defined(_WIN32)
122 _InterlockedExchangeAdd(reinterpret_cast<long volatile *>(&m_value[offset].value), 1);
123 return m_value[offset].value;
124 #elif defined(__POWERPC__) && !defined(_LP64)
125 return (uint64_t) __sync_fetch_and_add(&m_value[Thread::getID() &
NUM_COUNTERS_MASK].value, 1);
127 return __sync_fetch_and_add(&m_value[Thread::getID() &
NUM_COUNTERS_MASK].value, 1);
133 #ifdef MTS_NO_STATISTICS
135 #elif defined(_MSC_VER) && defined(_WIN64)
136 _InterlockedExchangeAdd64(reinterpret_cast<__int64 volatile *>(&m_value[Thread::getID() &
NUM_COUNTERS_MASK].value), amount);
137 #elif defined(_MSC_VER) && defined(_WIN32)
138 _InterlockedExchangeAdd(reinterpret_cast<long volatile *>(&m_value[Thread::getID() &
NUM_COUNTERS_MASK].value), amount);
140 __sync_fetch_and_add(&m_value[Thread::getID() &
NUM_COUNTERS_MASK].value, amount);
146 #ifdef MTS_NO_STATISTICS
148 #elif defined(_MSC_VER) && defined(_WIN64)
149 _InterlockedExchangeAdd64(reinterpret_cast<__int64 volatile *>(&m_base[Thread::getID() &
NUM_COUNTERS_MASK].value), amount);
150 #elif defined(_WIN32)
151 _InterlockedExchangeAdd(reinterpret_cast<long volatile *>(&m_base[Thread::getID() &
NUM_COUNTERS_MASK].value), amount);
153 __sync_fetch_and_add(&m_base[Thread::getID() &
NUM_COUNTERS_MASK].value, amount);
163 #if MTS_32BIT_COUNTERS == 1
164 volatile int32_t *ptr =
165 (
volatile int32_t *) &m_value[
id].value;
167 int32_t newMinimum = (int32_t) value;
169 volatile int64_t *ptr =
170 (
volatile int64_t *) &m_value[
id].value;
172 int64_t newMinimum = (int64_t) value;
177 if (newMinimum >= curMinimum)
179 #if (defined(__i386__) || defined(__amd64__))
180 __asm__ __volatile__ (
"pause\n");
191 #if MTS_32BIT_COUNTERS == 1
192 volatile int32_t *ptr =
193 (
volatile int32_t *) &m_value[
id].value;
195 int32_t newMaximum = (int32_t) value;
197 volatile int64_t *ptr =
198 (
volatile int64_t *) &m_value[
id].value;
200 int64_t newMaximum = (int64_t) value;
205 if (newMaximum <= curMaximum)
207 #if (defined(__i386__) || defined(__amd64__))
208 __asm__ __volatile__ (
"pause\n");
214 inline const std::string &
getName()
const {
return m_name; }
217 inline const std::string &
getCategory()
const {
return m_category; }
223 #ifdef MTS_NO_STATISTICS
224 inline uint64_t getValue()
const {
return 0L; }
225 inline uint64_t getMaximum()
const {
return 0L; }
226 inline uint64_t getMinimum()
const {
return 0L; }
231 result += m_value[i].value;
238 result = std::min(static_cast<uint64_t>(m_value[i].value), result);
245 result = std::max(static_cast<uint64_t>(m_value[i].value), result);
251 #ifdef MTS_NO_STATISTICS
252 inline uint64_t getBase()
const {
return 0L; }
257 result += m_base[i].value;
265 m_value[i].value = m_base[i].value = 0;
272 std::string m_category;
293 ProgressReporter(
const std::string &title,
long long total,
const void *ptr);
299 void update(
long long value);
302 inline long long getValue()
const {
return m_value; }
306 if (m_value < m_total)
311 static void setEnabled(
bool enabled);
317 void printTime(
Float time, std::ostream &os)
const;
319 static bool m_enabled;
321 long long m_total, m_value;
322 unsigned int m_lastMs;
324 int m_fillSize, m_fillPos;
348 void logPlugin(
const std::string &pname,
const std::string &descr);
354 std::string getStats();
370 virtual ~Statistics() { }
372 struct compareCategory {
381 std::vector<const StatsCounter *> m_counters;
382 std::vector<std::pair<std::string, std::string> > m_plugins;
Collects various rendering statistics and presents them in a human-readable form. ...
Definition: statistics.h:339
void incrementBase(size_t amount=1)
Increment the base counter by the specified amount (only for use with EPercentage/EAverage) ...
Definition: statistics.h:145
Simple unitless number, e.g. # of rays.
Definition: statistics.h:56
bool atomicCompareAndExchange(volatile int32_t *v, int32_t newValue, int32_t oldValue)
Atomically attempt to exchange a 32-bit integer with another value.
Definition: atomic.h:89
static void staticInitialization()
Initializes the built-in reference count debugger (if enabled)
void recordMinimum(size_t value)
When this is a minimum "counter", this function records an observation of the quantity whose minimum ...
Definition: statistics.h:161
static bool isEnabled()
Check whether progress bars are enabled.
Definition: statistics.h:314
uint64_t getMinimum() const
Definition: statistics.h:235
#define MTS_EXPORT_CORE
Definition: getopt.h:29
EStatsType
Determines the multiples (e.g. 1000, 1024) and units of a StatsCounter.
Definition: statistics.h:55
void recordMaximum(size_t value)
When this is a maximum "counter", this function records an observation of the quantity whose maximum ...
Definition: statistics.h:189
Minimum observed value of some quantity.
Definition: statistics.h:59
void reset()
Reset the stored counter values.
Definition: statistics.h:263
uint64_t getValue() const
Return the value of this counter as 64-bit unsigned integer.
Definition: statistics.h:228
const std::string & getName() const
Return the name of this counter.
Definition: statistics.h:214
uint64_t getBase() const
Get the reference number (only used with the EPercentage/EAverage counter type)
Definition: statistics.h:254
uint64_t getMaximum() const
Definition: statistics.h:242
uint64_t value
Definition: statistics.h:80
void operator+=(size_t amount)
Increment the counter by the specified amount.
Definition: statistics.h:132
Counter data structure, which is suitable for ccNUMA/SMP machines.
Definition: statistics.h:73
Maximum observed value of some quantity.
Definition: statistics.h:60
static Statistics * getInstance()
Return the global stats collector instance.
Definition: statistics.h:342
#define NUM_COUNTERS_MASK
Bitmask for NUM_COUNTERS.
Definition: statistics.h:52
#define MTS_DECLARE_CLASS()
This macro must be used in the initial definition in classes that derive from Object.
Definition: class.h:158
Reference counting helper.
Definition: ref.h:40
Number of read/written/transferred bytes.
Definition: statistics.h:57
General-purpose progress reporter.
Definition: statistics.h:287
General-purpose statistics counter.
Definition: statistics.h:94
uint64_t operator++()
Increment the counter value by one.
Definition: statistics.h:112
Average value with respect to a base counter.
Definition: statistics.h:61
const std::string & getCategory() const
Return the category of this counter.
Definition: statistics.h:217
#define NUM_COUNTERS
Definition: statistics.h:49
long long getValue() const
Return the current value.
Definition: statistics.h:302
Parent of all Mitsuba classes.
Definition: object.h:38
#define PROGRESS_MSG_SIZE
Size (in characters) of the console-based progress message.
Definition: statistics.h:39
void finish()
Finish.
Definition: statistics.h:305
EStatsType getType() const
Return the type of this counter.
Definition: statistics.h:220
static void staticShutdown()
Free the memory taken by staticInitialization()
Percentage with respect to a base counter.
Definition: statistics.h:58