(SIGAR-215) use swapctl SC_LIST for Solaris swap_get impl
This commit is contained in:
parent
30e8d0e2c1
commit
b40013def1
|
@ -247,25 +247,41 @@ int sigar_swap_get(sigar_t *sigar, sigar_swap_t *swap)
|
||||||
{
|
{
|
||||||
kstat_t *ksp;
|
kstat_t *ksp;
|
||||||
kstat_named_t *kn;
|
kstat_named_t *kn;
|
||||||
struct anoninfo anon;
|
swaptbl_t *stab;
|
||||||
|
int num, i;
|
||||||
|
char path[PATH_MAX+1]; /* {un,re}used */
|
||||||
|
|
||||||
/* XXX vm/anon.h says:
|
/* see: man swapctl(2) */
|
||||||
* "The swap data can be aquired more efficiently through the
|
if ((num = swapctl(SC_GETNSWP, NULL)) == -1) {
|
||||||
* kstats interface."
|
|
||||||
* but cannot find anything that explains howto convert those numbers.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (swapctl(SC_AINFO, &anon) == -1) {
|
|
||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
swap->total = anon.ani_max;
|
stab = malloc(num * sizeof(stab->swt_ent[0]) + sizeof(*stab));
|
||||||
swap->used = anon.ani_resv;
|
|
||||||
swap->free = anon.ani_max - anon.ani_resv;
|
stab->swt_n = num;
|
||||||
|
for (i=0; i<num; i++) {
|
||||||
|
stab->swt_ent[i].ste_path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((num = swapctl(SC_LIST, stab)) == -1) {
|
||||||
|
free(stab);
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
num = num < stab->swt_n ? num : stab->swt_n;
|
||||||
|
swap->total = swap->free = 0;
|
||||||
|
for (i=0; i<num; i++) {
|
||||||
|
if (stab->swt_ent[i].ste_flags & ST_INDEL) {
|
||||||
|
continue; /* swap file is being deleted */
|
||||||
|
}
|
||||||
|
swap->total += stab->swt_ent[i].ste_pages;
|
||||||
|
swap->free += stab->swt_ent[i].ste_free;
|
||||||
|
}
|
||||||
|
free(stab);
|
||||||
|
|
||||||
swap->total <<= sigar->pagesize;
|
swap->total <<= sigar->pagesize;
|
||||||
swap->free <<= sigar->pagesize;
|
swap->free <<= sigar->pagesize;
|
||||||
swap->used <<= sigar->pagesize;
|
swap->used = swap->total - swap->free;
|
||||||
|
|
||||||
if (sigar_kstat_update(sigar) == -1) {
|
if (sigar_kstat_update(sigar) == -1) {
|
||||||
return errno;
|
return errno;
|
||||||
|
|
Loading…
Reference in New Issue