- Aldebaran documentation |
- C++ Libraries |
- index

libqi-api 2.8.7.4

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 # include <algorithm>
13
14 namespace qi
15 {
17 class MinMaxSum
18 {
19 public:
21 MinMaxSum() : _minValue(0), _maxValue(0), _cumulatedValue(0) {}
28 MinMaxSum(float minValue, float maxValue, float cumulatedValue)
29 : _minValue(minValue), _maxValue(maxValue), _cumulatedValue(cumulatedValue)
30 {}
31
33 const float& minValue() const { return _minValue;}
35 const float& maxValue() const { return _maxValue;}
37 const float& cumulatedValue() const { return _cumulatedValue;}
43 void push(float val, bool init = false)
44 {
45 if (init)
46 _minValue = _maxValue = _cumulatedValue = val;
47 else
48 {
49 _cumulatedValue += val;
50 _minValue = (std::min)(_minValue, val);
51 _maxValue = (std::max)(_maxValue, val);
52 }
53 }
55 void reset()
56 {
57 _minValue = _maxValue = _cumulatedValue = 0;
58 }
65 std::string asString(unsigned int count) const
66 {
67 std::stringstream s;
68 s << (_cumulatedValue / (float)count) << ' ' << _minValue << ' ' << _maxValue;
69 return s.str();
70 }
71 private:
72 float _minValue;
73 float _maxValue;
74 float _cumulatedValue;
75 };
76
78 class MethodStatistics
79 {
80 public:
82 MethodStatistics()
83 : _count(0) {}
91 MethodStatistics(unsigned count, MinMaxSum wall, MinMaxSum user, MinMaxSum system)
92 : _count(count), _wall(wall), _user(user), _system(system)
93 {}
94
105 void push(float wall, float user, float system)
106 {
107 _wall.push(wall, _count==0);
108 _user.push(user, _count==0);
109 _system.push(system, _count==0);
110 ++_count;
111 }
116 const MinMaxSum& wall() const { return _wall;}
121 const MinMaxSum& user() const { return _user;}
126 const MinMaxSum& system() const { return _system;}
131 const unsigned int& count() const { return _count;}
135 void reset()
136 {
137 _count = 0;
138 _wall.reset();
139 _user.reset();
140 _system.reset();
141 }
142 private:
143 unsigned int _count;
144 MinMaxSum _wall;
145 MinMaxSum _user;
146 MinMaxSum _system;
147 };
148 }
149
150 #endif // !_QI_STATS_HPP_
qi::MinMaxSum
Stores min, max and sum of values fed to it.
Definition: stats.hpp:17
qi::MinMaxSum::push
void push(float val, bool init=false)
Push a new value, process new min/max and add the value to cumulated.
Definition: stats.hpp:43
qi::MethodStatistics::push
void push(float wall, float user, float system)
Add value for all tree statistics values.
Definition: stats.hpp:105
qi::MethodStatistics
Store statistics about method calls.
Definition: stats.hpp:78
qi::MethodStatistics::MethodStatistics
MethodStatistics(unsigned count, MinMaxSum wall, MinMaxSum user, MinMaxSum system)
Constructor and Set.
Definition: stats.hpp:91
qi::MinMaxSum::asString
std::string asString(unsigned int count) const
asString Get a string from min, max and cumulated.
Definition: stats.hpp:65
qi::MinMaxSum::MinMaxSum
MinMaxSum()
Default constructor.
Definition: stats.hpp:21
qi::MethodStatistics::count
const unsigned int & count() const
Get number of value added.
Definition: stats.hpp:131
qi::MinMaxSum::cumulatedValue
const float & cumulatedValue() const
Get sum of all value push value.
Definition: stats.hpp:37
qi::MethodStatistics::reset
void reset()
Reset all value to 0 (count and MinMaxSum of all 3 statistics values)
Definition: stats.hpp:135
qi::MethodStatistics::MethodStatistics
MethodStatistics()
Constructor.
Definition: stats.hpp:82
qi::MinMaxSum::reset
void reset()
Reset all three values to 0.
Definition: stats.hpp:55
qi::MinMaxSum::MinMaxSum
MinMaxSum(float minValue, float maxValue, float cumulatedValue)
Constructor.
Definition: stats.hpp:28
qi::MethodStatistics::user
const MinMaxSum & user() const
Get user MinMaxSum value.
Definition: stats.hpp:121
qi::MethodStatistics::wall
const MinMaxSum & wall() const
Get wall MinMaxSum value.
Definition: stats.hpp:116
qi::MethodStatistics::system
const MinMaxSum & system() const
Get system MinMaxSum value.
Definition: stats.hpp:126
qi::MinMaxSum::maxValue
const float & maxValue() const
Get maximum value.
Definition: stats.hpp:35
qi::log::init
void init(qi::LogLevel verb=qi::LogLevel_Info, qi::LogContext context=qi::LogContextAttr_ShortVerbosity|qi::LogContextAttr_Tid|qi::LogContextAttr_Category, bool synchronous=true)
Initialization of the logging system Creates and registers the default log handler according to QI_DE...
qi::MinMaxSum::minValue
const float & minValue() const
Get minimum value.
Definition: stats.hpp:33