diff --git a/src/sigar.c b/src/sigar.c index 2bf223aea..45ce5de5e 100644 --- a/src/sigar.c +++ b/src/sigar.c @@ -185,11 +185,13 @@ void copy_cached_disk_io_into_disk_io( sigar_cached_proc_disk_io_t *cached, sig } sigar_uint64_t get_io_diff(sigar_uint64_t current_value, sigar_uint64_t prev_value, sigar_uint64_t time_diff) { + double io_diff; + sigar_uint64_t int_io_diff; if ( current_value == SIGAR_FIELD_NOTIMPL ) { return SIGAR_FIELD_NOTIMPL; } - double io_diff = (( current_value - prev_value)/(double)time_diff)*SIGAR_MSEC; - sigar_uint64_t int_io_diff = (sigar_uint64_t)io_diff; + io_diff = (( current_value - prev_value)/(double)time_diff)*SIGAR_MSEC; + int_io_diff = (sigar_uint64_t)io_diff; if (int_io_diff >=0) { return int_io_diff; } @@ -220,7 +222,7 @@ SIGAR_DECLARE(int) sigar_proc_disk_io_get(sigar_t *sigar, sigar_pid_t pid, sigar_proc_cumulative_disk_io_t cumulative_proc_disk_io; sigar_uint64_t time_now = sigar_time_now_millis(); sigar_uint64_t time_diff; - int status; + int status, is_first_time; if (!sigar->proc_io) { sigar->proc_io = sigar_expired_cache_new(128, PID_CACHE_CLEANUP_PERIOD, PID_CACHE_ENTRY_EXPIRE_PERIOD); @@ -234,7 +236,7 @@ SIGAR_DECLARE(int) sigar_proc_disk_io_get(sigar_t *sigar, sigar_pid_t pid, prev = entry->value = malloc(sizeof(*prev)); SIGAR_ZERO(prev); } - int is_first_time = (prev->last_time == 0); + is_first_time = (prev->last_time == 0); time_diff = time_now - prev->last_time; if (time_diff < 1000) { diff --git a/src/sigar_cache.c b/src/sigar_cache.c index 57b08e006..5b158edca 100644 --- a/src/sigar_cache.c +++ b/src/sigar_cache.c @@ -113,18 +113,21 @@ static void sigar_cache_rehash(sigar_cache_t *table) t->entries + (k % t->size) void sigar_perform_cleanup_if_necessary(sigar_cache_t *table) { + sigar_uint64_t current_time; + int i; + sigar_cache_entry_t **entries; if (table->cleanup_period_millis == SIGAR_FIELD_NOTIMPL) { - /* no cleanup for this cache) */ + /* no cleanup for this cache) */ + return; } - sigar_uint64_t current_time = sigar_time_now_millis(); + current_time = sigar_time_now_millis(); if ((current_time - table->last_cleanup_time) < table->cleanup_period_millis) { /* not enough time has passed since last cleanup */ return; } - /* performing cleanup */ - int i; - sigar_cache_entry_t **entries = table->entries; + /* performing cleanup */ + entries = table->entries; table->last_cleanup_time = current_time; @@ -134,15 +137,15 @@ void sigar_perform_cleanup_if_necessary(sigar_cache_t *table) { entry = *entries++; while (entry) { - ptr = entry->next; - sigar_uint64_t period_with_no_access = current_time - entry->last_access_time; + sigar_uint64_t period_with_no_access = current_time - entry->last_access_time; + ptr = entry->next; if (table->entry_expire_period < period_with_no_access) { - /* no one acess this entry for too long - we can delete it */ - if (entry->value) { + /* no one acess this entry for too long - we can delete it */ + if (entry->value) { table->free_value(entry->value); } free(entry); - table->count--; + table->count--; if (entry_prev != NULL) { entry_prev->next = ptr; } @@ -154,7 +157,7 @@ void sigar_perform_cleanup_if_necessary(sigar_cache_t *table) { else { /* entry not expired - advance entry_prev to current entry*/ entry_prev = entry; - } + } entry = ptr; } }