Profiler.h
Go to the documentation of this file.
00001 /*      
00002  * File: Profiler.h
00003  * Project: DUtils library
00004  * Author: Dorian Galvez-Lopez
00005  * Date: September 14, 2010
00006  * Description: class for profiling code
00007  *
00008  * 
00009  * This program is free software: you can redistribute it and/or modify
00010  * it under the terms of the GNU Lesser General Public License as published by
00011  * the Free Software Foundation, either version 3 of the License, or
00012  * any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public License
00020  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00021  *
00022  */
00023 
00024 #pragma once
00025 #ifndef __D_PROFILER__
00026 #define __D_PROFILER__
00027 
00028 #include <map>
00029 #include <vector>
00030 #include <string>
00031 
00032 #include "Timestamp.h"
00033 
00034 namespace DUtils {
00035 
00036 #define PROFILE_S(cmd, s) \
00037   { DUtils::Timestamp t_begin, t_end; \
00038     t_begin.setToCurrentTime(); \
00039     cmd; \
00040     t_end.setToCurrentTime(); \
00041     std::cout << s << " - elapsed time: " \
00042       << DUtils::Timestamp::Format(t_end - t_begin) \
00043       << std::endl; \
00044   }
00045 
00046 #define PROFILE(cmd) PROFILE_S(cmd, "")
00047 
00048 class Profiler
00049 {
00050 public:
00051 
00052   Profiler(): m_last_profile(""){}
00053   virtual ~Profiler(){}
00054   
00060   void profile(const std::string &name = "");
00061   
00068   void stopAndScale(double scale, const std::string &name = "");
00069   
00075   inline void stop(const std::string &name = "")
00076   {
00077     stopAndScale(1.0, name);
00078   }
00079 
00080   double getMeanTime(const std::string &name = "") const ;
00081   double getStdevTime(const std::string &name = "") const ;
00082   double getMinTime(const std::string &name = "") const ;
00083   double getMaxTime(const std::string &name = "") const ;
00084   void getTime(std::vector<double> &time, const std::string &name = "") const;
00085 
00086 protected:
00087   
00088   std::map<std::string, std::vector<double> > m_profiles;
00089   std::map<std::string, Timestamp> m_start_points;
00090   std::string m_last_profile;
00091   
00092 };
00093 
00094 }
00095 
00096 #endif


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:32:13