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 <sys/time.h>
28 
29 #include <cstdio>
30 #include <map>
31 #include <string>
32 #include <vector>
33 
34 namespace fawkes {
35 
37 {
38 public:
39  static const unsigned int DEFAULT_CLASS;
40 
41  TimeTracker(const char *filename, bool add_default_class = false);
42  TimeTracker(bool add_default_class = false);
43  ~TimeTracker();
44 
45  unsigned int add_class(std::string name);
46  void remove_class(unsigned int cls);
47 
48  void ping(unsigned int cls);
49  void ping_start(unsigned int cls);
50  void ping_end(unsigned int cls);
51  void ping_abort(unsigned int cls);
52 
53  void ping(std::string comment = "");
54  void reset(std::string comment = "");
55  void print_to_stdout();
56 
57  void print_to_file();
58 
59 private:
60  void average_and_deviation(std::vector<struct timeval *> &values,
61  double & average_sec,
62  double & average_ms,
63  double & deviation_sec,
64  double & deviation_ms);
65 
66 private:
67  timeval start_time;
68  timeval last_time;
69  std::vector<std::vector<struct timeval *>> class_times_;
70  std::vector<std::string> class_names_;
71  std::vector<struct timeval *> times_;
72  std::map<unsigned int, std::string> comments_;
73  std::vector<struct timeval *>::iterator time_it_;
74  std::map<unsigned int, std::string>::iterator comment_it_;
75  std::string tracker_comment_;
76 
77  unsigned int write_cycle_;
78  FILE * timelog_;
79 };
80 
82 {
83 public:
84  explicit ScopedClassItemTracker(TimeTracker &tt, unsigned int cls);
86 
87 private:
88  TimeTracker &tt_;
89  unsigned int cls_;
90 };
91 
92 } // end namespace fawkes
93 
94 #endif
~TimeTracker()
Destructor.
Definition: tracker.cpp:95
TimeTracker(const char *filename, bool add_default_class=false)
Constructor for file logging.
Definition: tracker.cpp:80
void ping_start(unsigned int cls)
Start of given class task.
Definition: tracker.cpp:218
void ping(unsigned int cls)
Ping class.
Definition: tracker.cpp:185
Fawkes library namespace.
void remove_class(unsigned int cls)
Remove a class.
Definition: tracker.cpp:166
static const unsigned int DEFAULT_CLASS
The default tracking class.
Definition: tracker.h:39
void print_to_file()
Print data to file suitable for gnuplot.
Definition: tracker.cpp:426
void ping_abort(unsigned int cls)
End of given class task without recording.
Definition: tracker.cpp:270
Scoped time tracking for specific item.
Definition: tracker.h:81
unsigned int add_class(std::string name)
Add a new class.
Definition: tracker.cpp:149
Time tracking utility.
Definition: tracker.h:36
void ping_end(unsigned int cls)
End of given class task.
Definition: tracker.cpp:243
void reset(std::string comment="")
Reset times.
Definition: tracker.cpp:110
void print_to_stdout()
Print results to stdout.
Definition: tracker.cpp:307
~ScopedClassItemTracker()
Destructor.
Definition: tracker.cpp:471
ScopedClassItemTracker(TimeTracker &tt, unsigned int cls)
Constructor.
Definition: tracker.cpp:464