IMP  2.2.0
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  Timer(const Object *object, std::string operation) {
37  if (internal::stats_level > NO_STATISTICS) {
38  initialize(object->get_name() + "::" + operation);
39  }
40  }
41  Timer(std::string operation) {
42  if (internal::stats_level > NO_STATISTICS) {
43  initialize(operation);
44  }
45  }
46  ~Timer() {
47  if (!key_.empty()) save();
48  }
49 };
50 
51 /** Set the level of statistics to be gathered. */
52 IMPBASEEXPORT void set_statistics_level(StatisticsLevel l);
53 
54 IMPBASE_END_NAMESPACE
55 
56 #endif /* IMPBASE_STATISTICS_H */
void show_timings(TextOutput out)
StatisticsLevel
Specify the level of statistics to record.
Definition: base/enums.h:73
void set_statistics_level(StatisticsLevel l)
Basic types used by IMP.
Common base class for heavy weight IMP objects.
Definition: base/Object.h:106
void clear_statistics()
Handling of file input/output.