Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
WireCell::MemUsage Class Reference

#include <MemUsage.h>

Public Types

typedef std::pair< double, double > memusage
 
typedef std::pair< memusage, std::stringevent
 

Public Member Functions

 MemUsage (const std::string &msg="start")
 
 ~MemUsage ()
 
void push (const std::string &msg, MemUsage::memusage mu=memusage(-1,-1))
 
std::string operator() (std::string msg="<tick>", MemUsage::memusage mu=memusage(-1,-1))
 Record an event. More...
 
std::string summary () const
 Return summary up to now. More...
 
event operator[] (int ind) const
 Return event by index. More...
 
memusage current () const
 

Private Member Functions

std::string emit (int ind) const
 Emit a formatted message for the given event index. More...
 

Private Attributes

std::vector< eventm_events
 

Detailed Description

Definition at line 19 of file MemUsage.h.

Member Typedef Documentation

Definition at line 22 of file MemUsage.h.

typedef std::pair<double, double> WireCell::MemUsage::memusage

Definition at line 21 of file MemUsage.h.

Constructor & Destructor Documentation

MemUsage::MemUsage ( const std::string msg = "start")

Definition at line 66 of file MemUsage.cxx.

67 {
68  push(msg);
69 }
void msg(const char *fmt,...)
Definition: message.cpp:107
void push(const std::string &msg, MemUsage::memusage mu=memusage(-1,-1))
Definition: MemUsage.cxx:79
MemUsage::~MemUsage ( )

Definition at line 71 of file MemUsage.cxx.

72 {
73 }

Member Function Documentation

MemUsage::memusage MemUsage::current ( ) const

Definition at line 75 of file MemUsage.cxx.

76 {
78 }
double memusage_size()
Definition: MemUsage.cxx:57
double memusage_resident()
Definition: MemUsage.cxx:43
std::pair< double, double > memusage
Definition: MemUsage.h:21
std::string MemUsage::emit ( int  ind) const
private

Emit a formatted message for the given event index.

Definition at line 110 of file MemUsage.cxx.

111 {
112  while (ind < 0) { ind += m_events.size();}
113  int prev_ind = ind-1;
114  if (prev_ind<0) prev_ind=0;
115 
116  const memusage& prev_mem = (*this)[prev_ind].first;
117  const memusage& evt_mem = (*this)[ind].first;
118  const string& evt_msg = (*this)[ind].second;
119 
120  memusage from_prev(evt_mem.first - prev_mem.first, evt_mem.second - prev_mem.second);
121 
122  stringstream ss;
123  ss << "MEM: total: size=" << evt_mem.first << "K, res=" << evt_mem.second << "K "
124  << "increment: size=" << from_prev.first << "K, res=" << from_prev.second << "K "
125  << evt_msg;
126  return ss.str();
127 }
std::pair< double, double > memusage
Definition: MemUsage.h:21
std::vector< event > m_events
Definition: MemUsage.h:46
std::string MemUsage::operator() ( std::string  msg = "<tick>",
MemUsage::memusage  mu = memusage(-1,-1) 
)

Record an event.

Definition at line 87 of file MemUsage.cxx.

88 {
89  push(msg, mu);
90  return emit(-1);
91 }
void msg(const char *fmt,...)
Definition: message.cpp:107
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
MemUsage::event MemUsage::operator[] ( int  ind) const

Return event by index.

Definition at line 94 of file MemUsage.cxx.

95 {
96  while (ind < 0) { ind += m_events.size();}
97 
98  return m_events[ind];
99 }
std::vector< event > m_events
Definition: MemUsage.h:46
void MemUsage::push ( const std::string msg,
MemUsage::memusage  mu = memusage(-1,-1) 
)

Definition at line 79 of file MemUsage.cxx.

80 {
81  if (mu.first < 0 && mu.second < 0) {
82  mu = current();
83  }
84  m_events.push_back(event(mu,msg));
85 }
memusage current() const
Definition: MemUsage.cxx:75
void msg(const char *fmt,...)
Definition: message.cpp:107
std::pair< memusage, std::string > event
Definition: MemUsage.h:22
std::vector< event > m_events
Definition: MemUsage.h:46
std::string MemUsage::summary ( ) const

Return summary up to now.

Definition at line 101 of file MemUsage.cxx.

102 {
103  stringstream ss;
104  for (size_t ind=0; ind<m_events.size(); ++ind) {
105  ss << this->emit(ind) << "\n";
106  }
107  return ss.str();
108 }
std::string emit(int ind) const
Emit a formatted message for the given event index.
Definition: MemUsage.cxx:110
std::vector< event > m_events
Definition: MemUsage.h:46

Member Data Documentation

std::vector< event > WireCell::MemUsage::m_events
private

Definition at line 46 of file MemUsage.h.


The documentation for this class was generated from the following files: