CountedObjectRegistry.cc
Go to the documentation of this file.
1 #include <string>
2 #include <map>
3 #include <utility>
4 #include <typeinfo>
5 #include <cxxabi.h> // g++ specific
6 #include <cstdlib>
7 
8 #include <utl/TabularStream.h>
9 #include <utl/CountedObjectRegistry.h>
10 
11 using namespace utl;
12 using std::string;
13 using std::pair;
14 
15 
16 std::map<string, CountedObjectRegistry::Counters> CountedObjectRegistry::fgRegistry;
17 
18 
19 void
21 RegisterObjectCounters(const std::type_info& theType,
22  const CountedObjectRegistry::intFP countCreated,
23  const CountedObjectRegistry::intFP countDestroyed,
24  const CountedObjectRegistry::intFP countExisting,
25  const CountedObjectRegistry::intFP countCopied,
26  const CountedObjectRegistry::intFP countAssigned)
27 {
28  string name(theType.name());
29  fgRegistry.insert(make_pair(name,
31  countDestroyed,
32  countExisting,
33  countCopied,
34  countAssigned)));
35 }
36 
37 
38 void
40  const string& filter)
41 {
42  TabularStream tab("| l |r|r|r|r|r|");
43 
44  tab << hline
45  << "name" << endc
46  << "ctor" << endc
47  << "dtor" << endc
48  << " E " << endc
49  << "cctor" << endc
50  << " = " << endr
51  << hline;
52 
53  for (const auto& nc : fgRegistry) {
54  int status = 0;
55  char* const rName = abi::__cxa_demangle(nc.first.c_str(), 0, 0, &status);
56  const string realName(rName);
57  if (!realName.find(filter)) {
58  const Counters& c = nc.second;
59  tab << realName << endc
60  << c.GetCreated() << ' ' << endc
61  << c.GetDestroyed() << ' ' << endc
62  << c.GetExisting() << ' ' << endc
63  << c.GetCopied() << ' ' << endc
64  << c.GetAssigned() << ' ' << endr;
65  }
66  free(rName);
67  }
68  tab << hline;
69 
70  os << tab;
71 }
72 
73 
75 Counters(const intFP countCreated, const intFP countDestroyed,
76  const intFP countExisting, const intFP countCopied,
77  const intFP countAssigned) :
78  fCountCreated(countCreated),
79  fCountDestroyed(countDestroyed),
80  fCountExisting(countExisting),
81  fCountCopied(countCopied),
82  fCountAssigned(countAssigned)
83 { }
84 
85 
88  const
89 {
90  return fCountCreated();
91 }
92 
93 
96  const
97 {
98  return fCountDestroyed();
99 }
100 
101 
104  const
105 {
106  return fCountExisting();
107 }
108 
109 
112  const
113 {
114  return fCountCopied();
115 }
116 
117 
120  const
121 {
122  return fCountAssigned();
123 }
static std::map< std::string, Counters > fgRegistry
static void RegisterObjectCounters(const std::type_info &theType, const intFP countCreated, const intFP countDestroyed, const intFP countExisting, const intFP countCopied, const intFP countAssigned)
const EndRow endr
const int tab
Definition: SdInspector.cc:35
class to format data in tabular form
static void PrintStatistics(std::ostream &theStream, const std::string &filter="")
const HLine hline('-')
const EndColumn endc
Counters(const intFP countCreated, const intFP countDestroyed, const intFP countExisting, const intFP countCopied, const intFP countAssigned)

, generated on Tue Sep 26 2023.