ewmscp  ..
Classes | Public Member Functions | Static Public Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
timer::anchor Class Reference

#include <timer.h>

Collaboration diagram for timer::anchor:
[legend]

Classes

class  pointerCompare
 

Public Member Functions

 anchor (const char *aSubFunc, const char *aFunc=__builtin_FUNCTION(), int aLine=__builtin_LINE(), const char *aFile=__builtin_FILE())
 
const char * getFunc () const
 
const char * getFile () const
 
int getLine () const
 

Static Public Member Functions

static void print (std::ostream &out, const std::string &prefix)
 
static void reset ()
 

Static Private Member Functions

static std::set< anchor *, pointerCompare > & getList ()
 

Private Attributes

const char * subfunc
 
const char * function
 
const char * file
 
int line
 
std::atomic< int > counter
 
std::atomic< std::uint64_t > timeSpent
 
std::atomic< std::int64_t > maxTimeSpent
 

Static Private Attributes

static std::mutex listMutex
 

Friends

class instanceUnscoped
 
class pointerCompare
 

Detailed Description

Definition at line 22 of file timer.h.

Constructor & Destructor Documentation

◆ anchor()

timer::anchor::anchor ( const char *  aSubFunc,
const char *  aFunc = __builtin_FUNCTION(),
int  aLine = __builtin_LINE(),
const char *  aFile = __builtin_FILE() 
)
inline

Definition at line 56 of file timer.h.

59  :
60  #else // no info available....
61  anchor(const char * aSubFunc,
62  const char *aFunc = "unknown",
63  int aLine = 0,
64  const char *aFile = "unknown"):
65  #endif
66  subfunc(aSubFunc),
67  function(aFunc),
68  file(aFile),
69  line(aLine),
70  counter(0) {
71  std::unique_lock<decltype(listMutex)> lock(listMutex);
72  getList().emplace(this);
73  }

References getList(), and listMutex.

Here is the call graph for this function:

Member Function Documentation

◆ getFile()

const char* timer::anchor::getFile ( ) const
inline

Definition at line 77 of file timer.h.

77  {
78  return file;
79  };

References file.

◆ getFunc()

const char* timer::anchor::getFunc ( ) const
inline

Definition at line 74 of file timer.h.

74  {
75  return function;
76  };

◆ getLine()

int timer::anchor::getLine ( ) const
inline

Definition at line 80 of file timer.h.

80  {
81  return line;
82  };

References line.

◆ getList()

static std::set<anchor*, pointerCompare>& timer::anchor::getList ( )
inlinestaticprivate

Definition at line 49 of file timer.h.

49  {
50  static std::set<anchor*, pointerCompare> list;
51  return list;
52  }

Referenced by anchor(), print(), and reset().

Here is the caller graph for this function:

◆ print()

void timer::anchor::print ( std::ostream &  out,
const std::string &  prefix 
)
static

Definition at line 5 of file timer.cpp.

5  {
6  double totalTime = 0;
7  unsigned int totalCalls = 0;
8  std::unique_lock<decltype(listMutex)> lock(listMutex);
9  for (const auto item : getList()) {
10  double t = item->timeSpent / 1e9;
11  out << prefix
12  << item->getFile() << ":"
13  << item->getLine() << ": "
14  << item->getFunc() << ": "
15  << item->subfunc << ": "
16  << item->counter << " avg ";
17  if (item->counter > 0) {
18  out << t / item->counter << "s tot ";
19  } else {
20  out << "-- tot ";
21  }
22  out << t << "s max ";
23  out << item->maxTimeSpent/ 1e9 << "s \n";
24  totalTime += t;
25  totalCalls += item->counter;
26  }
27  out << prefix << "spent " << totalTime << "s in " << totalCalls << " calls\n";
28  }

References getList(), and listMutex.

Referenced by main(), and copyRequest::base::printStats().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

static void timer::anchor::reset ( )
inlinestatic

Definition at line 86 of file timer.h.

86  {
87  std::unique_lock<decltype(listMutex)> lock(listMutex);
88  for (auto item : getList()) {
89  item->timeSpent = 0;
90  item->counter = 0;
91  item->maxTimeSpent = 0;
92  }
93  }

References getList(), and listMutex.

Referenced by copyRequest::base::resetStats().

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ instanceUnscoped

friend class instanceUnscoped
friend

Definition at line 23 of file timer.h.

◆ pointerCompare

friend class pointerCompare
friend

Definition at line 24 of file timer.h.

Member Data Documentation

◆ counter

std::atomic<int> timer::anchor::counter
private

Definition at line 45 of file timer.h.

Referenced by timer::instanceUnscoped::stop().

◆ file

const char* timer::anchor::file
private

◆ function

const char* timer::anchor::function
private

Definition at line 26 of file timer.h.

Referenced by timer::instanceUnscoped::stop().

◆ line

int timer::anchor::line
private

◆ listMutex

std::mutex timer::anchor::listMutex
staticprivate

Definition at line 48 of file timer.h.

Referenced by anchor(), print(), and reset().

◆ maxTimeSpent

std::atomic<std::int64_t> timer::anchor::maxTimeSpent
private

Definition at line 47 of file timer.h.

Referenced by timer::instanceUnscoped::stop().

◆ subfunc

const char* timer::anchor::subfunc
private

Definition at line 25 of file timer.h.

Referenced by timer::instanceUnscoped::stop().

◆ timeSpent

std::atomic<std::uint64_t> timer::anchor::timeSpent
private

Definition at line 46 of file timer.h.

Referenced by timer::instanceUnscoped::stop().


The documentation for this class was generated from the following files:
timer::anchor::file
const char * file
Definition: timer.h:27
timer::anchor::line
int line
Definition: timer.h:28
timer::anchor::anchor
anchor(const char *aSubFunc, const char *aFunc=__builtin_FUNCTION(), int aLine=__builtin_LINE(), const char *aFile=__builtin_FILE())
Definition: timer.h:56
timer::anchor::counter
std::atomic< int > counter
Definition: timer.h:45
timer::anchor::getList
static std::set< anchor *, pointerCompare > & getList()
Definition: timer.h:49
timer::anchor::subfunc
const char * subfunc
Definition: timer.h:25
timer::anchor::listMutex
static std::mutex listMutex
Definition: timer.h:48
timer::anchor::function
const char * function
Definition: timer.h:26