- do not allow logger to write more than once per period

- fixed bug in statistics.c
This commit is contained in:
zolliker
2010-04-13 14:31:58 +00:00
parent 6c4f57ec6f
commit eebb6b06e9
3 changed files with 47 additions and 13 deletions

View File

@ -20,8 +20,9 @@ struct Logger {
char *old; char *old;
int oldsize; int oldsize;
int period; int period;
time_t last, lastWrite; time_t last, lastWrite, omitTime;
int numeric; int numeric;
float omitValue;
int exact; int exact;
Logger *next; Logger *next;
}; };
@ -30,6 +31,7 @@ static char *dir = NULL;
static Logger *list; static Logger *list;
static time_t lastLife = 0; static time_t lastLife = 0;
static time_t lastWritten = 0; static time_t lastWritten = 0;
static time_t omitCheck = 0;
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
char *LoggerName(Logger * log) char *LoggerName(Logger * log)
{ {
@ -238,6 +240,8 @@ int LoggerWrite(Logger * log, time_t now, int period, char *value)
time_t h0; time_t h0;
static int yday = -1; static int yday = -1;
struct tm *tm; struct tm *tm;
char *valp;
char buf[32];
int l; int l;
FILE *fil; FILE *fil;
@ -283,6 +287,25 @@ int LoggerWrite(Logger * log, time_t now, int period, char *value)
if (fil) if (fil)
fclose(fil); fclose(fil);
} }
if (now < log->last + log->period && strcmp(log->old, value) != 0) {
log->omitValue = strtod(value, &valp);
if (value != valp) {
log->omitTime = now;
return 1;
}
} else {
log->omitTime = 0;
}
if (now > omitCheck + 5) { /* check for omitted values only every 5 seconds */
for (p = list; p != NULL; p = p->next) {
if (p->omitTime > 0 && now > p->omitTime + p->period) {
snprintf(buf, sizeof buf, "%g", p->omitValue);
LoggerWrite0(p, p->omitTime, p->period, buf);
p->omitTime = 0;
}
}
omitCheck = now;
}
return LoggerWrite0(log, now, period, value); return LoggerWrite0(log, now, period, value);
} }
@ -398,6 +421,8 @@ Logger *LoggerMake(char *name, int period, int exact)
t = lastLife + period; t = lastLife + period;
} }
LoggerWrite(log, t, period, ""); /* value was undefined since last life of server */ LoggerWrite(log, t, period, ""); /* value was undefined since last life of server */
} else {
LoggerSetPeriod(log, period);
} }
return log; return log;
} }

View File

@ -14,6 +14,7 @@ static hdbCallbackReturn LoggerUpdateCallback(pHdb node,
hdbValue value; hdbValue value;
pHdbDataMessage mm = NULL; pHdbDataMessage mm = NULL;
pHdbDataSearch dsm = NULL; pHdbDataSearch dsm = NULL;
time_t now;
if ((dsm = GetHdbDataSearchMessage(message)) != NULL) { if ((dsm = GetHdbDataSearchMessage(message)) != NULL) {
if (dsm->testPtr == loggerID) { if (dsm->testPtr == loggerID) {
@ -29,9 +30,12 @@ static hdbCallbackReturn LoggerUpdateCallback(pHdb node,
value = *(mm->v); value = *(mm->v);
str = formatValue(value, node); time(&now);
LoggerWrite(logger, time(NULL), LoggerPeriod(logger), GetCharArray(str)); if (now > LoggerLastTime(logger)) { /* never write more than once per second */
DeleteDynString(str); str = formatValue(value, node);
LoggerWrite(logger, time(NULL), LoggerPeriod(logger), GetCharArray(str));
DeleteDynString(str);
}
return hdbContinue; return hdbContinue;
} }
@ -50,6 +54,7 @@ static int LogSetup(SConnection * pCon, SicsInterp * pSics, void *pData,
if (argc < 2) { if (argc < 2) {
SCPrintf(pCon, eError, SCPrintf(pCon, eError,
"ERROR: should be: logsetup <node> [<period> [<filename>]]"); "ERROR: should be: logsetup <node> [<period> [<filename>]]");
/* or logsetup <node> clear */
return 0; return 0;
} }
if (strcasecmp(argv[1], "basepath") == 0) { if (strcasecmp(argv[1], "basepath") == 0) {
@ -77,10 +82,6 @@ static int LogSetup(SConnection * pCon, SicsInterp * pSics, void *pData,
SCPrintf(pCon, eError, "ERROR: %s not found", argv[1]); SCPrintf(pCon, eError, "ERROR: %s not found", argv[1]);
return 0; return 0;
} }
period = 0;
if (argc > 2) {
period = atoi(argv[2]);
}
if (argc > 3) { if (argc > 3) {
snprintf(buf, sizeof buf, "%s", argv[3]); snprintf(buf, sizeof buf, "%s", argv[3]);
} else { } else {
@ -101,6 +102,14 @@ static int LogSetup(SConnection * pCon, SicsInterp * pSics, void *pData,
numeric = 0; numeric = 0;
} }
logger = FindHdbCallbackData(node, loggerID); logger = FindHdbCallbackData(node, loggerID);
period = 0;
if (argc > 2) {
if (logger != NULL && strcasecmp(argv[2], "clear") == 0) {
LoggerWrite(logger, time(NULL), LoggerPeriod(logger), "");
return 1;
}
period = atoi(argv[2]);
}
if (logger != 0) { /* logger exists already, changed only period */ if (logger != 0) { /* logger exists already, changed only period */
LoggerSetPeriod(logger, period); LoggerSetPeriod(logger, period);
} else { } else {

View File

@ -58,8 +58,8 @@ int StatisticsCommand(SConnection * con, SicsInterp * pSics, void *pData,
gettimeofday(&now, 0); gettimeofday(&now, 0);
dif = timeFloat(timeDif(lastStat, now)); dif = timeFloat(timeDif(lastStat, now));
SCPrintf(con, eValue, "calls/s time[%] full[%] mean[ms] command"); SCPrintf(con, eLog, "calls/s time[%] full[%] mean[ms] command");
SCPrintf(con, eValue, "----------------------------------------------"); SCPrintf(con, eLog, "----------------------------------------------");
for (p = list; p != NULL; p = p->next) { for (p = list; p != NULL; p = p->next) {
if (dif > 0) { if (dif > 0) {
calls = p->cnt / dif; calls = p->cnt / dif;
@ -71,7 +71,7 @@ int StatisticsCommand(SConnection * con, SicsInterp * pSics, void *pData,
} else { } else {
dt = 0; dt = 0;
} }
SCPrintf(con, eValue, "%7.1f %7.1f %7.1f %8.2f %s", calls, SCPrintf(con, eLog, "%7.1f %7.1f %7.1f %8.2f %s", calls,
percent, full, dt, p->name); percent, full, dt, p->name);
} }
} }
@ -81,8 +81,8 @@ int StatisticsCommand(SConnection * con, SicsInterp * pSics, void *pData,
p->total.tv_sec = 0; p->total.tv_sec = 0;
p->total.tv_usec = 0; p->total.tv_usec = 0;
} }
SCPrintf(con, eValue, "----------------------------------------------"); SCPrintf(con, eLog, "----------------------------------------------");
SCPrintf(con, eValue, "total time %.2f", dif); SCPrintf(con, eLog, "total time %.2f", dif);
lastStat = now; lastStat = now;
return 1; return 1;
} }