163 if (labels.empty()) {
164 glDeleteQueries(queries.size(), queries.data());
168 glEndQuery(GL_TIME_ELAPSED);
169 times.push_back(std::chrono::high_resolution_clock::now());
171 std::stringstream sst;
172 sst <<
"--- " << prof_name <<
" ---\n";
174 int max_name_length = 0;
175 for (
const auto& label : labels) {
176 max_name_length = std::max<int>(max_name_length, label.size());
178 std::string label_format =
"%-" + std::to_string(max_name_length) +
"s";
180 double sum_time_msec_gl = 0.0;
181 for (
int i = 0; i < labels.size(); i++) {
183 glGetQueryObjectiv(queries[i], GL_QUERY_RESULT, &result);
184 double time_msec_gl = result / 1e6;
185 sum_time_msec_gl += time_msec_gl;
187 double time_msec_real = std::chrono::duration_cast<std::chrono::nanoseconds>(times[i + 1] - times[i]).count() / 1e6;
188 double sum_time_msec_real = std::chrono::duration_cast<std::chrono::nanoseconds>(times[i + 1] - times.front()).count() / 1e6;
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
192 << std::setprecision(3) << sum_time_msec_real <<
"[msec])\n";
195 double sum_time_msec_real = std::chrono::duration_cast<std::chrono::nanoseconds>(times.back() - times.front()).count() / 1e6;
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)
199 << sum_time_msec_real <<
"[msec])\n";
201 std::cout << sst.str() << std::endl;
203 glDeleteQueries(queries.size(), queries.data());
206 void add(
const std::string& label) {
211 int current = labels.size();
213 glEndQuery(GL_TIME_ELAPSED);
216 if (current == queries.size()) {
217 int n = queries.size();
218 queries.resize(n * 2);
219 glGenQueries(n, queries.data() + n);
222 glBeginQuery(GL_TIME_ELAPSED, queries[current]);
223 labels.push_back(label);
224 times.push_back(std::chrono::high_resolution_clock::now());