- Adapted indenation to new agreed upon system
- Added support for second generation scriptcontext based counter
This commit is contained in:
377
perfmon.c
377
perfmon.c
@ -45,129 +45,124 @@
|
||||
#include "perfmon.h"
|
||||
#include "perfmon.i"
|
||||
/*-------------------------------------------------------------------------*/
|
||||
static void *PerfMonInter(void *pData, int iInterface)
|
||||
{
|
||||
pPerfMon self = NULL;
|
||||
|
||||
self = (pPerfMon)pData;
|
||||
assert(self);
|
||||
|
||||
if(iInterface == CALLBACKINTERFACE)
|
||||
{
|
||||
return self->pCall;
|
||||
}
|
||||
static void *PerfMonInter(void *pData, int iInterface)
|
||||
{
|
||||
pPerfMon self = NULL;
|
||||
|
||||
self = (pPerfMon) pData;
|
||||
assert(self);
|
||||
|
||||
if (iInterface == CALLBACKINTERFACE) {
|
||||
return self->pCall;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
pPerfMon CreatePerfMon(int iInteg)
|
||||
{
|
||||
|
||||
pPerfMon pNew = NULL;
|
||||
time_t tCurrent;
|
||||
|
||||
pNew = (pPerfMon) malloc(sizeof(PerfMon));
|
||||
if (!pNew) {
|
||||
return NULL;
|
||||
}
|
||||
memset(pNew, 0, sizeof(PerfMon));
|
||||
|
||||
/* initialise Descriptor */
|
||||
pNew->pDes = CreateDescriptor("PerfMon");
|
||||
if (!pNew->pDes) {
|
||||
free(pNew);
|
||||
return NULL;
|
||||
}
|
||||
pNew->pDes->GetInterface = PerfMonInter;
|
||||
|
||||
/* initalise callback */
|
||||
pNew->pCall = CreateCallBackInterface();
|
||||
if (!pNew->pCall) {
|
||||
DeleteDescriptor(pNew->pDes);
|
||||
free(pNew);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pNew->tLast = time(&tCurrent);
|
||||
pNew->tTarget = pNew->tLast + iInteg;
|
||||
pNew->iInteg = iInteg;
|
||||
|
||||
return pNew;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
pPerfMon CreatePerfMon(int iInteg)
|
||||
{
|
||||
|
||||
pPerfMon pNew = NULL;
|
||||
time_t tCurrent;
|
||||
|
||||
pNew = (pPerfMon)malloc(sizeof(PerfMon));
|
||||
if(!pNew)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
memset(pNew,0,sizeof(PerfMon));
|
||||
|
||||
/* initialise Descriptor */
|
||||
pNew->pDes = CreateDescriptor("PerfMon");
|
||||
if(!pNew->pDes)
|
||||
{
|
||||
free(pNew);
|
||||
return NULL;
|
||||
}
|
||||
pNew->pDes->GetInterface = PerfMonInter;
|
||||
|
||||
/* initalise callback */
|
||||
pNew->pCall = CreateCallBackInterface();
|
||||
if(!pNew->pCall)
|
||||
{
|
||||
DeleteDescriptor(pNew->pDes);
|
||||
free(pNew);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pNew->tLast = time(&tCurrent);
|
||||
pNew->tTarget = pNew->tLast + iInteg;
|
||||
pNew->iInteg = iInteg;
|
||||
|
||||
return pNew;
|
||||
}
|
||||
void DeletePerfMon(void *pData)
|
||||
{
|
||||
pPerfMon self = NULL;
|
||||
|
||||
self = (pPerfMon) pData;
|
||||
assert(self);
|
||||
|
||||
if (self->pDes) {
|
||||
DeleteDescriptor(self->pDes);
|
||||
}
|
||||
if (self->pCall) {
|
||||
DeleteCallBackInterface(self->pCall);
|
||||
}
|
||||
free(self);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void DeletePerfMon(void *pData)
|
||||
{
|
||||
pPerfMon self = NULL;
|
||||
|
||||
self = (pPerfMon)pData;
|
||||
assert(self);
|
||||
|
||||
if(self->pDes)
|
||||
{
|
||||
DeleteDescriptor(self->pDes);
|
||||
}
|
||||
if(self->pCall)
|
||||
{
|
||||
DeleteCallBackInterface(self->pCall);
|
||||
}
|
||||
free(self);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
int IncrementPerfMon(pPerfMon self)
|
||||
{
|
||||
time_t tCurrent;
|
||||
char pBueffel[80];
|
||||
|
||||
self->iCount++;
|
||||
|
||||
time(&tCurrent);
|
||||
if(tCurrent > self->tTarget) /* recalculation necessary */
|
||||
{
|
||||
self->fCPS = (float)self->iCount /
|
||||
(float)(tCurrent - self->tLast);
|
||||
self->iCount = 0;
|
||||
self->tLast = tCurrent;
|
||||
self->tTarget = tCurrent + self->iInteg;
|
||||
if(self->iLog)
|
||||
{
|
||||
sprintf(pBueffel,"PerfMon = %f",self->fCPS);
|
||||
SICSLogWrite(pBueffel,eValue);
|
||||
}
|
||||
InvokeCallBack(self->pCall, VALUECHANGE, &self->fCPS);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
int IncrementPerfMon(pPerfMon self)
|
||||
{
|
||||
time_t tCurrent;
|
||||
char pBueffel[80];
|
||||
|
||||
self->iCount++;
|
||||
|
||||
time(&tCurrent);
|
||||
if (tCurrent > self->tTarget) { /* recalculation necessary */
|
||||
self->fCPS = (float) self->iCount / (float) (tCurrent - self->tLast);
|
||||
self->iCount = 0;
|
||||
self->tLast = tCurrent;
|
||||
self->tTarget = tCurrent + self->iInteg;
|
||||
if (self->iLog) {
|
||||
sprintf(pBueffel, "PerfMon = %f", self->fCPS);
|
||||
SICSLogWrite(pBueffel, eValue);
|
||||
}
|
||||
InvokeCallBack(self->pCall, VALUECHANGE, &self->fCPS);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
float GetPerformance(pPerfMon self)
|
||||
{
|
||||
assert(self);
|
||||
return self->fCPS;
|
||||
}
|
||||
float GetPerformance(pPerfMon self)
|
||||
{
|
||||
assert(self);
|
||||
return self->fCPS;
|
||||
}
|
||||
|
||||
/*------------------- The CallBack function for interest ------------------*/
|
||||
static int InterestCallback(int iEvent, void *pEvent, void *pUser)
|
||||
{
|
||||
float *fPos;
|
||||
SConnection *pCon;
|
||||
char pBueffel[80];
|
||||
|
||||
assert(pEvent);
|
||||
assert(pUser);
|
||||
|
||||
fPos = (float *)pEvent;
|
||||
pCon = (SConnection *)pUser;
|
||||
|
||||
if(pCon == NULL || !SCisConnected(pCon))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
sprintf(pBueffel,"Performance = %f", *fPos);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
return 1;
|
||||
}
|
||||
static int InterestCallback(int iEvent, void *pEvent, void *pUser)
|
||||
{
|
||||
float *fPos;
|
||||
SConnection *pCon;
|
||||
char pBueffel[80];
|
||||
|
||||
assert(pEvent);
|
||||
assert(pUser);
|
||||
|
||||
fPos = (float *) pEvent;
|
||||
pCon = (SConnection *) pUser;
|
||||
|
||||
if (pCon == NULL || !SCisConnected(pCon)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
sprintf(pBueffel, "Performance = %f", *fPos);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
PerfMon understands this syntax:
|
||||
PerfMon : prints current CPS value
|
||||
@ -175,84 +170,78 @@
|
||||
PerfMon off : stops writing performance to ServLog
|
||||
PerfMon interest : makes perfmon writes any change of its
|
||||
value to the connection regsitering this.
|
||||
-----------------------------------------------------------------------------*/
|
||||
int PerfMonWrapper(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
pPerfMon self = NULL;
|
||||
char pBueffel[132];
|
||||
long lID;
|
||||
|
||||
self = (pPerfMon)pData;
|
||||
assert(self);
|
||||
assert(pCon);
|
||||
|
||||
argtolower(argc,argv);
|
||||
if(argc < 2) /* print value */
|
||||
{
|
||||
sprintf(pBueffel,"Performance = %f",self->fCPS);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(strcmp(argv[1],"on") == 0)
|
||||
{
|
||||
self->iLog = 1;
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(strcmp(argv[1],"off") == 0)
|
||||
{
|
||||
self->iLog = 0;
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(strcmp(argv[1],"interest") == 0)
|
||||
{
|
||||
lID = RegisterCallback(self->pCall,
|
||||
VALUECHANGE, InterestCallback,
|
||||
SCCopyConnection(pCon), SCDeleteConnection);
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
printf(pBueffel,"ERROR: unknown command %s",argv[1]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int PerfMonTask(void *pData)
|
||||
{
|
||||
pPerfMon self = NULL;
|
||||
|
||||
self = (pPerfMon)pData;
|
||||
assert(self);
|
||||
|
||||
if(self->iEnd)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
IncrementPerfMon(self);
|
||||
-----------------------------------------------------------------------------*/
|
||||
int PerfMonWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
pPerfMon self = NULL;
|
||||
char pBueffel[132];
|
||||
long lID;
|
||||
|
||||
self = (pPerfMon) pData;
|
||||
assert(self);
|
||||
assert(pCon);
|
||||
|
||||
argtolower(argc, argv);
|
||||
if (argc < 2) { /* print value */
|
||||
sprintf(pBueffel, "Performance = %f", self->fCPS);
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
return 1;
|
||||
}
|
||||
/*------------------------------------------------------------------------*/
|
||||
void PerfMonSignal(void *pUser, int iSignal, void *pEventData)
|
||||
{
|
||||
pPerfMon self = NULL;
|
||||
int *iInt;
|
||||
|
||||
self = (pPerfMon)pUser;
|
||||
assert(self);
|
||||
iInt = (int *)pEventData;
|
||||
|
||||
if(iSignal == SICSINT)
|
||||
{
|
||||
iInt = (int *)pEventData;
|
||||
if(*iInt == eEndServer)
|
||||
{
|
||||
self->iEnd = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "on") == 0) {
|
||||
self->iLog = 1;
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if (strcmp(argv[1], "off") == 0) {
|
||||
self->iLog = 0;
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "interest") == 0) {
|
||||
lID = RegisterCallback(self->pCall,
|
||||
VALUECHANGE, InterestCallback,
|
||||
SCCopyConnection(pCon), SCDeleteConnection);
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
printf(pBueffel, "ERROR: unknown command %s", argv[1]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int PerfMonTask(void *pData)
|
||||
{
|
||||
pPerfMon self = NULL;
|
||||
|
||||
self = (pPerfMon) pData;
|
||||
assert(self);
|
||||
|
||||
if (self->iEnd) {
|
||||
return 0;
|
||||
}
|
||||
IncrementPerfMon(self);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
void PerfMonSignal(void *pUser, int iSignal, void *pEventData)
|
||||
{
|
||||
pPerfMon self = NULL;
|
||||
int *iInt;
|
||||
|
||||
self = (pPerfMon) pUser;
|
||||
assert(self);
|
||||
iInt = (int *) pEventData;
|
||||
|
||||
if (iSignal == SICSINT) {
|
||||
iInt = (int *) pEventData;
|
||||
if (*iInt == eEndServer) {
|
||||
self->iEnd = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user