aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/stats/functions.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/stats/functions.c')
-rw-r--r--src/plugins/stats/functions.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/plugins/stats/functions.c b/src/plugins/stats/functions.c
index c3f4a9ee..846dd67b 100644
--- a/src/plugins/stats/functions.c
+++ b/src/plugins/stats/functions.c
@@ -440,19 +440,36 @@ static int getEffectivenessStats(const void * closure,
440 return OK; 440 return OK;
441} 441}
442 442
443
444static int statsProcessor(const char * optName, 443static int statsProcessor(const char * optName,
445 unsigned long long value, 444 unsigned long long value,
446 void * data) { 445 void * data) {
447 cron_t * delta = data; 446 /**
447 * Keep track of last match (or, more precisely, position
448 * of next expected match) since 99.99% of the time we
449 * go over the same stats in the same order and thus
450 * this will predict correctly).
451 */
452 static unsigned int last;
453 cron_t * delta = data;
448 int j; 454 int j;
449 int found; 455 int found;
450 456
457 if (last >= lsv_size)
458 last = 0;
459 j = last;
451 found = -1; 460 found = -1;
452 for (j=0;j<lsv_size;j++) 461 if (0 == strcmp(optName,
453 if (0 == strcmp(optName, 462 lastStatValues[j].statName))
454 lastStatValues[j].statName)) 463 found = j;
455 found = j; 464 if (found == -1) {
465 for (j=0;j<lsv_size;j++) {
466 if (0 == strcmp(optName,
467 lastStatValues[j].statName)) {
468 found = j;
469 break;
470 }
471 }
472 }
456 if (found == -1) { 473 if (found == -1) {
457 found = lsv_size; 474 found = lsv_size;
458 GROW(lastStatValues, 475 GROW(lastStatValues,
@@ -467,6 +484,7 @@ static int statsProcessor(const char * optName,
467 = value; 484 = value;
468 lastStatValues[found].delta 485 lastStatValues[found].delta
469 = *delta; 486 = *delta;
487 last = found + 1;
470 return OK; 488 return OK;
471} 489}
472 490
@@ -481,10 +499,10 @@ static void updateStatValues(void * unused) {
481 now = get_time(); 499 now = get_time();
482 delta = now - lastUpdate; 500 delta = now - lastUpdate;
483 MUTEX_LOCK(lock); 501 MUTEX_LOCK(lock);
484 if (OK == requestStatistics(ectx, 502 if (OK == STATS_getStatistics(ectx,
485 sock, 503 sock,
486 &statsProcessor, 504 &statsProcessor,
487 &delta)) 505 &delta))
488 lastUpdate = now; 506 lastUpdate = now;
489 MUTEX_UNLOCK(lock); 507 MUTEX_UNLOCK(lock);
490} 508}