Gazebo Transport

API Reference

14.1.0
TopicStatistics.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 Open Source Robotics Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16*/
17#ifndef GZ_TRANSPORT_TOPICSTATISTICS_HH_
18#define GZ_TRANSPORT_TOPICSTATISTICS_HH_
19
20#include <gz/msgs/statistic.pb.h>
21
22#include <algorithm>
23#include <limits>
24#include <memory>
25#include <string>
26#include "gz/transport/config.hh"
27#include "gz/transport/Export.hh"
28
29#ifdef _WIN32
30#ifndef NOMINMAX
31 #define NOMINMAX
32#endif
33#ifdef min
34 #undef min
35 #undef max
36#endif
37#include <windows.h>
38#endif
39
40namespace gz::transport
41{
42 // Inline bracket to help doxygen filtering.
43 inline namespace GZ_TRANSPORT_VERSION_NAMESPACE {
44 //
45 // Forward declarations.
46 class TopicStatisticsPrivate;
47
50 class GZ_TRANSPORT_VISIBLE Statistics
51 {
53 public: Statistics() = default;
54
56 public: ~Statistics() = default;
57
60 public: void Update(double _stat);
61
64 public: double Avg() const;
65
68 public: double StdDev() const;
69
72 public: double Min() const;
73
76 public: double Max() const;
77
80 public: uint64_t Count() const;
81
83 private: uint64_t count = 0;
84
86 private: double average = 0;
87
90 private: double sumSquareMeanDist = 0;
91
93 private: double min = std::numeric_limits<double>::max();
94
96 private: double max = std::numeric_limits<double>::min();
97 };
98
111 class GZ_TRANSPORT_VISIBLE TopicStatistics
112 {
115
118 public: TopicStatistics(const TopicStatistics &_stats);
119
122
127 public: void Update(const std::string &_sender,
128 uint64_t _stamp, uint64_t _seq);
129
133 public: void FillMessage(msgs::Metric &_msg) const;
134
137 public: uint64_t DroppedMsgCount() const;
138
142
146
149 public: Statistics AgeStatistics() const;
150#ifdef _WIN32
151// Disable warning C4251 which is triggered by
152// std::unique_ptr
153#pragma warning(push)
154#pragma warning(disable: 4251)
155#endif
158#ifdef _WIN32
159#pragma warning(pop)
160#endif
161 };
162 }
163}
164#endif