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