added the code for ioc statistic processing on IOC and workstation

This commit is contained in:
Jim Kowalkowski
1996-10-21 16:01:28 +00:00
parent e22ae5f857
commit 0f4b4deb80
5 changed files with 324 additions and 4 deletions

View File

@@ -10,14 +10,14 @@ INC += dbVarSub.h
SRCS.c = ../dbVarSub.c dbLoadTemplate_lex.c dbLoadTemplate.c \
dbLoadRecords_lex.c dbLoadRecords.c \
../BSlib.c ../PVSserver.c ../rdbapplist.c ../rdbls.c
../BSlib.c ../PVSserver.c ../rdbapplist.c ../rdbls.c ../ioc_stats.c
VAR_OBJS = dbVarSub.o dbLoadTemplate.o dbLoadRecords.o
LIBOBJS = BSlib.o
LIBNAME = BSlib.a
PROD = subtool dbLoadTemplate rdbls rdbapplist PVSserver
PROD = subtool dbLoadTemplate rdbls rdbapplist PVSserver ioc_stats
MAN1 = dbLoadTemplate.1 subtool.1
MAN3 = dbLoadRecords.3 dbLoadTemplate.3
@@ -34,6 +34,9 @@ PVSserver: PVSserver.o BSlib.o
rdbls: rdbls.o BSlib.o
$(LINK.c) -o $@ $^ $(LDLIBS)
ioc_stats: ioc_stats.o BSlib.o
$(LINK.c) -o $@ $^ $(LDLIBS)
rdbapplist: rdbapplist.o BSlib.o
$(LINK.c) -o $@ $^ $(LDLIBS)

View File

@@ -5,9 +5,9 @@ YACCOPT = -l
LEXOPT = -L
SRCS.c = ../dbVarSub.c dbLoadTemplate_lex.c dbLoadTemplate.c \
dbLoadRecords_lex.c dbLoadRecords.c ../BSlib.c ../PVSvx.c
dbLoadRecords_lex.c dbLoadRecords.c ../BSlib.c ../PVSvx.c ../vx_stats.c ../client_stats.c
LIBOBJS = dbVarSub.o dbLoadTemplate.o dbLoadRecords.o BSlib.o PVSvx.o
LIBOBJS = dbVarSub.o dbLoadTemplate.o dbLoadRecords.o BSlib.o PVSvx.o vx_stats.o client_stats.o
LIBNAME = dbSubs
@@ -17,6 +17,8 @@ MAN5 = templatefile.5 dbfile.5
include $(TOP)/config/RULES.Vx
USR_CFLAGS = -I../../rsrv -I../../ca
#dbLoadTemplate.o: dbLoadTemplate_lex.c dbLoadTemplate.c
#dbLoadRecords.o: dbLoadRecords_lex.c dbLoadRecords.c
dbLoadTemplate.o: dbLoadTemplate_lex.c

View File

@@ -0,0 +1,66 @@
/*
You must run PVSstart() in your vxWorks startup script before these
functions can be used.
Just ld() the object file for this code in your vxWorks startup script.
Services added in this file:
PVS_MemStats - Send the bytes free and allocated to the requestor.
PVS_ClientStats - Send a CA client statistics summary report to
the requestor. Includes host name, user id, number of channels
in use.
PVS_TaskList - Send a report of all the tasks in the IOC, along
with there state and priority.
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <vxWorks.h>
#include <iv.h>
#include <taskLib.h>
#include <memLib.h>
#include <private/memPartLibP.h> /* sucks, don't it */
/* required for client stat section */
#include <sockLib.h>
#include <socket.h>
#include <in.h>
#include <ellLib.h>
#include <server.h>
#include "PVS.h"
void PVS_ClientStats(BS* bs)
{
int len;
char line[120];
char* ptr;
struct client *pclient;
/* report columns:
client_host_name client_login_id number_of_channels
*/
LOCK_CLIENTQ;
pclient = (struct client *) ellFirst(&clientQ);
while (pclient)
{
sprintf(line,"%s %s %d\n",
pclient->pHostName, pclient->pUserName, ellCount(&pclient->addrq));
len=strlen(line)+1;
if(BSsendHeader(bs,PVS_Data,len)<0)
printf("PVSserver: data cmd failed\n");
else
{
if(BSsendData(bs,line,len)<0)
printf("PVSserver: data send failed\n");
}
pclient = (struct client *) ellNext(&pclient->node);
}
UNLOCK_CLIENTQ;
BSsendHeader(bs,BS_Done,0);
}

99
src/dbtools/ioc_stats.c Normal file
View File

