YARP
Yet Another Robot Platform
Ping.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef YARP_OS_PING_H
8 #define YARP_OS_PING_H
9 
10 #include <yarp/os/api.h>
11 
12 #include <cmath>
13 #include <string>
14 
15 
16 namespace yarp {
17 namespace os {
18 
19 class Stat
20 {
21 public:
22  Stat();
23 
24  void clear();
25 
26  void add(double val);
27  void add(const Stat& alt);
28  double mean();
29  double deviation();
30  double count();
31 
32  operator double();
33 
34 private:
35  void compute();
36 
37  int ct;
38  int at;
39  double tot;
40  double tot2;
41  double mu;
42  double sigma;
43 };
44 
46 {
47 public:
48  Stat totalTime; // total includes name server lookups
49  Stat targetTime; // all time involving the target port
50 
51  void clear();
52  void add(const ConnectResult& alt);
53 };
54 
56 {
57 public:
59 
60  void clear();
61  void add(const RateResult& alt);
62 };
63 
64 
70 {
71 public:
72  Ping(const char* target = nullptr);
73 
74  bool setTarget(const char* target);
75 
76  void connect();
77 
78  void sample();
79 
80  void clear();
81  ConnectResult getLastConnect();
82  ConnectResult getAverageConnect();
83 
84  void report();
85 
86  static std::string renderTime(double t, int space, int decimal);
87 
88 private:
89  std::string target;
90  ConnectResult lastConnect, accumConnect;
91 };
92 
93 } // namespace os
94 } // namespace yarp
95 
96 #endif // YARP_OS_PING_H
float t
void add(const ConnectResult &alt)
Definition: Ping.cpp:98
Measure performance of a YARP port.
Definition: Ping.h:70
void add(const RateResult &alt)
Definition: Ping.cpp:110
void add(double val)
Definition: Ping.cpp:41
void clear()
Definition: Ping.cpp:31
double mean()
Definition: Ping.cpp:55
double count()
Definition: Ping.cpp:67
double deviation()
Definition: Ping.cpp:61
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_os_API
Definition: api.h:18