-
Notifications
You must be signed in to change notification settings - Fork 0
/
snoopServer.cc
870 lines (777 loc) · 21.4 KB
/
snoopServer.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* This file is distributed subject to a Software License Agreement found
* in the file LICENSE that is included with this distribution.
\*************************************************************************/
// CaSnooper: Server that logs broadcasts
#include <math.h>
#include <cadef.h>
#include "snoopServer.h"
#include "ut.h"
#include "gddApps.h"
#define DEBUG_SORT 0
#define DEBUG_HASH 0
#define DEBUG_TIMER 0
#define DEBUG_PROCESS_STAT 0
#define DEBUG_STAT 0
#define DEBUG_PUT 0
#define ULONG_DIFF(n1,n2) (((n1) >= (n2))?((n1)-(n2)):((n1)+(ULONG_MAX-(n2))))
#define HOST_NAMESIZE 256
#if EPICS_REVISION > 13
#include <osiSock.h>
#else
#include <bsdSocketResource.h>
// server.h is private and not in base/include. We are including it
// so we can access casCtx, which is not normally possible (by
// intent). Note: The src files have to be available to do this.
#include "server.h"
inline casCoreClient * casCtx::getClient() const
{
return this->pClient;
}
#endif
// Static initializations
unsigned long dataNode::nodeCount=0;
snoopData *dataNode::dataArray=(snoopData *)0;
char connTable[][10]={
"NC", /* cs_never_conn */
"NC", /* cs_prev_conn */
"C", /* cs_conn */
"NC", /* cs_closed */
};
////////////////////////////////////////////////////////////////////////
// snoopServer
////////////////////////////////////////////////////////////////////////
// snoopServer::snoopServer() //////////////////////////////////////////
snoopServer::snoopServer(char *prefixIn, char *individualNameIn,
int nCheckIn, int nPrintIn, int nSigmaIn, double nLimitIn) :
processTime(0.0),
reportFlag(0),
resetFlag(0),
quitFlag(0),
enabled(0),
nCheck(nCheckIn),
nPrint(nPrintIn),
nSigma(nSigmaIn),
nLimit(nLimitIn),
dataArray((snoopData *)0),
doStats(0),
statPrefix(0),
statPrefixLength(0),
individualName(individualNameIn),
individualCount(0)
{
// Initialize the PV list
#if EPICS_REVISION > 13
// No longer required
#else
pvList.init(2048u);
#endif
// Set the individual name
if(individualNameIn && *individualNameIn) individualName=individualNameIn;
else individualName=INDIVIDUAL_NAME;
// Initialize the stats
initStats(prefixIn);
requestCount=0u;
// Set the select mask to everything supported
#if EPICS_REVISION > 13
selectMask=(alarmEventMask()|valueEventMask()|logEventMask());
#else
selectMask=(alarmEventMask|valueEventMask|logEventMask);
#endif
}
// snoopServer::~snoopServer ///////////////////////////////////////////
snoopServer::~snoopServer(void)
{
// Clear the pvList
#if EPICS_REVISION > 13
pvList.traverse(&dataNode::destroy);
#else
pvList.destroyAllEntries();
#endif
}
// snoopServer::clearStat //////////////////////////////////////////////
void snoopServer::clearStat(int type)
{
statTable[type].pv=NULL;
}
// snoopServer::pvExistTest ////////////////////////////////////////////
// This function is called by Base 3.13 and earlier
pvExistReturn snoopServer::pvExistTest(const casCtx& ctx, const char *pvName)
{
#if EPICS_REVISION > 13
// Should not get here
return pverDoesNotExistHere;
#else
casClient *pClient=(casClient *)ctx.getClient();
// Return if data taking is not enabled
if(!enabled) return pverDoesNotExistHere;
// Get the caNetAddr
const caNetAddr &addr=pClient->fetchRespAddr();
return pvExistTest(ctx,addr,pvName);
#endif
}
// This function is called by Base 3.14 and later
pvExistReturn snoopServer::pvExistTest(const casCtx& ctx, const caNetAddr& addr,
const char* pvName)
{
char hostName[HOST_NAMESIZE]="";
char name[NAMESIZE+HOST_NAMESIZE]="";
dataNode *node=(dataNode *)0;
int i=0,len;
// Return if data taking is not enabled
if(!enabled) return pverDoesNotExistHere;
requestCount++;
// Make the hash name
struct sockaddr_in inaddr=(struct sockaddr_in)addr;
ipAddrToA(&inaddr,hostName,HOST_NAMESIZE);
if(strlen(pvName) > NAMESIZE-1) printf("Extra long pv name; truncating %s\n", pvName);
strncpy(name,pvName,NAMESIZE-1);
len=strlen(name);
name[len++]=DELIMITER;
strncpy(name+len,hostName,NAMESIZE-len);
name[NAMESIZE-1]='\0';
stringId id(name,stringId::refString);
// See if we have it
node=pvList.lookup(id);
if(node) {
node->getData()->incrCount();
} else {
snoopData *sData = new snoopData(name);
if(sData) {
node = new dataNode(name,*sData,pvList);
if(node) {
node->getData()->incrCount();
pvList.add(*node);
} else {
delete sData;
errMsg("Unable to create node for %s\n",name);
}
}
}
// Check for the individual name
if(individualName && !strcmp(pvName,individualName)) {
individualCount++;
}
// Check for stat PVs
if(doStats) {
for(i=0; i < statCount; i++) {
if(strcmp(pvName,statTable[i].pvName) == 0) {
return pverExistsHere;
}
}
}
return pverDoesNotExistHere;
}
// snoopServer::createPV ///////////////////////////////////////////////
pvCreateReturn snoopServer::createPV(const casCtx &NU(ctx), const char *pvName)
{
// Create stat PVs
if(doStats) {
for(int i=0; i < statCount; i++) {
if(strcmp(pvName,statTable[i].pvName)==0) {
if(statTable[i].pv==NULL) {
statTable[i].pv=new snoopStat(this,pvName,i);
}
#if DEBUG_PUT
print("createPV: %d %x %s\n",i,statTable[i],pvName);
#endif
return pvCreateReturn(*statTable[i].pv);
}
}
}
return S_casApp_pvNotFound;
}
// snoopServer::makeArray //////////////////////////////////////////////
// Make an array of the hash table.
int snoopServer::makeArray(unsigned long *nVals)
{
// Return if already allocated
if(dataArray) return SS_ERROR;
// Find out how many nodes
dataNode::setNodeCount(0u);
pvList.traverse(&dataNode::addToNodeCount);
*nVals=dataNode::getNodeCount();
#if DEBUG_HASH
print("nVals=%lu\n",*nVals);
#endif
dataArray=new snoopData[*nVals];
if(!dataArray) {
*nVals=0;
return SS_ERROR;
}
// Fill the dataArray
dataNode::setNodeCount(0u);
dataNode::setDataArray(dataArray);
pvList.traverse(&dataNode::addToDataArray);
*nVals=dataNode::getNodeCount();
#if DEBUG_HASH
print("nVals=%lu\n",*nVals);
for(i=0; i < *nVals; i++) {
print("%3d %s\n",i,dataArray[i].getName());
}
#endif
return SS_OK;
}
// snoopServer::report /////////////////////////////////////////////////
void snoopServer::report(void)
{
chid *pChid=(chid *)0;
unsigned long nNodes=0,nNodes1,nRequestsTotal,nRequests;
unsigned long *index=0,ii;
double x;
double max=0.0;
double sum=0.0;
double sumsq=0.0;
double sigma, nSigmaVal, avg;
unsigned long il,jl;
int i;
int status;
char name[NAMESIZE];
char *ptr;
// Reset the report flag
if(doStats) {
reportFlag=0;
setStat(statReport,(unsigned long)resetFlag);
}
// Check time
if(processTime <= 0.0) {
print("snoopServer::report: The time interval is zero\n");
return;
}
// Make an array out of the hash table
status=makeArray(&nNodes);
if(status != SS_OK) {
errMsg("snoopServer::report: Cannot make data array");
return;
}
if(status != SS_OK) {
print("\nThere is no data to report\n");
return;
}
// Loop over the nodes to get data for statistics
nRequests=nRequestsTotal=0;
for(il=0; il < nNodes; il++) {
nRequests=dataArray[il].getCount();
nRequestsTotal+=nRequests;
x=(double)nRequests;
sum+=x;
sumsq+=(x*x);
if(x > max) max=x;
}
// Calculate statistics
if(nNodes == 0) {
avg=0;
sigma=0;
} else if (nNodes == 1) {
avg=sum;
sigma=0;
} else {
avg=sum/(double)nNodes;
sigma=sqrt((sumsq-avg*avg)/(nNodes-1));
}
print("\n%s:\nThere were %ld requests to check for PV existence "
"for %ld different PVs.\n",
timeStamp(),nRequestsTotal,nNodes);
print(" Max(Hz): %.2f\n",max/processTime);
print(" Mean(Hz): %.2f\n",avg/processTime);
print(" StDev(Hz): %.2f\n",sigma/processTime);
// Print the n sigma values
if(nSigma >= 0) {
nSigmaVal=nSigma*sigma;
print("\nThe following were above the %d-sigma value (%.2f):\n",
nSigma,nSigmaVal);
max=sum=sumsq=0.0;
nRequestsTotal=nNodes1=0;
for(il=jl=0; il < nNodes; il++) {
nRequests=dataArray[il].getCount();
if((double)nRequests > nSigmaVal) {
strcpy(name,dataArray[il].getName());
ptr=strchr(name,DELIMITER);
if(ptr) *ptr='\0';
else ptr=name;
print("%4ld %-30s %-33s %.2f\n",++jl,ptr+1,name,
dataArray[il].getCount()/processTime);
} else {
nNodes1++;
nRequestsTotal+=nRequests;
x=(double)nRequests;
sum+=x;
sumsq+=(x*x);
if(x > max) max=x;
}
}
// Calculate statistics without outliers
if(nNodes1 == 0) {
avg=0;
sigma=0;
} else if (nNodes1 == 1) {
avg=sum;
sigma=0;
} else {
avg=sum/(double)nNodes1;
sigma=sqrt((sumsq-avg*avg)/(nNodes1-1));
}
print("\nThere were %ld requests for %ld PVs excluding these.\n",
nRequestsTotal,nNodes1);
print(" Max(Hz): %.2f\n",max/processTime);
print(" Mean(Hz): %.2f\n",avg/processTime);
print(" StDev(Hz): %.2f\n",sigma/processTime);
}
// Print the top PVs
int nPrint0;
if(nPrint == 0) nPrint0 = nNodes;
else nPrint0=nPrint;
if(nPrint0 > (int)nNodes) nPrint0 = (int)nNodes;
if(nPrint0 > 0) {
if(!index) {
status=sortArray(&index,nNodes);
if(status != SS_OK || !index) {
if(index) {
delete [] index;
index=0;
}
errMsg("snoopServer::report: Cannot sort data");
goto CLEANUP;
}
}
print("\nPVs with top %d requests:\n",nPrint0);
for(i=0; i < nPrint0; i++) {
ii=index[i];
strcpy(name,dataArray[ii].getName());
ptr=strchr(name,DELIMITER);
if(ptr) *ptr='\0';
else ptr=name;
print("%4ld %-30s %-33s %.2f\n",i+1,ptr+1,name,
dataArray[ii].getCount()/processTime);
}
}
// Print the PVs over the limit
if(nLimit >= 0.0) {
if(!index) {
status=sortArray(&index,nNodes);
if(status != SS_OK || !index) {
if(index) {
delete [] index;
index=0;
}
errMsg("snoopServer::report: Cannot sort data");
goto CLEANUP;
}
}
print("\nPVs over %.2f Hz\n",nLimit);
for(il=0; il < nNodes; il++) {
ii=index[il];
if(dataArray[ii].getCount()/processTime < nLimit) break;
strcpy(name,dataArray[ii].getName());
ptr=strchr(name,DELIMITER);
if(ptr) *ptr='\0';
else ptr=name;
print("%4ld %-30s %-33s %.2f\n",il+1,ptr+1,name,
dataArray[ii].getCount()/processTime);
}
}
// Check PV existence
int nCheck0;
if(nCheck == 0) nCheck0 = nNodes;
else nCheck0=nCheck;
if(nCheck0 > (int)nNodes) nCheck0 = (int)nNodes;
if(nCheck0 > 0) {
if(!index) {
status=sortArray(&index,nNodes);
if(status != SS_OK || !index) {
if(index) {
delete [] index;
index=0;
}
errMsg("snoopServer::report: Cannot sort data");
goto CLEANUP;
}
}
print("\nConnection status for top %d PVs after %.2f sec:\n",
nCheck0,CA_PEND_IO_TIME);
// Allocate chids
pChid = new chid[nCheck0];
if(!pChid) {
errMsg("snoopServer::report: Cannot allocate space for CA");
goto CLEANUP;
}
// Initialize CA
status=ca_task_initialize();
if(status != ECA_NORMAL) {
errMsg("snoopServer::report: "
"ca_task_initialize failed:\n%s",ca_message(status));
goto CLEANUP;
}
// Search
for(i=0; i < nCheck0; i++) {
ii=index[i];
strcpy(name,dataArray[ii].getName());
ptr=strchr(name,DELIMITER);
if(ptr) *ptr='\0';
else ptr=name;
status=ca_search(name,&pChid[i]);
if(status != ECA_NORMAL) {
errMsg("snoopServer::report: [%d %s] "
" ca_search failed:\n%s",ii,dataArray[ii].getName(),
ca_message(status));
}
}
// Wait
ca_pend_io(CA_PEND_IO_TIME);
// Print results
for(i=0; i < nCheck0; i++) {
ii=index[i];
strcpy(name,dataArray[ii].getName());
ptr=strchr(name,DELIMITER);
if(ptr) *ptr='\0';
else ptr=name;
print("%4ld %-30s %-33s %-2s %.2f\n",i+1,ptr+1,name,
connTable[ca_state(pChid[i])],
dataArray[ii].getCount()/processTime);
}
// Close CA
status=ca_task_exit();
if(status != ECA_NORMAL) {
errMsg("snoopServer::report: "
"ca_task_exit failed:\n%s",ca_message(status));
}
}
CLEANUP:
if(dataArray) {
delete [] dataArray;
dataArray=(snoopData *)0;
dataNode::setDataArray((snoopData *)0);
}
if(index) {
delete [] index;
}
if(pChid) {
delete [] pChid;
}
}
// snoopServer::reset //////////////////////////////////////////////////
void snoopServer::reset(void)
{
// Clear the pvList
#if EPICS_REVISION > 13
pvList.traverse(&dataNode::destroy);
#else
pvList.destroyAllEntries();
#endif
print("\n%s Reset\n",timeStamp());
// Reset the reset flag
resetFlag=0;
setStat(statReport,(unsigned long)resetFlag);
// Do not zero requestCount, IndividualCpount, etc. since it will
// screw up the rates
}
// snoopServer::initStat ///////////////////////////////////////////////
void snoopServer::initStats(char *prefix)
{
int i;
// Define the prefix for the server stats
if(!prefix) {
for(i=0; i < statCount; i++) {
statTable[i].pv=NULL;
}
doStats=0;
return;
}
if(*prefix) {
// Use the specified one
statPrefix=prefix;
} else {
statPrefix=DEFAULT_PREFIX;
}
statPrefixLength=strlen(statPrefix);
doStats=1;
// Set up PV names for server stats and fill them into the statTable
for(i=0; i < statCount; i++) {
switch(i) {
case statRequestRate:
requestCount=0u;
statTable[i].name="requestRate";
statTable[i].initValue=0.0;
statTable[i].units="Hz";
statTable[i].precision=2;
break;
case statIndividualRate:
individualCount=0u;
statTable[i].name="individualRate";
statTable[i].initValue=0.0;
statTable[i].units="Hz";
statTable[i].precision=2;
break;
case statReport:
reportFlag=0;
statTable[i].name="report";
statTable[i].initValue=0.0;
statTable[i].units="";
statTable[i].precision=0;
break;
case statReset:
resetFlag=0;
statTable[i].name="reset";
statTable[i].initValue=(double)resetFlag;
statTable[i].units="";
statTable[i].precision=0;
break;
case statQuit:
quitFlag=0;
statTable[i].name="quit";
statTable[i].initValue=(double)quitFlag;
statTable[i].units="";
statTable[i].precision=0;
break;
case statCheck:
statTable[i].name="nCheck";
statTable[i].initValue=(double)nCheck;
statTable[i].units="";
statTable[i].precision=0;
break;
case statPrint:
statTable[i].name="nPrint";
statTable[i].initValue=(double)nPrint;
statTable[i].units="";
statTable[i].precision=0;
break;
case statSigma:
statTable[i].name="nSigma";
statTable[i].initValue=(double)nSigma;
statTable[i].units="";
statTable[i].precision=0;
break;
case statLimit:
statTable[i].name="nLimit";
statTable[i].initValue=nLimit;
statTable[i].units="";
statTable[i].precision=2;
break;
}
statTable[i].pvName=new char[statPrefixLength+1+strlen(statTable[i].name)+1];
sprintf(statTable[i].pvName,"%s.%s",statPrefix,statTable[i].name);
statTable[i].pv=NULL;
}
}
// snoopServer::processStat ////////////////////////////////////////////
void snoopServer::processStat(int type, double val)
{
switch(type) {
case statReport:
if(val > 0.0) reportFlag=1;
break;
case statReset:
if(val > 0.0) resetFlag=1;
break;
case statQuit:
if(val > 0.0) quitFlag=1;
break;
case statCheck:
nCheck=(int)floor(val+.5);
break;
case statPrint:
nPrint=(int)floor(val+.5);
break;
case statSigma:
nSigma=(int)floor(val+.5);
break;
case statLimit:
nLimit=val;
break;
}
#if DEBUG_PROCESS_STAT
print("snoopServer::processStat:\n"
"val=%.2f nCheck=%d nPrint=%d nSigma=%d nLimit=%.2f\n",
val,nCheck,nPrint,nSigma,nLimit);
#endif
}
// snoopServer::setStat ////////////////////////////////////////////////
void snoopServer::setStat(int type, double val)
{
if(doStats && statTable[type].pv) statTable[type].pv->postData(val);
#if DEBUG_STAT
print("snoopServer::setStat: type=%d val=%.2f\n",
type,val);
#endif
}
void snoopServer::setStat(int type, unsigned long val)
{
if(doStats && statTable[type].pv) statTable[type].pv->postData(val);
}
// snoopServer::show ///////////////////////////////////////////////////
void snoopServer::show(unsigned level) const
{
//
// server tool specific show code goes here
//
//
// print information about ca server libarary
// internals
//
// print("caServer:\n");
this->caServer::show(level);
}
// snoopServer::sortArray //////////////////////////////////////////////
int snoopServer::sortArray(unsigned long **index, unsigned long nVals)
{
int rc=SS_OK;
unsigned long i;
// Check if the index has already been made
if(*index) return SS_OK;
if(nVals <= 0) return SS_ERROR;
if(!dataArray) return SS_ERROR;
// Allocate space
*index = new unsigned long[nVals];
double *vals = new double[nVals];
if(!*index) {
errMsg("snoopServer::sortArray: Cannot allocate space for index");
rc=SS_ERROR;
goto HANDLE_ERROR;
}
if(!vals) {
errMsg("snoopServer::sortArray: Cannot allocate space for values");
rc=SS_ERROR;
goto HANDLE_ERROR;
}
// Fill the vals array
for(i=0; i < nVals; i++) {
vals[i]=dataArray[i].getCount();
}
// Sort
hsort(vals,*index,nVals);
#if DEBUG_SORT
print("\nDebug sort\n");
for(i=0; i < nVals; i++) {
print("%3lu %.2f -> %3lu %.2f\n",
i,vals[i],(*index)[i],vals[(*index)[i]]);
}
#endif
goto CLEAN;
HANDLE_ERROR:
if(*index) {
delete *index;
*index=0;
}
CLEAN:
if(vals) delete [] vals;
return rc;
}
////////////////////////////////////////////////////////////////////////
// snoopData
////////////////////////////////////////////////////////////////////////
// snoopData::snoopData ////////////////////////////////////////////////
snoopData::snoopData() :
count(0)
{
*name='\0';
}
snoopData::snoopData(const char *nameIn) :
count(0)
{
strcpy(name,nameIn);
}
// Copy constructor
snoopData::snoopData(const snoopData &snoopDataIn)
{
count=snoopDataIn.getCount();
strcpy(name,snoopDataIn.getName());
}
snoopData &snoopData::operator=(const snoopData &snoopDataIn)
{
if(this != &snoopDataIn) {
count=snoopDataIn.getCount();
strcpy(name,snoopDataIn.getName());
}
return *this;
}
////////////////////////////////////////////////////////////////////////
// snoopRateStatsTimer
////////////////////////////////////////////////////////////////////////
// snoopRateStatsTimer::expire /////////////////////////////////////////
#if EPICS_REVISION > 13
epicsTimerNotify::expireStatus
snoopRateStatsTimer::expire(const epicsTime &curTime)
{
static int first=1;
static epicsTime prevTime;
double delTime;
static unsigned long rrPrevCount;
static unsigned long srPrevCount;
unsigned long rrCurCount=serv->getRequestCount();
unsigned long srCurCount=serv->getIndividualCount();
double rrRate;
double srRate;
// Initialize the first time
if(first) {
prevTime=curTime;
rrPrevCount=rrCurCount;
srPrevCount=srCurCount;
first=0;
}
delTime=(double)(curTime-prevTime);
// Calculate the request rate
rrRate=(delTime > 0)?(double)(ULONG_DIFF(rrCurCount,rrPrevCount))/
delTime:0.0;
serv->setStat(statRequestRate,rrRate);
srRate=(delTime > 0)?(double)(ULONG_DIFF(srCurCount,srPrevCount))/
delTime:0.0;
serv->setStat(statIndividualRate,srRate);
#if DEBUG_TIMER
print("snoopRateStatsTimer::expire():\n");
print(" rrCurCount=%ld rrPrevCount=%ld rrRate=%g\n",
rrCurCount,rrPrevCount,rrRate);
print(" srCurCount=%ld srPrevCount=%ld srRate=%g\n",
srCurCount,srPrevCount,srRate);
#endif
// Reset the values for previous
prevTime=curTime;
rrPrevCount=rrCurCount;
srPrevCount=srCurCount;
// Set to continue
return epicsTimerNotify::expireStatus(restart,interval);
}
#else
void snoopRateStatsTimer::expire()
{
static int first=1;
static osiTime prevTime;
osiTime curTime=osiTime::getCurrent();
double delTime;
static unsigned long rrPrevCount;
static unsigned long srPrevCount;
unsigned long rrCurCount=serv->getRequestCount();
unsigned long srCurCount=serv->getIndividualCount();
double rrRate;
double srRate;
// Initialize the first time
if(first) {
prevTime=curTime;
rrPrevCount=rrCurCount;
srPrevCount=srCurCount;
first=0;
}
delTime=(double)(curTime-prevTime);
// Calculate the request rate
rrRate=(delTime > 0)?(double)(ULONG_DIFF(rrCurCount,rrPrevCount))/
delTime:0.0;
serv->setStat(statRequestRate,rrRate);
srRate=(delTime > 0)?(double)(ULONG_DIFF(srCurCount,srPrevCount))/
delTime:0.0;
serv->setStat(statIndividualRate,srRate);
#if DEBUG_TIMER
print("snoopRateStatsTimer::expire():\n");
print(" rrCurCount=%ld rrPrevCount=%ld rrRate=%g\n",
rrCurCount,rrPrevCount,rrRate);
print(" srCurCount=%ld srPrevCount=%ld srRate=%g\n",
srCurCount,srPrevCount,srRate);
#endif
// Reset the values for previous
prevTime=curTime;
rrPrevCount=rrCurCount;
srPrevCount=srCurCount;
}
#endif