summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbustico2008-03-21 09:10:43 +0000
committerbustico2008-03-21 09:10:43 +0000
commitcfb4acdef5a9fe812a95d73b3144cb894717a360 (patch)
tree28daf815b5f6d752975c93f79168a36c761a6575 /src
parentfadfb64209670a7275c5b9be40e89bcd7db031f3 (diff)
downloadivy-c-cfb4acdef5a9fe812a95d73b3144cb894717a360.zip
ivy-c-cfb4acdef5a9fe812a95d73b3144cb894717a360.tar.gz
ivy-c-cfb4acdef5a9fe812a95d73b3144cb894717a360.tar.bz2
ivy-c-cfb4acdef5a9fe812a95d73b3144cb894717a360.tar.xz
files had been moved to directory tools
Diffstat (limited to 'src')
-rw-r--r--src/ivyperf.c116
-rw-r--r--src/ivyprobe.c442
-rw-r--r--src/ivythroughput.cpp511
3 files changed, 0 insertions, 1069 deletions
diff --git a/src/ivyperf.c b/src/ivyperf.c
deleted file mode 100644
index 07453e3..0000000
--- a/src/ivyperf.c
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Ivy perf mesure le temp de round trip
- *
- * Copyright (C) 1997-2004
- * Centre d'Études de la Navigation Aérienne
- *
- * Main and only file
- *
- * Authors: François-Régis Colin <fcolin@cena.fr>
- * Yannick Jestin <jestin@cena.fr>
- *
- * Please refer to file version.h for the
- * copyright notice regarding this software
- */
-
-#include "version.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#ifdef WIN32
-#include <windows.h>
-#ifdef __MINGW32__
-#include <regex.h>
-#include <getopt.h>
-#endif
-#else
-#include <sys/time.h>
-#include <unistd.h>
-#ifdef __INTERIX
-extern char *optarg;
-extern int optind;
-#endif
-#endif
-
-
-#include "ivysocket.h"
-#include "ivy.h"
-#include "timer.h"
-#include "ivyloop.h"
-#define MILLISEC 1000.0
-
-const char *mymessages[] = { "IvyPerf", "ping", "pong" };
-static double origin = 0;
-
-static double currentTime()
-{
- double current;
-#ifdef WIN32
- current = GetTickCount();
-#else
- struct timeval stamp;
- gettimeofday( &stamp, NULL );
- current = (double)stamp.tv_sec * MILLISEC + (double)(stamp.tv_usec/MILLISEC);
-#endif
- return current;
-}
-
-void Reply (IvyClientPtr app, void *user_data, int argc, char *argv[])
-{
- IvySendMsg ("pong ts=%s tr=%f", *argv, currentTime()- origin);
-}
-void Pong (IvyClientPtr app, void *user_data, int argc, char *argv[])
-{
- double current = currentTime() - origin ;
- double ts = atof( *argv++ );
- double tr = atof( *argv++ );
- double roundtrip1 = tr-ts;
- double roundtrip2 = current - tr;
- double roundtrip3 = current - ts;
- fprintf(stderr,"roundtrip %f %f %f \n", roundtrip1, roundtrip2, roundtrip3 );
-}
-
-void TimerCall(TimerId id, void *user_data, unsigned long delta)
-{
- int count = IvySendMsg ("ping ts=%f", currentTime() - origin );
- if ( count == 0 ) fprintf(stderr, "." );
-}
-
-void binCB( IvyClientPtr app, void *user_data, int id, char* regexp, IvyBindEvent event )
-{
- char *app_name = IvyGetApplicationName( app );
- switch ( event )
- {
- case IvyAddBind:
- printf("Application:%s bind '%s' ADDED\n", app_name, regexp );
- break;
- case IvyRemoveBind:
- printf("Application:%s bind '%s' REMOVED\n", app_name, regexp );
- break;
- case IvyFilterBind:
- printf("Application:%s bind '%s' FILTRED\n", app_name, regexp );
- break;
-
- }
-}
-int main(int argc, char *argv[])
-{
- long time=200;
-
- /* Mainloop management */
- if ( argc > 1 ) time = atol( argv[1] );
-
- IvyInit ("IvyPerf", "IvyPerf ready", NULL,NULL,NULL,NULL);
- IvySetFilter( sizeof( mymessages )/ sizeof( char *),mymessages );
- IvySetBindCallback( binCB, 0 ),
- IvyBindMsg (Reply, NULL, "^ping ts=(.*)");
- IvyBindMsg (Pong, NULL, "^pong ts=(.*) tr=(.*)");
- origin = currentTime();
- IvyStart (0);
-
- TimerRepeatAfter (TIMER_LOOP, time, TimerCall, (void*)1);
-
-
- IvyMainLoop ();
- return 0;
-}
diff --git a/src/ivyprobe.c b/src/ivyprobe.c
deleted file mode 100644
index b6d9607..0000000
--- a/src/ivyprobe.c
+++ /dev/null
@@ -1,442 +0,0 @@
-/*
- * Ivy probe
- *
- * Copyright (C) 1997-2004
- * Centre d'Études de la Navigation Aérienne
- *
- * Main and only file
- *
- * Authors: François-Régis Colin <fcolin@cena.fr>
- * Yannick Jestin <jestin@cena.fr>
- *
- * Please refer to file version.h for the
- * copyright notice regarding this software
- */
-#define DEFAULT_IVYPROBE_NAME "IVYPROBE"
-#define DEFAULT_READY " Ready"
-#include "version.h"
-
-#define IVYMAINLOOP
-
-#ifdef XTMAINLOOP
-#undef IVYMAINLOOP
-#endif
-#ifdef GLIBMAINLOOP
-#undef IVYMAINLOOP
-#endif
-
-#ifdef GLUTMAINLOOP
-#undef IVYMAINLOOP
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#ifdef WIN32
-#include <windows.h>
-#include "getopt.h"
-#ifdef __MINGW32__
-#include <regex.h>
-#include <getopt.h>
-#endif
-#else
-#include <sys/time.h>
-#include <unistd.h>
-#ifdef __INTERIX
-extern char *optarg;
-extern int optind;
-#endif
-
-#endif
-#ifdef XTMAINLOOP
-#include "ivyxtloop.h"
-#endif
-#ifdef GLIBMAINLOOP
-#include <glib.h>
-#include "ivyglibloop.h"
-#endif
-#ifdef GLUTMAINLOOP
-#include "ivyglutloop.h"
-#endif
-#ifdef IVYMAINLOOP
-#include "ivyloop.h"
-#endif
-#include "ivysocket.h"
-#include "ivychannel.h"
-#include "ivybind.h" /* to test regexp before passing to BinMsg */
-#include "ivy.h"
-#include "timer.h"
-#ifdef XTMAINLOOP
-#include <X11/Intrinsic.h>
-XtAppContext cntx;
-#endif
-
-int app_count = 0;
-int wait_count = 0;
-int fbindcallback = 0;
-int filter_count = 0;
-const char *filter[4096];
-char *classes;
-
-void DirectCallback(IvyClientPtr app, void *user_data, int id, char *msg )
-{
- printf("%s sent a direct message, id=%d, message=%s\n",
- IvyGetApplicationName(app),id,msg);
-}
-
-
-void Callback (IvyClientPtr app, void *user_data, int argc, char *argv[])
-{
- int i;
- printf ("%s sent ",IvyGetApplicationName(app));
- for (i = 0; i < argc; i++)
- printf(" '%s'",argv[i]);
- printf("\n");
-}
-
-char * Chop(char *arg)
-{
- size_t len;
- if (arg==NULL) return arg;
- len=strlen(arg)-1;
- if ((*(arg+len))=='\n') *(arg+len)=0;
- return arg;
-}
-
-void HandleStdin (Channel channel, HANDLE fd, void *data)
-{
- char buf[4096];
- char *line;
- char *cmd;
- char *arg;
- int id;
- IvyClientPtr app;
- int err;
- line = fgets(buf, 4096, stdin);
- if (!line) {
-
- IvyChannelRemove (channel);
- IvyStop();
- return;
- }
- if (*line == '.') {
- cmd = strtok (line, ".: \n");
-
- if (strcmp (cmd, "die") == 0) {
- arg = strtok (NULL, " \n");
- if (arg) {
- app = IvyGetApplication (arg);
- if (app)
- IvySendDieMsg (app);
- else printf ("No Application %s!!!\n",arg);
- }
-
- } else if (strcmp(cmd, "dieall-yes-i-am-sure") == 0) {
- arg = IvyGetApplicationList("#");
- arg = strtok (arg, "#");
- while (arg) {
- app = IvyGetApplication (arg);
- if (app)
- IvySendDieMsg (app);
- else
- printf ("No Application %s!!!\n",arg);
- arg = strtok (NULL, " ");
- }
-
- } else if (strcmp(cmd, "bind") == 0) {
- arg = strtok (NULL, "'");
- Chop(arg);
- if (arg) {
- IvyBinding bind;
- const char *errbuf;
- int erroffset;
- bind = IvyBindingCompile(arg, & erroffset, & errbuf);
- if (bind==NULL) {
- printf("Error compiling '%s', %s, not bound\n", arg, errbuf);
- } else {
- IvyBindingFree( bind );
- IvyBindMsg (Callback, NULL, arg);
- }
- }
-
- } else if (strcmp(cmd, "where") == 0) {
- arg = strtok (NULL, " \n");
- if (arg) {
- app = IvyGetApplication (arg);
- if (app)
- printf ("Application %s on %s\n",arg, IvyGetApplicationHost (app));
- else printf ("No Application %s!!!\n",arg);
- }
- } else if (strcmp(cmd, "direct") == 0) {
- arg = strtok (NULL, " \n");
- if (arg) {
- app = IvyGetApplication (arg);
- if (app) {
- arg = strtok (NULL, " ");
- id = atoi (arg) ;
- arg = strtok (NULL, "'");
- IvySendDirectMsg (app, id, Chop(arg));
- } else
- printf ("No Application %s!!!\n",arg);
- }
-
- } else if (strcmp(cmd, "who") == 0) {
- printf("Apps: %s\n", IvyGetApplicationList(","));
-
- } else if (strcmp(cmd, "help") == 0) {
- fprintf(stderr,"Commands list:\n");
- printf(" .help - this help\n");
- printf(" .quit - terminate this application\n");
- printf(" .die appname - send die msg to appname\n");
- printf(" .dieall-yes-i-am-sure - send die msg to all applis\n");
- printf(" .direct appname id 'arg' - send direct msg to appname\n");
- printf(" .where appname - on which host is appname\n");
- printf(" .bind 'regexp' - add a msg to receive\n");
- printf(" .showbind - show bindings \n");
-
- printf(" .who - who is on the bus\n");
- } else if (strcmp(cmd, "showbind") == 0) {
- if (!fbindcallback) {
- IvySetBindCallback(IvyDefaultBindCallback, NULL);
- fbindcallback=1;
- } else {
- IvySetBindCallback(NULL, NULL);
- fbindcallback=0;
- }
- } else if (strcmp(cmd, "quit") == 0) {
- exit(0);
- }
- } else {
- cmd = strtok (buf, "\n");
- err = IvySendMsg (cmd);
- printf("-> Sent to %d peer%s\n", err, err == 1 ? "" : "s");
- }
-}
-
-void ApplicationCallback (IvyClientPtr app, void *user_data, IvyApplicationEvent event)
-{
- char *appname;
- char *host;
-/* char **msgList;*/
- appname = IvyGetApplicationName (app);
- host = IvyGetApplicationHost (app);
- switch (event) {
-
- case IvyApplicationConnected:
- app_count++;
- printf("%s connected from %s\n", appname, host);
-/* printf("Application(%s): Begin Messages\n", appname);*/
-/* double usage with -s flag remove it
- msgList = IvyGetApplicationMessages (app);
- while (*msgList )
- printf("%s subscribes to '%s'\n",appname,*msgList++);
-*/
-/* printf("Application(%s): End Messages\n",appname);*/
-#ifndef WIN32
-/* Stdin not compatible with select , select only accept socket */
- if (app_count == wait_count)
- IvyChannelAdd (0, NULL, NULL, HandleStdin);
-#endif
- break;
-
- case IvyApplicationDisconnected:
- app_count--;
- printf("%s disconnected from %s\n", appname, host);
- break;
-
- default:
- printf("%s: unkown event %d\n", appname, event);
- break;
- }
-}
-void IvyPrintBindCallback( IvyClientPtr app, void *user_data, int id, char* regexp, IvyBindEvent event)
-{
- switch ( event ) {
- case IvyAddBind:
- if ( fbindcallback )
- printf("Application: %s on %s add regexp %d : %s\n",
- IvyGetApplicationName( app ), IvyGetApplicationHost(app), id, regexp);
- break;
- case IvyRemoveBind:
- if ( fbindcallback )
- printf("Application: %s on %s remove regexp %d :%s\n",
- IvyGetApplicationName( app ), IvyGetApplicationHost(app), id, regexp);
- break;
- case IvyFilterBind:
- printf("Application: %s on %s as been filtred regexp %d :%s\n",
- IvyGetApplicationName( app ), IvyGetApplicationHost(app), id, regexp);
- break;
- case IvyChangeBind:
- if ( fbindcallback )
- printf("Application: %s on %s change regexp %d : %s\n",
- IvyGetApplicationName( app ), IvyGetApplicationHost(app), id, regexp);
- break;
- default:
- printf("Application: %s unkown event %d\n",IvyGetApplicationName( app ), event);
- break;
- }
-}
-
-
-#ifdef IVYMAINLOOP
-void TimerCall(TimerId id, void *user_data, unsigned long delta)
-{
- printf("Timer callback: %ld delta %lu ms\n", (long)user_data, delta);
- IvySendMsg ("TEST TIMER %d", (long)user_data);
- /*if ((int)user_data == 5) TimerModify (id, 2000);*/
-}
-#endif
-#ifdef GLUTMAINLLOP
-void
-display(void)
-{
- glClear(GL_COLOR_BUFFER_BIT);
- glFlush();
-}
-#endif
-
-void BindMsgOfFile( const char * regex_file )
-{
- char line[4096];
- size_t size;
- FILE* file;
- file = fopen( regex_file, "r" );
- if ( !file ) {
- perror( "Regexp file open ");
- return;
- }
- while( !feof( file ) )
- {
- if ( fgets( line, sizeof(line), file ) )
- {
- size = strlen(line);
- if ( size > 1 )
- {
- line[size-1] = '\0'; /* supress \n */
- IvyBindMsg (Callback, NULL, line);
- }
- }
- }
-}
-void BuildFilterRegexp()
-{
- char *word=strtok( classes, "," );
- while ( word != NULL && (filter_count < 4096 ))
- {
- filter[filter_count++] = word;
- word = strtok( NULL, ",");
- }
- if ( filter_count )
- IvySetFilter( filter_count, filter );
-}
-int main(int argc, char *argv[])
-{
- int c;
- int timer_test = 0;
- char busbuf [1024] = "";
- const char* bus = 0;
- const char* regex_file = 0;
- char agentnamebuf [1024] = "";
- const char* agentname = DEFAULT_IVYPROBE_NAME;
- char agentready [1024] = "";
- const char* helpmsg =
- "[options] [regexps]\n\t-b bus\tdefines the Ivy bus to which to connect to, defaults to 127:2010\n"
- "\t-t\ttriggers the timer test\n"
- "\t-n name\tchanges the name of the agent, defaults to IVYPROBE\n"
- "\t-v\tprints the ivy relase number\n\n"
- "regexp is a Perl5 compatible regular expression (see ivyprobe(1) and pcrepattern(3) for more info\n"
- "use .help within ivyprobe\n"
- "\t-s bindcall\tactive the interception of regexp's subscribing or unscribing\n"
- "\t-f regexfile\tread list of regexp's from file one by line\n"
- "\t-c msg1,msg2,msg3,...\tfilter the regexp's not beginning with words\n"
- ;
- while ((c = getopt(argc, argv, "vn:d:b:w:t:sf:c:")) != EOF)
- switch (c) {
- case 'b':
- strcpy (busbuf, optarg);
- bus = busbuf;
- break;
- case 'w':
- wait_count = atoi(optarg) ;
- break;
- case 'f':
- regex_file = optarg ;
- break;
- case 'n':
- strcpy(agentnamebuf, optarg);
- agentname=agentnamebuf;
- case 'v':
- printf("ivy c library version %d.%d\n",IVYMAJOR_VERSION,IVYMINOR_VERSION);
- break;
- case 't':
- timer_test = 1;
- break;
- case 's':
- fbindcallback=1;
- break;
- case 'c':
- classes= strdup(optarg);
- break;
- default:
- printf("usage: %s %s",argv[0],helpmsg);
- exit(1);
- }
- sprintf(agentready,"%s Ready",agentname);
-
- /* Mainloop management */
-#ifdef XTMAINLOOP
- /*XtToolkitInitialize();*/
- cntx = XtCreateApplicationContext();
- IvyXtChannelAppContext (cntx);
-#endif
-#ifdef GLUTMAINLLOOP
- glutInit(&argc, argv);
- glutCreateWindow("IvyProbe Test");
- glClearColor(0.49, 0.62, 0.75, 0.0);
- glutDisplayFunc(display);
-#endif
- IvyInit (agentname, agentready, ApplicationCallback,NULL,NULL,NULL);
- IvySetBindCallback(IvyPrintBindCallback, NULL);
-
- IvyBindDirectMsg( DirectCallback,NULL);
- if ( classes )
- BuildFilterRegexp();
- if ( regex_file )
- BindMsgOfFile( regex_file );
- for (; optind < argc; optind++)
- IvyBindMsg (Callback, NULL, argv[optind]);
-
- if (wait_count == 0)
-#ifndef WIN32
-/* Stdin not compatible with select , select only accept socket */
- IvyChannelAdd (0, NULL, NULL, HandleStdin);
-#endif
-
- IvyStart (bus);
-
- if (timer_test) {
-#ifdef IVYMAINLOOP
- TimerRepeatAfter (TIMER_LOOP, 1000, TimerCall, (void*)1);
- TimerRepeatAfter (5, 5000, TimerCall, (void*)5);
-#endif
- }
-
-#ifdef XTMAINLOOP
- XtAppMainLoop (cntx);
-#endif
-#ifdef GLIBMAINLOOP
- {
- GMainLoop *ml = g_main_loop_new(NULL, FALSE);
- g_main_loop_run(ml);
- }
-#endif
-#ifdef GLUTMAINLOOP
- glutMainLoop();
-#endif
-
-#ifdef IVYMAINLOOP
- IvyMainLoop ();
-#endif
- return 0;
-}
-
diff --git a/src/ivythroughput.cpp b/src/ivythroughput.cpp
deleted file mode 100644
index 21d04a9..0000000
--- a/src/ivythroughput.cpp
+++ /dev/null
@@ -1,511 +0,0 @@
-/*
- * IvyThroughput
- *
- * Copyright (C) 2008
- * Centre d'Études de la Navigation Aérienne
- */
-
-/*
-
- TODO : ° utiliser la commande script pour logger le nb de
- ° bug pourquoi ça marche plus si plus d'un client ?
-
- */
-
-
-// g++ ivythroughput.cpp -o ivythroughput -L/usr/local/lib64/ -Wl,-rpath,/usr/local/lib64/ -livy -lpcrecpp
-
-/* SCENARIO
-
- ° traitement des options :
- -v (affi version) -b bus, -r regexp file, -m message file, -n : nombre de recepteurs
- -t [type de test => ml (memory leak), tp (throughput)
-
- test memory leak
- ° fork d'un emetteur et d'un recepteur : le recepteur s'abonne à toutes les regexps,
- se desabonne, se reabonne etc etc en boucle : on teste que l'empreinte mémoire
- de l'emetteur ne grossisse pas
-
- test throughput :
- ° fork d'un emetteur et d'un ou plusieurs recepteurs : les recepteurs s'abonnent à toutes les regexps
- ° l'emetteur envoie en boucle tous les messages du fichier de message
- ° l'emetteur note le temps d'envoi des messages
- ° l'emetteur envoie un die all et quitte
-*/
-
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include "version.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <iostream>
-#include <sstream>
-#include <signal.h>
-
-#include "ivysocket.h"
-#include "ivy.h"
-#include "timer.h"
-#include "ivyloop.h"
-#include <pcrecpp.h>
-
-#include <string>
-#include <list>
-#include <map>
-
-typedef std::list<std::string> ListOfString;
-typedef std::list<pid_t> ListOfPid;
-typedef std::map<unsigned int, bool> MapUintToBool;
-typedef struct {
- unsigned int currentBind;
- unsigned int totalBind;
-} InfoBind;
-typedef std::map<string, InfoBind> MapBindByClnt;
-
-#define MILLISEC 1000.0
-
-typedef enum {memoryLeak, throughput} KindOfTest ;
-
-
-extern char *optarg;
-extern int optind, opterr, optopt;
-
-void recepteur (const char* bus, KindOfTest kod, unsigned int inst,
- const ListOfString& regexps);
-void emetteur (const char* bus, KindOfTest kod, int testDuration,
- const ListOfString& messages, int regexpSize);
-
-bool getMessages (const char*fileName, ListOfString &messages);
-bool getRegexps (const char*fileName, ListOfString &regexps);
-
-double currentTime();
-void binCB( IvyClientPtr app, void *user_data, int id, char* regexp, IvyBindEvent event ) ;
-void binCBR( IvyClientPtr app, void *user_data, int id, char* regexp, IvyBindEvent event ) ;
-void stopCB (TimerId id, void *user_data, unsigned long delta);
-void sendAllMessageCB (TimerId id, void *user_data, unsigned long delta);
-void recepteurReadyCB (IvyClientPtr app, void *user_data, int argc, char *argv[]);
-void otherRecepteurReadyCB (IvyClientPtr app, void *user_data, int argc, char *argv[]);
-void recepteurCB (IvyClientPtr app, void *user_data, int argc, char *argv[]);
-void startOfSeqCB (IvyClientPtr app, void *user_data, int argc, char *argv[]);
-void endOfSeqCB (IvyClientPtr app, void *user_data, int argc, char *argv[]);
-void aliveCB (TimerId id, void *user_data, unsigned long delta);
-
-unsigned int nbMess=0, nbReg=0, numClients =1, globalInst;
-MapUintToBool recReady;
-KindOfTest kindOfTest = throughput;
-bool regexpAreUniq = false;
-
-int main(int argc, char *argv[])
-{
- int c;
- int testDuration = 10;
- char *bus ;
- char regexpFile[1024] = "testivy/regexp.txt";
- char messageFile[1024] = "testivy/plantageradargl.ivy";
- ListOfString messages, regexps;
- pid_t pid;
- ListOfPid recPid;
-
- const char* helpmsg =
- "[options] \n"
- "\t -b bus\tdefines the Ivy bus to which to connect to, defaults to 127:2010\n"
- "\t -v \t prints the ivy relase number\n\n"
- "\t -t \t type of test : ml (memory leak) or tp (throughput)\n"
- "\t -r \t regexfile\tread list of regexp's from file\n"
- "\t -p \t each client will prepend regexp with uniq string to "
- "simulate N clients with differents regexps\n"
- "\t -m \t messageFile\tread list of messages from file\n"
- "\t -n \t number of clients\n"
- "\t -d \t duration of the test in seconds\n" ;
-
-
- if (getenv("IVYBUS") != NULL) {
- bus = strdup (getenv("IVYBUS"));
- } else {
- bus = strdup ("127.0.0.1:2000") ;
- }
-
-
- while ((c = getopt(argc, argv, "vpb:r:m:n:t:d:")) != EOF)
- switch (c) {
- case 'b':
- strcpy (bus, optarg);
- break;
- case 'v':
- printf("ivy c library version %d.%d\n",IVYMAJOR_VERSION, IVYMINOR_VERSION);
- break;
- case 'p':
- regexpAreUniq = true;
- break;
- case 't':
- kindOfTest = (strncasecmp (optarg, "ml", 2) == 0) ? memoryLeak : throughput;
- break;
- case 'r':
- strcpy (regexpFile, optarg);
- break;
- case 'm':
- strcpy (messageFile, optarg);
- break;
- case 'n':
- numClients = atoi (optarg);
- break;
- case 'd':
- testDuration = atoi (optarg);
- break;
- default:
- printf("usage: %s %s",argv[0],helpmsg);
- exit(1);
- }
-
- if (!getRegexps (regexpFile, regexps))
- {return (1);};
-
- if (kindOfTest != memoryLeak) {
- if (!getMessages (messageFile, messages))
- {return (1);};
- }
-
-#ifdef DEBUG
- ListOfString::iterator iter;
- for (iter=regexps.begin(); iter != regexps.end(); iter++) {
- std::cout << "DBG> |" << *iter << "|\n";
- }
-
- for (iter=messages.begin(); iter != messages.end(); iter++) {
- std::cout << "DBG> |" << *iter << "|\n";
- }
-#endif // DEBUG
-
-
-
- for (unsigned int i=0; i< numClients; i++) {
- if ((pid = fork ()) == 0) {
- // fils
- recepteur (bus, kindOfTest, i, regexps);
- exit (0);
- } else {
- recPid.push_back (pid);
- recReady[i]=false;
- }
- }
-
- emetteur (bus, kindOfTest, testDuration, messages, regexps.size());
-
- ListOfPid::iterator iter;
- for (iter=recPid.begin(); iter != recPid.end(); iter++) {
- kill (*iter, SIGTERM);
- }
-
- for (iter=recPid.begin(); iter != recPid.end(); iter++) {
- waitpid (*iter, NULL, 0);
- }
-
-
-
- return (0);
-}
-
-
-
-
-/*
-# _ _
-# | | | |
-# ___ _ __ ___ ___ | |_ | |_ ___ _ _ _ __
-# / _ \ | '_ ` _ \ / _ \ | __| | __| / _ \ | | | | | '__|
-# | __/ | | | | | | | __/ \ |_ \ |_ | __/ | |_| | | |
-# \___| |_| |_| |_| \___| \__| \__| \___| \__,_| |_|
-*/
-void emetteur (const char* bus, KindOfTest kod, int testDuration,
- const ListOfString& messages, int regexpSize)
-{
- printf ("DBG> emetteur start, pid=%d\n", getpid());
- IvyInit ("IvyThroughputEmit", "IvyThroughputEmit Ready", NULL,NULL,NULL,NULL);
- // double origin = currentTime();
-
-
- IvySetBindCallback (binCB, (void *) regexpSize);
- IvyBindMsg (recepteurReadyCB, (void *) &messages,
- "^IvyThroughputReceive_(\\d+)\\s+(Bindone|Ready)");
-
- TimerRepeatAfter (1, testDuration *1000, stopCB, NULL);
-
- IvyStart (bus);
- IvyMainLoop ();
-}
-
-
-
-/*
-# _ __ _
-# | '_ \ | |
-# _ __ ___ ___ ___ | |_) | | |_ ___ _ _ _ __
-# | '__| / _ \ / __| / _ \ | .__/ | __| / _ \ | | | | | '__|
-# | | | __/ | (__ | __/ | | \ |_ | __/ | |_| | | |
-# |_| \___| \___| \___| |_| \__| \___| \__,_| |_|
-*/
-void recepteur (const char* bus, KindOfTest kod, unsigned int inst,
- const ListOfString& regexps)
-{
- std::string agentName = "IvyThroughputReceive_";
- std::stringstream stream ;
- stream << inst;
- agentName += stream.str();
- std::string agentNameReady (agentName + " Ready");
- //double origin = currentTime();
- globalInst = inst;
- static int nbOtherReady = numClients -1;
-
- usleep (100 * 1000);
-
- printf ("DBG> recepteur_%d start, pid=%d\n", inst, getpid());
- IvyInit (agentName.c_str(), agentNameReady.c_str(), NULL,NULL,NULL,NULL);
-
- unsigned int debugInt = 0;
- ListOfString::const_iterator iter;
- for (iter=regexps.begin(); iter != regexps.end(); iter++) {
- debugInt++;
- string reg = *iter;
- if (regexpAreUniq) { (reg += " ") += stream.str();}
- IvyBindMsg (recepteurCB, (void *) inst, reg.c_str());
- }
- IvyBindMsg (startOfSeqCB, NULL, "^start(OfSequence)");
- IvyBindMsg (endOfSeqCB, NULL, "^end(OfSequence)");
- IvyBindMsg (otherRecepteurReadyCB, (void *) &nbOtherReady,
- "^IvyThroughputReceive_(\\d+)\\s+Ready");
-
-
- TimerRepeatAfter (TIMER_LOOP, 1000, aliveCB, NULL);
-
- IvyStart (bus);
- IvyMainLoop ();
-}
-
-// ===========================================================================
-
-
-
-/*
-# __ _ _ __ __ __ _
-# / _` | | | | \/ | / _` |
-# | (_| | ___ | |_ | \ / | ___ ___ ___ __ _ | (_| | ___
-# \__, | / _ \ | __| | |\/| | / _ \ / __| / __| / _` | \__, | / _ \
-# __/ | | __/ \ |_ | | | | | __/ \__ \ \__ \ | (_| | __/ | | __/
-# |___/ \___| \__| |_| |_| \___| |___/ |___/ \__,_| |___/ \___|
-*/
-
-bool getMessages (const char*fileName, ListOfString &messages)
-{
- FILE *infile;
- char buffer [1024*64];
- pcrecpp::RE pcreg ("\"(.*)\"$");
- string aMsg;
-
- infile = fopen(fileName, "r");
- if (!infile) {
- fprintf (stderr, "impossible d'ouvrir %s en lecture\n", fileName);
- return false;
- }
-
- while (fgets (buffer, sizeof (buffer), infile) != NULL) {
- if (pcreg.PartialMatch (buffer, &aMsg)) {
- messages.push_back (aMsg);
- nbMess++;
- }
- }
- fclose (infile);
- return (true);
-}
-
-
-/*
-# __ _ _ _____ __ _ _ __
-# / _` | | | | __ \ / _` | | '_ \
-# | (_| | ___ | |_ | |__) | ___ | (_| | ___ __ __ | |_) | ___
-# \__, | / _ \ | __| | _ / / _ \ \__, | / _ \ \ \/ / | .__/ / __|
-# __/ | | __/ \ |_ | | \ \ | __/ __/ | | __/ > < | | \__ \
-# |___/ \___| \__| |_| \_\ \___| |___/ \___| /_/\_\ |_| |___/
-*/
-bool getRegexps (const char*fileName, ListOfString &regexps)
-{
- FILE *infile;
- char buffer [1024*64];
- pcrecpp::RE pcreg ("add regexp \\d+ : (.*)$");
- string aMsg;
-
- infile = fopen(fileName, "r");
- if (!infile) {
- fprintf (stderr, "impossible d'ouvrir %s en lecture\n", fileName);
- return false;
- }
-
- while (fgets (buffer, sizeof (buffer), infile) != NULL) {
- if (pcreg.PartialMatch (buffer, &aMsg)) {
- regexps.push_back (aMsg);
- nbReg++;
- }
- }
- fclose (infile);
-
- return (true);
-}
-
-
-
-/*
-# _______ _
-# |__ __| (_)
-# ___ _ _ _ __ _ __ | | _ _ __ ___ ___
-# / __| | | | | | '__| | '__| | | | | | '_ ` _ \ / _ \
-# | (__ | |_| | | | | | | | | | | | | | | | | __/
-# \___| \__,_| |_| |_| |_| |_| |_| |_| |_| \___|
-*/
-double currentTime()
-{
- double current;
-
- struct timeval stamp;
- gettimeofday( &stamp, NULL );
- current = (double)stamp.tv_sec * MILLISEC + (double)(stamp.tv_usec/MILLISEC);
- return current;
-}
-
-
-/*
-# _ _ _____ ____
-# | | (_) / ____| | _ \
-# | |__ _ _ __ | | | |_) |
-# | '_ \ | | | '_ \ | | | _ <
-# | |_) | | | | | | | | |____ | |_) |
-# |_.__/ |_| |_| |_| \_____| |____/
-*/
-void binCB( IvyClientPtr app, void *user_data, int id, char* regexp, IvyBindEvent event )
-{
- string appName = IvyGetApplicationName( app );
- static MapBindByClnt bindByClnt;
-
- if (bindByClnt.find (appName) == bindByClnt.end()) {
- (bindByClnt[appName]).currentBind = 0;
- (bindByClnt[appName]).totalBind = (unsigned long) user_data;
- }
-
- switch ( event )
- {
- case IvyAddBind:
- (bindByClnt[appName]).currentBind ++;
- if ((bindByClnt[appName]).currentBind == (bindByClnt[appName]).totalBind) {
- printf("Application:%s ALL REGEXPS BINDED\n", appName.c_str());
- } else {
- // printf("Application:%s bind [%d/%d]\n", appName.c_str(),
- // (bindByClnt[appName]).currentBind, (bindByClnt[appName]).totalBind);
- }
- break;
- case IvyRemoveBind:
- printf("Application:%s bind '%s' REMOVED\n", appName.c_str(), regexp );
- break;
- case IvyFilterBind:
- printf("Application:%s bind '%s' FILTRED\n", appName.c_str(), regexp );
- break;
- case IvyChangeBind:
- printf("Application:%s bind '%s' CHANGED\n", appName.c_str(), regexp );
- break;
- }
-}
-
-
-void stopCB (TimerId id, void *user_data, unsigned long delta)
-{
- IvyStop ();
-}
-
-
-void sendAllMessageCB (TimerId id, void *user_data, unsigned long delta)
-{
- ListOfString *messages = (ListOfString *) user_data;
- double startTime = currentTime();
- unsigned int envoyes=0;
-
- IvySendMsg ("startOfSequence");
- ListOfString::iterator iter;
- for (iter=messages->begin(); iter != messages->end(); iter++) {
- envoyes += IvySendMsg ((*iter).c_str());
- }
- IvySendMsg ("endOfSequence");
-
- printf ("[ivy %d.%d] envoyer [%d/%d] messages filtrés par %d regexps a %d clients "
- "prends %.1f secondes\n",
- IVYMAJOR_VERSION, IVYMINOR_VERSION,
- envoyes, nbMess, nbReg, numClients,
- (currentTime()-startTime) / 1000.0) ;
- TimerRepeatAfter (1, 1000, sendAllMessageCB ,user_data);
-}
-
-void recepteurCB (IvyClientPtr app, void *user_data, int argc, char *argv[])
-{
- // unsigned long recN = (long) user_data;
- // printf (".");
- // if (!((argc == 1) && (strcmp (argv[0], "OfSequence")) == 0))
- nbMess++;
-}
-
-
-void recepteurReadyCB (IvyClientPtr app, void *user_data, int argc, char *argv[])
-{
- ListOfString *messages = (ListOfString *) user_data;
- unsigned int instance = atoi( *argv++ );
- if ((strcmp (*argv, "Ready") == 0) && (numClients != 1)) {
- return;
- }
-
-
- recReady[instance] = true;
- bool readyToStart = true;
-
- for (unsigned int i=0; i< numClients; i++) {
- if (recReady[i]==false) {
- // printf ("Emetteur : manque recepteur [%d/%d]\n", i, numClients-1);
- readyToStart = false;
- }
- }
-
- if (readyToStart == true) {
- if (kindOfTest == throughput) {
- TimerRepeatAfter (1, 2000, sendAllMessageCB , messages);
- // printf ("Emetteur : tous recepteurs prets : on envoie la puree !!\n");
- }
- }
-}
-
-void otherRecepteurReadyCB (IvyClientPtr app, void *user_data, int argc, char *argv[])
-{
- int *nbOtherReady = (int *) user_data;
-
- // printf ("DBG>> otherRecepteurReadyCB\n");
-
- if ((--(*nbOtherReady)) == 0) {
- IvySendMsg ("IvyThroughputReceive_%d Bindone", globalInst);
- } else {
- // printf ("IvyThroughputReceive_%d nbOtherReady=%d\n", globalInst, *nbOtherReady);
- }
-}
-
-
-void startOfSeqCB (IvyClientPtr app, void *user_data, int argc, char *argv[])
-{
- nbMess = 0;
-}
-
-
-void endOfSeqCB (IvyClientPtr app, void *user_data, int argc, char *argv[])
-{
- //nbMess--;
- printf ("recepteur %d a recu %d messages\n", globalInst, nbMess);
-}
-
-
-void aliveCB (TimerId id, void *user_data, unsigned long delta)
-{
- // printf ("********* recepteur alive CALLED ***********\n");
-}