Fawkes API  Fawkes Development Version
tracker.h
1 
2 /***************************************************************************
3  * tracker.h - Time tracker, which can be used to track a process's times
4  *
5  * Created: Fri Jun 03 13:43:20 2005 (copied from RCSoft5 FireVision)
6  * Copyright 2005-2009 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __UTILS_TIME_TRACKER_H_
25 #define __UTILS_TIME_TRACKER_H_
26 
27 #include <cstdio>
28 #include <vector>
29 #include <map>
30 #include <string>
31 #include <sys/time.h>
32 
33 namespace fawkes {
34 #if 0 /* just to make Emacs auto-indent happy */
35 }
36 #endif
37 
38 class TimeTracker {
39  public:
40  static const unsigned int DEFAULT_CLASS;
41 
42  TimeTracker(const char *filename, bool add_default_class = false);
43  TimeTracker(bool add_default_class = false);
44  ~TimeTracker();
45 
46  unsigned int add_class(std::string name);
47  void remove_class(unsigned int cls);
48 
49  void ping(unsigned int cls);
50  void ping_start(unsigned int cls);
51  void ping_end(unsigned int cls);
52  void ping_abort(unsigned int cls);
53 
54  void ping(std::string comment = "");
55  void reset(std::string comment = "");
56  void print_to_stdout();
57 
58  void print_to_file();
59 
60  private:
61  void average_and_deviation(std::vector<struct timeval *> &values,
62  double &average_sec, double &average_ms,
63  double &deviation_sec, double &deviation_ms);
64 
65  private:
66  timeval start_time;
67  timeval last_time;
68  std::vector<std::vector<struct timeval *> > __class_times;
69  std::vector<std::string> __class_names;
70  std::vector<struct timeval *> __times;
71  std::map<unsigned int, std::string> __comments;
72  std::vector<struct timeval *>::iterator __time_it;
73  std::map<unsigned int, std::string>::iterator __comment_it;
74  std::string __tracker_comment;
75 
76  unsigned int __write_cycle;
77  FILE *__timelog;
78 };
79 
80 
82 public:
83  explicit ScopedClassItemTracker(TimeTracker &tt, unsigned int cls);
85 private:
86  TimeTracker &tt_;
87  unsigned int cls_;
88 };
89 
90 
91 } // end namespace fawkes
92 
93 #endif
~TimeTracker()
Destructor.
Definition: tracker.cpp:100
TimeTracker(const char *filename, bool add_default_class=false)
Constructor for file logging.
Definition: tracker.cpp:84
void ping_start(unsigned int cls)
Start of given class task.
Definition: tracker.cpp:228
void ping(unsigned int cls)
Ping class.
Definition: tracker.cpp:194
Fawkes library namespace.
void remove_class(unsigned int cls)
Remove a class.
Definition: tracker.cpp:174
static const unsigned int DEFAULT_CLASS
The default tracking class.
Definition: tracker.h:40
void print_to_file()
Print data to file suitable for gnuplot.
Definition: tracker.cpp:442
void ping_abort(unsigned int cls)
End of given class task without recording.
Definition: tracker.cpp:282
Scoped time tracking for specific item.
Definition: tracker.h:81
unsigned int add_class(std::string name)
Add a new class.
Definition: tracker.cpp:156
Time tracking utility.
Definition: tracker.h:38
void ping_end(unsigned int cls)
End of given class task.
Definition: tracker.cpp:254
void reset(std::string comment="")
Reset times.
Definition: tracker.cpp:116
void print_to_stdout()
Print results to stdout.
Definition: tracker.cpp:317