52 const char*
id, clock_t time,
RealTime rt
61 pair.second.first += time;
62 pair.second.second = pair.second.second + rt;
65 lastPair.first = time;
69 if (time > worstPair.first) {
70 worstPair.first = time;
72 if (rt > worstPair.second) {
73 worstPair.second = rt;
82 fprintf(stderr,
"Profiling points:\n");
84 fprintf(stderr,
"\nBy name:\n");
86 typedef std::set<const char *, std::less<std::string> > StringSet;
88 StringSet profileNames;
89 for (ProfileMap::const_iterator i =
m_profiles.begin();
91 profileNames.insert(i->first);
94 for (StringSet::const_iterator i = profileNames.begin();
95 i != profileNames.end(); ++i) {
97 ProfileMap::const_iterator j =
m_profiles.find(*i);
103 fprintf(stderr,
"%s(%d):\n", *i, pp.first);
105 fprintf(stderr,
"\tCPU: \t%.9g ms/call \t[%d ms total]\n",
106 (((
double)pp.second.first * 1000.0 /
107 (
double)pp.first) / CLOCKS_PER_SEC),
108 int((pp.second.first * 1000.0) / CLOCKS_PER_SEC));
110 fprintf(stderr,
"\tReal: \t%s ms \t[%s ms total]\n",
111 ((pp.second.second / pp.first) * 1000).toString().c_str(),
112 (pp.second.second * 1000).toString().c_str());
119 fprintf(stderr,
"\tWorst:\t%s ms/call \t[%d ms CPU]\n",
120 (wc.second * 1000).toString().c_str(),
121 int((wc.first * 1000.0) / CLOCKS_PER_SEC));
124 typedef std::multimap<RealTime, const char *> TimeRMap;
125 typedef std::multimap<int, const char *> IntRMap;
127 TimeRMap totmap, avgmap, worstmap;
130 for (ProfileMap::const_iterator i =
m_profiles.begin();
132 totmap.insert(TimeRMap::value_type(i->second.second.second, i->first));
133 avgmap.insert(TimeRMap::value_type(i->second.second.second /
134 i->second.first, i->first));
135 ncallmap.insert(IntRMap::value_type(i->second.first, i->first));
138 for (WorstCallMap::const_iterator i =
m_worstCalls.begin();
140 worstmap.insert(TimeRMap::value_type(i->second.second,
145 fprintf(stderr,
"\nBy total:\n");
146 for (TimeRMap::const_iterator i = totmap.end(); i != totmap.begin(); ) {
148 fprintf(stderr,
"%-40s %s ms\n", i->second,
149 (i->first * 1000).toString().c_str());
152 fprintf(stderr,
"\nBy average:\n");
153 for (TimeRMap::const_iterator i = avgmap.end(); i != avgmap.begin(); ) {
155 fprintf(stderr,
"%-40s %s ms\n", i->second,
156 (i->first * 1000).toString().c_str());
159 fprintf(stderr,
"\nBy worst case:\n");
160 for (TimeRMap::const_iterator i = worstmap.end(); i != worstmap.begin(); ) {
162 fprintf(stderr,
"%-40s %s ms\n", i->second,
163 (i->first * 1000).toString().c_str());
166 fprintf(stderr,
"\nBy number of calls:\n");
167 for (IntRMap::const_iterator i = ncallmap.end(); i != ncallmap.begin(); ) {
169 fprintf(stderr,
"%-40s %d\n", i->second, i->first);
179 m_showOnDestruct(showOnDestruct),
185 (void)gettimeofday(&tv, 0);
195 (void)gettimeofday(&tv, 0);
198 cerr <<
"Profiler : id = " <<
m_c 199 <<
" - elapsed so far = " << ((elapsedCPU * 1000) / CLOCKS_PER_SEC)
200 <<
"ms CPU, " << elapsedTime <<
" real" << endl;
214 (void)gettimeofday(&tv, 0);
220 cerr <<
"Profiler : id = " <<
m_c 221 <<
" - elapsed = " << ((elapsedCPU * 1000) / CLOCKS_PER_SEC)
222 <<
"ms CPU, " << elapsedTime <<
" real" << endl;
static RealTime fromTimeval(const struct timeval &)
WorstCallMap m_worstCalls
std::pair< clock_t, RealTime > TimePair
static Profiles * m_instance
static Profiles * getInstance()
std::pair< int, TimePair > ProfilePair
Profiler(const char *name, bool showOnDestruct=false)
Create a profile point instance that records time consumed against the given profiling point name.
void accumulate(const char *id, clock_t time, RealTime rt)
RealTime represents time values to nanosecond precision with accurate arithmetic and frame-rate conve...