- Adapted indenation to new agreed upon system
- Added support for second generation scriptcontext based counter
This commit is contained in:
64
statistics.c
64
statistics.c
@ -18,33 +18,40 @@ static tv_t last, lastStat;
|
||||
static Statistics *idle = NULL, *list = NULL;
|
||||
static int init = 1;
|
||||
/*-----------------------------------------------------------------------*/
|
||||
tv_t timeDif(tv_t t1, tv_t t2) {
|
||||
tv_t timeDif(tv_t t1, tv_t t2)
|
||||
{
|
||||
tv_t result;
|
||||
|
||||
result.tv_usec = t2.tv_usec - t1.tv_usec;
|
||||
result.tv_sec = t2.tv_sec - t1.tv_sec;
|
||||
if (result.tv_usec < 0) {
|
||||
result.tv_usec += 1000000;
|
||||
result.tv_sec --;
|
||||
result.tv_sec--;
|
||||
}
|
||||
if (result.tv_sec < 0) {
|
||||
result.tv_sec += 24*3600;
|
||||
result.tv_sec += 24 * 3600;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
void timeAdd(tv_t *t1, tv_t t2) {
|
||||
void timeAdd(tv_t * t1, tv_t t2)
|
||||
{
|
||||
t1->tv_usec += t2.tv_usec;
|
||||
t1->tv_sec += t2.tv_sec + (t1->tv_usec / 1000000);
|
||||
t1->tv_usec %= 1000000;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
double timeFloat(tv_t t) {
|
||||
double timeFloat(tv_t t)
|
||||
{
|
||||
return t.tv_sec + 1e-6 * t.tv_usec;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
int StatisticsCommand(SConnection *con, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[]) {
|
||||
int StatisticsCommand(SConnection * con, SicsInterp * pSics, void *pData,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
Statistics *p;
|
||||
tv_t now;
|
||||
double dif, percent, full, dt, calls;
|
||||
@ -65,7 +72,7 @@ int StatisticsCommand(SConnection *con, SicsInterp *pSics, void *pData,
|
||||
dt = 0;
|
||||
}
|
||||
SCPrintf(con, eValue, "%7.1f %7.1f %7.1f %8.2f %s", calls,
|
||||
percent, full, dt, p->name);
|
||||
percent, full, dt, p->name);
|
||||
}
|
||||
}
|
||||
p->cnt = 0;
|
||||
@ -79,8 +86,10 @@ int StatisticsCommand(SConnection *con, SicsInterp *pSics, void *pData,
|
||||
lastStat = now;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
Statistics *StatisticsNew(char *name) {
|
||||
Statistics *StatisticsNew(char *name)
|
||||
{
|
||||
Statistics *new;
|
||||
|
||||
if (init) {
|
||||
@ -88,7 +97,7 @@ Statistics *StatisticsNew(char *name) {
|
||||
last = lastStat;
|
||||
init = 0;
|
||||
}
|
||||
new = calloc(1,sizeof(*new));
|
||||
new = calloc(1, sizeof(*new));
|
||||
if (new) {
|
||||
new->cnt = 0;
|
||||
new->tim.tv_sec = 0;
|
||||
@ -102,8 +111,10 @@ Statistics *StatisticsNew(char *name) {
|
||||
}
|
||||
return new;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
void StatisticsKill(Statistics *stat) {
|
||||
void StatisticsKill(Statistics * stat)
|
||||
{
|
||||
Statistics *p, **last;
|
||||
|
||||
/* find in list */
|
||||
@ -124,39 +135,45 @@ void StatisticsKill(Statistics *stat) {
|
||||
}
|
||||
free(stat);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
Statistics *StatisticsBegin(Statistics *stat) {
|
||||
Statistics *StatisticsBegin(Statistics * stat)
|
||||
{
|
||||
Statistics *res;
|
||||
tv_t now;
|
||||
|
||||
|
||||
res = current;
|
||||
gettimeofday(&now, 0);
|
||||
if(current != NULL){
|
||||
timeAdd(¤t->tim, timeDif(last, now));
|
||||
if (current != NULL) {
|
||||
timeAdd(¤t->tim, timeDif(last, now));
|
||||
}
|
||||
last = now;
|
||||
current = stat;
|
||||
stat->last = now;
|
||||
stat->cnt ++;
|
||||
stat->cnt++;
|
||||
return res;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
void StatisticsEnd(Statistics *stat) {
|
||||
void StatisticsEnd(Statistics * stat)
|
||||
{
|
||||
tv_t now;
|
||||
|
||||
gettimeofday(&now, 0);
|
||||
timeAdd(¤t->tim, timeDif(last, now));
|
||||
last = now;
|
||||
if(current != NULL){
|
||||
if (current->last.tv_sec >= 0) {
|
||||
timeAdd(¤t->total, timeDif(current->last, now));
|
||||
}
|
||||
current->last.tv_sec = -1;
|
||||
if (current != NULL) {
|
||||
if (current->last.tv_sec >= 0) {
|
||||
timeAdd(¤t->total, timeDif(current->last, now));
|
||||
}
|
||||
current->last.tv_sec = -1;
|
||||
}
|
||||
current = stat;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
void StatisticsInit(void) {
|
||||
void StatisticsInit(void)
|
||||
{
|
||||
if (idle == NULL) {
|
||||
AddCmd("statistics", StatisticsCommand);
|
||||
last = lastStat;
|
||||
@ -164,4 +181,3 @@ void StatisticsInit(void) {
|
||||
current = idle;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user