From 41ab25636882f12eed1c31a818a70aed12a46bbf Mon Sep 17 00:00:00 2001 From: fcolin Date: Mon, 6 Jul 2009 08:38:06 +0000 Subject: modif mesure du temps min moy avg --- tools/ivyperf.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/tools/ivyperf.c b/tools/ivyperf.c index 8babd35..402c08d 100644 --- a/tools/ivyperf.c +++ b/tools/ivyperf.c @@ -41,6 +41,14 @@ extern int optind; const char *mymessages[] = { "IvyPerf", "ping", "pong" }; static double origin = 0; +int nbMsgReceive=0; +int nbMsgEmit=0; +int nbMsg = 10; + + +double minRoundTrip=1e12; +double maxRoundTrip=0; +double averageRoundTrip=0; static double currentTime() { @@ -54,6 +62,8 @@ static double currentTime() #endif return current; } +TimerId send_timer; + void Reply (IvyClientPtr app, void *user_data, int argc, char *argv[]) { @@ -61,19 +71,35 @@ void Reply (IvyClientPtr app, void *user_data, int argc, char *argv[]) } void Pong (IvyClientPtr app, void *user_data, int argc, char *argv[]) { + nbMsgReceive++; + 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 ); + if ( roundtrip3 > maxRoundTrip ) maxRoundTrip = roundtrip3; + if ( roundtrip3 < minRoundTrip ) minRoundTrip = roundtrip3; + averageRoundTrip = (averageRoundTrip * ( nbMsgReceive - 1 ) + roundtrip3) /nbMsgReceive; + + if ( nbMsg == nbMsgReceive ) + { + printf("roundtrip[%d] min %f av %f max %f ms\n", nbMsgReceive, minRoundTrip, averageRoundTrip, maxRoundTrip ); + //IvyStop(); + } + } void TimerCall(TimerId id, void *user_data, unsigned long delta) { int count = IvySendMsg ("ping ts=%f", currentTime() - origin ); - if ( count == 0 ) fprintf(stderr, "." ); + if ( count ) nbMsgEmit++; + if ( nbMsg == nbMsgEmit ) + { + TimerRemove(send_timer); + //IvyStop(); + } } void binCB( IvyClientPtr app, void *user_data, int id, const char* regexp, IvyBindEvent event ) @@ -99,19 +125,22 @@ void binCB( IvyClientPtr app, void *user_data, int id, const char* regexp, IvyB int main(int argc, char *argv[]) { long time=200; - + /* Mainloop management */ if ( argc > 1 ) time = atol( argv[1] ); + if ( argc > 2 ) nbMsg = atol( argv[2] ); 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); + if ( nbMsg ) + send_timer = TimerRepeatAfter (TIMER_LOOP, time, TimerCall, (void*)nbMsg); IvyMainLoop (); -- cgit v1.1