mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-16 15:01:15 +02:00
3808 icmp statistics (#3982)
* fix(ICMPClinet): ICMPEventArgs Statistics bugs #3808 * fix(SpinlockMutex): 100 % CPU usage on single-core system #3852
This commit is contained in:
parent
93d18162f3
commit
bcae06f423
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -94,7 +94,8 @@
|
|||||||
"valarray": "cpp",
|
"valarray": "cpp",
|
||||||
"strstream": "cpp",
|
"strstream": "cpp",
|
||||||
"future": "cpp",
|
"future": "cpp",
|
||||||
"shared_mutex": "cpp"
|
"shared_mutex": "cpp",
|
||||||
|
"stop_token": "cpp"
|
||||||
},
|
},
|
||||||
"files.exclude": {
|
"files.exclude": {
|
||||||
"**/.dep": true,
|
"**/.dep": true,
|
||||||
|
@ -158,8 +158,9 @@ class Foundation_API SpinlockMutex
|
|||||||
///
|
///
|
||||||
/// While in some cases (eg. locking small blocks of code)
|
/// While in some cases (eg. locking small blocks of code)
|
||||||
/// busy-waiting may be an optimal solution, in many scenarios
|
/// busy-waiting may be an optimal solution, in many scenarios
|
||||||
/// spinlock may not be the right choice - it is up to the user to
|
/// spinlock may not be the right choice (especially on single-core
|
||||||
/// choose the proper mutex type for their particular case.
|
/// systems) - it is up to the user to choose the proper mutex type
|
||||||
|
/// for their particular case.
|
||||||
///
|
///
|
||||||
/// Works with the ScopedLock class.
|
/// Works with the ScopedLock class.
|
||||||
{
|
{
|
||||||
|
@ -145,18 +145,6 @@ inline int ICMPEventArgs::sent() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline int ICMPEventArgs::minRTT() const
|
|
||||||
{
|
|
||||||
return *std::min_element(_rtt.begin(), _rtt.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline int ICMPEventArgs::maxRTT() const
|
|
||||||
{
|
|
||||||
return *std::max_element(_rtt.begin(), _rtt.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} } // namespace Poco::Net
|
} } // namespace Poco::Net
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,11 +57,7 @@ public:
|
|||||||
typedef AutoPtr<UDPHandlerImpl> Ptr;
|
typedef AutoPtr<UDPHandlerImpl> Ptr;
|
||||||
typedef std::vector<Ptr> List;
|
typedef std::vector<Ptr> List;
|
||||||
typedef typename List::iterator Iterator;
|
typedef typename List::iterator Iterator;
|
||||||
#ifdef POCO_HAVE_STD_ATOMICS
|
|
||||||
typedef Poco::SpinlockMutex DFMutex;
|
|
||||||
#else
|
|
||||||
typedef Poco::FastMutex DFMutex;
|
typedef Poco::FastMutex DFMutex;
|
||||||
#endif
|
|
||||||
|
|
||||||
static const MsgSizeT BUF_STATUS_IDLE = 0;
|
static const MsgSizeT BUF_STATUS_IDLE = 0;
|
||||||
static const MsgSizeT BUF_STATUS_BUSY = -1;
|
static const MsgSizeT BUF_STATUS_BUSY = -1;
|
||||||
|
@ -35,7 +35,7 @@ ICMPEventArgs::ICMPEventArgs(const SocketAddress& address, int repetitions, int
|
|||||||
_sent(0),
|
_sent(0),
|
||||||
_dataSize(dataSize),
|
_dataSize(dataSize),
|
||||||
_ttl(ttl),
|
_ttl(ttl),
|
||||||
_rtt(repetitions, 0),
|
_rtt(repetitions, -1),
|
||||||
_errors(repetitions)
|
_errors(repetitions)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ std::string ICMPEventArgs::hostAddress() const
|
|||||||
void ICMPEventArgs::setRepetitions(int repetitions)
|
void ICMPEventArgs::setRepetitions(int repetitions)
|
||||||
{
|
{
|
||||||
_rtt.clear();
|
_rtt.clear();
|
||||||
_rtt.resize(repetitions, 0);
|
_rtt.resize(repetitions, -1);
|
||||||
_errors.assign(repetitions, "");
|
_errors.assign(repetitions, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,9 +101,9 @@ int ICMPEventArgs::received() const
|
|||||||
{
|
{
|
||||||
int received = 0;
|
int received = 0;
|
||||||
|
|
||||||
for (int i = 0; i < _rtt.size(); ++i)
|
for (const auto& r : _rtt)
|
||||||
{
|
{
|
||||||
if (_rtt[i]) ++received;
|
if (r != -1) ++received;
|
||||||
}
|
}
|
||||||
return received;
|
return received;
|
||||||
}
|
}
|
||||||
@ -133,7 +133,6 @@ void ICMPEventArgs::setReplyTime(int index, int time)
|
|||||||
{
|
{
|
||||||
if (index >= _rtt.size())
|
if (index >= _rtt.size())
|
||||||
throw InvalidArgumentException("Supplied index exceeds array capacity.");
|
throw InvalidArgumentException("Supplied index exceeds array capacity.");
|
||||||
if (0 == time) time = 1;
|
|
||||||
_rtt[index] = time;
|
_rtt[index] = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,8 +143,9 @@ int ICMPEventArgs::replyTime(int index) const
|
|||||||
throw InvalidArgumentException("Supplied index exceeds array capacity.");
|
throw InvalidArgumentException("Supplied index exceeds array capacity.");
|
||||||
|
|
||||||
if (-1 == index) index = _sent - 1;
|
if (-1 == index) index = _sent - 1;
|
||||||
|
poco_assert (index < _rtt.size());
|
||||||
return _rtt[index];
|
int ret = _rtt[index];
|
||||||
|
return (ret < 0) ? 0 : ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -153,7 +153,16 @@ int ICMPEventArgs::avgRTT() const
|
|||||||
{
|
{
|
||||||
if (0 == _rtt.size()) return 0;
|
if (0 == _rtt.size()) return 0;
|
||||||
|
|
||||||
return (int) (std::accumulate(_rtt.begin(), _rtt.end(), 0) / _rtt.size());
|
int avg = 0, cnt = 0;
|
||||||
|
for (const auto& r : _rtt)
|
||||||
|
{
|
||||||
|
if (r != -1)
|
||||||
|
{
|
||||||
|
avg += r;
|
||||||
|
++cnt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cnt ? static_cast<int>(avg/cnt) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -165,4 +174,28 @@ float ICMPEventArgs::percent() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int ICMPEventArgs::minRTT() const
|
||||||
|
{
|
||||||
|
int min = 0;
|
||||||
|
for (const auto& r : _rtt)
|
||||||
|
{
|
||||||
|
if (r != -1 && (r < min || min == 0))
|
||||||
|
min = r;
|
||||||
|
}
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int ICMPEventArgs::maxRTT() const
|
||||||
|
{
|
||||||
|
int max = 0;
|
||||||
|
for (const auto& r : _rtt)
|
||||||
|
{
|
||||||
|
if (r != -1 && r > max)
|
||||||
|
max = r;
|
||||||
|
}
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} } // namespace Poco::Net
|
} } // namespace Poco::Net
|
||||||
|
Loading…
x
Reference in New Issue
Block a user