- added statistics command

This commit is contained in:
zolliker
2006-08-17 15:38:46 +00:00
parent a050de71d0
commit bdc988f164

View File

@@ -6,6 +6,8 @@ typedef struct timeval tv_t;
struct Statistics { struct Statistics {
tv_t tim; tv_t tim;
tv_t last;
tv_t total;
long cnt; long cnt;
char *name; char *name;
Statistics *next; Statistics *next;
@@ -45,28 +47,31 @@ int StatisticsCommand(SConnection *con, SicsInterp *pSics, void *pData,
int argc, char *argv[]) { int argc, char *argv[]) {
Statistics *p; Statistics *p;
tv_t now; tv_t now;
double dif, percent, dt; double dif, percent, full, dt;
gettimeofday(&now, 0); gettimeofday(&now, 0);
dif = timeFloat(timeDif(lastStat, now)); dif = timeFloat(timeDif(lastStat, now));
SCPrintf(con, eStatus, " calls time[%] mean[ms] command"); SCPrintf(con, eStatus, " calls time[%] full[%] mean[ms] command");
SCPrintf(con, eStatus, "--------------------------------------"); SCPrintf(con, eStatus, "----------------------------------------------");
for (p = list; p != NULL; p = p->next) { for (p = list; p != NULL; p = p->next) {
if (dif > 0) { if (dif > 0) {
percent = timeFloat(p->tim) * 100 / dif; percent = timeFloat(p->tim) * 100 / dif;
if (percent > 0) { full = timeFloat(p->total) * 100 / dif;
if (full > 0 || percent > 0) {
if (p->cnt > 0) { if (p->cnt > 0) {
dt = timeFloat(p->tim) * 1000.0 / p->cnt; dt = timeFloat(p->total) * 1000.0 / p->cnt;
} else { } else {
dt = 0; dt = 0;
} }
SCPrintf(con, eStatus, "%7ld %7.1f %8.2f %s", p->cnt, SCPrintf(con, eStatus, "%7ld %7.1f %7.1f %8.2f %s", p->cnt,
percent, dt, p->name); percent, full, dt, p->name);
} }
} }
p->cnt = 0; p->cnt = 0;
p->tim.tv_sec = 0; p->tim.tv_sec = 0;
p->tim.tv_usec = 0; p->tim.tv_usec = 0;
p->total.tv_sec = 0;
p->total.tv_usec = 0;
} }
lastStat = now; lastStat = now;
return 1; return 1;
@@ -85,6 +90,9 @@ Statistics *StatisticsNew(char *name) {
new->cnt = 0; new->cnt = 0;
new->tim.tv_sec = 0; new->tim.tv_sec = 0;
new->tim.tv_usec = 0; new->tim.tv_usec = 0;
new->total.tv_sec = 0;
new->total.tv_usec = 0;
new->last.tv_sec = -1;
new->next = list; new->next = list;
new->name = strdup(name); new->name = strdup(name);
list = new; list = new;
@@ -114,28 +122,31 @@ void StatisticsKill(Statistics *stat) {
free(stat); free(stat);
} }
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
static void StatisticsSet(Statistics *stat) { Statistics *StatisticsBegin(Statistics *stat) {
Statistics *res;
tv_t now; tv_t now;
if (stat != NULL) { res = current;
gettimeofday(&now, 0); gettimeofday(&now, 0);
timeAdd(&current->tim, timeDif(last, now)); timeAdd(&current->tim, timeDif(last, now));
last = now; last = now;
}
current = stat; current = stat;
} stat->last = now;
/*-----------------------------------------------------------------------*/ stat->cnt ++;
Statistics *StatisticsBegin(Statistics *stat) {
Statistics *res;
res = current;
StatisticsSet(stat);
current->cnt ++;
return res; return res;
} }
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
void StatisticsEnd(Statistics *stat) { void StatisticsEnd(Statistics *stat) {
StatisticsSet(stat); tv_t now;
gettimeofday(&now, 0);
timeAdd(&current->tim, timeDif(last, now));
last = now;
if (current->last.tv_sec >= 0) {
timeAdd(&current->total, timeDif(current->last, now));
}
current->last.tv_sec = -1;
current = stat;
} }
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
void StatisticsInit(void) { void StatisticsInit(void) {