IMP logo
IMP Reference Guide  2.7.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-2017 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPKERNEL_BASE_STATISTICS_H
10 #define IMPKERNEL_BASE_STATISTICS_H
11 
12 #include <IMP/kernel_config.h>
13 #include "file.h"
14 #include "enums.h"
15 #include "internal/base_static.h"
16 #include <string>
17 #include <ctime>
18 
19 IMPKERNEL_BEGIN_NAMESPACE
20 
21 IMPKERNEL_DEPRECATED_FUNCTION_DECL(2.7)
22 IMPKERNELEXPORT void clear_statistics();
23 
24 IMPKERNEL_DEPRECATED_FUNCTION_DECL(2.7)
25 IMPKERNELEXPORT void show_timings(TextOutput out);
26 
27 //! Time an operation and save the timings.
28 class IMPKERNELEXPORT 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 IMPKERNEL_DEPRECATED_FUNCTION_DECL(2.7)
63 IMPKERNELEXPORT void set_statistics_level(StatisticsLevel l);
64 
65 IMPKERNEL_END_NAMESPACE
66 
67 #endif /* IMPKERNEL_BASE_STATISTICS_H */
Temporarily change something; undo the change when this object is destroyed.
Definition: RAII.h:26
Handling of file input/output.
StatisticsLevel
Specify the level of statistics to record.
Definition: enums.h:72
Common base class for heavy weight IMP objects.
Definition: Object.h:106
Time an operation and save the timings.
Basic types used by IMP.