Add profile points; switch to microseconds

This commit is contained in:
Chris Cannam
2022-07-14 10:02:39 +01:00
parent 7179c2626c
commit dc74c993cf
7 changed files with 85 additions and 43 deletions

View File

@@ -50,23 +50,23 @@ Profiler::m_worstCalls;
static Mutex profileMutex; static Mutex profileMutex;
void void
Profiler::add(const char *id, double ms) Profiler::add(const char *id, double us)
{ {
profileMutex.lock(); profileMutex.lock();
ProfileMap::iterator pmi = m_profiles.find(id); ProfileMap::iterator pmi = m_profiles.find(id);
if (pmi != m_profiles.end()) { if (pmi != m_profiles.end()) {
++pmi->second.first; ++pmi->second.first;
pmi->second.second += ms; pmi->second.second += us;
} else { } else {
m_profiles[id] = TimePair(1, ms); m_profiles[id] = TimePair(1, us);
} }
WorstCallMap::iterator wci = m_worstCalls.find(id); WorstCallMap::iterator wci = m_worstCalls.find(id);
if (wci != m_worstCalls.end()) { if (wci != m_worstCalls.end()) {
if (ms > wci->second) wci->second = ms; if (us > wci->second) wci->second = us;
} else { } else {
m_worstCalls[id] = ms; m_worstCalls[id] = us;
} }
profileMutex.unlock(); profileMutex.unlock();
@@ -100,6 +100,8 @@ Profiler::getReport()
TimeRMap totmap, avgmap, worstmap; TimeRMap totmap, avgmap, worstmap;
IntRMap ncallmap; IntRMap ncallmap;
const unsigned char mu_s[] = { 0xce, 0xbc, 's', 0x0 };
for (ProfileMap::const_iterator i = m_profiles.begin(); for (ProfileMap::const_iterator i = m_profiles.begin();
i != m_profiles.end(); ++i) { i != m_profiles.end(); ++i) {
totmap.insert(TimeRMap::value_type(i->second.second, i->first)); totmap.insert(TimeRMap::value_type(i->second.second, i->first));
@@ -113,38 +115,6 @@ Profiler::getReport()
worstmap.insert(TimeRMap::value_type(i->second, i->first)); worstmap.insert(TimeRMap::value_type(i->second, i->first));
} }
snprintf(buffer, buflen, "\nBy total:\n");
report += buffer;
for (TimeRMap::const_iterator i = totmap.end(); i != totmap.begin(); ) {
--i;
snprintf(buffer, buflen, "%-40s %f ms\n", i->second, i->first);
report += buffer;
}
snprintf(buffer, buflen, "\nBy average:\n");
report += buffer;
for (TimeRMap::const_iterator i = avgmap.end(); i != avgmap.begin(); ) {
--i;
snprintf(buffer, buflen, "%-40s %f ms\n", i->second, i->first);
report += buffer;
}
snprintf(buffer, buflen, "\nBy worst case:\n");
report += buffer;
for (TimeRMap::const_iterator i = worstmap.end(); i != worstmap.begin(); ) {
--i;
snprintf(buffer, buflen, "%-40s %f ms\n", i->second, i->first);
report += buffer;
}
snprintf(buffer, buflen, "\nBy number of calls:\n");
report += buffer;
for (IntRMap::const_iterator i = ncallmap.end(); i != ncallmap.begin(); ) {
--i;
snprintf(buffer, buflen, "%-40s %d\n", i->second, i->first);
report += buffer;
}
snprintf(buffer, buflen, "\nBy name:\n"); snprintf(buffer, buflen, "\nBy name:\n");
report += buffer; report += buffer;
@@ -165,15 +135,47 @@ Profiler::getReport()
const TimePair &pp(j->second); const TimePair &pp(j->second);
snprintf(buffer, buflen, "%s(%d):\n", *i, pp.first); snprintf(buffer, buflen, "%s(%d):\n", *i, pp.first);
report += buffer; report += buffer;
snprintf(buffer, buflen, "\tReal: \t%f ms \t[%f ms total]\n", snprintf(buffer, buflen, "\tReal: \t%12f %s \t[%f %s total]\n",
(pp.second / pp.first), (pp.second / pp.first), mu_s,
(pp.second)); (pp.second), mu_s);
report += buffer; report += buffer;
WorstCallMap::const_iterator k = m_worstCalls.find(*i); WorstCallMap::const_iterator k = m_worstCalls.find(*i);
if (k == m_worstCalls.end()) continue; if (k == m_worstCalls.end()) continue;
snprintf(buffer, buflen, "\tWorst:\t%f ms/call\n", k->second); snprintf(buffer, buflen, "\tWorst:\t%14f %s/call\n", k->second, mu_s);
report += buffer;
}
snprintf(buffer, buflen, "\nBy total:\n");
report += buffer;
for (TimeRMap::const_iterator i = totmap.end(); i != totmap.begin(); ) {
--i;
snprintf(buffer, buflen, "%-40s %14f %s\n", i->second, i->first, mu_s);
report += buffer;
}
snprintf(buffer, buflen, "\nBy average:\n");
report += buffer;
for (TimeRMap::const_iterator i = avgmap.end(); i != avgmap.begin(); ) {
--i;
snprintf(buffer, buflen, "%-40s %14f %s\n", i->second, i->first, mu_s);
report += buffer;
}
snprintf(buffer, buflen, "\nBy worst case:\n");
report += buffer;
for (TimeRMap::const_iterator i = worstmap.end(); i != worstmap.begin(); ) {
--i;
snprintf(buffer, buflen, "%-40s %14f %s\n", i->second, i->first, mu_s);
report += buffer;
}
snprintf(buffer, buflen, "\nBy number of calls:\n");
report += buffer;
for (IntRMap::const_iterator i = ncallmap.end(); i != ncallmap.begin(); ) {
--i;
snprintf(buffer, buflen, "%-40s %14d\n", i->second, i->first);
report += buffer; report += buffer;
} }
@@ -198,8 +200,8 @@ void
Profiler::end() Profiler::end()
{ {
auto finish = std::chrono::steady_clock::now(); auto finish = std::chrono::steady_clock::now();
std::chrono::duration<double, std::milli> ms = finish - m_start; std::chrono::duration<double, std::micro> us = finish - m_start;
add(m_c, ms.count()); add(m_c, us.count());
m_ended = true; m_ended = true;
} }

