- Introduced a new trace facility

- Fixed performance problems in many protocol drivers.


SKIPPED:
	psi/julprot.c
	psi/phytron.c
	psi/pmacprot.c
	psi/polterwrite.c
	psi/spss7.c
This commit is contained in:
koennecke
2011-06-29 07:53:54 +00:00
parent 9abb3584f1
commit 3ee1865f9b
31 changed files with 868 additions and 35 deletions

View File

@@ -35,6 +35,7 @@ struct SctController {
Hdb *node; /* the controller node */
SConnection *conn;
int verbose;
FILE *fd;
};
/* action data and write callback data */
@@ -284,6 +285,9 @@ int SctCallInContext(SConnection * con, char *script, Hdb * node,
if (verbose) {
SCPrintf(con, eLog, "%6.3f script: %s", secondsOfMinute(), script);
}
if (controller->fd != NULL) {
fprintf(controller->fd,"%6.3f script: %s\n", secondsOfMinute(), script);
}
MacroPush(con);
l = strlen(script);
@@ -298,7 +302,10 @@ int SctCallInContext(SConnection * con, char *script, Hdb * node,
}
}
if (verbose) {
SCPrintf(con, eLog, "%6.3f error: %s", secondsOfMinute(), result);
SCPrintf(con, eLog, "%6.3f error: %s", secondsOfMinute(), result);
}
if(controller->fd != NULL){
fprintf(controller->fd, "%6.3f error: %s\n", secondsOfMinute(), result);
}
iRet = 0;
}
@@ -365,10 +372,17 @@ static char *SctActionHandler(void *actionData, char *lastReply,
script = NULL;
if (!commError && controller->verbose && lastReply != NULL
&& *lastReply != '\0') {
SCPrintf(con, eLog, "%6.3f reply : %s\n", secondsOfMinute(), lastReply);
/**
* TODO: This is the end place of any communication for statistics measurement
*/
SCPrintf(con, eLog, "%6.3f reply : %s\n", secondsOfMinute(), lastReply);
}
if(!commError && controller->fd != NULL && lastReply != NULL && *lastReply != '\0'){
fprintf(controller->fd, "%6.3f reply : %s\n", secondsOfMinute(), lastReply);
}
if(lastReply != NULL && *lastReply != '\0'){
if(data != NULL && data->controller != NULL){
traceIO(data->controller->node->name, "reply:%s", lastReply);
} else {
traceIO("sctunknown", "reply:%s", lastReply);
}
}
/*
@@ -511,9 +525,14 @@ static char *SctActionHandler(void *actionData, char *lastReply,
if (controller->verbose) {
SCPrintf(con, eLog, "%6.3f send : %s", secondsOfMinute(), send);
}
/**
* TODO: this is another point where to introduce statistics, this is the start
*/
if (controller->fd != NULL) {
fprintf(controller->fd, "%6.3f send : %s\n", secondsOfMinute(), send);
}
if(data != NULL && data->controller != NULL){
traceIO(data->controller->node->name, "send:%s", send);
} else {
traceIO("sctunknown", "send:%s", send);
}
return send;
}
}
@@ -1115,13 +1134,29 @@ static char *TransactionHandler(void *actionData, char *lastReply,
if (st->controller->verbose) {
SCPrintf(st->con, eLog, "%6.3f send : %s", secondsOfMinute(), st->command);
}
if (st->controller->fd != NULL) {
fprintf(st->controller->fd, "%6.3f send : %s\n", secondsOfMinute(), st->command);
}
if(st->controller != NULL){
traceIO(st->controller->node->name, "transsend:%s", st->command);
} else {
traceIO("sctunknown", "transsend:%s", st->command);
}
return st->command;
} else {
st->sent = 2;
if (st->controller->verbose) {
SCPrintf(st->con, eLog, "%6.3f reply : %s", secondsOfMinute(), lastReply);
}
if (st->controller->fd != NULL) {
fprintf(st->controller->fd,"%6.3f reply : %s\n", secondsOfMinute(), lastReply);
}
/* printf("Transact: %s got %s\n", st->command, lastReply); */
if(st->controller != NULL){
traceIO(st->controller->node->name, "transreply:%s", lastReply);
} else {
traceIO("sctunknown", "transreply:%s", lastReply);
}
st->reply = strdup(lastReply);
return NULL;
@@ -1141,6 +1176,11 @@ static int SctTransactCmd(pSICSOBJ ccmd, SConnection * con,
c = (SctController *) ccmd->pPrivate;
if(nPar < 1 || par[0] == NULL){
SCWrite(con,"ERROR: no data to transact found", eError);
return 0;
}
st = calloc(sizeof(SctTransact), 1);
if (st == NULL) {
SCWrite(con, "ERROR: out of memory in SctTransactCommand", eError);
@@ -1239,14 +1279,14 @@ static int SctStatistics(pSICSOBJ ccmd, SConnection * con,
char state[16];
c = (SctController *) ccmd->pPrivate;
DevStatistics(c->devser,&avg, &max, &errCount, &errState);
DevStatistics(c->devser,&avg, &max, &maxCount, &errCount, &errState);
if(errState == 1){
strcpy(state,"in error");
} else {
strcpy(state,"good");
}
SCPrintf(con,eValue,"Average roundtrip time: %lf, maximum roundtrip time %lf, com error count: %ld, com state: %s",
avg, max, errCount, state);
SCPrintf(con,eValue,"Average roundtrip time: %lf, maximum roundtrip time %lf, count max roundtrip/2 %d, com error count: %ld, com state: %s",
avg, max, maxCount, errCount, state);
DevAsconStatistics(c->devser,&avg, &max, &maxState, &maxCount);
SCPrintf(con,eValue,"Average time in AsconTask: %lf, maximum time spent in AsconTask %lf, state of Ascon on max %d, count > max/2 %d",
avg, max, maxState, maxCount);
@@ -1254,6 +1294,34 @@ static int SctStatistics(pSICSOBJ ccmd, SConnection * con,
return 1;
}
static int SctLog(pSICSOBJ ccmd, SConnection * con,
Hdb * cmdNode, Hdb * par[], int nPar)
{
SctController *c;
char *filename = NULL;
c = (SctController *) ccmd->pPrivate;
filename = par[0]->value.v.text;
if(strcmp(filename,"close") == 0 ){
if(c->fd != NULL){
fclose(c->fd);
c->fd = NULL;
}
} else {
if(c->fd != NULL){
fclose(c->fd);
}
c->fd = fopen(filename,"w");
if(c->fd == NULL){
SCPrintf(con,eError,"ERROR: failed to open %s for logging", filename);
return 0;
} else {
SCPrintf(con,eValue,"Logging to %s", filename);
}
}
return 1;
}
static hdbCallbackReturn SctDebugCallback(Hdb * node, void *userData,
hdbMessage * msg)
{
@@ -1305,6 +1373,12 @@ static void SctKillController(void *c)
}
DevKill(controller->devser);
controller->devser = NULL;
if(controller->fd != NULL){
fclose(controller->fd);
controller->fd = NULL;
}
if (pServ->pTasker) {
TaskRegister(pServ->pTasker, SctDeferredTask, NULL, SctDeferredFree,
controller, 0);
@@ -1395,6 +1469,11 @@ static int SctMakeController(SConnection * con, SicsInterp * sics,
AddSICSHdbPar(cmd, "prio", usMugger, MakeHdbText("write"));
AddSICSHdbPar(cmd, "action", usMugger, MakeHdbText("write"));
cmd = AddSICSHdbPar(controller->node,
"log", usMugger, MakeSICSFunc(SctLog));
AddSICSHdbPar(cmd, "filename", usMugger, MakeHdbText(""));
cmd = AddSICSHdbPar(controller->node,
"transact", usMugger, MakeSICSFunc(SctTransactCmd));
AddSICSHdbPar(cmd, "data", usMugger, MakeHdbText(""));