2014-12-22 00:39:57 -05:00
|
|
|
/*
|
2019-08-02 23:10:55 -04:00
|
|
|
* Copyright (C) 2014-2016 Tim Mayberry <mojofunk@gmail.com>
|
|
|
|
* Copyright (C) 2015-2018 John Emmas <john@creativepost.co.uk>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2014-12-22 00:39:57 -05:00
|
|
|
|
|
|
|
#include "pbd/timing.h"
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <limits>
|
2020-03-26 06:40:36 -04:00
|
|
|
#include <algorithm>
|
2014-12-22 00:39:57 -05:00
|
|
|
|
|
|
|
namespace PBD {
|
|
|
|
|
|
|
|
bool
|
2021-06-28 16:47:18 -04:00
|
|
|
get_min_max_avg_total (const std::vector<microseconds_t>& values, microseconds_t& min, microseconds_t& max, microseconds_t& avg, microseconds_t& total)
|
2014-12-22 00:39:57 -05:00
|
|
|
{
|
|
|
|
if (values.empty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
total = 0;
|
2021-06-28 16:47:18 -04:00
|
|
|
min = std::numeric_limits<microseconds_t>::max();
|
2014-12-22 00:39:57 -05:00
|
|
|
max = 0; avg = 0;
|
|
|
|
|
2021-06-28 16:47:18 -04:00
|
|
|
for (std::vector<microseconds_t>::const_iterator ci = values.begin(); ci != values.end(); ++ci) {
|
2014-12-22 00:39:57 -05:00
|
|
|
total += *ci;
|
|
|
|
min = std::min (min, *ci);
|
|
|
|
max = std::max (max, *ci);
|
|
|
|
}
|
|
|
|
|
|
|
|
avg = total / values.size();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
2021-06-28 16:47:18 -04:00
|
|
|
timing_summary (const std::vector<microseconds_t>& values)
|
2014-12-22 00:39:57 -05:00
|
|
|
{
|
|
|
|
std::ostringstream oss;
|
|
|
|
|
2021-06-28 16:47:18 -04:00
|
|
|
microseconds_t min, max, avg, total;
|
2014-12-22 00:39:57 -05:00
|
|
|
|
|
|
|
if (get_min_max_avg_total (values, min, max, avg, total)) {
|
|
|
|
oss << "Count: " << values.size()
|
|
|
|
<< " Min: " << min
|
|
|
|
<< " Max: " << max
|
|
|
|
<< " Total: " << total
|
2016-09-25 22:35:27 -04:00
|
|
|
<< " Avg: " << avg << " (" << avg / 1000 << " msecs)"
|
2014-12-22 00:39:57 -05:00
|
|
|
<< std::endl;
|
|
|
|
}
|
|
|
|
return oss.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace PBD
|