View File

@@ -101,6 +101,8 @@ R2Stretcher::R2Stretcher(size_t sampleRate,
m_freq2(12000), m_freq2(12000),
m_baseFftSize(m_defaultFftSize) m_baseFftSize(m_defaultFftSize)
{ {
Profiler profiler("R2Stretcher::R2Stretcher");
if (!_initialised) { if (!_initialised) {
system_specific_initialise(); system_specific_initialise();
_initialised = true; _initialised = true;

View File

@@ -27,6 +27,7 @@
#include "../common/Allocators.h" #include "../common/Allocators.h"
#include "../common/MovingMedian.h" #include "../common/MovingMedian.h"
#include "../common/RingBuffer.h" #include "../common/RingBuffer.h"
#include "../common/Profiler.h"
#include <vector> #include <vector>
#include <memory> #include <memory>
@@ -97,6 +98,8 @@ public:
void classify(const process_t *const mag, // input, of at least binCount bins void classify(const process_t *const mag, // input, of at least binCount bins
Classification *classification) // output, of binCount bins Classification *classification) // output, of binCount bins
{ {
Profiler profiler("BinClassifier::classify");
const int n = m_parameters.binCount; const int n = m_parameters.binCount;
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {

View File

@@ -28,6 +28,7 @@
#include "../common/HistogramFilter.h" #include "../common/HistogramFilter.h"
#include "../common/mathmisc.h" #include "../common/mathmisc.h"
#include "../common/Profiler.h"
#include <vector> #include <vector>
@@ -65,6 +66,9 @@ public:
} }
Segmentation segment(const BinClassifier::Classification *classification) { Segmentation segment(const BinClassifier::Classification *classification) {
Profiler profiler("BinSegmenter::segment");
int n = m_parameters.binCount; int n = m_parameters.binCount;
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
switch (classification[i]) { switch (classification[i]) {

View File

@@ -25,6 +25,7 @@
#define RUBBERBAND_GUIDE_H #define RUBBERBAND_GUIDE_H
#include "../common/Log.h" #include "../common/Log.h"
#include "../common/Profiler.h"
#include <functional> #include <functional>
#include <sstream> #include <sstream>
@@ -159,6 +160,8 @@ public:
bool tighterChannelLock, bool tighterChannelLock,
Guidance &guidance) const { Guidance &guidance) const {
Profiler profiler("Guide::updateGuidance");
bool hadPhaseReset = guidance.phaseReset.present; bool hadPhaseReset = guidance.phaseReset.present;
guidance.phaseReset.present = false; guidance.phaseReset.present = false;

View File

@@ -28,6 +28,7 @@
#include "../common/Log.h" #include "../common/Log.h"
#include "../common/mathmisc.h" #include "../common/mathmisc.h"
#include "../common/Profiler.h"
#include <sstream> #include <sstream>
#include <functional> #include <functional>
@@ -93,6 +94,8 @@ public:
int inhop, int inhop,
int outhop) { int outhop) {
Profiler profiler("GuidedPhaseAdvance::advance");
int myFftBand = 0; int myFftBand = 0;
int i = 0; int i = 0;
for (const auto &fband : guidance[0]->fftBands) { for (const auto &fband : guidance[0]->fftBands) {

View File

@@ -24,6 +24,7 @@
#include "R3Stretcher.h" #include "R3Stretcher.h"
#include "../common/VectorOpsComplex.h" #include "../common/VectorOpsComplex.h"
#include "../common/Profiler.h"
#include <array> #include <array>
@@ -54,6 +55,8 @@ R3Stretcher::R3Stretcher(Parameters parameters,
m_totalOutputDuration(0), m_totalOutputDuration(0),
m_mode(ProcessMode::JustCreated) m_mode(ProcessMode::JustCreated)
{ {
Profiler profiler("R3Stretcher::R3Stretcher");
m_log.log(1, "R3Stretcher::R3Stretcher: rate, options", m_log.log(1, "R3Stretcher::R3Stretcher: rate, options",
m_parameters.sampleRate, m_parameters.options); m_parameters.sampleRate, m_parameters.options);
m_log.log(1, "R3Stretcher::R3Stretcher: initial time ratio and pitch scale", m_log.log(1, "R3Stretcher::R3Stretcher: initial time ratio and pitch scale",
@@ -233,6 +236,8 @@ R3Stretcher::setKeyFrameMap(const std::map<size_t, size_t> &mapping)
void void
R3Stretcher::createResampler() R3Stretcher::createResampler()
{ {
Profiler profiler("R3Stretcher::createResampler");
Resampler::Parameters resamplerParameters; Resampler::Parameters resamplerParameters;
if (m_parameters.options & RubberBandStretcher::OptionPitchHighQuality) { if (m_parameters.options & RubberBandStretcher::OptionPitchHighQuality) {
@@ -463,6 +468,8 @@ R3Stretcher::reset()
void void
R3Stretcher::study(const float *const *, size_t samples, bool) R3Stretcher::study(const float *const *, size_t samples, bool)
{ {
Profiler profiler("R3Stretcher::study");
if (isRealTime()) { if (isRealTime()) {
m_log.log(0, "R3Stretcher::study: Not meaningful in realtime mode"); m_log.log(0, "R3Stretcher::study: Not meaningful in realtime mode");
return; return;
@@ -520,6 +527,8 @@ R3Stretcher::setMaxProcessSize(size_t n)
void void
R3Stretcher::process(const float *const *input, size_t samples, bool final) R3Stretcher::process(const float *const *input, size_t samples, bool final)
{ {
Profiler profiler("R3Stretcher::process");
if (m_mode == ProcessMode::Finished) { if (m_mode == ProcessMode::Finished) {
m_log.log(0, "R3Stretcher::process: Cannot process again after final chunk"); m_log.log(0, "R3Stretcher::process: Cannot process again after final chunk");
return; return;
@@ -615,6 +624,8 @@ R3Stretcher::available() const
size_t size_t
R3Stretcher::retrieve(float *const *output, size_t samples) const R3Stretcher::retrieve(float *const *output, size_t samples) const
{ {
Profiler profiler("R3Stretcher::retrieve");
int got = samples; int got = samples;
for (int c = 0; c < m_parameters.channels; ++c) { for (int c = 0; c < m_parameters.channels; ++c) {
@@ -633,6 +644,8 @@ R3Stretcher::retrieve(float *const *output, size_t samples) const
void void
R3Stretcher::consume() R3Stretcher::consume()
{ {
Profiler profiler("R3Stretcher::consume");
int longest = m_guideConfiguration.longestFftSize; int longest = m_guideConfiguration.longestFftSize;
int channels = m_parameters.channels; int channels = m_parameters.channels;
int inhop = m_inhop; int inhop = m_inhop;
@@ -680,6 +693,8 @@ R3Stretcher::consume()
while (cd0->outbuf->getWriteSpace() >= outhop) { while (cd0->outbuf->getWriteSpace() >= outhop) {
Profiler profiler("R3Stretcher::consume/loop");
// NB our ChannelData, ScaleData, and ChannelScaleData maps // NB our ChannelData, ScaleData, and ChannelScaleData maps
// contain shared_ptrs; whenever we retain one of them in a // contain shared_ptrs; whenever we retain one of them in a
// variable, we do so by reference to avoid copying the // variable, we do so by reference to avoid copying the
@@ -827,6 +842,8 @@ R3Stretcher::consume()
void void
R3Stretcher::analyseChannel(int c, int inhop, int prevInhop, int prevOuthop) R3Stretcher::analyseChannel(int c, int inhop, int prevInhop, int prevOuthop)
{ {
Profiler profiler("R3Stretcher::analyseChannel");
int longest = m_guideConfiguration.longestFftSize; int longest = m_guideConfiguration.longestFftSize;
int classify = m_guideConfiguration.classificationFftSize; int classify = m_guideConfiguration.classificationFftSize;
@@ -1067,6 +1084,8 @@ R3Stretcher::analyseChannel(int c, int inhop, int prevInhop, int prevOuthop)
void void
R3Stretcher::analyseFormant(int c) R3Stretcher::analyseFormant(int c)
{ {
Profiler profiler("R3Stretcher::analyseFormant");
auto &cd = m_channelData.at(c); auto &cd = m_channelData.at(c);
auto &f = *cd->formant; auto &f = *cd->formant;
@@ -1101,6 +1120,8 @@ R3Stretcher::analyseFormant(int c)
void void
R3Stretcher::adjustFormant(int c) R3Stretcher::adjustFormant(int c)
{ {
Profiler profiler("R3Stretcher::adjustFormant");
auto &cd = m_channelData.at(c); auto &cd = m_channelData.at(c);
for (auto &it : cd->scales) { for (auto &it : cd->scales) {
@@ -1135,6 +1156,8 @@ R3Stretcher::adjustFormant(int c)
void void
R3Stretcher::adjustPreKick(int c) R3Stretcher::adjustPreKick(int c)
{ {
Profiler profiler("R3Stretcher::adjustPreKick");
auto &cd = m_channelData.at(c); auto &cd = m_channelData.at(c);
auto fftSize = cd->guidance.fftBands[0].fftSize; auto fftSize = cd->guidance.fftBands[0].fftSize;
if (cd->guidance.preKick.present) { if (cd->guidance.preKick.present) {
@@ -1166,6 +1189,8 @@ R3Stretcher::adjustPreKick(int c)
void void
R3Stretcher::synthesiseChannel(int c, int outhop, bool draining) R3Stretcher::synthesiseChannel(int c, int outhop, bool draining)
{ {
Profiler profiler("R3Stretcher::synthesiseChannel");
int longest = m_guideConfiguration.longestFftSize; int longest = m_guideConfiguration.longestFftSize;
auto &cd = m_channelData.at(c); auto &cd = m_channelData.at(c);