mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-12 18:20:26 +01: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",
|
||||
"strstream": "cpp",
|
||||
"future": "cpp",
|
||||
"shared_mutex": "cpp"
|
||||
"shared_mutex": "cpp",
|
||||
"stop_token": "cpp"
|
||||
},
|
||||
"files.exclude": {
|
||||
"**/.dep": true,
|
||||
|
@ -158,8 +158,9 @@ class Foundation_API SpinlockMutex
|
||||
///
|
||||
/// While in some cases (eg. locking small blocks of code)
|
||||
/// busy-waiting may be an optimal solution, in many scenarios
|
||||
/// spinlock may not be the right choice - it is up to the user to
|
||||
/// choose the proper mutex type for their particular case.
|
||||
/// spinlock may not be the right choice (especially on single-core
|
||||
/// systems) - it is up to the user to choose the proper mutex type
|
||||
/// for their particular case.
|
||||
///
|
||||
/// 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
|
||||
|
||||
|
||||
|
@ -57,11 +57,7 @@ public:
|
||||
typedef AutoPtr<UDPHandlerImpl> Ptr;
|
||||
typedef std::vector<Ptr> List;
|
||||
typedef typename List::iterator Iterator;
|
||||
#ifdef POCO_HAVE_STD_ATOMICS
|
||||
typedef Poco::SpinlockMutex DFMutex;
|
||||
#else
|
||||
typedef Poco::FastMutex DFMutex;
|
||||
#endif
|
||||
|
||||
static const MsgSizeT BUF_STATUS_IDLE = 0;
|
||||
static const MsgSizeT BUF_STATUS_BUSY = -1;
|
||||
|
@ -35,7 +35,7 @@ ICMPEventArgs::ICMPEventArgs(const SocketAddress& address, int repetitions, int
|
||||
_sent(0),
|
||||
_dataSize(dataSize),
|
||||
_ttl(ttl),
|
||||
_rtt(repetitions, 0),
|
||||
_rtt(repetitions, -1),
|
||||
_errors(repetitions)
|
||||
{
|
||||
}
|
||||
@ -77,7 +77,7 @@ std::string ICMPEventArgs::hostAddress() const
|
||||
void ICMPEventArgs::setRepetitions(int repetitions)
|
||||
{
|
||||
_rtt.clear();
|
||||
_rtt.resize(repetitions, 0);
|
||||
_rtt.resize(repetitions, -1);
|
||||
_errors.assign(repetitions, "");
|
||||
}
|
||||
|
||||
@ -101,9 +101,9 @@ int ICMPEventArgs::received() const
|
||||
{
|
||||
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;
|
||||
}
|
||||
@ -133,7 +133,6 @@ void ICMPEventArgs::setReplyTime(int index, int time)
|
||||
{
|
||||
if (index >= _rtt.size())
|
||||
throw InvalidArgumentException("Supplied index exceeds array capacity.");
|
||||
if (0 == time) time = 1;
|
||||
_rtt[index] = time;
|
||||
}
|
||||
|
||||
@ -144,8 +143,9 @@ int ICMPEventArgs::replyTime(int index) const
|
||||
throw InvalidArgumentException("Supplied index exceeds array capacity.");
|
||||
|
||||
if (-1 == index) index = _sent - 1;
|
||||
|
||||
return _rtt[index];
|
||||
poco_assert (index < _rtt.size());
|
||||
int ret = _rtt[index];
|
||||
return (ret < 0) ? 0 : ret;
|
||||
}
|
||||
|
||||
|
||||
@ -153,7 +153,16 @@ int ICMPEventArgs::avgRTT() const
|
||||
{
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user