c on win compatability poblems
This commit is contained in:
parent
924c4c7476
commit
6ed8f3c9b5
10
src/sigar.c
10
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) {
|
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 ) {
|
if ( current_value == SIGAR_FIELD_NOTIMPL ) {
|
||||||
return SIGAR_FIELD_NOTIMPL;
|
return SIGAR_FIELD_NOTIMPL;
|
||||||
}
|
}
|
||||||
double io_diff = (( current_value - prev_value)/(double)time_diff)*SIGAR_MSEC;
|
io_diff = (( current_value - prev_value)/(double)time_diff)*SIGAR_MSEC;
|
||||||
sigar_uint64_t int_io_diff = (sigar_uint64_t)io_diff;
|
int_io_diff = (sigar_uint64_t)io_diff;
|
||||||
if (int_io_diff >=0) {
|
if (int_io_diff >=0) {
|
||||||
return int_io_diff;
|
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_proc_cumulative_disk_io_t cumulative_proc_disk_io;
|
||||||
sigar_uint64_t time_now = sigar_time_now_millis();
|
sigar_uint64_t time_now = sigar_time_now_millis();
|
||||||
sigar_uint64_t time_diff;
|
sigar_uint64_t time_diff;
|
||||||
int status;
|
int status, is_first_time;
|
||||||
|
|
||||||
if (!sigar->proc_io) {
|
if (!sigar->proc_io) {
|
||||||
sigar->proc_io = sigar_expired_cache_new(128, PID_CACHE_CLEANUP_PERIOD, PID_CACHE_ENTRY_EXPIRE_PERIOD);
|
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));
|
prev = entry->value = malloc(sizeof(*prev));
|
||||||
SIGAR_ZERO(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;
|
time_diff = time_now - prev->last_time;
|
||||||
|
|
||||||
if (time_diff < 1000) {
|
if (time_diff < 1000) {
|
||||||
|
|
|
@ -113,18 +113,21 @@ static void sigar_cache_rehash(sigar_cache_t *table)
|
||||||
t->entries + (k % t->size)
|
t->entries + (k % t->size)
|
||||||
|
|
||||||
void sigar_perform_cleanup_if_necessary(sigar_cache_t *table) {
|
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) {
|
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) {
|
if ((current_time - table->last_cleanup_time) < table->cleanup_period_millis) {
|
||||||
/* not enough time has passed since last cleanup */
|
/* not enough time has passed since last cleanup */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* performing cleanup */
|
/* performing cleanup */
|
||||||
int i;
|
entries = table->entries;
|
||||||
sigar_cache_entry_t **entries = table->entries;
|
|
||||||
|
|
||||||
table->last_cleanup_time = current_time;
|
table->last_cleanup_time = current_time;
|
||||||
|
|
||||||
|
@ -134,15 +137,15 @@ void sigar_perform_cleanup_if_necessary(sigar_cache_t *table) {
|
||||||
entry = *entries++;
|
entry = *entries++;
|
||||||
|
|
||||||
while (entry) {
|
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) {
|
if (table->entry_expire_period < period_with_no_access) {
|
||||||
/* no one acess this entry for too long - we can delete it */
|
/* no one acess this entry for too long - we can delete it */
|
||||||
if (entry->value) {
|
if (entry->value) {
|
||||||
table->free_value(entry->value);
|
table->free_value(entry->value);
|
||||||
}
|
}
|
||||||
free(entry);
|
free(entry);
|
||||||
table->count--;
|
table->count--;
|
||||||
if (entry_prev != NULL) {
|
if (entry_prev != NULL) {
|
||||||
entry_prev->next = ptr;
|
entry_prev->next = ptr;
|
||||||
}
|
}
|
||||||
|
@ -154,7 +157,7 @@ void sigar_perform_cleanup_if_necessary(sigar_cache_t *table) {
|
||||||
else {
|
else {
|
||||||
/* entry not expired - advance entry_prev to current entry*/
|
/* entry not expired - advance entry_prev to current entry*/
|
||||||
entry_prev = entry;
|
entry_prev = entry;
|
||||||
}
|
}
|
||||||
entry = ptr;
|
entry = ptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue