PSI update

r1464 | ffr | 2007-02-12 12:20:21 +1100 (Mon, 12 Feb 2007) | 2 lines
This commit is contained in:
Ferdi Franceschini
2007-02-12 12:20:21 +11:00
committed by Douglas Clowes
parent 634f2023b1
commit 3168325921
157 changed files with 29053 additions and 910 deletions

View File

@@ -6,14 +6,16 @@ typedef struct timeval tv_t;
struct Statistics {
tv_t tim;
tv_t last;
tv_t total;
long cnt;
char *name;
Statistics *next;
};
static Statistics *current;
static Statistics *current = NULL;
static tv_t last, lastStat;
static Statistics *idle = NULL, *list;
static Statistics *idle = NULL, *list = NULL;
static int init = 1;
/*-----------------------------------------------------------------------*/
tv_t timeDif(tv_t t1, tv_t t2) {
@@ -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,35 @@ 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);
if(current != NULL){
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 != NULL){
if (current->last.tv_sec >= 0) {
timeAdd(&current->total, timeDif(current->last, now));
}
current->last.tv_sec = -1;
}
current = stat;
}
/*-----------------------------------------------------------------------*/
void StatisticsInit(void) {