MemUsage.h
Go to the documentation of this file.
1 // http://stackoverflow.com/questions/63166/how-to-determine-cpu-and-memory-consumption-from-inside-a-process
2 // http://stackoverflow.com/questions/669438/how-to-get-memory-usage-at-run-time-in-c
3 
4 #ifndef WIRECELL_MEMUSAGE
5 #define WIRECELL_MEMUSAGE
6 
7 #include <fstream>
8 #include <vector>
9 #include <string>
10 
11 
12 namespace WireCell {
13 
14  double memusage_resident();
15  double memusage_shared();
16  double memusage_size();
17 
18 
19  class MemUsage {
20  public:
21  typedef std::pair<double, double> memusage;
22  typedef std::pair<memusage, std::string> event;
23  MemUsage(const std::string& msg = "start");
24  ~MemUsage();
25 
26  void push(const std::string& msg, MemUsage::memusage mu = memusage(-1,-1));
27 
28  /// Record an event.
30  std::string msg = "<tick>",
31  MemUsage::memusage mu = memusage(-1,-1));
32 
33  /// Return summary up to now.
34  std::string summary() const;
35 
36  /// Return event by index.
37  event operator[](int ind) const;
38 
39  memusage current() const;
40 
41  private:
42  /// Emit a formatted message for the given event index.
43  std::string emit(int ind) const;
44 
45 
46  std::vector< event > m_events;
47 
48  };
49 
50 }
51 
52 
53 #endif
double memusage_size()
Definition: MemUsage.cxx:57
memusage current() const
Definition: MemUsage.cxx:75
void msg(const char *fmt,...)
Definition: message.cpp:107
std::string string
Definition: nybbler.cc:12
std::string operator()(std::string msg="<tick>", MemUsage::memusage mu=memusage(-1,-1))
Record an event.
Definition: MemUsage.cxx:87
std::pair< memusage, std::string > event
Definition: MemUsage.h:22
double memusage_resident()
Definition: MemUsage.cxx:43
Definition: Main.h:22
std::pair< double, double > memusage
Definition: MemUsage.h:21
std::string emit(int ind) const
Emit a formatted message for the given event index.
Definition: MemUsage.cxx:110
void push(const std::string &msg, MemUsage::memusage mu=memusage(-1,-1))
Definition: MemUsage.cxx:79
std::string summary() const
Return summary up to now.
Definition: MemUsage.cxx:101
MemUsage(const std::string &msg="start")
Definition: MemUsage.cxx:66
std::vector< event > m_events
Definition: MemUsage.h:46
event operator[](int ind) const
Return event by index.
Definition: MemUsage.cxx:94
double memusage_shared()
Definition: MemUsage.cxx:50