Fawkes API  Fawkes Development Version
tracker.h
00001 
00002 /***************************************************************************
00003  *  tracker.h - Time tracker, which can be used to track a process's times
00004  *
00005  *  Created: Fri Jun 03 13:43:20 2005 (copied from RCSoft5 FireVision)
00006  *  Copyright  2005-2009  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
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 /* just to make Emacs auto-indent happy */
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   void ping_abort(unsigned int cls);
00053 
00054   void ping(std::string comment = "");
00055   void reset(std::string comment = "");
00056   void print_to_stdout();
00057 
00058   void print_to_file();
00059   
00060  private:
00061   void average_and_deviation(std::vector<struct timeval *> &values,
00062                              double &average_sec, double &average_ms,
00063                              double &deviation_sec, double &deviation_ms);
00064 
00065  private:
00066   timeval start_time;
00067   timeval last_time;
00068   std::vector<std::vector<struct timeval *> >    __class_times;
00069   std::vector<std::string>                       __class_names;
00070   std::vector<struct timeval *>                  __times;
00071   std::map<unsigned int, std::string>            __comments;
00072   std::vector<struct timeval *>::iterator        __time_it;
00073   std::map<unsigned int, std::string>::iterator  __comment_it;
00074   std::string                                    __tracker_comment;
00075 
00076   unsigned int __write_cycle;
00077   FILE *__timelog;
00078 };
00079 
00080 } // end namespace fawkes
00081 
00082 #endif