Scroom  0.14
BaseCounter Class Reference
Inheritance diagram for BaseCounter:
Inheritance graph
Collaboration diagram for BaseCounter:
Collaboration graph

Public Member Functions

 BaseCounter (const std::string &name, unsigned int secs)
 
bool operator() ()
 

Private Attributes

std::string name
 
unsigned int secs
 
bool started {false}
 
unsigned int count {0}
 
struct timespec t = {0, 0}
 

Static Private Attributes

static unsigned int columnWidth = 0
 

Constructor & Destructor Documentation

◆ BaseCounter()

BaseCounter::BaseCounter ( const std::string &  name,
unsigned int  secs 
)
104  : name(name_)
105  , secs(secs_)
106 {
107  columnWidth = std::max(columnWidth, static_cast<unsigned int>(name_.length()));
108 }

Member Function Documentation

◆ operator()()

bool BaseCounter::operator() ( )
111 {
112  if(!started && 0 == clock_gettime(CLOCK_REALTIME, &t))
113  {
114  started = true;
115  return true;
116  }
117 
118  count++;
119 
120  struct timespec now = {0, 0};
121  if(0 == clock_gettime(CLOCK_REALTIME, &now))
122  {
123  if(now.tv_sec > t.tv_sec + secs)
124  {
125  // We're done. Compute frequency.
126  double elapsed = now.tv_nsec - t.tv_nsec * 1e-9;
127  elapsed += now.tv_sec - t.tv_sec;
128  spdlog::info("{:{}}: {:10.2} Hz", name, columnWidth, count / elapsed);
129 
130  return false;
131  }
132  }
133 
134  return true;
135 }

Referenced by InvalidatingCounter::operator()().

Here is the caller graph for this function:

Member Data Documentation

◆ columnWidth

unsigned int BaseCounter::columnWidth = 0
staticprivate

Referenced by BaseCounter(), and operator()().

◆ count

unsigned int BaseCounter::count {0}
private

Referenced by operator()().

◆ name

std::string BaseCounter::name
private

Referenced by operator()().

◆ secs

unsigned int BaseCounter::secs
private

Referenced by operator()().

◆ started

bool BaseCounter::started {false}
private

Referenced by operator()().

◆ t

struct timespec BaseCounter::t = {0, 0}
private

Referenced by operator()().


The documentation for this class was generated from the following file:
BaseCounter::columnWidth
static unsigned int columnWidth
Definition: measure-framerate-tests.cc:47
BaseCounter::started
bool started
Definition: measure-framerate-tests.cc:43
BaseCounter::count
unsigned int count
Definition: measure-framerate-tests.cc:44
BaseCounter::t
struct timespec t
Definition: measure-framerate-tests.cc:45
BaseCounter::name
std::string name
Definition: measure-framerate-tests.cc:41
BaseCounter::secs
unsigned int secs
Definition: measure-framerate-tests.cc:42