52 const char*
id, clock_t time,
RealTime rt
57 pair.second.first += time;
58 pair.second.second = pair.second.second + rt;
61 lastPair.first = time;
65 if (time > worstPair.first) {
66 worstPair.first = time;
68 if (rt > worstPair.second) {
69 worstPair.second = rt;
78 fprintf(stderr,
"Profiling points:\n");
80 fprintf(stderr,
"\nBy name:\n");
82 typedef std::set<const char *, std::less<std::string> > StringSet;
84 StringSet profileNames;
85 for (ProfileMap::const_iterator i =
m_profiles.begin();
87 profileNames.insert(i->first);
90 for (StringSet::const_iterator i = profileNames.begin();
91 i != profileNames.end(); ++i) {
93 ProfileMap::const_iterator j =
m_profiles.find(*i);
99 fprintf(stderr,
"%s(%d):\n", *i, pp.first);
101 fprintf(stderr,
"\tCPU: \t%.9g ms/call \t[%d ms total]\n",
102 (((
double)pp.second.first * 1000.0 /
103 (
double)pp.first) / CLOCKS_PER_SEC),
104 int((
double(pp.second.first) * 1000.0) / CLOCKS_PER_SEC));
106 fprintf(stderr,
"\tReal: \t%s ms \t[%s ms total]\n",
107 ((pp.second.second / pp.first) * 1000).toString().c_str(),
108 (pp.second.second * 1000).toString().c_str());
115 fprintf(stderr,
"\tWorst:\t%s ms/call \t[%d ms CPU]\n",
116 (wc.second * 1000).toString().c_str(),
117 int((
double(wc.first) * 1000.0) / CLOCKS_PER_SEC));
120 typedef std::multimap<RealTime, const char *> TimeRMap;
121 typedef std::multimap<int, const char *> IntRMap;
123 TimeRMap totmap, avgmap, worstmap;
126 for (ProfileMap::const_iterator i =
m_profiles.begin();
128 totmap.insert(TimeRMap::value_type(i->second.second.second, i->first));
129 avgmap.insert(TimeRMap::value_type(i->second.second.second /
130 i->second.first, i->first));
131 ncallmap.insert(IntRMap::value_type(i->second.first, i->first));
134 for (WorstCallMap::const_iterator i =
m_worstCalls.begin();
136 worstmap.insert(TimeRMap::value_type(i->second.second,
141 fprintf(stderr,
"\nBy number of calls:\n");
142 for (IntRMap::const_iterator i = ncallmap.end(); i != ncallmap.begin(); ) {
144 fprintf(stderr,
"%-40s %d\n", i->second, i->first);
147 fprintf(stderr,
"\nBy average:\n");
148 for (TimeRMap::const_iterator i = avgmap.end(); i != avgmap.begin(); ) {
150 fprintf(stderr,
"%-40s %s ms\n", i->second,
151 (i->first * 1000).toString().c_str());
154 fprintf(stderr,
"\nBy worst case:\n");
155 for (TimeRMap::const_iterator i = worstmap.end(); i != worstmap.begin(); ) {
157 fprintf(stderr,
"%-40s %s ms\n", i->second,
158 (i->first * 1000).toString().c_str());
161 fprintf(stderr,
"\nBy total:\n");
162 for (TimeRMap::const_iterator i = totmap.end(); i != totmap.begin(); ) {
164 fprintf(stderr,
"%-40s %s ms\n", i->second,
165 (i->first * 1000).toString().c_str());
175 m_showOnDestruct(showOnDestruct),
181 (void)gettimeofday(&tv, 0);
191 (void)gettimeofday(&tv, 0);
194 cerr <<
"Profiler : id = " <<
m_c 195 <<
" - elapsed so far = " << ((elapsedCPU * 1000) / CLOCKS_PER_SEC)
196 <<
"ms CPU, " << elapsedTime <<
" real" << endl;
210 (void)gettimeofday(&tv, 0);
216 cerr <<
"Profiler : id = " <<
m_c 217 <<
" - elapsed = " << ((elapsedCPU * 1000) / CLOCKS_PER_SEC)
218 <<
"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...