1
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
5
An audio time-stretching and pitch-shifting library.
6
Copyright 2007-2008 Chris Cannam.
8
This program is free software; you can redistribute it and/or
9
modify it under the terms of the GNU General Public License as
10
published by the Free Software Foundation; either version 2 of the
11
License, or (at your option) any later version. See the file
12
COPYING included with this distribution for more information.
24
namespace RubberBand {
31
Profiler::WorstCallMap
32
Profiler::m_worstCalls;
35
Profiler::add(const char *id, float ms)
37
ProfileMap::iterator pmi = m_profiles.find(id);
38
if (pmi != m_profiles.end()) {
40
pmi->second.second += ms;
42
m_profiles[id] = TimePair(1, ms);
45
WorstCallMap::iterator wci = m_worstCalls.find(id);
46
if (wci != m_worstCalls.end()) {
47
if (ms > wci->second) wci->second = ms;
49
m_worstCalls[id] = ms;
57
fprintf(stderr, "Profiling points [CPU time]:\n");
59
fprintf(stderr, "Profiling points [Wall time]:\n");
62
fprintf(stderr, "\nBy name:\n");
64
typedef std::set<const char *, std::less<std::string> > StringSet;
66
StringSet profileNames;
67
for (ProfileMap::const_iterator i = m_profiles.begin();
68
i != m_profiles.end(); ++i) {
69
profileNames.insert(i->first);
72
for (StringSet::const_iterator i = profileNames.begin();
73
i != profileNames.end(); ++i) {
75
ProfileMap::const_iterator j = m_profiles.find(*i);
76
if (j == m_profiles.end()) continue;
78
const TimePair &pp(j->second);
79
fprintf(stderr, "%s(%d):\n", *i, pp.first);
80
fprintf(stderr, "\tReal: \t%f ms \t[%f ms total]\n",
81
(pp.second / pp.first),
84
WorstCallMap::const_iterator k = m_worstCalls.find(*i);
85
if (k == m_worstCalls.end()) continue;
87
fprintf(stderr, "\tWorst:\t%f ms/call\n", k->second);
90
typedef std::multimap<float, const char *> TimeRMap;
91
typedef std::multimap<int, const char *> IntRMap;
92
TimeRMap totmap, avgmap, worstmap;
95
for (ProfileMap::const_iterator i = m_profiles.begin();
96
i != m_profiles.end(); ++i) {
97
totmap.insert(TimeRMap::value_type(i->second.second, i->first));
98
avgmap.insert(TimeRMap::value_type(i->second.second /
99
i->second.first, i->first));
100
ncallmap.insert(IntRMap::value_type(i->second.first, i->first));
103
for (WorstCallMap::const_iterator i = m_worstCalls.begin();
104
i != m_worstCalls.end(); ++i) {
105
worstmap.insert(TimeRMap::value_type(i->second, i->first));
108
fprintf(stderr, "\nBy total:\n");
109
for (TimeRMap::const_iterator i = totmap.end(); i != totmap.begin(); ) {
111
fprintf(stderr, "%-40s %f ms\n", i->second, i->first);
114
fprintf(stderr, "\nBy average:\n");
115
for (TimeRMap::const_iterator i = avgmap.end(); i != avgmap.begin(); ) {
117
fprintf(stderr, "%-40s %f ms\n", i->second, i->first);
120
fprintf(stderr, "\nBy worst case:\n");
121
for (TimeRMap::const_iterator i = worstmap.end(); i != worstmap.begin(); ) {
123
fprintf(stderr, "%-40s %f ms\n", i->second, i->first);
126
fprintf(stderr, "\nBy number of calls:\n");
127
for (IntRMap::const_iterator i = ncallmap.end(); i != ncallmap.begin(); ) {
129
fprintf(stderr, "%-40s %d\n", i->second, i->first);
133
Profiler::Profiler(const char* c) :
137
#ifdef PROFILE_CLOCKS
140
(void)gettimeofday(&m_start, 0);
144
Profiler::~Profiler()
152
#ifdef PROFILE_CLOCKS
153
clock_t end = clock();
154
clock_t elapsed = end - m_start;
155
float ms = float((double(elapsed) / double(CLOCKS_PER_SEC)) * 1000.0);
158
(void)gettimeofday(&tv, 0);
160
tv.tv_sec -= m_start.tv_sec;
161
if (tv.tv_usec < m_start.tv_usec) {
162
tv.tv_usec += 1000000;
165
tv.tv_usec -= m_start.tv_usec;
166
float ms = float((double(tv.tv_sec) + (double(tv.tv_usec) / 1000000.0)) * 1000.0);