13
0

change PBD::microseconds_t to a signed type and check for -1 in TimingStats::update

This may help a Windows issue with the return value of QueryPerformanceCounter
This commit is contained in:
Paul Davis 2021-06-28 14:47:18 -06:00
parent 45c8944789
commit b20a541d7e
7 changed files with 22 additions and 22 deletions

View File

@ -198,7 +198,7 @@ public:
bool load_preset (Plugin::PresetRecord);
bool provides_stats () const;
bool get_stats (uint64_t& min, uint64_t& max, double& avg, double& dev) const;
bool get_stats (PBD::microseconds_t& min, PBD::microseconds_t& max, double& avg, double& dev) const;
void clear_stats ();
/** A control that manipulates a plugin parameter (control port). */

View File

@ -3383,7 +3383,7 @@ PluginInsert::provides_stats () const
}
bool
PluginInsert::get_stats (uint64_t& min, uint64_t& max, double& avg, double& dev) const
PluginInsert::get_stats (PBD::microseconds_t& min, PBD::microseconds_t& max, double& avg, double& dev) const
{
/* TODO: consider taking a try/lock: Don't run concurrently with
* TimingStats::update, TimingStats::reset.

View File

@ -26,7 +26,7 @@
#include "pbd/libpbd_visibility.h"
namespace PBD {
typedef uint64_t microseconds_t;
typedef int64_t microseconds_t;
LIBPBD_API microseconds_t get_microseconds();
void microsecond_timer_init ();
}

View File

@ -116,8 +116,7 @@ public:
return elapsed () / 1000;
}
private:
protected:
microseconds_t m_start_val;
microseconds_t m_last_val;
@ -138,17 +137,18 @@ public:
reset ();
} else {
Timing::update ();
calc ();
}
}
/* interval computed externally */
void update (microseconds_t interval)
{
if (_queue_reset) {
reset ();
} else {
Timing::update (interval);
/* querying the performance counter can fail occasionally (-1).
* Also on some multi-core systems, timers are CPU specific and not
* synchronized. We assume they differ more than a few milliseconds
* (4 * nominal cycle time) and simply ignore cases where the
* execution switches cores.
*/
if (m_start_val < 0 || m_last_val < 0 || m_start_val > m_last_val) {
return;
}
calc ();
}
}

View File

@ -26,17 +26,17 @@
namespace PBD {
bool
get_min_max_avg_total (const std::vector<uint64_t>& values, uint64_t& min, uint64_t& max, uint64_t& avg, uint64_t& total)
get_min_max_avg_total (const std::vector<microseconds_t>& values, microseconds_t& min, microseconds_t& max, microseconds_t& avg, microseconds_t& total)
{
if (values.empty()) {
return false;
}
total = 0;
min = std::numeric_limits<uint64_t>::max();
min = std::numeric_limits<microseconds_t>::max();
max = 0; avg = 0;
for (std::vector<uint64_t>::const_iterator ci = values.begin(); ci != values.end(); ++ci) {
for (std::vector<microseconds_t>::const_iterator ci = values.begin(); ci != values.end(); ++ci) {
total += *ci;
min = std::min (min, *ci);
max = std::max (max, *ci);
@ -47,11 +47,11 @@ get_min_max_avg_total (const std::vector<uint64_t>& values, uint64_t& min, uint6
}
std::string
timing_summary (const std::vector<uint64_t>& values)
timing_summary (const std::vector<microseconds_t>& values)
{
std::ostringstream oss;
uint64_t min, max, avg, total;
microseconds_t min, max, avg, total;
if (get_min_max_avg_total (values, min, max, avg, total)) {
oss << "Count: " << values.size()

View File

@ -951,7 +951,7 @@ Surface::zero_controls ()
}
void
Surface::periodic (uint64_t now_usecs)
Surface::periodic (PBD::microseconds_t now_usecs)
{
master_gain_changed();
for (Strips::iterator s = strips.begin(); s != strips.end(); ++s) {

View File

@ -909,7 +909,7 @@ Surface::zero_controls ()
}
void
Surface::periodic (uint64_t now_usecs)
Surface::periodic (PBD::microseconds_t now_usecs)
{
if (_active) {
master_gain_changed();