resourceMonitor.hh

Go to the documentation of this file.
1 
6 #ifndef resourceMonitor_hh
7 #define resourceMonitor_hh
8 
9 #include <iostream>
10 
11 #include <sys/time.h>
12 #include <sys/resource.h>
13 #include <unistd.h>
14 #include <string.h>
15 #include <time.h>
16 
17 extern "C" {
18 #ifdef __sun__
19  // Solaris 2.5 does not have getrusage in <sys/resource.h>
20  int getrusage(int who, struct rusage* ru);
21 #endif
22 }
23 
24 namespace concepts {
25 
26  // ******************************************************* ResourceMonitor **
27 
30  friend std::ostream& operator <<(std::ostream& os, ResourceMonitor& rm) {
31  return rm.sample(os); }
32 
36  rusage ru_;
37  public:
41  ResourceMonitor() { getrusage(RUSAGE_SELF, &ru_); }
42 
56  std::ostream& sample(std::ostream& os);
57 
61  float utime();
62  };
63 
64 }
65 
66  // ******************************************************** ResourceTimer **
67 
72 public:
73 
75  memset(&t_old, 0, sizeof(t_old));
76  memset(&t_cur, 0, sizeof(t_cur));
77  start();
78  }
79 
81 
82  void start();
83  double stop(int nrun = 1);
84 
85  double reset(int nrun = 1) {
86  double t = stop(nrun);
87  //start();
88  t_old = t_cur;
89  return t;
90  }
91 
92 
93  timespec t_old;
94  timespec t_cur;
95 };
96 
97 #endif // resourceMonitor_hh
rusage ru_
Stores snapshot of resources since construction or last output.
Timer and resource monitor.
friend std::ostream & operator<<(std::ostream &os, ResourceMonitor &rm)
double stop(int nrun=1)
double reset(int nrun=1)
std::ostream & sample(std::ostream &os)
Returns an output stream with resource information.
more precise timer
ResourceMonitor()
Default constructor.
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
float utime()
Returns the user time since the last call of ResourceMonitor using getrusage.
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich