Ignition Transport

API Reference

10.0.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 IGN_TRANSPORT_TOPICSTATISTICS_HH_
18 #define IGN_TRANSPORT_TOPICSTATISTICS_HH_
19 
20 #include <ignition/msgs/statistic.pb.h>
21 
22 #include <limits>
23 #include <memory>
24 #include <string>
25 #include "ignition/transport/config.hh"
26 #include "ignition/transport/Export.hh"
27 
28 namespace ignition
29 {
30  namespace transport
31  {
32  // Inline bracket to help doxygen filtering.
33  inline namespace IGNITION_TRANSPORT_VERSION_NAMESPACE {
34  //
35  // Forward declarations.
36  class TopicStatisticsPrivate;
37 
40  class IGNITION_TRANSPORT_VISIBLE Statistics
41  {
43  public: Statistics() = default;
44 
46  public: ~Statistics() = default;
47 
50  public: void Update(double _stat);
51 
54  public: double Avg() const;
55 
58  public: double StdDev() const;
59 
62  public: double Min() const;
63 
66  public: double Max() const;
67 
70  public: uint64_t Count() const;
71 
73  private: uint64_t count = 0;
74 
76  private: double average = 0;
77 
80  private: double sumSquareMeanDist = 0;
81 
83  private: double min = std::numeric_limits<double>::max();
84 
86  private: double max = std::numeric_limits<double>::min();
87  };
88 
101  class IGNITION_TRANSPORT_VISIBLE TopicStatistics
102  {
104  public: TopicStatistics();
105 
108  public: TopicStatistics(const TopicStatistics &_stats);
109 
111  public: ~TopicStatistics();
112 
117  public: void Update(const std::string &_sender,
118  uint64_t _stamp, uint64_t _seq);
119 
123  public: void FillMessage(msgs::Metric &_msg) const;
124 
127  public: uint64_t DroppedMsgCount() const;
128 
131  public: Statistics PublicationStatistics() const;
132 
135  public: Statistics ReceptionStatistics() const;
136 
139  public: Statistics AgeStatistics() const;
140 #ifdef _WIN32
141 // Disable warning C4251 which is triggered by
142 // std::unique_ptr
143 #pragma warning(push)
144 #pragma warning(disable: 4251)
145 #endif
148 #ifdef _WIN32
149 #pragma warning(pop)
150 #endif
151  };
152  }
153  }
154 }
155 #endif
Encapsulates statistics for a single topic. The set of statistics include:
Definition: TopicStatistics.hh:101
STL class.
T min(T... args)
T max(T... args)
Computes the rolling average, min, max, and standard deviation for a set of samples.
Definition: TopicStatistics.hh:40
Definition: AdvertiseOptions.hh:28