Created
August 6, 2011 20:57
-
-
Save syuu1228/1129736 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (c) 1980, 1986, 1991, 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. | |
* 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. | |
*/ | |
#include <sys/cdefs.h> | |
#include <sys/param.h> | |
#include <sys/time.h> | |
#include <sys/proc.h> | |
#include <sys/uio.h> | |
#include <sys/namei.h> | |
#include <sys/malloc.h> | |
#include <sys/signal.h> | |
#include <sys/fcntl.h> | |
#include <sys/ioctl.h> | |
#include <sys/resource.h> | |
#include <sys/sysctl.h> | |
#include <sys/time.h> | |
#include <sys/vmmeter.h> | |
#include <sys/pcpu.h> | |
#include <vm/vm_param.h> | |
#include <ctype.h> | |
#include <devstat.h> | |
#include <err.h> | |
#include <errno.h> | |
#include <kvm.h> | |
#include <limits.h> | |
#include <memstat.h> | |
#include <nlist.h> | |
#include <paths.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <sysexits.h> | |
#include <time.h> | |
#include <unistd.h> | |
#include <libutil.h> | |
static kvm_t *kd; | |
static void | |
fill_pcpu(struct pcpu **pcpu, int maxcpu) | |
{ | |
int i; | |
for (i = 0; i < maxcpu; i++) { | |
pcpu[i] = kvm_getpcpu(kd, i); | |
if (pcpu[i] == (struct pcpu *)-1) | |
errx(1, "kvm_getpcpu: %s", kvm_geterr(kd)); | |
} | |
} | |
int main(int argc, char **argv) | |
{ | |
char *memf, *nlistf; | |
char errbuf[_POSIX2_LINE_MAX]; | |
struct pcpu **pcpu_start, **pcpu_end; | |
int maxcpu, i; | |
int sec; | |
if (argc < 2) { | |
printf("%s [sec]\n", argv[0]); | |
exit(1); | |
} | |
sec = atoi(argv[1]); | |
memf = nlistf = NULL; | |
kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf); | |
if (kd == NULL) | |
errx(1, "kvm_openfiles: %s", errbuf); | |
maxcpu = kvm_getmaxcpu(kd); | |
if (maxcpu < 0) | |
errx(1, "kvm_getmaxcpu: %s", kvm_geterr(kd)); | |
pcpu_start = calloc(maxcpu, sizeof(struct pcpu *)); | |
if (pcpu_start == NULL) | |
err(1, "calloc"); | |
pcpu_end = calloc(maxcpu, sizeof(struct pcpu *)); | |
if (pcpu_end == NULL) | |
err(1, "calloc"); | |
fill_pcpu(pcpu_start, maxcpu); | |
sleep(sec); | |
fill_pcpu(pcpu_end, maxcpu); | |
for (i = 0; i < maxcpu; i++) { | |
if (pcpu_start[i] == NULL || pcpu_end[i] == NULL) | |
continue; | |
printf("cpu%d:\n", i); | |
#define PRINT_VPARAM_PCPU(i, name) \ | |
printf(#name ":%d\n", pcpu_end[i]->pc_cnt.name - pcpu_start[i]->pc_cnt.name) | |
PRINT_VPARAM_PCPU(i, v_swtch); | |
PRINT_VPARAM_PCPU(i, v_trap); | |
PRINT_VPARAM_PCPU(i, v_syscall); | |
PRINT_VPARAM_PCPU(i, v_intr); | |
PRINT_VPARAM_PCPU(i, v_soft); | |
PRINT_VPARAM_PCPU(i, v_vm_faults); | |
PRINT_VPARAM_PCPU(i, v_cow_faults); | |
PRINT_VPARAM_PCPU(i, v_cow_optim); | |
PRINT_VPARAM_PCPU(i, v_zfod); | |
PRINT_VPARAM_PCPU(i, v_ozfod); | |
PRINT_VPARAM_PCPU(i, v_swapin); | |
PRINT_VPARAM_PCPU(i, v_swapout); | |
PRINT_VPARAM_PCPU(i, v_swappgsin); | |
PRINT_VPARAM_PCPU(i, v_swappgsout); | |
PRINT_VPARAM_PCPU(i, v_vnodein); | |
PRINT_VPARAM_PCPU(i, v_vnodeout); | |
PRINT_VPARAM_PCPU(i, v_vnodepgsin); | |
PRINT_VPARAM_PCPU(i, v_vnodepgsout); | |
PRINT_VPARAM_PCPU(i, v_intrans); | |
PRINT_VPARAM_PCPU(i, v_tfree); | |
PRINT_VPARAM_PCPU(i, v_forks); | |
PRINT_VPARAM_PCPU(i, v_vforks); | |
PRINT_VPARAM_PCPU(i, v_rforks); | |
PRINT_VPARAM_PCPU(i, v_kthreads); | |
PRINT_VPARAM_PCPU(i, v_forkpages); | |
PRINT_VPARAM_PCPU(i, v_vforkpages); | |
PRINT_VPARAM_PCPU(i, v_rforkpages); | |
PRINT_VPARAM_PCPU(i, v_kthreadpages); | |
#undef PRINT_VPARAM_PCPU | |
printf("\n\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment