Flowlessly  0.1
Minimum cost maximum cost solver
 All Classes Functions Pages
statistics.h
1 // The Flowlessly project
2 // Copyright (c) 2013-2016 Ionel Gog <ionel.gog@cl.cam.ac.uk>
3 
4 #ifndef STATISTICS_H
5 #define STATISTICS_H
6 
7 #include <gflags/gflags.h>
8 #include <sys/time.h>
9 #include <sys/resource.h>
10 
11 DECLARE_bool(statistics);
12 
13 namespace flowlessly {
14 
19 class Statistics {
20  public:
21  void ResetStatistics();
22  void LogStatistics();
23 
24  inline double get_arcs_fixing_time() {
25  return arcs_fixing_time_;
26  }
27 
28  inline double get_arcs_unfixing_time() {
29  return arcs_unfixing_time_;
30  }
31 
32  inline double get_discharge_time() {
33  return discharge_time_;
34  }
35 
36  inline double get_global_update_time() {
37  return global_update_time_;
38  }
39 
40  inline uint32_t get_num_pushes() {
41  return num_pushes_;
42  }
43 
44  inline uint32_t get_num_refines() {
45  return num_refines_;
46  }
47 
48  inline uint32_t get_num_relabels() {
49  return num_relabels_;
50  }
51 
52  inline double get_price_refine_time() {
53  return price_refine_time_;
54  }
55 
56  inline double get_refine_time_() {
57  return refine_time_;
58  }
59 
60  inline double get_relabel_time() {
61  return relabel_time_;
62  }
63 
64  inline double get_push_time() {
65  return push_time_;
66  }
67 
68  inline double get_time() {
69  struct rusage r;
70  getrusage(0, &r);
71  return r.ru_utime.tv_sec + static_cast<double>(r.ru_utime.tv_usec) /
72  1000000.0;
73  }
74 
75  inline double get_update_admissible_time() {
76  return update_admissible_time_;
77  }
78 
79  inline void increment_num_pushes() {
80  num_pushes_++;
81  }
82 
83  inline void increment_num_refines() {
84  num_refines_++;
85  }
86 
87  inline void increment_num_relabels() {
88  num_relabels_++;
89  }
90 
91  inline void update_admissible_start_time() {
92  if (FLAGS_statistics) {
93  update_admissible_time_ -= get_time();
94  }
95  }
96 
97  inline void update_admissible_end_time() {
98  if (FLAGS_statistics) {
99  update_admissible_time_ += get_time();
100  }
101  }
102 
103  inline void update_arcs_fixing_start_time() {
104  if (FLAGS_statistics) {
105  arcs_fixing_time_ -= get_time();
106  }
107  }
108 
109  inline void update_arcs_fixing_end_time() {
110  if (FLAGS_statistics) {
111  arcs_fixing_time_ += get_time();
112  }
113  }
114 
115  inline void update_arcs_unfixing_start_time() {
116  if (FLAGS_statistics) {
117  arcs_unfixing_time_ -= get_time();
118  }
119  }
120 
121  inline void update_arcs_unfixing_end_time() {
122  if (FLAGS_statistics) {
123  arcs_unfixing_time_ += get_time();
124  }
125  }
126 
127  inline void update_discharge_start_time() {
128  if (FLAGS_statistics) {
129  discharge_time_ -= get_time();
130  }
131  }
132 
133  inline void update_discharge_end_time() {
134  if (FLAGS_statistics) {
135  discharge_time_ += get_time();
136  }
137  }
138 
139  inline void update_global_update_start_time() {
140  if (FLAGS_statistics) {
141  global_update_time_ -= get_time();
142  }
143  }
144 
145  inline void update_global_update_end_time() {
146  if (FLAGS_statistics) {
147  global_update_time_ += get_time();
148  }
149  }
150 
151  inline void update_price_refine_start_time() {
152  if (FLAGS_statistics) {
153  price_refine_time_ -= get_time();
154  }
155  }
156 
157  inline void update_price_refine_end_time() {
158  if (FLAGS_statistics) {
159  price_refine_time_ += get_time();
160  }
161  }
162 
163  inline void update_push_start_time() {
164  if (FLAGS_statistics) {
165  push_time_ -= get_time();
166  }
167  }
168 
169  inline void update_push_end_time() {
170  if (FLAGS_statistics) {
171  push_time_ += get_time();
172  }
173  }
174 
175  inline void update_refine_start_time() {
176  if (FLAGS_statistics) {
177  refine_time_ -= get_time();
178  }
179  }
180 
181  inline void update_refine_end_time() {
182  if (FLAGS_statistics) {
183  refine_time_ += get_time();
184  }
185  }
186 
187  inline void update_relabel_start_time() {
188  if (FLAGS_statistics) {
189  relabel_time_ -= get_time();
190  }
191  }
192 
193  inline void update_relabel_end_time() {
194  if (FLAGS_statistics) {
195  relabel_time_ += get_time();
196  }
197  }
198 
199  double arcs_fixing_time_;
200  double arcs_unfixing_time_;
201  double refine_time_;
202  double discharge_time_;
203  double global_update_time_;
204  double price_refine_time_;
205  double relabel_time_;
206  double push_time_;
207  double update_admissible_time_;
208  uint32_t num_relabels_;
209  uint32_t num_pushes_;
210  uint32_t num_refines_;
211 };
212 
213 } // namespace flowlessly
214 #endif
Definition: statistics.h:19