00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __UTILS_TIME_TRACKER_H_
00025 #define __UTILS_TIME_TRACKER_H_
00026
00027 #include <cstdio>
00028 #include <vector>
00029 #include <map>
00030 #include <string>
00031 #include <sys/time.h>
00032
00033 namespace fawkes {
00034 #if 0
00035 }
00036 #endif
00037
00038 class TimeTracker {
00039 public:
00040 static const unsigned int DEFAULT_CLASS;
00041
00042 TimeTracker(const char *filename, bool add_default_class = false);
00043 TimeTracker(bool add_default_class = false);
00044 ~TimeTracker();
00045
00046 unsigned int add_class(std::string name);
00047 void remove_class(unsigned int cls);
00048
00049 void ping(unsigned int cls);
00050 void ping_start(unsigned int cls);
00051 void ping_end(unsigned int cls);
00052
00053 void ping(std::string comment = "");
00054 void reset(std::string comment = "");
00055 void print_to_stdout();
00056
00057 void print_to_file();
00058
00059 private:
00060 void average_and_deviation(std::vector<struct timeval *> &values,
00061 double &average_sec, double &average_ms,
00062 double &deviation_sec, double &deviation_ms);
00063
00064 private:
00065 timeval start_time;
00066 timeval last_time;
00067 std::vector<std::vector<struct timeval *> > __class_times;
00068 std::vector<std::string> __class_names;
00069 std::vector<struct timeval *> __times;
00070 std::map<unsigned int, std::string> __comments;
00071 std::vector<struct timeval *>::iterator __time_it;
00072 std::map<unsigned int, std::string>::iterator __comment_it;
00073 std::string __tracker_comment;
00074
00075 unsigned int __write_cycle;
00076 FILE *__timelog;
00077 };
00078
00079 }
00080
00081 #endif