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 
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 } // end namespace fawkes
00080 
00081 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends