Gazebo Transport

API Reference

11.4.1
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::transport
41 {
42  // Inline bracket to help doxygen filtering.
43  inline namespace IGNITION_TRANSPORT_VERSION_NAMESPACE {
44  //
45  // Forward declarations.
46  class TopicStatisticsPrivate;
47 
50  class IGNITION_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 IGNITION_TRANSPORT_VISIBLE TopicStatistics
112  {
114  public: TopicStatistics();
115 
118  public: TopicStatistics(const TopicStatistics &_stats);
119 
121  public: ~TopicStatistics();
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 
141  public: Statistics PublicationStatistics() const;
142 
145  public: Statistics ReceptionStatistics() const;
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
Encapsulates statistics for a single topic. The set of statistics include:
Definition: gz/transport/TopicStatistics.hh:111
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:50
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)
Definition: gz/transport/AdvertiseOptions.hh:28
~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.