Gazebo Transport

API Reference

13.4.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 
40 namespace gz
41 {
42  namespace transport
43  {
44  // Inline bracket to help doxygen filtering.
45  inline namespace GZ_TRANSPORT_VERSION_NAMESPACE {
46  //
47  // Forward declarations.
48  class TopicStatisticsPrivate;
49 
52  class GZ_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 GZ_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 
144 
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