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

📄 sw.c

📁 很好的TCP_IP协议源代码分析,很适用很好
💻 C
字号:
#include <stdio.h>
#include "global.h"
#include "nospc.h"

struct stopwatch Sw[NSW];

/* Stop a stopwatch and record its value.
 * Uses stopval() routine in stopwatch.asm
 */
void
swstop(n)
int n;
{
	register struct stopwatch *sw;
	int32 ticks;

	ticks = 65536 - stopval();
	sw = &Sw[n];

	if(sw->calls++ == 0){
		sw->maxval = ticks;
		sw->minval = ticks;
	} else if(ticks > sw->maxval){
		sw->maxval = ticks;
	} else if(ticks < sw->minval){
		sw->minval = ticks;
	}
	sw->totval += ticks;
}
int
doswatch(argc,argv,p)
int argc;
char *argv[];
void *p;
{
	register struct stopwatch *sw;
	long maxval,minval,avgval;
	int i;

	if(argc > 1){
		/* Clear timers */
		for(i=0,sw=Sw;i < NSW;i++,sw++){
			sw->calls = 0;
			sw->totval = 0;
		}
	}
	for(i=0,sw=Sw;sw < &Sw[NSW];i++,sw++){
		if(sw->calls == 0)
			continue;
		minval = sw->minval * 838L/1000;
		maxval = sw->maxval * 838L/1000;
		avgval = sw->totval / sw->calls * 838L / 1000L;
		printf("%u: calls %lu min %lu max %lu avg %lu tot %lu\n",
		 i,sw->calls,minval,maxval,avgval,sw->totval);

	}
	return 0;
}

⌨️ 快捷键说明

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