libqi-api
2.0.6.8
|
00001 #pragma once 00002 /* 00003 * Copyright (c) 2013 Aldebaran Robotics. All rights reserved. 00004 * Use of this source code is governed by a BSD-style license that can be 00005 * found in the COPYING file. 00006 */ 00007 00008 #ifndef _QI_STATS_HPP_ 00009 #define _QI_STATS_HPP_ 00010 00011 #include <sstream> 00012 00013 namespace qi 00014 { 00016 class MinMaxSum 00017 { 00018 public: 00019 MinMaxSum() : _minValue(0), _maxValue(0), _cumulatedValue(0) {} 00020 MinMaxSum(float minValue, float maxValue, float cumulatedValue) 00021 : _minValue(minValue), _maxValue(maxValue), _cumulatedValue(cumulatedValue) 00022 {} 00023 00024 const float& minValue() const { return _minValue;} 00025 const float& maxValue() const { return _maxValue;} 00026 const float& cumulatedValue() const { return _cumulatedValue;} 00027 void push(float val, bool init = false) 00028 { 00029 if (init) 00030 _minValue = _maxValue = _cumulatedValue = val; 00031 else 00032 { 00033 _cumulatedValue += val; 00034 _minValue = (std::min)(_minValue, val); 00035 _maxValue = (std::max)(_maxValue, val); 00036 } 00037 } 00038 void reset() 00039 { 00040 _minValue = _maxValue = _cumulatedValue = 0; 00041 } 00042 std::string asString(unsigned int count) const 00043 { 00044 std::stringstream s; 00045 s << (_cumulatedValue / (float)count) << ' ' << _minValue << ' ' << _maxValue; 00046 return s.str(); 00047 } 00048 private: 00049 float _minValue; 00050 float _maxValue; 00051 float _cumulatedValue; 00052 }; 00053 00055 class MethodStatistics 00056 { 00057 public: 00058 MethodStatistics() 00059 : _count(0) {} 00060 MethodStatistics(unsigned count, MinMaxSum wall, MinMaxSum user, MinMaxSum system) 00061 : _count(count), _wall(wall), _user(user), _system(system) 00062 {} 00063 void push(float wall, float user, float system) 00064 { 00065 _wall.push(wall, _count==0); 00066 _user.push(user, _count==0); 00067 _system.push(system, _count==0); 00068 ++_count; 00069 } 00070 const MinMaxSum& wall() const { return _wall;} 00071 const MinMaxSum& user() const { return _user;} 00072 const MinMaxSum& system() const { return _system;} 00073 const unsigned int& count() const { return _count;} 00074 void reset() 00075 { 00076 _count = 0; 00077 _wall.reset(); 00078 _user.reset(); 00079 _system.reset(); 00080 } 00081 private: 00082 unsigned int _count; 00083 MinMaxSum _wall; 00084 MinMaxSum _user; 00085 MinMaxSum _system; 00086 }; 00087 } 00088 #endif