YARP
Yet Another Robot Platform
Ping.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 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
yarp::os::Stat
Definition: Ping.h:23
yarp::os::ConnectResult::totalTime
Stat totalTime
Definition: Ping.h:51
yarp::os::ConnectResult::add
void add(const ConnectResult &alt)
Definition: Ping.cpp:101
yarp::os::ConnectResult
Definition: Ping.h:49
t
float t
Definition: FfmpegWriter.cpp:74
yarp::os::RateResult::clear
void clear()
Definition: Ping.cpp:108
yarp::os::ConnectResult::targetTime
Stat targetTime
Definition: Ping.h:52
yarp::os::Stat::count
double count()
Definition: Ping.cpp:70
yarp::os::RateResult::add
void add(const RateResult &alt)
Definition: Ping.cpp:113
api.h
YARP_os_API
#define YARP_os_API
Definition: api.h:19
yarp::os::Stat::add
void add(double val)
Definition: Ping.cpp:44
yarp::os::Stat::deviation
double deviation()
Definition: Ping.cpp:64
yarp::os::Ping
Measure performance of a YARP port.
Definition: Ping.h:73
yarp::os::RateResult
Definition: Ping.h:59
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::os::Stat::clear
void clear()
Definition: Ping.cpp:34
yarp::os::ConnectResult::clear
void clear()
Definition: Ping.cpp:95
yarp::os::Stat::Stat
Stat()
Definition: Ping.cpp:29
yarp::os::RateResult::period
Stat period
Definition: Ping.h:61
yarp::os::Stat::mean
double mean()
Definition: Ping.cpp:58