33#endif
44
55#include < stdio.h>
6+ #include < stdarg.h>
67#include < InfoLogger/InfoLogger.hxx>
78using namespace AliceO2 ::InfoLogger;
89
@@ -15,23 +16,71 @@ int main(int argc, char **argv) {
1516 setenv (" O2_INFOLOGGER_MODE" , " stdout" , 1 );
1617 InfoLogger theLog;
1718
18- const char *cfgLogbookUrl=" localhost:4001" ;
19-
20- if (argc>1 ) {
21- cfgLogbookUrl=argv[1 ];
19+ // get options from command line
20+ std::string cfgLogbookUrl=" localhost:4001" ; // bookkeeping API server end-point
21+ int syncTime = 0 ; // startup synchronization
22+ std::string occRole = " flp-test" ;
23+ unsigned int occRunNumber = 1 ;
24+ int sleepTime = 1000 ; // sleep time between iterations (milliseconds)
25+ int nPerRun = 10 ; // iterations per run
26+ int nPerHost = 0 ; // iterations per host
27+
28+ for (int i = 1 ; i < argc; i++) {
29+ char *k = argv[i];
30+ char *v = strchr (k, ' =' );
31+ if (v != nullptr ) {
32+ *v = 0 ;
33+ v++;
34+ }
35+ if (strcmp (k, " cfgLogbookUrl" ) == 0 ) {
36+ cfgLogbookUrl = v;
37+ } else if (strcmp (k, " syncTime" ) == 0 ) {
38+ syncTime = atoi (v);
39+ } else if (strcmp (k, " occRole" ) == 0 ) {
40+ occRole = v;
41+ } else if (strcmp (k, " occRunNumber" ) == 0 ) {
42+ occRunNumber = atoi (v);
43+ } else if (strcmp (k, " sleepTime" ) == 0 ) {
44+ sleepTime = atoi (v);
45+ } else if (strcmp (k, " nPerRun" ) == 0 ) {
46+ nPerRun = atoi (v);
47+ } else if (strcmp (k, " nPerHost" ) == 0 ) {
48+ nPerHost = atoi (v);
49+ } else {
50+ printf (" unknown option %s\n " , k);
51+ return -1 ;
52+ }
53+ }
54+ // wait until scheduled startup time (given modulo round number of seconds)
55+ if (syncTime>0 ) {
56+ time_t t = time (NULL );
57+ time_t waitT = syncTime - (t % syncTime);
58+ theLog.log (" Waiting sync time (%ds)" , (int )waitT);
59+ t = t + waitT;
60+ while (time (NULL ) != t) {
61+ usleep (10000 );
62+ }
2263 }
2364
2465 try {
25- theLog.log (" Create handle" );
66+ theLog.log (" Create handle to %s " , cfgLogbookUrl. c_str () );
2667 auto logbookHandle = o2::bkp::api::BkpClientFactory::create (cfgLogbookUrl);
27-
28- std::string occRole = " flp-test" ;
29- unsigned int occRunNumber = 1 ;
30-
31- theLog.log (" Updating" );
32- for (int i=0 ; i<10 ; i++) {
33- logbookHandle->flp ()->updateReadoutCountersByFlpNameAndRunNumber (occRole, occRunNumber, i,i,i,i);
34- sleep (1 );
68+
69+ theLog.log (" Updating %s:%d (%d loops for %d hosts, %d ms sleep between each)" , occRole.c_str (), (int )occRunNumber, nPerRun, nPerHost, sleepTime);
70+ for (int i=0 ; i<nPerRun; i++) {
71+ for (int k=1 ; k <= (nPerHost ? nPerHost : 1 ); k++) {
72+ char host[256 ];
73+ if (nPerHost>0 ) {
74+ snprintf (host,256 ," %s-%03d" , occRole.c_str (), k+1 );
75+ } else {
76+ snprintf (host,256 ," %s" , occRole.c_str ());
77+ }
78+ printf (" %s : %d\n " , host, i);
79+ logbookHandle->flp ()->updateReadoutCountersByFlpNameAndRunNumber (host, occRunNumber, i,i,i,i);
80+ if (sleepTime>0 ) {
81+ usleep (sleepTime * 1000 );
82+ }
83+ }
3584 }
3685 theLog.log (" Done updating" );
3786 }
0 commit comments