pstat.c
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 1,614 行 · 第 1/3 页
C
1,614 行
printf("maxfile \t%d\n", U.u_omax); printf("cdir rdir\t%9.1x %9.1x\n", U.u_cdir, U.u_rdir); printf("ttyd \t%d,%d\n", major(U.u_ttyd), minor(U.u_ttyd)); printf("cmask \t0%o\n", U.u_cmask); printf("ru\t"); ip = (int *)&U.u_ru; for (i = 0; i < sizeof(U.u_ru)/sizeof(int); i++) { if ( i % 10 == 0 && i ) printf("\n\t"); printf("%d ", ip[i]); } if (sizeof(U.u_ru)/sizeof(int) % 10 != 0) printf("\n"); ip = (int *)&U.u_cru; printf("cru\t"); for (i = 0; i < sizeof(U.u_cru)/sizeof(int); i++) { if ( i % 10 == 0 && i ) printf("\n\t"); printf("%d ", ip[i]); } if (sizeof(U.u_cru)/sizeof(int) % 10 != 0) printf("\n"); printf("timers"); for(i=0;i<sizeof(U.u_timer)/sizeof(struct itimerval);i++) { printf("\t%12d %12d %12d %12d\n", U.u_timer[i].it_interval.tv_sec, U.u_timer[i].it_interval.tv_usec, U.u_timer[i].it_value.tv_sec, U.u_timer[i].it_value.tv_usec); }/* * Nothing now but will handle larger timer structure in the future! * printf("u_XXX[3]\t%x %x %x\n",U.u_XXX[0],U.u_XXX[1],U.u_XXX[2]); */ printf("tracedev \t%d\n", U.u_tracedev); printf("start \t%ds %dus\n", U.u_start.tv_sec,U.u_start.tv_usec); printf("acflag \t%d\n", U.u_acflag); printf("limits \t"); for(i=0;i<RLIM_NLIMITS;i++) { printf("%d ",U.u_rlimit[i]); } printf("\n"); printf("quota \t%9.1x\n",U.u_quota); printf("quotaflag\t%9.1x\n",U.u_qflags); printf("smem \t%9.1x %9.1x %9.1x\n", U.u_smsize,U.u_osmsize,U.u_lock); printf("prof \t%9.1x %9.1x %9.1x %9.1x\n", U.u_prof.pr_base, U.u_prof.pr_size, U.u_prof.pr_off, U.u_prof.pr_scale); printf("u_nache \toff %d ino %d dev %d tim %d\n", U.u_ncache.nc_prevoffset,U.u_ncache.nc_inumber, U.u_ncache.nc_dev,U.u_ncache.nc_time); printf("nameidata\n"); printf("\tnameiop, error, endoff\t%8x %8d %8d\n", nd->ni_nameiop,nd->ni_error,nd->ni_endoff); printf("\t base, count, offset\t%8x %8d %8d\n", nd->ni_base,nd->ni_count,nd->ni_offset); printf("\tdent ino %d name %.14s\n", nd->ni_dent.d_ino,nd->ni_dent.d_name); printf("\tsegflg\t%8d\n", nd->ni_segflg); printf("u_stack \t%9.1x\n",U.u_stack[0]);/* i = U.u_stack - &U; while (U[++i] == 0); i &= ~07; while (i < 512) { printf("%x ", 0140000+2*i); for (j=0; j<8; j++) printf("%9x", U[i++]); printf("\n"); }*/}oatoi(s)register char *s;{ register int v; v = 0; while (*s) v = (v<<3) + *s++ - '0'; return(v);}dofile(){ register int nfile; struct file *xfile; register struct file *afile; register struct file *fp; register nf; register int loc; static char *dtypes[] = { "???", "gnode", "socket" }; nf = 0; nfile = getw(nl[SNFILE].n_value); if((xfile = (struct file *)calloc(nfile, sizeof (struct file))) == (struct file *) NULL) { perror("calloc: dofile"); exit(1); } klseek(fc, (int)(afile = (struct file *)getw(nl[SFIL].n_value)), 0); read(fc, xfile, nfile * sizeof (struct file)); for (fp=xfile; fp < &xfile[nfile]; fp++) if (fp->f_count) nf++; if (totflg) { printf("%4d/%4d\tfiles\n", nf, nfile); return; } printf("%d/%d open files\n", nf, nfile); printf(" LOC TYPE FLG CNT MSG DATA OFFSET\n"); for (fp=xfile,loc=(int)afile; fp < &xfile[nfile]; fp++,loc+=sizeof(xfile[0])) { if (fp->f_count==0) continue; printf("%8x ", loc); if (fp->f_type <= DTYPE_SOCKET) printf("%-8.8s", dtypes[fp->f_type]); else printf("8d", fp->f_type); putf(fp->f_flag&FREAD, 'R'); putf(fp->f_flag&FWRITE, 'W'); putf(fp->f_flag&FAPPEND, 'A'); putf(fp->f_flag&FSHLOCK, 'S'); putf(fp->f_flag&FEXLOCK, 'X'); putf(fp->f_flag&FASYNC, 'I'); putf(fp->f_flag&FBLKINUSE, 'B'); printf(" %3d", mask(fp->f_count)); printf(" %3d", mask(fp->f_msgcount)); printf(" %8.1x", fp->f_data); if (fp->f_offset < 0) printf(" %x\n", fp->f_offset); else printf(" %ld\n", fp->f_offset); }}int swapfrag,nswdev;doswap(){ struct map *swapmap; struct swapu_t swapu; /* ptr to swap useage structure */ register int nswapmap; struct swdevt *swdevt, *sw; int nswap, free, j, avas; register struct mapent *me; int sys_clsize = getpagesize() / 512; /* 512 is clicks, not pages */ avas = btodb(ctob(getw(nl[AVAILVAS].n_value))); nswapmap = getw(nl[SNSWAPMAP].n_value); if((swapmap = (struct map *)calloc(nswapmap, sizeof (struct map))) == (struct map *) NULL) { perror("calloc: doswap swapmap"); exit(1); } nswdev = getw(nl[SNSWDEV].n_value); if((swdevt = (struct swdevt *)calloc(nswdev, sizeof (struct swdevt))) == (struct swdevt *) NULL) { perror("calloc: doswap swdevt"); exit(1); } klseek(fc, nl[SSWAPU].n_value, L_SET); read(fc, &swapu, sizeof (struct swapu_t)); klseek(fc, nl[SSWDEVT].n_value, L_SET); read(fc, swdevt, nswdev * sizeof (struct swdevt)); klseek(fc, getw(nl[SWAPMAP].n_value), 0); read(fc, swapmap, nswapmap * sizeof (struct map)); swapmap->m_name = "swap"; swapmap->m_limit = (struct mapent *)&swapmap[nswapmap]; swapfrag = getw(nl[SSWAPFRAG].n_value); nswap = 0; for (sw = swdevt; sw < &swdevt[nswdev]; sw++) nswap += sw->sw_nblks; /* * in swapmap blk addr 0 is unused and also another * CLSIZE is thrown away -- */ nswap = nswap -ctod(CLSIZE) - ctod(CLSIZE); free = 0; for (me = (struct mapent *)(swapmap+1); me < (struct mapent *)&swapmap[nswapmap]; me++) free += me->m_size;#ifdef vax#define CLRND(x) (((x) + (sys_clsize-1)) & ~(sys_clsize-1))#endif vax#ifdef mips#define CLRND(x) (x)#endif mips if (totflg) {#define btok(x) ((x) / (1024 / DEV_BSIZE)) printf("%4d/%4d\t00k swap\n", btok(swapu.total_used/100), btok((swapu.total_used+free)/100)); return; } printf("%dk swap configured\n%dk reserved virtual address space\n\t%dk used (%dk text, %dk smem)\n", btok(nswap), btok(nswap - avas), btok(swapu.total_used), btok(swapu.txt), btok(swapu.smem)); printf("\t%dk free, %dk wasted, %dk missing\n", btok(free), btok(swapu.wasted), btok(nswap - (swapu.total_used + free))); printf("avail: "); j = 0; while (rmalloc(swapmap, swapfrag) != 0) j++; if (j) printf("%d*%dk ", j, btok(swapfrag)); free = 0; for (me = (struct mapent *)(swapmap+1); me < (struct mapent *)&swapmap[nswapmap]; me++) free += me->m_size; printf("%d*1k\n", btok(free));}/* * Allocate 'size' units from the given * map. Return the base of the allocated space. * In a map, the addresses are increasing and the * list is terminated by a 0 size. * * Algorithm is first-fit. * * This routine knows about the interleaving of the swapmap * and handles that. */longrmalloc(mp, size) register struct map *mp; register long size;{ register struct mapent *ep = (struct mapent *)(mp+1); register int addr; register struct mapent *bp; swblk_t first, rest; if (size <= 0 || size > swapfrag) return (0); /* * Search for a piece of the resource map which has enough * free space to accomodate the request. */ for (bp = ep; bp->m_size; bp++) { if (bp->m_size >= size) { /* * If allocating from swapmap, * then have to respect interleaving * boundaries. */ if (nswdev > 1 && (first = swapfrag - bp->m_addr%swapfrag) < bp->m_size) { if (bp->m_size - first < size) continue; addr = bp->m_addr + first; rest = bp->m_size - first - size; bp->m_size = first; if (rest) rmfree(mp, rest, addr+size); return (addr); } /* * Allocate from the map. * If there is no space left of the piece * we allocated from, move the rest of * the pieces to the left. */ addr = bp->m_addr; bp->m_addr += size; if ((bp->m_size -= size) == 0) { do { bp++; (bp-1)->m_addr = bp->m_addr; } while ((bp-1)->m_size = bp->m_size); } if (addr % CLSIZE) return (0); return (addr); } } return (0);}/* * Free the previously allocated space at addr * of size units into the specified map. * Sort addr into map and combine on * one or both ends if possible. */rmfree(mp, size, addr) struct map *mp; long size, addr;{ register struct mapent *firstbp; register struct mapent *bp; register int t; /* * Both address and size must be * positive, or the protocol has broken down. */ if (addr <= 0 || size <= 0) goto badrmfree; /* * Locate the piece of the map which starts after the * returned space (or the end of the map). */ firstbp = bp = (struct mapent *)(mp + 1); for (; bp->m_addr <= addr && bp->m_size != 0; bp++) continue; /* * If the piece on the left abuts us, * then we should combine with it. */ if (bp > firstbp && (bp-1)->m_addr+(bp-1)->m_size >= addr) { /* * Check no overlap (internal error). */ if ((bp-1)->m_addr+(bp-1)->m_size > addr) goto badrmfree; /* * Add into piece on the left by increasing its size. */ (bp-1)->m_size += size; /* * If the combined piece abuts the piece on * the right now, compress it in also, * by shifting the remaining pieces of the map over. */ if (bp->m_addr && addr+size >= bp->m_addr) { if (addr+size > bp->m_addr) goto badrmfree; (bp-1)->m_size += bp->m_size; while (bp->m_size) { bp++; (bp-1)->m_addr = bp->m_addr; (bp-1)->m_size = bp->m_size; } } goto done; } /* * Don't abut on the left, check for abutting on * the right. */ if (addr+size >= bp->m_addr && bp->m_size) { if (addr+size > bp->m_addr) goto badrmfree; bp->m_addr -= size; bp->m_size += size; goto done; } /* * Don't abut at all. Make a new entry * and check for map overflow. */ do { t = bp->m_addr; bp->m_addr = addr; addr = t; t = bp->m_size; bp->m_size = size; bp++; } while (size = t); /* * Segment at bp is to be the delimiter; * If there is not room for it * then the table is too full * and we must discard something. */ if (bp+1 > mp->m_limit) { /* * Back bp up to last available segment. * which contains a segment already and must * be made into the delimiter. * Discard second to last entry, * since it is presumably smaller than the last * and move the last entry back one. */ bp--; printf("%s: rmap ovflo, lost [%d,%d)\n", mp->m_name, (bp-1)->m_addr, (bp-1)->m_addr+(bp-1)->m_size); bp[-1] = bp[0]; bp[0].m_size = bp[0].m_addr = 0; }done: return;badrmfree: printf("bad rmfree\n");}/* * * klseek taken from source for ps with slight modifications. * */klseek(fd, loc, off) int fd; unsigned long loc; int off;{#ifdef vax if( kflg && Sysmap == 0) {/* initialize Sysmap */ sizeSysmap = nl[SSYSSIZE].n_value * sizeof( struct pte); if((Sysmap = (struct pte *)calloc( sizeSysmap, 1)) == (struct pte *) NULL) { perror("calloc: klseek"); exit(1); } lseek( fc, clear( nl[SSYSMAP].n_value), 0); if( read( fc, Sysmap, sizeSysmap) != sizeSysmap) { printf( "Can't read system page table from %s\n", fcore); exit(1); } } if( kflg && (loc&0x80000000)) {/* do mapping for kernel virtual addresses */ struct pte *ptep; loc &= 0x7fffffff; ptep = &Sysmap[btop(loc)]; if( (char *)ptep - (char *)Sysmap > sizeSysmap) { printf( "no system pte for %s\n", loc); exit(1); } if( ptep->pg_v == 0) { printf( "system pte invalid for %x\n", loc); exit(1); } loc = (off_t)((loc&PGOFSET) + ptob(ptep->pg_pfnum)); } (void) lseek(fd, (long)loc, off);#endif vax#ifdef mips /* mkphys handles mapping on mips*/ if (kflg && (loc & 0x80000000)) loc = mkphys(loc); (void) lseek(fd, loc, off);#endif mips}#ifdef mips/* * "addr" is a kern virt addr and does not correspond * To a phys addr after zipping out the high bit.. * since it was valloc'd in the kernel. * * We return the phys addr by simulating kernel vm (/dev/kmem) * when we are reading a crash dump. */#include <machine/cpu.h>off_tmkphys(addr) unsigned long addr;{ register off_t o; unsigned long addr2=addr; if (IS_KSEG0(addr)) { return(K0_TO_PHYS(addr)); } if (IS_KSEG1(addr)) { return(K1_TO_PHYS(addr)); } o = addr & PGOFSET; addr = 4 * btop(addr2 - K2BASE); addr = getsys((unsigned)nl[SSYSMAP].n_value + addr); addr = (addr & PG_PFNUM) << (PGSHIFT - PTE_PFNSHIFT) | o; return(addr);}getsys(loc) register unsigned loc;{ register unsigned seekloc = 0; int word; if (IS_KSEG0(loc)) { seekloc = K0_TO_PHYS(loc); } if (IS_KSEG1(loc)) { seekloc = K1_TO_PHYS(loc); } lseek(fc, seekloc, 0); read(fc, &word, sizeof(word)); return(word);}#endif mips/* * smp_stat * * Compute statistics on smp lock struct. * Calculate the average number of spins needed to acquire the lock and * the percentage of locks that were failed to be acquired. * * "line" is used to represent the tty line for example in a case where * there are many stats to be printed out under one title line. * setting "line" to -1 will prevent the use of this parameter. */smp_stat(line,spin,lost,won) int line; unsigned int spin, lost,won;{ float avg,pct; if (smp_title) { if (line >= 0) printf("LINE WON LOST SPUN AVGSPIN %%LOST NORM\n"); else printf(" WON LOST SPUN AVGSPIN %%LOST NORM\n"); smp_title = 0; } if ((won != 0) || (lost != 0)) { if (lost != 0) avg = (float)spin/(float)lost; else avg = 0; if (won != 0) pct = 100*((float)lost/(float)won); else pct = 0; if (line >= 0) printf("%4d",line); printf("%8d %8d %8d %6.3f %6.3f %6.3f\n", won, lost, spin, avg, pct, avg*pct); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?