mirror of
https://github.com/nmap/nmap.git
synced 2026-07-11 18:55:08 +00:00
Avoid recalculating timeval that doesn't change for life of RateMeter
This commit is contained in:
parent
7b20a38099
commit
ba249b2d65
2 changed files with 9 additions and 5 deletions
12
timing.cc
12
timing.cc
|
|
@ -302,6 +302,8 @@ RateMeter::RateMeter(double current_rate_history) {
|
|||
stop_tv.tv_usec = 0;
|
||||
last_update_tv.tv_sec = 0;
|
||||
last_update_tv.tv_usec = 0;
|
||||
history_threshold.tv_sec = 0;
|
||||
history_threshold.tv_usec = 0;
|
||||
total = 0.0;
|
||||
current_rate = 0.0;
|
||||
assert(!isSet(&start_tv));
|
||||
|
|
@ -315,6 +317,10 @@ void RateMeter::start(const struct timeval *now) {
|
|||
gettimeofday(&start_tv, NULL);
|
||||
else
|
||||
start_tv = *now;
|
||||
/* Find the time current_rate_history seconds after the start. That's our
|
||||
threshold for deciding how far back to look for moving average. */
|
||||
TIMEVAL_ADD(history_threshold, start_tv,
|
||||
(time_t) (current_rate_history * 1000000.0));
|
||||
}
|
||||
|
||||
void RateMeter::stop(const struct timeval *now) {
|
||||
|
|
@ -369,11 +375,7 @@ void RateMeter::update(double amount, const struct timeval *now) {
|
|||
/* Find out how far back in time to look. We want to look back
|
||||
current_rate_history seconds, or to when the last update occurred,
|
||||
whichever is longer. However, we never look past the start. */
|
||||
struct timeval tmp;
|
||||
/* Find the time current_rate_history seconds after the start. That's our
|
||||
threshold for deciding how far back to look. */
|
||||
TIMEVAL_ADD(tmp, start_tv, (time_t) (current_rate_history * 1000000.0));
|
||||
if (TIMEVAL_AFTER(*now, tmp))
|
||||
if (TIMEVAL_AFTER(*now, history_threshold))
|
||||
interval = MAX(current_rate_history, diff);
|
||||
else
|
||||
interval = TIMEVAL_FSEC_SUBTRACT(*now, start_tv);
|
||||
|
|
|
|||
2
timing.h
2
timing.h
|
|
@ -183,6 +183,8 @@ class RateMeter {
|
|||
struct timeval stop_tv;
|
||||
/* The last time the current sample rates were updated. */
|
||||
struct timeval last_update_tv;
|
||||
/* The time current_rate_history after start_tv. */
|
||||
struct timeval history_threshold;
|
||||
|
||||
double total;
|
||||
double current_rate;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue