Gazebo Transport

API Reference

8.5.0
gz/transport/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 
40 namespace ignition
41 {
42  namespace transport
43  {
44  // Inline bracket to help doxygen filtering.
45  inline namespace IGNITION_TRANSPORT_VERSION_NAMESPACE {
46  //
47  // Forward declarations.
48  class TopicStatisticsPrivate;
49 
52  class IGNITION_TRANSPORT_VISIBLE Statistics
53  {
55  public: Statistics() = default;
56 
58  public: ~Statistics() = default;
59 
62  public: void Update(double _stat);
63 
66  public: double Avg() const;
67 
70  public: double StdDev() const;
71 
74  public: double Min() const;
75 
78  public: double Max() const;
79 
82  public: uint64_t Count() const;
83 
85  private: uint64_t count = 0;
86 
88  private: double average = 0;
89 
92  private: double sumSquareMeanDist = 0;
93 
95  private: double min = std::numeric_limits<double>::max();
96 
98  private: double max = std::numeric_limits<double>::min();
99  };
100 
113  class IGNITION_TRANSPORT_VISIBLE TopicStatistics
114  {
116  public: TopicStatistics();
117 
120  public: TopicStatistics(const TopicStatistics &_stats);
121 
123  public: ~TopicStatistics();
124 
129  public: void Update(const std::string &_sender,
130  uint64_t _stamp, uint64_t _seq);
131 
135  public: void FillMessage(msgs::Metric &_msg) const;
136 
139  public: uint64_t DroppedMsgCount() const;
140 
143  public: Statistics PublicationStatistics() const;
144 
147  public: Statistics ReceptionStatistics() const;
148 
151  public: Statistics AgeStatistics() const;
152 #ifdef _WIN32
153 // Disable warning C4251 which is triggered by
154 // std::unique_ptr
155 #pragma warning(push)
156 #pragma warning(disable: 4251)
157 #endif
160 #ifdef _WIN32
161 #pragma warning(pop)
162 #endif
163  };
164  }
165  }
166 }
167 #endif
Encapsulates statistics for a single topic. The set of statistics include:
Definition: gz/transport/TopicStatistics.hh:113
Definition: gz/transport/AdvertiseOptions.hh:28
STL class.
Statistics()=default
Default constructor.
double StdDev() const
Get the standard deviation.
void Update(const std::string &_sender, uint64_t _stamp, uint64_t _seq)
Update the topic statistics.
Computes the rolling average, min, max, and standard deviation for a set of samples.
Definition: gz/transport/TopicStatistics.hh:52
double Min() const
Get the minimum sample value.
double Avg() const
Get the average value.
Statistics ReceptionStatistics() const
Get the statistics about reception of messages.
T min(T... args)
~TopicStatistics()
Default destructor.
void FillMessage(msgs::Metric &_msg) const
Populate an gz::msgs::Metric message with topic statistics.
~Statistics()=default
Default destructor.
void Update(double _stat)
Update with a new sample.
Statistics PublicationStatistics() const
Get statistics about publication of messages.
Statistics AgeStatistics() const
Get the message age statistics.
double Max() const
Get the maximum sample value.
T max(T... args)
TopicStatistics()
Default constructor.
uint64_t Count() const
Get the number of samples.
uint64_t DroppedMsgCount() const
Get the number of dropped messages.