Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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