Photon Common Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
stats.h
Go to the documentation of this file.
1#pragma once
2
3#include <atomic>
4#include <chrono>
5#include <cstdint>
6#include <string>
7#include <string_view>
8#include <vector>
9
10namespace ph
11{
12
13namespace detail::stats
14{
15
16struct TimeCounter final
17{
18 const std::string name;
19 const std::string category;
20 std::atomic_uint64_t totalMicroseconds;
21 std::atomic_uint64_t count;
22
23 TimeCounter(std::string name, std::string category);
24 void addMicroseconds(std::uint64_t microseconds);
25};
26
27struct ScopedTimer final
28{
29 using Clock = std::chrono::steady_clock;
30
32 Clock::time_point startTime;
33
36};
37
38}// end namespace detail::stats
39
41{
42public:
43 struct TimeRecord final
44 {
45 std::string name;
46 std::string category;
47 std::uint64_t totalMicroseconds;
48 std::uint64_t count;
49
50 TimeRecord();
51 };
52
53 struct GroupedTimeRecord final
54 {
55 std::string groupName;
56 std::uint64_t totalMicroseconds;
57 std::uint64_t count;
58
59 std::vector<GroupedTimeRecord> subgroups;
60
62 };
63
65
67 std::string proportionalReport() const;
68 std::string averagedReport() const;
69 std::string detailedReport() const;
70 std::string rawReport() const;
71
72private:
73 enum class EGroupedReport
74 {
75 ProportionOnly,
76 AverageOnly,
77 ProportionWithAverage,
78 ProportionWithAverageAndTotal
79 };
80
81 std::vector<TimeRecord> m_records;
82
83 static GroupedTimeRecord makeGroupedTimeRecordRecursive(const std::vector<TimeRecord>& records);
84
85 static std::string makeGroupedReportRecursive(
86 const GroupedTimeRecord& records,
87 EGroupedReport reportType,
88 const std::string& linePrefix);
89};
90
91}// end namespace ph
92
93#define PH_DEFINE_INLINE_TIMER_STAT(statName, categoryName)\
94 inline ::ph::detail::stats::TimeCounter& internal_impl_time_counter_access_##statName()\
95 {\
96 static ::ph::detail::stats::TimeCounter counter(#statName, #categoryName);\
97 return counter;\
98 }
99
100#define PH_DEFINE_INTERNAL_TIMER_STAT(statName, categoryName)\
101 namespace\
102 {\
103 PH_DEFINE_INLINE_TIMER_STAT(statName, categoryName);\
104 }
105
106#define PH_DEFINE_EXTERNAL_TIMER_STAT(statName, categoryName)\
107 PH_DEFINE_INLINE_TIMER_STAT(statName, categoryName)
108
109#define PH_SCOPED_TIMER(statName)\
110 ::ph::detail::stats::ScopedTimer internal_impl_scopedTimer##statName(\
111 internal_impl_time_counter_access_##statName())
Definition stats.h:41
GroupedTimeRecord getGroupedTimeRecord() const
Definition stats.cpp:87
std::string rawReport() const
Definition stats.cpp:125
std::string detailedReport() const
Definition stats.cpp:114
TimerStatsReport()
Definition stats.cpp:69
std::string averagedReport() const
Definition stats.cpp:103
std::string proportionalReport() const
Definition stats.cpp:92
The root for all renderer implementations.
Definition assertion.h:9
std::vector< GroupedTimeRecord > subgroups
Definition stats.h:59
GroupedTimeRecord()
Definition stats.cpp:65
std::uint64_t count
Definition stats.h:57
std::uint64_t totalMicroseconds
Definition stats.h:56
std::string groupName
Definition stats.h:55
TimeRecord()
Definition stats.cpp:61
std::uint64_t totalMicroseconds
Definition stats.h:47
std::string category
Definition stats.h:46
std::uint64_t count
Definition stats.h:48
std::string name
Definition stats.h:45
Definition stats.h:28
TimeCounter & counter
Definition stats.h:31
Clock::time_point startTime
Definition stats.h:32
ScopedTimer(TimeCounter &counter)
Definition stats.cpp:46
~ScopedTimer()
Definition stats.cpp:50
std::chrono::steady_clock Clock
Definition stats.h:29
Definition stats.h:17
void addMicroseconds(std::uint64_t microseconds)
Definition stats.cpp:40
const std::string name
Definition stats.h:18
const std::string category
Definition stats.h:19
TimeCounter(std::string name, std::string category)
Definition stats.cpp:32
std::atomic_uint64_t totalMicroseconds
Definition stats.h:20
std::atomic_uint64_t count
Definition stats.h:21