@@ -0,0 +1,99 @@
#include "PVS.h"
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
static int read_data(BSDATA* info,char* service_name);
int main(int argc,char** argv)
{
BSDATA info;
int rc;
if(argc<3)
{
fprintf(stderr,"usage: %s IOC-name service-name\n",argv[0]);
return -1;
}
BSsetAddress(&info,argv[1]);
rc=read_data(&info,argv[2]);
if(rc<0) fprintf(stderr,"read of data failed horribly\n");
return 0;
}
static int read_data(BSDATA* info,char* sname)
{
BS* bs;
int verb,size,done,len,i,port,rsize;
char* buffer;
char ip_from[40];
FILE* fd;
BSgetAddressPort(info,ip_from,&port);
BSsetPort(info,PVS_TCP_PORT);
done=0;
rsize=strlen(sname)+1;
fd=stdout;
if((bs=BSipOpenData(info))==NULL)
{
fprintf(stderr,"Open of socket to IOC failed\n");
return -1;
}
if(BSsendHeader(bs,9999,rsize)<0)
{
fprintf(stderr,"Command send failed\n");
return -1;
}
if(rsize>0)
{
if(BSsendData(bs,sname,rsize)<0)
{
fprintf(stderr,"send of command name failed\n");
return -1;
}
}
buffer=(char*)malloc(PVS_TRANSFER_SIZE+2);
while(done==0)
{
if(BSreceiveHeader(bs,&verb,&size)<0)
{
fprintf(stderr,"Receive header failed\n");
done=-1;
}
else
{
switch(verb)
{
case PVS_Data: /* read a block of names */
if((len=BSreceiveData(bs,buffer,size))<0)
fprintf(stderr,"Receive data failed\n");
else
{
/* buffer[len]='\n'; */
buffer[len+1]='\0';
fputs(buffer,fd);
}
break;
case BS_Done: /* transfers complete */
BSclose(bs);
done=-1;
break;
default:
if(size>0) done=-1;
break;
}
}
}
free(buffer);
return 0;
}

150
src/dbtools/vx_stats.c Normal file
View File

@@ -0,0 +1,150 @@
/*
You must run PVSstart() in your vxWorks startup script before these
functions can be used.
Just ld() the object file for this code in your vxWorks startup script.
Services added in this file:
PVS_MemStats - Send the bytes free and allocated to the requestor.
PVS_ClientStats - Send a CA client statistics summary report to
the requestor. Includes host name, user id, number of channels
in use.
PVS_TaskList - Send a report of all the tasks in the IOC, along
with there state and priority.
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <vxWorks.h>
#include <iv.h>
#include <taskLib.h>
#include <memLib.h>
#include <private/memPartLibP.h> /* sucks, don't it */
/* required for client stat section */
#include <sockLib.h>
#include <socket.h>
#include <in.h>
#include <dbStaticLib.h>
#include "PVS.h"
#define MAX_TASK 100
extern struct dbBase *pdbbase;
static int* task_list=NULL;
void PVS_MemStats(BS* bs)
{
int len;
unsigned long b_free, b_alloc;
char line[100];
b_free=2*(memSysPartId->totalWords-memSysPartId->curWordsAllocated);
b_alloc=2*memSysPartId->curWordsAllocated;
/* report columns:
bytes_free bytes allocated
*/
sprintf(line,"%lu %lu\n",b_free,b_alloc);
len=strlen(line)+1;
if(BSsendHeader(bs,PVS_Data,len)<0)
printf("PVSserver: data cmd failed\n");
else
{
if(BSsendData(bs,line,len)<0)
printf("PVSserver: data send failed\n");
}
BSsendHeader(bs,BS_Done,0);
}
void PVS_TaskList(BS* bs)
{
int len,i,tot,pri;
char line[100];
char state[30];
char* name;
if(task_list==NULL)
task_list=(int*)malloc(sizeof(int)*MAX_TASK);
if((tot=taskIdListGet(task_list,MAX_TASK))==0)
{
BSsendHeader(bs,BS_Done,0);
return;
}
/* report columns:
name_of_task state_of_task priority of task
*/
for(i=0;i<tot;i++)
{
if((name=taskName(task_list[i]))==NULL) continue;
if((taskPriorityGet(task_list[i],&pri))==ERROR) continue;
if((taskStatusString(task_list[i],state))==ERROR) continue;
sprintf(line,"%s %s %d\n",name,state,pri);
len=strlen(line)+1;
if(BSsendHeader(bs,PVS_Data,len)<0)
printf("PVSserver: data cmd failed\n");
else
{
if(BSsendData(bs,line,len)<0)
printf("PVSserver: data send failed\n");
}
}
BSsendHeader(bs,BS_Done,0);
}
#if 0
void PVS_FieldList(BS* bs)
{
DBENTRY dbe;
char buffer[50]; /* max size of a PV */
char *name,*value;
int size,verb;
long rc,len;
if(BSreceiveHeader(bs,&verb,&size)<0)
{
printf("PVS_FieldList(): Receive header failed\n");
}
else
{
switch(verb)
{
case PVS_Data:
/* read the PV name */
if((len=BSreceiveData(bs,buffer,size))<0)
fprintf(stderr,"PVS_FieldList(): Receive data failed\n");
else
{
if(ptr=strchr(buffer,'.')) *ptr='\0';
dbInitEntry(pdbbase,&dbe);
dbFindRecord(&dbe,buffer);
for(rc=dbFirstFielddes(&dbe,FALSE); rc==0;
rc=dbNextFieldDes(&dbe,FALSE))
{
name=dbGetFieldName(&dbe);
value=dbGetString(&dbe);
printf("name=<%s>, value=<%s>\n",name,value);
}
}
break;
default:
fprintf(stderr,"PVS_FieldList(): Unknown packet received\n");
break;
default:
}
}
BSsendHeader(bs,BS_Done,0);
}
#endif