libqi-api  2.1.4.13
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stats.hpp
Go to the documentation of this file.
1 #pragma once
2 /*
3  * Copyright (c) 2013 Aldebaran Robotics. All rights reserved.
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the COPYING file.
6  */
7 
8  #ifndef _QI_STATS_HPP_
9  #define _QI_STATS_HPP_
10 
11  #include <sstream>
12 
13  namespace qi
14  {
16  class MinMaxSum
17  {
18  public:
19  MinMaxSum() : _minValue(0), _maxValue(0), _cumulatedValue(0) {}
21  : _minValue(minValue), _maxValue(maxValue), _cumulatedValue(cumulatedValue)
22  {}
23 
24  const float& minValue() const { return _minValue;}
25  const float& maxValue() const { return _maxValue;}
26  const float& cumulatedValue() const { return _cumulatedValue;}
27  void push(float val, bool init = false)
28  {
29  if (init)
30  _minValue = _maxValue = _cumulatedValue = val;
31  else
32  {
33  _cumulatedValue += val;
34  _minValue = (std::min)(_minValue, val);
35  _maxValue = (std::max)(_maxValue, val);
36  }
37  }
38  void reset()
39  {
40  _minValue = _maxValue = _cumulatedValue = 0;
41  }
42  std::string asString(unsigned int count) const
43  {
44  std::stringstream s;
45  s << (_cumulatedValue / (float)count) << ' ' << _minValue << ' ' << _maxValue;
46  return s.str();
47  }
48  private:
49  float _minValue;
50  float _maxValue;
51  float _cumulatedValue;
52  };
53 
56  {
57  public:
59  : _count(0) {}
61  : _count(count), _wall(wall), _user(user), _system(system)
62  {}
63  void push(float wall, float user, float system)
64  {
65  _wall.push(wall, _count==0);
66  _user.push(user, _count==0);
67  _system.push(system, _count==0);
68  ++_count;
69  }
70  const MinMaxSum& wall() const { return _wall;}
71  const MinMaxSum& user() const { return _user;}
72  const MinMaxSum& system() const { return _system;}
73  const unsigned int& count() const { return _count;}
74  void reset()
75  {
76  _count = 0;
77  _wall.reset();
78  _user.reset();
79  _system.reset();
80  }
81  private:
82  unsigned int _count;
83  MinMaxSum _wall;
84  MinMaxSum _user;
85  MinMaxSum _system;
86  };
87  }
88  #endif
Store statistics about method calls.
Definition: stats.hpp:55
std::string asString(unsigned int count) const
Definition: stats.hpp:42
void reset()
Definition: stats.hpp:38
const float & maxValue() const
Definition: stats.hpp:25
Stores min, max and sum of values fed to it.
Definition: stats.hpp:16
MethodStatistics(unsigned count, MinMaxSum wall, MinMaxSum user, MinMaxSum system)
Definition: stats.hpp:60
MinMaxSum(float minValue, float maxValue, float cumulatedValue)
Definition: stats.hpp:20
void push(float val, bool init=false)
Definition: stats.hpp:27
const MinMaxSum & wall() const
Definition: stats.hpp:70
const unsigned int & count() const
Definition: stats.hpp:73
void push(float wall, float user, float system)
Definition: stats.hpp:63
const MinMaxSum & system() const
Definition: stats.hpp:72
const MinMaxSum & user() const
Definition: stats.hpp:71
const float & cumulatedValue() const
Definition: stats.hpp:26
const float & minValue() const
Definition: stats.hpp:24
QI_API_DEPRECATED void init(int &argc, char **&argv)