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