1#ifndef GLK_PROFILER_HPP
2#define GLK_PROFILER_HPP
37 std::stringstream
sst;
38 sst <<
"--- " << prof_name <<
" ---\n";
41 for (
const auto& label : labels) {
47 for (
int i = 0;
i < labels.size();
i++) {
53 sst <<
"- " << std::left << std::setfill(
' ') << std::setw(
max_name_length) << labels[
i] <<
" : " << std::fixed << std::setprecision(3) <<
time_msec <<
"[msec] ("
54 << std::fixed << std::setprecision(3) <<
sum_time_msec <<
"[msec])\n";
57 sst <<
"- total(approx) : " << std::fixed << std::setprecision(3) <<
sum_time_msec <<
"[msec]";
59 std::cout <<
sst.str() << std::endl;
64 void add(
const std::string& label) {
69 int current = labels.size();
74 if (current == queries.size()) {
75 int n = queries.size();
76 queries.resize(
n * 2);
81 labels.push_back(label);
85 const std::string prof_name;
88 std::vector<std::string> labels;
89 std::vector<GLuint> queries;
94 RealProfiler(
const std::string& prof_name,
bool enabled =
true) : prof_name(prof_name), enabled(enabled) {}
101 if (labels.empty()) {
105 labels.push_back(
"end");
106 times.push_back(std::chrono::high_resolution_clock::now());
108 std::stringstream
sst;
109 sst <<
"--- " << prof_name <<
" ---\n";
112 for (
const auto& label : labels) {
116 for (
int i = 0;
i < labels.size() - 1;
i++) {
117 double time_msec = std::chrono::duration_cast<std::chrono::nanoseconds>(times[
i + 1] - times[
i]).count() / 1
e6;
118 double sum_time_msec = std::chrono::duration_cast<std::chrono::nanoseconds>(times[
i + 1] - times.front()).count() / 1
e6;
120 sst <<
"- " << std::left << std::setfill(
' ') << std::setw(
max_name_length) << labels[
i] <<
" : " << std::fixed << std::setprecision(3) <<
time_msec <<
"[msec] ("
121 << std::fixed << std::setprecision(3) <<
sum_time_msec <<
"[msec])\n";
125 double sum_time_msec = std::chrono::duration_cast<std::chrono::nanoseconds>(times.back() - times.front()).count() / 1
e6;
127 sst <<
" - total(approx) : " << std::fixed << std::setprecision(3) <<
sum_time_msec <<
"[msec]";
128 std::cout <<
sst.str() << std::endl;
131 void add(
const std::string& label) {
136 labels.push_back(label);
137 times.push_back(std::chrono::high_resolution_clock::now());
141 const std::string prof_name;
144 std::vector<std::string> labels;
145 std::vector<std::chrono::high_resolution_clock::time_point> times;
163 if (labels.empty()) {
169 times.push_back(std::chrono::high_resolution_clock::now());
171 std::stringstream
sst;
172 sst <<
"--- " << prof_name <<
" ---\n";
175 for (
const auto& label : labels) {
181 for (
int i = 0;
i < labels.size();
i++) {
187 double time_msec_real = std::chrono::duration_cast<std::chrono::nanoseconds>(times[
i + 1] - times[
i]).count() / 1
e6;
188 double sum_time_msec_real = std::chrono::duration_cast<std::chrono::nanoseconds>(times[
i + 1] - times.front()).count() / 1
e6;
190 sst <<
"- " << std::left << std::setfill(
' ') << std::setw(
max_name_length) << labels[
i] <<
" : " << std::fixed << std::setprecision(3) <<
time_msec_gl <<
"[msec] " <<
"r"
191 << std::fixed << std::setprecision(3) <<
time_msec_real <<
"[msec] (" << std::fixed << std::setprecision(3) <<
sum_time_msec_gl <<
"[msec] r" << std::fixed
195 double sum_time_msec_real = std::chrono::duration_cast<std::chrono::nanoseconds>(times.back() - times.front()).count() / 1
e6;
197 sst <<
"- " << std::left << std::setfill(
' ') << std::setw(
max_name_length) << labels.back() <<
" : " << std::fixed << std::setprecision(3) << 0.0 <<
"[msec] " <<
"r"
198 << std::fixed << std::setprecision(3) << 0.0 <<
"[msec] (" << std::fixed << std::setprecision(3) <<
sum_time_msec_gl <<
"[msec] r" << std::fixed << std::setprecision(3)
201 std::cout <<
sst.str() << std::endl;
206 void add(
const std::string& label) {
211 int current = labels.size();
216 if (current == queries.size()) {
217 int n = queries.size();
218 queries.resize(
n * 2);
223 labels.push_back(label);
224 times.push_back(std::chrono::high_resolution_clock::now());
228 const std::string prof_name;
231 std::vector<std::string> labels;
232 std::vector<GLuint> queries;
233 std::vector<std::chrono::high_resolution_clock::time_point> times;
Definition profiler.hpp:15
void add(const std::string &label)
Definition profiler.hpp:64
~GLProfiler()
Definition profiler.hpp:25
GLProfiler(const std::string &prof_name, bool enabled=true, int max_num_queries=16)
Definition profiler.hpp:17
Definition profiler.hpp:148
~GLRealProfiler()
Definition profiler.hpp:158
GLRealProfiler(const std::string &prof_name, bool enabled=true, int max_num_queries=16)
Definition profiler.hpp:150
void add(const std::string &label)
Definition profiler.hpp:206
Definition profiler.hpp:92
~RealProfiler()
Definition profiler.hpp:96
void add(const std::string &label)
Definition profiler.hpp:131
RealProfiler(const std::string &prof_name, bool enabled=true)
Definition profiler.hpp:94
Definition async_buffer_copy.hpp:6
std::enable_if_t< needs_aligned_allocator< T >::value, std::shared_ptr< T > > make_shared(Args &&... args)
Definition make_shared.hpp:20