⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mem.c

📁 早期freebsd实现
💻 C
字号:
/* * Copyright (c) 1993 *	The Regents of the University of California.  All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *	This product includes software developed by the University of *	California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors *    may be used to endorse or promote products derived from this software *    without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */#ifndef lintstatic char sccsid[] = "@(#)mem.c	8.1 (Berkeley) 6/6/93";#endif /* not lint */#include <sys/param.h>#include <sys/malloc.h>#include <errno.h>#include <kvm.h>#include <nlist.h>#include <stdio.h>#include "extern.h"static struct nlist nl[] = {#define	X_KMEMSTATS	0	{ "_kmemstats" },#define	X_BUCKET	1	{ "_bucket" },	0};/* * These names are defined in <sys/malloc.h>. */char *kmemnames[] = INITKMEMNAMES;voiddomem(){	register struct kmembuckets *kp;	register struct kmemstats *ks;	register int i;	int size;	long totuse = 0, totfree = 0, totreq = 0;	struct kmemstats kmemstats[M_LAST];	struct kmembuckets buckets[MINBUCKET + 16];	knlist(nl);	kread(nl[X_BUCKET].n_value, &buckets, sizeof buckets, "kmembucket");	(void)printf("Memory statistics by bucket size\n");	(void)printf(	    "    Size   In Use   Free   Requests  HighWater  Couldfree\n");	for (i = MINBUCKET, kp = &buckets[i]; i < MINBUCKET + 16; i++, kp++) {		if (kp->kb_calls == 0)			continue;		size = 1 << i;		(void)printf("%8d %8ld %6ld %10ld %7ld %10ld\n", size, 			kp->kb_total - kp->kb_totalfree,			kp->kb_totalfree, kp->kb_calls,			kp->kb_highwat, kp->kb_couldfree);		totfree += size * kp->kb_totalfree;	}	kread(nl[X_KMEMSTATS].n_value, &kmemstats, sizeof kmemstats,	    "kmemstats");	(void)printf("\nMemory statistics by type\n");	(void)printf("       Type  In Use  MemUse   HighUse  Limit Requests  TypeLimit KernLimit\n");	for (i = 0, ks = &kmemstats[0]; i < M_LAST; i++, ks++) {		if (ks->ks_calls == 0)			continue;		(void)printf("%11s %6ld %7ldK %8ldK %5ldK %8ld %6u %9u\n",		    kmemnames[i] ? kmemnames[i] : "undefined",		    ks->ks_inuse, (ks->ks_memuse + 1023) / 1024,		    (ks->ks_maxused + 1023) / 1024,		    (ks->ks_limit + 1023) / 1024, ks->ks_calls,		    ks->ks_limblocks, ks->ks_mapblocks);		totuse += ks->ks_memuse;		totreq += ks->ks_calls;	}	(void)printf("\nMemory Totals:  In Use    Free    Requests\n");	(void)printf("              %7ldK %6ldK    %8ld\n",	     (totuse + 1023) / 1024, (totfree + 1023) / 1024, totreq);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -