ardour
timing.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 Tim Mayberry
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 
18 */
19 
20 #include "pbd/timing.h"
21 
22 #include <sstream>
23 #include <limits>
24 
25 #ifdef COMPILER_MSVC
26 #undef min
27 #undef max
28 #endif
29 
30 namespace PBD {
31 
32 bool
33 get_min_max_avg_total (const std::vector<uint64_t>& values, uint64_t& min, uint64_t& max, uint64_t& avg, uint64_t& total)
34 {
35  if (values.empty()) {
36  return false;
37  }
38 
39  total = 0;
40  min = std::numeric_limits<uint64_t>::max();
41  max = 0; avg = 0;
42 
43  for (std::vector<uint64_t>::const_iterator ci = values.begin(); ci != values.end(); ++ci) {
44  total += *ci;
45  min = std::min (min, *ci);
46  max = std::max (max, *ci);
47  }
48 
49  avg = total / values.size();
50  return true;
51 }
52 
53 std::string
54 timing_summary (const std::vector<uint64_t>& values)
55 {
56  std::ostringstream oss;
57 
58  uint64_t min, max, avg, total;
59 
60  if (get_min_max_avg_total (values, min, max, avg, total)) {
61  oss << "Count: " << values.size()
62  << " Min: " << min
63  << " Max: " << max
64  << " Avg: " << avg
65  << " Total: " << total
66  << std::endl;
67  }
68  return oss.str();
69 }
70 
71 } // namespace PBD
LIBPBD_API bool get_min_max_avg_total(const std::vector< uint64_t > &values, uint64_t &min, uint64_t &max, uint64_t &avg, uint64_t &total)
Definition: timing.cc:33
Definition: debug.h:30
LIBPBD_API std::string timing_summary(const std::vector< uint64_t > &values)
Definition: timing.cc:54