void Profiler::dump() { #ifdef PROFILE_CLOCKS fprintf(stderr, "Profiling points [CPU time]:\n"); #else fprintf(stderr, "Profiling points [Wall time]:\n"); #endif fprintf(stderr, "\nBy name:\n"); typedef std::set<const char *, std::less<std::string> > StringSet; StringSet profileNames; for (ProfileMap::const_iterator i = m_profiles.begin(); i != m_profiles.end(); ++i) { profileNames.insert(i->first); } for (StringSet::const_iterator i = profileNames.begin(); i != profileNames.end(); ++i) { ProfileMap::const_iterator j = m_profiles.find(*i); if (j == m_profiles.end()) continue; const TimePair &pp(j->second); fprintf(stderr, "%s(%d):\n", *i, pp.first); fprintf(stderr, "\tReal: \t%f ms \t[%f ms total]\n", (pp.second / pp.first), (pp.second)); WorstCallMap::const_iterator k = m_worstCalls.find(*i); if (k == m_worstCalls.end()) continue; fprintf(stderr, "\tWorst:\t%f ms/call\n", k->second); } typedef std::multimap<float, const char *> TimeRMap; typedef std::multimap<int, const char *> IntRMap; TimeRMap totmap, avgmap, worstmap; IntRMap ncallmap; for (ProfileMap::const_iterator i = m_profiles.begin(); i != m_profiles.end(); ++i) { totmap.insert(TimeRMap::value_type(i->second.second, i->first)); avgmap.insert(TimeRMap::value_type(i->second.second / i->second.first, i->first)); ncallmap.insert(IntRMap::value_type(i->second.first, i->first)); } for (WorstCallMap::const_iterator i = m_worstCalls.begin(); i != m_worstCalls.end(); ++i) { worstmap.insert(TimeRMap::value_type(i->second, i->first)); } fprintf(stderr, "\nBy total:\n"); for (TimeRMap::const_iterator i = totmap.end(); i != totmap.begin(); ) { --i; fprintf(stderr, "%-40s %f ms\n", i->second, i->first); } fprintf(stderr, "\nBy average:\n"); for (TimeRMap::const_iterator i = avgmap.end(); i != avgmap.begin(); ) { --i; fprintf(stderr, "%-40s %f ms\n", i->second, i->first); } fprintf(stderr, "\nBy worst case:\n"); for (TimeRMap::const_iterator i = worstmap.end(); i != worstmap.begin(); ) { --i; fprintf(stderr, "%-40s %f ms\n", i->second, i->first); } fprintf(stderr, "\nBy number of calls:\n"); for (IntRMap::const_iterator i = ncallmap.end(); i != ncallmap.begin(); ) { --i; fprintf(stderr, "%-40s %d\n", i->second, i->first); } }
void Profiles::dump() const { #ifndef NO_TIMING fprintf(stderr, "Profiling points:\n"); fprintf(stderr, "\nBy name:\n"); typedef std::set<const char *, std::less<std::string> > StringSet; StringSet profileNames; for (ProfileMap::const_iterator i = m_profiles.begin(); i != m_profiles.end(); ++i) { profileNames.insert(i->first); } for (StringSet::const_iterator i = profileNames.begin(); i != profileNames.end(); ++i) { ProfileMap::const_iterator j = m_profiles.find(*i); if (j == m_profiles.end()) continue; const ProfilePair &pp(j->second); fprintf(stderr, "%s(%d):\n", *i, pp.first); fprintf(stderr, "\tCPU: \t%.9g ms/call \t[%d ms total]\n", (((double)pp.second.first * 1000.0 / (double)pp.first) / CLOCKS_PER_SEC), int((pp.second.first * 1000.0) / CLOCKS_PER_SEC)); fprintf(stderr, "\tReal: \t%s ms \t[%s ms total]\n", ((pp.second.second / pp.first) * 1000).toString().c_str(), (pp.second.second * 1000).toString().c_str()); WorstCallMap::const_iterator k = m_worstCalls.find(*i); if (k == m_worstCalls.end()) continue; const TimePair &wc(k->second); fprintf(stderr, "\tWorst:\t%s ms/call \t[%d ms CPU]\n", (wc.second * 1000).toString().c_str(), int((wc.first * 1000.0) / CLOCKS_PER_SEC)); } typedef std::multimap<RealTime, const char *> TimeRMap; typedef std::multimap<int, const char *> IntRMap; TimeRMap totmap, avgmap, worstmap; IntRMap ncallmap; for (ProfileMap::const_iterator i = m_profiles.begin(); i != m_profiles.end(); ++i) { totmap.insert(TimeRMap::value_type(i->second.second.second, i->first)); avgmap.insert(TimeRMap::value_type(i->second.second.second / i->second.first, i->first)); ncallmap.insert(IntRMap::value_type(i->second.first, i->first)); } for (WorstCallMap::const_iterator i = m_worstCalls.begin(); i != m_worstCalls.end(); ++i) { worstmap.insert(TimeRMap::value_type(i->second.second, i->first)); } fprintf(stderr, "\nBy total:\n"); for (TimeRMap::const_iterator i = totmap.end(); i != totmap.begin(); ) { --i; fprintf(stderr, "%-40s %s ms\n", i->second, (i->first * 1000).toString().c_str()); } fprintf(stderr, "\nBy average:\n"); for (TimeRMap::const_iterator i = avgmap.end(); i != avgmap.begin(); ) { --i; fprintf(stderr, "%-40s %s ms\n", i->second, (i->first * 1000).toString().c_str()); } fprintf(stderr, "\nBy worst case:\n"); for (TimeRMap::const_iterator i = worstmap.end(); i != worstmap.begin(); ) { --i; fprintf(stderr, "%-40s %s ms\n", i->second, (i->first * 1000).toString().c_str()); } fprintf(stderr, "\nBy number of calls:\n"); for (IntRMap::const_iterator i = ncallmap.end(); i != ncallmap.begin(); ) { --i; fprintf(stderr, "%-40s %d\n", i->second, i->first); } #endif }