1N/A/***********************************************************************
1N/A* *
1N/A* This software is part of the ast package *
1N/A* Copyright (c) 1985-2011 AT&T Intellectual Property *
1N/A* and is licensed under the *
1N/A* Common Public License, Version 1.0 *
1N/A* by AT&T Intellectual Property *
1N/A* *
1N/A* A copy of the License is available at *
1N/A* http://www.opensource.org/licenses/cpl1.0.txt *
1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
1N/A* *
1N/A* Information and Software Systems Research *
1N/A* AT&T Research *
1N/A* Florham Park NJ *
1N/A* *
1N/A* Glenn Fowler <gsf@research.att.com> *
1N/A* David Korn <dgk@research.att.com> *
1N/A* Phong Vo <kpv@research.att.com> *
1N/A* *
1N/A***********************************************************************/
1N/A#if defined(_UWIN) && defined(_BLD_ast)
1N/A
1N/Avoid _STUB_vmstat(){}
1N/A
1N/A#else
1N/A
1N/A#include "vmhdr.h"
1N/A
1N/A/* Get statistics from a region.
1N/A**
1N/A** Written by Kiem-Phong Vo, kpv@research.att.com, 01/16/94.
1N/A*/
1N/A
1N/A#if __STD_C
1N/Aint vmstat(Vmalloc_t* vm, Vmstat_t* st)
1N/A#else
1N/Aint vmstat(vm, st)
1N/AVmalloc_t* vm;
1N/AVmstat_t* st;
1N/A#endif
1N/A{
1N/A reg Seg_t* seg;
1N/A reg Block_t *b, *endb;
1N/A reg size_t s = 0;
1N/A reg Vmdata_t* vd = vm ? vm->data : Vmregion->data;
1N/A reg int inuse;
1N/A
1N/A SETINUSE(vd, inuse);
1N/A if(!st)
1N/A { CLRINUSE(vd, inuse);
1N/A return inuse ? 1 : 0;
1N/A }
1N/A if(!(vd->mode&VM_TRUST))
1N/A { if(ISLOCK(vd,0))
1N/A { CLRINUSE(vd, inuse);
1N/A return -1;
1N/A }
1N/A SETLOCK(vd,0);
1N/A }
1N/A
1N/A st->n_busy = st->n_free = 0;
1N/A st->s_busy = st->s_free = st->m_busy = st->m_free = 0;
1N/A st->n_seg = 0;
1N/A st->extent = 0;
1N/A st->mode = vd->mode;
1N/A
1N/A if(vd->mode&VM_MTLAST)
1N/A st->n_busy = 0;
1N/A else if((vd->mode&VM_MTPOOL) && (s = vd->pool) > 0)
1N/A { s = ROUND(s,ALIGN);
1N/A for(b = vd->free; b; b = SEGLINK(b))
1N/A st->n_free += 1;
1N/A }
1N/A
1N/A for(seg = vd->seg; seg; seg = seg->next)
1N/A { st->n_seg += 1;
1N/A st->extent += seg->extent;
1N/A
1N/A b = SEGBLOCK(seg);
1N/A endb = BLOCK(seg->baddr);
1N/A
1N/A if(vd->mode&(VM_MTDEBUG|VM_MTBEST|VM_MTPROFILE))
1N/A { while(b < endb)
1N/A { s = SIZE(b)&~BITS;
1N/A if(ISJUNK(SIZE(b)) || !ISBUSY(SIZE(b)))
1N/A { if(s > st->m_free)
1N/A st->m_free = s;
1N/A st->s_free += s;
1N/A st->n_free += 1;
1N/A }
1N/A else /* get the real size */
1N/A { if(vd->mode&VM_MTDEBUG)
1N/A { /* strict-aliasing dance */
1N/A void* d = DB2DEBUG(DATA(b));
1N/A s = DBSIZE(d);
1N/A }
1N/A else if(vd->mode&VM_MTPROFILE)
1N/A s = PFSIZE(DATA(b));
1N/A if(s > st->m_busy)
1N/A st->m_busy = s;
1N/A st->s_busy += s;
1N/A st->n_busy += 1;
1N/A }
1N/A
1N/A b = (Block_t*)((Vmuchar_t*)DATA(b) + (SIZE(b)&~BITS) );
1N/A }
1N/A }
1N/A else if(vd->mode&VM_MTLAST)
1N/A { if((s = seg->free ? (SIZE(seg->free) + sizeof(Head_t)) : 0) > 0)
1N/A { st->s_free += s;
1N/A st->n_free += 1;
1N/A }
1N/A if((s = ((char*)endb - (char*)b) - s) > 0)
1N/A { st->s_busy += s;
1N/A st->n_busy += 1;
1N/A }
1N/A }
1N/A else if((vd->mode&VM_MTPOOL) && s > 0)
1N/A { if(seg->free)
1N/A st->n_free += ((int)SIZE(seg->free)+sizeof(Head_t))/(int)s;
1N/A st->n_busy += ((int)(seg->baddr - (Vmuchar_t*)b) - sizeof(Head_t))/(int)s;
1N/A }
1N/A }
1N/A
1N/A if((vd->mode&VM_MTPOOL) && s > 0)
1N/A { st->n_busy -= st->n_free;
1N/A if(st->n_busy > 0)
1N/A st->s_busy = (st->m_busy = vd->pool)*st->n_busy;
1N/A if(st->n_free > 0)
1N/A st->s_free = (st->m_free = vd->pool)*st->n_free;
1N/A }
1N/A
1N/A CLRLOCK(vd,0);
1N/A CLRINUSE(vd, inuse);
1N/A return inuse ? 1 : 0;
1N/A}
1N/A
1N/A#endif