13
0

make it possible to debug one of the RAII TimingStats objects

This commit is contained in:
Paul Davis 2021-06-29 09:25:18 -06:00
parent 821d79e5a8
commit 24ea6c4d30

View File

@ -19,6 +19,8 @@
#ifndef __libpbd_timing_h__
#define __libpbd_timing_h__
#include <iostream>
#include <glib.h>
#include <stdint.h>
@ -116,6 +118,9 @@ public:
return elapsed () / 1000;
}
microseconds_t start_time() const { return m_start_val; }
microseconds_t last_time() const { return m_last_val; }
protected:
microseconds_t m_start_val;
microseconds_t m_last_val;
@ -229,9 +234,12 @@ private:
class LIBPBD_API TimerRAII
{
public:
TimerRAII (TimingStats& ts) : stats (ts) { stats.start(); }
~TimerRAII() { stats.update(); }
TimerRAII (TimingStats& ts, bool dbg = false) : stats (ts), debug (dbg) { stats.start(); if (debug) std::cout << "Timer @ " << &stats << " start at " << stats.start_time() << std::endl;}
~TimerRAII() { stats.update(); if (debug) std::cout << "Timer @ " << &stats << " stamp " << stats.last_time() << std::endl; }
TimingStats& stats;
private:
bool debug;
};
/** Reverse semantics from TimerRAII. This starts the timer at scope exit,