scoped_timer.cpp
Go to the documentation of this file.
00001 #include "scoped_timer.h"
00002 #include <ros/console.h>
00003 #include "parameter_server.h"
00004 
00005 ScopedTimer::ScopedTimer(const char* thename, bool only_for_logging, bool unconditional_logging)
00006  : name(thename), unconditional_triggering(unconditional_logging)
00007 {
00008 #if (ROSCONSOLE_MIN_SEVERITY > ROSCONSOLE_SEVERITY_INFO)
00009   if(!only_for_logging) //would not log anything if level above INFO anyway
00010 #endif
00011   {
00012     clock_gettime(CLOCK_MONOTONIC, &start);
00013   }
00014 }
00015 
00016 double ScopedTimer::elapsed(){
00017   struct timespec now; 
00018   clock_gettime(CLOCK_MONOTONIC, &now);
00019   return (now.tv_sec - start.tv_sec) + (now.tv_nsec - start.tv_nsec) * 1e-9;
00020 }
00021 
00022 ScopedTimer::~ScopedTimer(){
00023   //No output anyway if above INFO level - ergo do nothing
00024 #if (ROSCONSOLE_MIN_SEVERITY < ROSCONSOLE_SEVERITY_WARN)
00025   double min_time = ParameterServer::instance()->get<double>("min_time_reported");
00026   if(unconditional_triggering || min_time > 0){
00027     double runtime = elapsed();
00028     if(unconditional_triggering || runtime > min_time){
00029       ROS_INFO_STREAM_NAMED("timings", name << " runtime: "<< runtime <<" s");
00030     }
00031   }
00032 #endif
00033 }
00034 


rgbdslam_v2
Author(s): Felix Endres, Juergen Hess, Nikolas Engelhard
autogenerated on Thu Jun 6 2019 21:49:45