Skip to content

Commit

Permalink
Encapsulate into a class timer_stats_ #18
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafa de la Torre committed May 25, 2017
1 parent 94c5134 commit d84ad7a
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions include/mapnik/timer.hpp
Expand Up @@ -66,7 +66,25 @@ struct timer_metrics {
double wall_clock_elapsed;
};

std::unordered_map<std::string, timer_metrics> timer_stats;
class timer_stats_
{
public:
void add(std::string metric_name, double cpu_elapsed, double wall_clock_elapsed)
{
timer_metrics metrics;

metrics = timer_stats_[metric_name];
metrics.cpu_elapsed += cpu_elapsed;
metrics.wall_clock_elapsed += wall_clock_elapsed;
timer_stats_[metric_name] = metrics;
}

private:
std::unordered_map<std::string, timer_metrics> timer_stats_;
};

timer_stats_ timer_stats;



// Measure times in both wall clock time and CPU times. Results are returned in milliseconds.
Expand Down Expand Up @@ -146,7 +164,7 @@ class progress_timer : public timer
timer::stop();
try
{
timer_stats.insert({metric_name_, {cpu_elapsed(), wall_clock_elapsed()}});
timer_stats.add(metric_name_, cpu_elapsed(), wall_clock_elapsed());
}
catch (...) {} // eat any exceptions
}
Expand Down

0 comments on commit d84ad7a

Please sign in to comment.