Skip to content

Commit

Permalink
c on win compatability poblems
Browse files Browse the repository at this point in the history
  • Loading branch information
nira11 committed Sep 15, 2013
1 parent 924c4c7 commit 6ed8f3c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
10 changes: 6 additions & 4 deletions src/sigar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
25 changes: 14 additions & 11 deletions src/sigar_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand All @@ -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;
}
}
Expand Down

0 comments on commit 6ed8f3c

Please sign in to comment.