X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=lttv%2Flttv%2Fsync%2Fevent_matching_broadcast.c;h=4c66d18157d1ffa28c7c4afa7ce8d877c9b1d606;hb=df64b31664467d7217fa08fcdee423577856b38a;hp=297de2cd39033c79f53765e62312c622dac749c5;hpb=d6ee500355b870e83d5cdbc431629999ec97794e;p=lttv.git diff --git a/lttv/lttv/sync/event_matching_broadcast.c b/lttv/lttv/sync/event_matching_broadcast.c index 297de2cd..4c66d181 100644 --- a/lttv/lttv/sync/event_matching_broadcast.c +++ b/lttv/lttv/sync/event_matching_broadcast.c @@ -1,19 +1,18 @@ /* This file is part of the Linux Trace Toolkit viewer - * Copyright (C) 2009 Benjamin Poirier + * Copyright (C) 2009, 2010 Benjamin Poirier * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License Version 2 as - * published by the Free Software Foundation; + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at + * your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifdef HAVE_CONFIG_H @@ -21,6 +20,7 @@ #endif #include +#include #include #include #include @@ -31,24 +31,25 @@ #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); static void matchEventBroadcast(SyncState* const syncState, Event* const event); -static GArray* finalizeMatchingBroadcast(SyncState* const syncState); +static AllFactors* 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,15 +59,16 @@ static MatchingModule matchingModuleBroadcast = { .matchEvent= &matchEventBroadcast, .finalizeMatching= &finalizeMatchingBroadcast, .printMatchingStats= &printMatchingStatsBroadcast, - .writeMatchingGraphsPlots= NULL, - .writeMatchingGraphsOptions= NULL, + .graphFunctions= { + .writeTraceTimeForePlots= &writeMatchingGraphsPlotsBroadcast, + } }; /* * Matching module registering function */ -static void registerMatchingBroadcast() +void registerMatchingBroadcast() { g_queue_push_tail(&matchingModules, &matchingModuleBroadcast); } @@ -104,6 +106,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 +131,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 +146,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 +185,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. @@ -224,6 +249,11 @@ static void matchEventBroadcast(SyncState* const syncState, Event* const event) g_hash_table_steal(matchingData->pendingBroadcasts, datagramKey); free(datagramKey); syncState->analysisModule->analyzeBroadcast(syncState, broadcast); + + if (syncState->graphsStream) + { + writeAccuracyPoints(matchingData->graphs, broadcast); + } destroyBroadcast(broadcast); } } @@ -265,9 +295,9 @@ static void matchEventBroadcast(SyncState* const syncState, Event* const event) * syncState container for synchronization data. * * Returns: - * Factors[traceNb] synchronization factors for each trace + * AllFactors* synchronization factors for each trace pair */ -static GArray* finalizeMatchingBroadcast(SyncState* const syncState) +static AllFactors* finalizeMatchingBroadcast(SyncState* const syncState) { MatchingDataBroadcast* matchingData; @@ -319,3 +349,146 @@ static void printMatchingStatsBroadcast(SyncState* const syncState) 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= changeToGraphsDir(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("%s", strerror(errno)); + } + } + } + + retval= chdir(cwd); + if (retval == -1) + { + g_error("%s", 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 (eventI->traceNum < eventJ->traceNum) + { + fprintf(graphs->accuracyPoints[eventJ->traceNum][eventI->traceNum], + "%20" PRIu64 " %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("%s", 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]) + { + 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); + } +}