[SIGAR-92] Add memory free and used in percentage units

This commit is contained in:
Doug MacEachern 2008-04-03 04:45:28 +00:00
parent 31a5f214d3
commit d826684c33
10 changed files with 53 additions and 12 deletions

View File

@ -312,6 +312,34 @@ our %classes = (
Win32 => 'taskman',
},
},
{
name => 'used_percent', type => 'Double',
desc => 'Percent total used system memory',
plat => '*',
cmd => {
AIX => '',
Darwin => '',
FreeBSD => '',
HPUX => '',
Linux => 'free',
Solaris => '',
Win32 => 'taskman',
},
},
{
name => 'free_percent', type => 'Double',
desc => 'Percent total free system memory',
plat => '*',
cmd => {
AIX => '',
Darwin => '',
FreeBSD => '',
HPUX => '',
Linux => 'free',
Solaris => '',
Win32 => 'taskman',
},
},
],
Swap => [
{

View File

@ -36,6 +36,10 @@ public class TestMem extends SigarTestCase {
assertGtZeroTrace("Used", mem.getUsed());
traceln("UsedPercent=" + mem.getUsedPercent());
traceln("FreePercent=" + mem.getFreePercent());
assertGtZeroTrace("Free", mem.getFree());
assertGtZeroTrace("ActualUsed", mem.getUsed());

View File

@ -141,6 +141,8 @@ typedef struct {
free,
actual_used,
actual_free;
double used_percent;
double free_percent;
} sigar_mem_t;
SIGAR_DECLARE(int) sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem);

View File

@ -457,11 +457,11 @@ int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
mem->used = mem->total - mem->free;
sigar_mem_calc_ram(sigar, mem);
mem->actual_free = mem->free;
mem->actual_used = mem->used;
sigar_mem_calc_ram(sigar, mem);
return SIGAR_OK;
}

View File

@ -79,8 +79,6 @@ int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
mem->total = sigar->pstatic.physical_memory * pagesize;
sigar_mem_calc_ram(sigar, mem);
pstat_getdynamic(&stats, sizeof(stats), 1, 0);
mem->free = stats.psd_free * pagesize;
@ -89,6 +87,8 @@ int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
mem->actual_free = mem->free;
mem->actual_used = mem->used;
sigar_mem_calc_ram(sigar, mem);
return SIGAR_OK;
}

View File

@ -441,9 +441,10 @@ int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
mem->actual_free = mem->free + kern;
mem->actual_used = mem->used - kern;
sigar_mem_calc_ram(sigar, mem);
if (get_ram(sigar, mem) != SIGAR_OK) {
/* XXX other options on failure? */
sigar_mem_calc_ram(sigar, mem);
}
return SIGAR_OK;

View File

@ -65,11 +65,11 @@ int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
mem->free + mem->used +
((vmstats.inactive_count + vmstats.wire_count) * vmstats.pagesize);
sigar_mem_calc_ram(sigar, mem);
mem->actual_free = mem->free;
mem->actual_used = mem->used;
sigar_mem_calc_ram(sigar, mem);
return SIGAR_OK;
}

View File

@ -172,8 +172,6 @@ int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
mem->total = sysconf(_SC_PHYS_PAGES);
mem->total <<= sigar->pagesize;
sigar_mem_calc_ram(sigar, mem);
if (sigar_kstat_update(sigar) == -1) {
return errno;
}
@ -194,6 +192,8 @@ int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
mem->actual_free = mem->free;
mem->actual_used = mem->used;
sigar_mem_calc_ram(sigar, mem);
return SIGAR_OK;
}

View File

@ -627,11 +627,11 @@ SIGAR_DECLARE(int) sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
mem->used = mem->total - mem->free;
sigar_mem_calc_ram(sigar, mem);
mem->actual_free = mem->free;
mem->actual_used = mem->used;
sigar_mem_calc_ram(sigar, mem);
return SIGAR_OK;
}

View File

@ -334,6 +334,12 @@ int sigar_mem_calc_ram(sigar_t *sigar, sigar_mem_t *mem)
mem->ram = ram;
mem->used_percent =
((double)(mem->total - mem->actual_free) * 100) / mem->total;
mem->free_percent =
((double)(mem->total - mem->actual_used) * 100) / mem->total;
return ram;
}