X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=lttv%2Flttv%2Fsync%2Fevent_matching_broadcast.c;h=ff45a8a71b7729848a6ef61d2918629211063482;hb=fafb0a2998296c564cbc26c2c0fa5142b181b332;hp=9eb6e10861ef5ada8f5e6dcfd03a4a00c220230c;hpb=f10c27a850e57bf88bf1d4440eb450729782f409;p=lttv.git diff --git a/lttv/lttv/sync/event_matching_broadcast.c b/lttv/lttv/sync/event_matching_broadcast.c index 9eb6e108..ff45a8a7 100644 --- a/lttv/lttv/sync/event_matching_broadcast.c +++ b/lttv/lttv/sync/event_matching_broadcast.c @@ -26,16 +26,11 @@ #include #include "event_analysis.h" -#include "sync_chain_lttv.h" +#include "sync_chain.h" #include "event_matching_broadcast.h" -#ifndef g_info -#define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format) -#endif - - // Functions common to all matching modules static void initMatchingBroadcast(SyncState* const syncState); static void destroyMatchingBroadcast(SyncState* const syncState); @@ -43,12 +38,20 @@ static void destroyMatchingBroadcast(SyncState* const syncState); static void matchEventBroadcast(SyncState* const syncState, Event* const event); static GArray* finalizeMatchingBroadcast(SyncState* const syncState); static void printMatchingStatsBroadcast(SyncState* const syncState); +static void writeMatchingGraphsPlotsBroadcast(SyncState* const syncState, const + unsigned int i, const unsigned int j); // Functions specific to this module static void registerMatchingBroadcast() __attribute__((constructor (101))); static void partialDestroyMatchingBroadcast(SyncState* const syncState); +static void openGraphDataFiles(SyncState* const syncState); +static void writeAccuracyPoints(MatchingGraphsBroadcast* graphs, const + Broadcast* const broadcast); +static void closeGraphDataFiles(SyncState* const syncState); + + static MatchingModule matchingModuleBroadcast = { .name= "broadcast", .canMatch[TCP]= false, @@ -58,8 +61,9 @@ static MatchingModule matchingModuleBroadcast = { .matchEvent= &matchEventBroadcast, .finalizeMatching= &finalizeMatchingBroadcast, .printMatchingStats= &printMatchingStatsBroadcast, - .writeMatchingGraphsPlots= NULL, - .writeMatchingGraphsOptions= NULL, + .graphFunctions= { + .writeTraceTimeForePlots= &writeMatchingGraphsPlotsBroadcast, + } }; @@ -104,6 +108,16 @@ static void initMatchingBroadcast(SyncState* const syncState) { matchingData->stats= NULL; } + + if (syncState->graphsStream) + { + matchingData->graphs= malloc(sizeof(MatchingGraphsBroadcast)); + openGraphDataFiles(syncState); + } + else + { + matchingData->graphs= NULL; + } } @@ -119,9 +133,8 @@ static void initMatchingBroadcast(SyncState* const syncState) */ static void destroyMatchingBroadcast(SyncState* const syncState) { - MatchingDataBroadcast* matchingData; - - matchingData= (MatchingDataBroadcast*) syncState->matchingData; + MatchingDataBroadcast* matchingData= syncState->matchingData; + unsigned int i; if (matchingData == NULL) { @@ -135,6 +148,16 @@ static void destroyMatchingBroadcast(SyncState* const syncState) free(matchingData->stats); } + if (syncState->graphsStream) + { + for (i= 0; i < syncState->traceNb; i++) + { + free(matchingData->graphs->pointsNb[i]); + } + free(matchingData->graphs->pointsNb); + free(matchingData->graphs); + } + free(syncState->matchingData); syncState->matchingData= NULL; } @@ -164,14 +187,18 @@ static void partialDestroyMatchingBroadcast(SyncState* const syncState) g_hash_table_destroy(matchingData->pendingBroadcasts); matchingData->pendingBroadcasts= NULL; + + if (syncState->graphsStream && matchingData->graphs->accuracyPoints) + { + closeGraphDataFiles(syncState); + } } /* * Try to match one broadcast with previously received broadcasts (based on * the addresses and the fist bytes of data they contain). Deliver them to the - * analysis module once a traceNb events have been accumulated for a - * broadcast. + * analysis module once traceNb events have been accumulated for a broadcast. * * Args: * syncState container for synchronization data. @@ -198,13 +225,14 @@ static void matchEventBroadcast(SyncState* const syncState, Event* const event) matchingData->stats->totReceive++; } - // s'il est déjà dans pendingBroadcasts - // l'ajouter à son broadcast - // s'il y a traceNb éléments - // le retirer de pending et le livrer à analysis - // détruire le broadcast (et ses éléments) - // sinon - // créer un broadcast et l'ajouter à pending + /* if event in pendingBroadcasts: + * add it to its broadcast + * if this broadcast has traceNb events: + * remove it from pending and deliver it to analysis + * destroy the broadcast (and its elements) + * else: + * create a broadcast and add it to pending + */ result= g_hash_table_lookup_extended(matchingData->pendingBroadcasts, @@ -215,9 +243,19 @@ static void matchEventBroadcast(SyncState* const syncState, Event* const event) g_queue_push_tail(broadcast->events, event); if (broadcast->events->length == syncState->traceNb) { + if (matchingData->stats) + { + matchingData->stats->totComplete++; + } + g_hash_table_steal(matchingData->pendingBroadcasts, datagramKey); free(datagramKey); syncState->analysisModule->analyzeBroadcast(syncState, broadcast); + + if (syncState->graphsStream) + { + writeAccuracyPoints(matchingData->graphs, broadcast); + } destroyBroadcast(broadcast); } } @@ -226,6 +264,12 @@ static void matchEventBroadcast(SyncState* const syncState, Event* const event) broadcast= malloc(sizeof(Broadcast)); broadcast->events= g_queue_new(); g_queue_push_tail(broadcast->events, event); + + datagramKey= malloc(sizeof(DatagramKey)); + *datagramKey= *event->event.udpEvent->datagramKey; + + g_hash_table_insert(matchingData->pendingBroadcasts, + datagramKey, broadcast); } } else @@ -274,8 +318,8 @@ static GArray* finalizeMatchingBroadcast(SyncState* const syncState) /* - * Print statistics related to matching and downstream modules. Must be - * called after finalizeMatching. + * Print statistics related to matching. Must be called after + * finalizeMatching. * * Args: * syncState container for synchronization data. @@ -288,7 +332,6 @@ static void printMatchingStatsBroadcast(SyncState* const syncState) { return; } - matchingData= (MatchingDataBroadcast*) syncState->matchingData; printf("Broadcast matching stats:\n"); @@ -296,9 +339,9 @@ static void printMatchingStatsBroadcast(SyncState* const syncState) matchingData->stats->totTransmit); printf("\ttotal broadcasts datagrams received: %u\n", matchingData->stats->totReceive); - printf("\ttotal broadcast groups for which all emissions were identified: %u\n", + printf("\ttotal broadcast groups for which all receptions were identified: %u\n", matchingData->stats->totComplete); - printf("\ttotal broadcast groups missing some emissions: %u\n", + printf("\ttotal broadcast groups missing some receptions: %u\n", matchingData->stats->totIncomplete); if (matchingData->stats->totIncomplete > 0) { @@ -307,9 +350,147 @@ static void printMatchingStatsBroadcast(SyncState* const syncState) matchingData->stats->totComplete * syncState->traceNb) / matchingData->stats->totIncomplete); } +} + + +/* + * Create and open files used to store accuracy points to genereate graphs. + * Allocate and populate array to store file pointers and counters. + * + * Args: + * syncState: container for synchronization data + */ +static void openGraphDataFiles(SyncState* const syncState) +{ + unsigned int i, j; + int retval; + char* cwd; + char name[36]; + MatchingGraphsBroadcast* graphs= ((MatchingDataBroadcast*) + syncState->matchingData)->graphs; + + cwd= changeToGraphDir(syncState->graphsDir); + + graphs->accuracyPoints= malloc(syncState->traceNb * sizeof(FILE**)); + graphs->pointsNb= malloc(syncState->traceNb * sizeof(unsigned int*)); + for (i= 0; i < syncState->traceNb; i++) + { + graphs->accuracyPoints[i]= malloc(i * sizeof(FILE*)); + graphs->pointsNb[i]= calloc(i, sizeof(unsigned int)); + for (j= 0; j < i; j++) + { + retval= snprintf(name, sizeof(name), + "matching_broadcast-%03u_and_%03u.data", j, i); + g_assert_cmpint(retval, <=, sizeof(name) - 1); + if ((graphs->accuracyPoints[i][j]= fopen(name, "w")) == NULL) + { + g_error(strerror(errno)); + } + } + } + + retval= chdir(cwd); + if (retval == -1) + { + g_error(strerror(errno)); + } + free(cwd); +} + + +/* + * Calculate and write points used to generate graphs + * + * Args: + * graphs: structure containing array of file pointers and counters + * broadcast: broadcast for which to write the points + */ +static void writeAccuracyPoints(MatchingGraphsBroadcast* graphs, const + Broadcast* const broadcast) +{ + unsigned int i, j; + GArray* events; + unsigned int eventNb= broadcast->events->length; + + events= g_array_sized_new(FALSE, FALSE, sizeof(Event*), eventNb); + g_queue_foreach(broadcast->events, &gfAddEventToArray, events); + + for (i= 0; i < eventNb; i++) + { + for (j= 0; j < eventNb; j++) + { + Event* eventI= g_array_index(events, Event*, i), * eventJ= + g_array_index(events, Event*, j); - if (syncState->analysisModule->printAnalysisStats != NULL) + if (eventI->traceNum < eventJ->traceNum) + { + fprintf(graphs->accuracyPoints[eventJ->traceNum][eventI->traceNum], + "%20llu %20.9f\n", eventI->cpuTime, + wallTimeSub(&eventJ->wallTime, &eventI->wallTime)); + graphs->pointsNb[eventJ->traceNum][eventI->traceNum]++; + } + } + } + + g_array_free(events, TRUE); +} + + +/* + * Close files used to store accuracy points to genereate graphs. Deallocate + * array to store file pointers (but not array for counters). + * + * Args: + * syncState: container for synchronization data + */ +static void closeGraphDataFiles(SyncState* const syncState) +{ + unsigned int i, j; + MatchingGraphsBroadcast* graphs= ((MatchingDataBroadcast*) + syncState->matchingData)->graphs; + int retval; + + if (graphs->accuracyPoints == NULL) + { + return; + } + + for (i= 0; i < syncState->traceNb; i++) + { + for (j= 0; j < i; j++) + { + retval= fclose(graphs->accuracyPoints[i][j]); + if (retval != 0) + { + g_error(strerror(errno)); + } + } + free(graphs->accuracyPoints[i]); + } + free(graphs->accuracyPoints); + + graphs->accuracyPoints= NULL; +} + + +/* + * Write the matching-specific graph lines in the gnuplot script. + * + * Args: + * syncState: container for synchronization data + * i: first trace number + * j: second trace number, garanteed to be larger than i + */ +static void writeMatchingGraphsPlotsBroadcast(SyncState* const syncState, const + unsigned int i, const unsigned int j) +{ + if (((MatchingDataBroadcast*) + syncState->matchingData)->graphs->pointsNb[j][i]) { - syncState->analysisModule->printAnalysisStats(syncState); + fprintf(syncState->graphsStream, + "\t\"matching_broadcast-%03d_and_%03d.data\" " + "title \"Broadcast differential delays\" with points " + "linecolor rgb \"black\" pointtype 6 pointsize 2, \\\n", i, + j); } }