IMP  2.3.1
The Integrative Modeling Platform
base/statistics.h
Go to the documentation of this file.
1 /**
2  * \file IMP/base/statistics.h
3  * \brief Manage statistics on IMP runs.
4  *
5  * Copyright 2007-2014 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPBASE_STATISTICS_H
10 #define IMPBASE_STATISTICS_H
11 
12 #include <IMP/base/base_config.h>
13 #include "file.h"
14 #include "enums.h"
15 #include "internal/static.h"
16 #include <string>
17 #include <ctime>
18 
19 IMPBASE_BEGIN_NAMESPACE
20 
21 /** Reset all the statistics for IMP. */
22 IMPBASEEXPORT void clear_statistics();
23 
24 /** Show all captured timings. */
25 IMPBASEEXPORT void show_timings(TextOutput out);
26 
27 /** Time an operation and save the timings.*/
28 class IMPBASEEXPORT Timer : public RAII {
29  std::clock_t start_;
30  std::string key_;
31 
32  void initialize(std::string key);
33  void save();
34 
35  public:
36  // TODO: string ops may be wasteful - could pass pointer
37  // to const char* or reference to stringsto be initialized?
38  Timer(const Object *object, std::string const& operation) {
39  if (internal::stats_level > NO_STATISTICS) {
40  initialize(object->get_name() + "::" + operation);
41  }
42  }
43  // TODO: string ops may be wasteful - could pass pointer
44  // to const char* or reference to stringsto be initialized?
45  Timer(const Object *object, const char* operation) {
46  if (internal::stats_level > NO_STATISTICS) {
47  std::string s_operation(operation);
48  initialize(object->get_name() + "::" + operation);
49  }
50  }
51 
52  Timer(std::string operation) {
53  if (internal::stats_level > NO_STATISTICS) {
54  initialize(operation);
55  }
56  }
57  ~Timer() {
58  if (!key_.empty()) save();
59  }
60 };
61 
62 /** Set the level of statistics to be gathered. */
63 IMPBASEEXPORT void set_statistics_level(StatisticsLevel l);
64 
65 IMPBASE_END_NAMESPACE
66 
67 #endif /* IMPBASE_STATISTICS_H */
void show_timings(TextOutput out)
Handling of file input/output.
StatisticsLevel
Specify the level of statistics to record.
Definition: enums.h:73
void set_statistics_level(StatisticsLevel l)
Common base class for heavy weight IMP objects.
Definition: Object.h:106
Basic types used by IMP.
void clear_statistics()