Show the latency histograms by IP address rather than by trace
authorBenjamin Poirier <benjamin.poirier@polymtl.ca>
Fri, 6 Nov 2009 19:22:31 +0000 (14:22 -0500)
committerBenjamin Poirier <benjamin.poirier@polymtl.ca>
Fri, 18 Dec 2009 19:04:16 +0000 (14:04 -0500)
A trace may contain traffic between more than just one pair of hosts.

Signed-off-by: Benjamin Poirier <benjamin.poirier@polymtl.ca>
lttv/lttv/sync/event_analysis_eval.c
lttv/lttv/sync/event_analysis_eval.h
lttv/lttv/sync/event_matching_distributor.c
lttv/lttv/sync/sync_chain_lttv.c
lttv/modules/text/sync_chain_batch.c

index 57ee73ec7a9fdead2f6312d12811a9bf9d32ff18..5dd1f6df16677e502b32d420cef594d45731d697 100644 (file)
 #include "event_analysis_eval.h"
 
 
+struct WriteGraphInfo
+{
+       GHashTable* rttInfo;
+       FILE* graphsStream;
+};
+
+
 // Functions common to all analysis modules
 static void initAnalysisEval(SyncState* const syncState);
 static void destroyAnalysisEval(SyncState* const syncState);
@@ -52,10 +59,6 @@ static void analyzeBroadcastEval(SyncState* const syncState, Broadcast* const
        broadcast);
 static GArray* finalizeAnalysisEval(SyncState* const syncState);
 static void printAnalysisStatsEval(SyncState* const syncState);
-static void writeAnalysisGraphsPlotsEval(SyncState* const syncState, const
-       unsigned int i, const unsigned int j);
-static void writeAnalysisGraphsOptionsEval(SyncState* const syncState, const
-       unsigned int i, const unsigned int j);
 
 // Functions specific to this module
 static void registerAnalysisEval() __attribute__((constructor (102)));
@@ -70,17 +73,21 @@ static void gfSum(gpointer data, gpointer userData);
 static void gfSumSquares(gpointer data, gpointer userData);
 static void ghfPrintExchangeRtt(gpointer key, gpointer value, gpointer user_data);
 
-static void initGraphs(SyncState* const syncState);
-static void writeGraphFiles(SyncState* const syncState);
-static void dumpBinToFile(const uint32_t* const bin, const uint32_t total,
-       FILE* const file);
-static void destroyGraphs(SyncState* const syncState);
+static void hitBin(struct Bins* const bins, const double value);
 static unsigned int binNum(const double value) __attribute__((pure));
 static double binStart(const unsigned int binNum) __attribute__((pure));
 static double binEnd(const unsigned int binNum) __attribute__((pure));
 
+static AnalysisGraphEval* constructAnalysisGraphEval(const char* const
+       graphsDir, const struct RttKey* const rttKey);
+static void destroyAnalysisGraphEval(AnalysisGraphEval* const graph);
+static void gdnDestroyAnalysisGraphEval(gpointer data);
+static void ghfWriteGraph(gpointer key, gpointer value, gpointer user_data);
+static void dumpBinToFile(const struct Bins* const bins, FILE* const file);
+static void writeHistogram(FILE* graphsStream, const struct RttKey* rttKey,
+       double* minRtt);
+
 
-const unsigned int binNb= 10000;
 double binBase;
 
 static AnalysisModule analysisModuleEval= {
@@ -92,8 +99,8 @@ static AnalysisModule analysisModuleEval= {
        .analyzeBroadcast= &analyzeBroadcastEval,
        .finalizeAnalysis= &finalizeAnalysisEval,
        .printAnalysisStats= &printAnalysisStatsEval,
-       .writeAnalysisGraphsPlots= &writeAnalysisGraphsPlotsEval,
-       .writeAnalysisGraphsOptions= &writeAnalysisGraphsOptionsEval,
+       .writeAnalysisGraphsPlots= NULL,
+       .writeAnalysisGraphsOptions= NULL,
 };
 
 static ModuleOption optionEvalRttFile= {
@@ -174,95 +181,63 @@ static void initAnalysisEval(SyncState* const syncState)
 
        if (syncState->graphsStream)
        {
-               binBase= exp10(6. / (binNb - 2));
-               analysisData->graphs= malloc(sizeof(AnalysisGraphsEval));
-               initGraphs(syncState);
+               binBase= exp10(6. / (BIN_NB - 3));
+               analysisData->graphs= g_hash_table_new_full(&ghfRttKeyHash,
+                       &gefRttKeyEqual, &gdnDestroyRttKey, &gdnDestroyAnalysisGraphEval);
        }
 }
 
 
 /*
- * Create and open files used to store histogram points to genereate
- * graphs. Allocate and populate array to store file pointers.
- *
- * Also create data structures to store histogram points during analysis.
+ * Create and open files used to store histogram points to generate graphs.
+ * Create data structures to store histogram points during analysis.
  *
  * Args:
- *   syncState:    container for synchronization data
+ *   graphsDir:    folder where to write files
+ *   rttKey:       host pair, make sure saddr < daddr
  */
-static void initGraphs(SyncState* const syncState)
+static AnalysisGraphEval* constructAnalysisGraphEval(const char* const
+       graphsDir, const struct RttKey* const rttKey)
 {
-       unsigned int i, j;
        int retval;
+       unsigned int i;
        char* cwd;
-       char name[36];
-       AnalysisDataEval* analysisData= syncState->analysisData;
-
-       cwd= changeToGraphDir(syncState->graphsDir);
-
-       analysisData->graphs->ttPoints= malloc(syncState->traceNb *
-               sizeof(FILE**));
-       analysisData->graphs->ttBinsArray= malloc(syncState->traceNb *
-               sizeof(uint32_t**));
-       analysisData->graphs->ttBinsTotal= malloc(syncState->traceNb *
-               sizeof(uint32_t*));
-       for (i= 0; i < syncState->traceNb; i++)
+       char name[60], saddr[16], daddr[16];
+       AnalysisGraphEval* graph= calloc(1, sizeof(*graph));
+       const struct {
+               size_t pointsOffset;
+               const char* fileName;
+               const char* host1, *host2;
+       } loopValues[]= {
+               {offsetof(AnalysisGraphEval, ttSendPoints), "analysis_eval_tt-%s_to_%s.data",
+                       saddr, daddr},
+               {offsetof(AnalysisGraphEval, ttRecvPoints), "analysis_eval_tt-%s_to_%s.data",
+                       daddr, saddr},
+               {offsetof(AnalysisGraphEval, hrttPoints), "analysis_eval_hrtt-%s_and_%s.data",
+                       saddr, daddr},
+       };
+
+       graph->ttSendBins.max= BIN_NB - 1;
+       graph->ttRecvBins.max= BIN_NB - 1;
+       graph->hrttBins.max= BIN_NB - 1;
+
+       convertIP(saddr, rttKey->saddr);
+       convertIP(daddr, rttKey->daddr);
+
+       cwd= changeToGraphDir(graphsDir);
+
+       for (i= 0; i < sizeof(loopValues) / sizeof(*loopValues); i++)
        {
-               analysisData->graphs->ttPoints[i]= malloc(syncState->traceNb *
-                       sizeof(FILE*));
-               analysisData->graphs->ttBinsArray[i]= malloc(syncState->traceNb *
-                       sizeof(uint32_t*));
-               analysisData->graphs->ttBinsTotal[i]= calloc(syncState->traceNb,
-                       sizeof(uint32_t));
-               for (j= 0; j < syncState->traceNb; j++)
+               retval= snprintf(name, sizeof(name), loopValues[i].fileName,
+                       loopValues[i].host1, loopValues[i].host2);
+               if (retval > sizeof(name) - 1)
                {
-                       if (i != j)
-                       {
-                               retval= snprintf(name, sizeof(name),
-                                       "analysis_eval_tt-%03u_to_%03u.data", i, j);
-                               if (retval > sizeof(name) - 1)
-                               {
-                                       name[sizeof(name) - 1]= '\0';
-                               }
-                               if ((analysisData->graphs->ttPoints[i][j]= fopen(name, "w")) ==
-                                       NULL)
-                               {
-                                       g_error(strerror(errno));
-                               }
-
-                               analysisData->graphs->ttBinsArray[i][j]= calloc(binNb,
-                                       sizeof(uint32_t));
-                       }
+                       name[sizeof(name) - 1]= '\0';
                }
-       }
-
-       analysisData->graphs->hrttPoints= malloc(syncState->traceNb *
-               sizeof(FILE**));
-       analysisData->graphs->hrttBinsArray= malloc(syncState->traceNb *
-               sizeof(uint32_t**));
-       analysisData->graphs->hrttBinsTotal= malloc(syncState->traceNb *
-               sizeof(uint32_t*));
-       for (i= 0; i < syncState->traceNb; i++)
-       {
-               analysisData->graphs->hrttPoints[i]= malloc(i * sizeof(FILE*));
-               analysisData->graphs->hrttBinsArray[i]= malloc(i * sizeof(uint32_t*));
-               analysisData->graphs->hrttBinsTotal[i]= calloc(i, sizeof(uint32_t));
-               for (j= 0; j < i; j++)
+               if ((*(FILE**)((void*) graph + loopValues[i].pointsOffset)=
+                               fopen(name, "w")) == NULL)
                {
-                       retval= snprintf(name, sizeof(name),
-                               "analysis_eval_hrtt-%03u_and_%03u.data", i, j);
-                       if (retval > sizeof(name) - 1)
-                       {
-                               name[sizeof(name) - 1]= '\0';
-                       }
-                       if ((analysisData->graphs->hrttPoints[i][j]= fopen(name, "w")) ==
-                               NULL)
-                       {
-                               g_error(strerror(errno));
-                       }
-
-                       analysisData->graphs->hrttBinsArray[i][j]= calloc(binNb,
-                               sizeof(uint32_t));
+                       g_error(strerror(errno));
                }
        }
 
@@ -272,133 +247,154 @@ static void initGraphs(SyncState* const syncState)
                g_error(strerror(errno));
        }
        free(cwd);
+
+       return graph;
 }
 
 
 /*
- * Write histogram points to all files to generate graphs.
+ * Close files used to store histogram points to generate graphs.
  *
  * Args:
- *   syncState:    container for synchronization data
+ *   graphsDir:    folder where to write files
+ *   rttKey:       host pair, make sure saddr < daddr
  */
-static void writeGraphFiles(SyncState* const syncState)
+static void destroyAnalysisGraphEval(AnalysisGraphEval* const graph)
 {
-       unsigned int i, j;
-       AnalysisDataEval* analysisData= syncState->analysisData;
-
-       for (i= 0; i < syncState->traceNb; i++)
+       unsigned int i;
+       int retval;
+       const struct {
+               size_t pointsOffset;
+       } loopValues[]= {
+               {offsetof(AnalysisGraphEval, ttSendPoints)},
+               {offsetof(AnalysisGraphEval, ttRecvPoints)},
+               {offsetof(AnalysisGraphEval, hrttPoints)},
+       };
+
+       for (i= 0; i < sizeof(loopValues) / sizeof(*loopValues); i++)
        {
-               for (j= 0; j < syncState->traceNb; j++)
+               retval= fclose(*(FILE**)((void*) graph + loopValues[i].pointsOffset));
+               if (retval != 0)
                {
-                       if (i != j)
-                       {
-                               dumpBinToFile(analysisData->graphs->ttBinsArray[i][j],
-                                       analysisData->graphs->ttBinsTotal[i][j] -
-                                       analysisData->graphs->ttBinsArray[i][j][binNb - 1],
-                                       analysisData->graphs->ttPoints[i][j]);
-                       }
-
-                       if (i > j)
-                       {
-                               dumpBinToFile(analysisData->graphs->hrttBinsArray[i][j],
-                                       analysisData->graphs->hrttBinsTotal[i][j] -
-                                       analysisData->graphs->hrttBinsArray[i][j][binNb - 1],
-                                       analysisData->graphs->hrttPoints[i][j]);
-                       }
+                       g_error(strerror(errno));
                }
        }
 }
 
 
+/*
+ * A GDestroyNotify function for g_hash_table_new_full()
+ *
+ * Args:
+ *   data:         AnalysisGraphEval*
+ */
+static void gdnDestroyAnalysisGraphEval(gpointer data)
+{
+       destroyAnalysisGraphEval(data);
+}
+
+
+/*
+ * A GHFunc for g_hash_table_foreach()
+ *
+ * Args:
+ *   key:          RttKey* where saddr < daddr
+ *   value:        AnalysisGraphEval*
+ *   user_data     struct WriteGraphInfo*
+ */
+static void ghfWriteGraph(gpointer key, gpointer value, gpointer user_data)
+{
+       double* rtt1, * rtt2;
+       struct RttKey* rttKey= key;
+       struct RttKey oppositeRttKey= {.saddr= rttKey->daddr, .daddr=
+               rttKey->saddr};
+       AnalysisGraphEval* graph= value;
+       struct WriteGraphInfo* info= user_data;
+
+       rtt1= g_hash_table_lookup(info->rttInfo, rttKey);
+       rtt2= g_hash_table_lookup(info->rttInfo, &oppositeRttKey);
+
+       if (rtt1 == NULL)
+       {
+               rtt1= rtt2;
+       }
+       else if (rtt2 != NULL)
+       {
+               rtt1= MIN(rtt1, rtt2);
+       }
+
+       dumpBinToFile(&graph->ttSendBins, graph->ttSendPoints);
+       dumpBinToFile(&graph->ttRecvBins, graph->ttRecvPoints);
+       dumpBinToFile(&graph->hrttBins, graph->hrttPoints);
+       writeHistogram(info->graphsStream, rttKey, rtt1);
+}
+
+
 /*
  * Write the content of one bin in a histogram point file
  *
  * Args:
  *   bin:          array of values that make up a histogram
- *   total:        total number of messages in bins 0 to binNb - 2
- *   file:         FILE*
+ *   file:         FILE*, write to this file
  */
-static void dumpBinToFile(const uint32_t* const bin, const uint32_t total,
-       FILE* const file)
+static void dumpBinToFile(const struct Bins* const bins, FILE* const file)
 {
        unsigned int i;
 
-       // Last bin is skipped because is continues till infinity
-       for (i= 0; i < binNb - 1; i++)
+       // The first and last bins are skipped, see struct Bins
+       for (i= 1; i < BIN_NB - 1; i++)
        {
-               if (bin[i] > 0)
+               if (bins->bin[i] > 0)
                {
-                       fprintf(file, "%20.9f %20.9f %20.9f\n", (binStart(i) + binEnd(i)) / 2, (double) bin[i]
-                               / ((binEnd(i) - binStart(i)) * total), binEnd(i) - binStart(i));
+                       fprintf(file, "%20.9f %20.9f %20.9f\n", (binStart(i) + binEnd(i))
+                               / 2., (double) bins->bin[i] / ((binEnd(i) - binStart(i)) *
+                                       bins->total), binEnd(i) - binStart(i));
                }
        }
 }
 
 
 /*
- * Close files used to store histogram points to generate graphs. Deallocate
- * arrays of file pointers and arrays used to store histogram points during
- * analysis.
+ * Write the analysis-specific plot in the gnuplot script.
  *
  * Args:
- *   syncState:    container for synchronization data
+ *   graphsStream: write to this file
+ *   rttKey:       must be sorted such that saddr < daddr
+ *   minRtt:       if available, else NULL
  */
-static void destroyGraphs(SyncState* const syncState)
+static void writeHistogram(FILE* graphsStream, const struct RttKey* rttKey,
+       double* minRtt)
 {
-       unsigned int i, j;
-       AnalysisDataEval* analysisData= syncState->analysisData;
-       int retval;
+       char saddr[16], daddr[16];
 
-       if (analysisData->graphs == NULL || analysisData->graphs->ttPoints ==
-               NULL)
-       {
-               return;
-       }
-
-       for (i= 0; i < syncState->traceNb; i++)
-       {
-               for (j= 0; j < syncState->traceNb; j++)
-               {
-                       if (i != j)
-                       {
-                               retval= fclose(analysisData->graphs->ttPoints[i][j]);
-                               if (retval != 0)
-                               {
-                                       g_error(strerror(errno));
-                               }
+       convertIP(saddr, rttKey->saddr);
+       convertIP(daddr, rttKey->daddr);
 
-                               free(analysisData->graphs->ttBinsArray[i][j]);
-                       }
-               }
-               free(analysisData->graphs->ttPoints[i]);
-               free(analysisData->graphs->ttBinsArray[i]);
-               free(analysisData->graphs->ttBinsTotal[i]);
-       }
-       free(analysisData->graphs->ttPoints);
-       free(analysisData->graphs->ttBinsArray);
-       free(analysisData->graphs->ttBinsTotal);
+       fprintf(graphsStream,
+               "reset\n"
+               "set output \"histogram-%s-%s.eps\"\n"
+               "set title \"\"\n"
+               "set xlabel \"Message Latency (s)\"\n"
+               "set ylabel \"Proportion of messages per second\"\n", saddr, daddr);
 
-       for (i= 0; i < syncState->traceNb; i++)
+       if (minRtt != NULL)
        {
-               for (j= 0; j < i; j++)
-               {
-                       retval= fclose(analysisData->graphs->hrttPoints[i][j]);
-                       if (retval != 0)
-                       {
-                               g_error(strerror(errno));
-                       }
-
-                       free(analysisData->graphs->hrttBinsArray[i][j]);
-               }
-               free(analysisData->graphs->hrttPoints[i]);
-               free(analysisData->graphs->hrttBinsArray[i]);
-               free(analysisData->graphs->hrttBinsTotal[i]);
+               fprintf(graphsStream,
+                       "set arrow from %.9f, 0 rto 0, graph 1 "
+                       "nohead linetype 3 linewidth 3 linecolor rgb \"black\"\n", *minRtt / 2);
        }
-       free(analysisData->graphs->hrttPoints);
-       free(analysisData->graphs->hrttBinsArray);
-       free(analysisData->graphs->hrttBinsTotal);
 
-       analysisData->graphs->ttPoints= NULL;
+       fprintf(graphsStream,
+               "plot \\\n"
+               "\t\"analysis_eval_hrtt-%1$s_and_%2$s.data\" "
+                       "title \"RTT/2\" with linespoints linetype 1 linewidth 2 "
+                       "linecolor rgb \"black\" pointtype 6 pointsize 1,\\\n"
+               "\t\"analysis_eval_tt-%1$s_to_%2$s.data\" "
+                       "title \"%1$s to %2$s\" with linespoints linetype 4 linewidth 2 "
+                       "linecolor rgb \"gray60\" pointtype 6 pointsize 1,\\\n"
+               "\t\"analysis_eval_tt-%2$s_to_%1$s.data\" "
+                       "title \"%2$s to %1$s\" with linespoints linetype 4 linewidth 2 "
+                       "linecolor rgb \"gray30\" pointtype 6 pointsize 1\n", saddr, daddr);
 }
 
 
@@ -440,8 +436,7 @@ static void destroyAnalysisEval(SyncState* const syncState)
 
        if (syncState->graphsStream && analysisData->graphs)
        {
-               destroyGraphs(syncState);
-               free(analysisData->graphs);
+               g_hash_table_destroy(analysisData->graphs);
        }
 
        free(syncState->analysisData);
@@ -460,8 +455,9 @@ static void destroyAnalysisEval(SyncState* const syncState)
  */
 static void analyzeMessageEval(SyncState* const syncState, Message* const message)
 {
-       AnalysisDataEval* analysisData;
-       MessageStats* messageStats;
+       AnalysisDataEval* analysisData= syncState->analysisData;
+       MessageStats* messageStats=
+               &analysisData->stats->messageStats[message->outE->traceNum][message->inE->traceNum];;
        double* rtt;
        double tt;
        struct RttKey rttKey;
@@ -471,9 +467,7 @@ static void analyzeMessageEval(SyncState* const syncState, Message* const messag
                return;
        }
 
-       analysisData= (AnalysisDataEval*) syncState->analysisData;
-       messageStats=
-               &analysisData->stats->messageStats[message->outE->traceNum][message->inE->traceNum];
+       g_assert(message->inE->type == TCP);
 
        messageStats->total++;
 
@@ -484,11 +478,35 @@ static void analyzeMessageEval(SyncState* const syncState, Message* const messag
        }
        else if (syncState->graphsStream)
        {
-               analysisData->graphs->ttBinsArray[message->outE->traceNum][message->inE->traceNum][binNum(tt)]++;
-               analysisData->graphs->ttBinsTotal[message->outE->traceNum][message->inE->traceNum]++;
+               struct RttKey rttKey= {
+                       .saddr=MIN(message->inE->event.tcpEvent->segmentKey->connectionKey.saddr,
+                               message->inE->event.tcpEvent->segmentKey->connectionKey.daddr),
+                       .daddr=MAX(message->inE->event.tcpEvent->segmentKey->connectionKey.saddr,
+                               message->inE->event.tcpEvent->segmentKey->connectionKey.daddr),
+               };
+               AnalysisGraphEval* graph= g_hash_table_lookup(analysisData->graphs,
+                       &rttKey);
+
+               if (graph == NULL)
+               {
+                       struct RttKey* tableKey= malloc(sizeof(*tableKey));
+
+                       graph= constructAnalysisGraphEval(syncState->graphsDir, &rttKey);
+                       memcpy(tableKey, &rttKey, sizeof(*tableKey));
+                       g_hash_table_insert(analysisData->graphs, tableKey, graph);
+               }
+
+               if (message->inE->event.udpEvent->datagramKey->saddr <
+                       message->inE->event.udpEvent->datagramKey->daddr)
+               {
+                       hitBin(&graph->ttSendBins, tt);
+               }
+               else
+               {
+                       hitBin(&graph->ttRecvBins, tt);
+               }
        }
 
-       g_assert(message->inE->type == TCP);
        rttKey.saddr=
                message->inE->event.tcpEvent->segmentKey->connectionKey.saddr;
        rttKey.daddr=
@@ -534,21 +552,13 @@ static void analyzeExchangeEval(SyncState* const syncState, Exchange* const exch
                return;
        }
 
+       g_assert(m1->inE->type == TCP);
+
        // (T2 - T1) - (T3 - T4)
        rtt= malloc(sizeof(double));
        *rtt= wallTimeSub(&m1->inE->wallTime, &m1->outE->wallTime) -
                wallTimeSub(&m2->outE->wallTime, &m2->inE->wallTime);
 
-       if (syncState->graphsStream)
-       {
-               unsigned int row= MAX(m1->inE->traceNum, m1->outE->traceNum);
-               unsigned int col= MIN(m1->inE->traceNum, m1->outE->traceNum);
-
-               analysisData->graphs->hrttBinsArray[row][col][binNum(*rtt / 2.)]++;
-               analysisData->graphs->hrttBinsTotal[row][col]++;
-       }
-
-       g_assert(m1->inE->type == TCP);
        rttKey= malloc(sizeof(struct RttKey));
        rttKey->saddr=
                MIN(m1->inE->event.tcpEvent->segmentKey->connectionKey.saddr,
@@ -556,6 +566,24 @@ static void analyzeExchangeEval(SyncState* const syncState, Exchange* const exch
        rttKey->daddr=
                MAX(m1->inE->event.tcpEvent->segmentKey->connectionKey.saddr,
                        m1->inE->event.tcpEvent->segmentKey->connectionKey.daddr);
+
+       if (syncState->graphsStream)
+       {
+               AnalysisGraphEval* graph= g_hash_table_lookup(analysisData->graphs,
+                       rttKey);
+
+               if (graph == NULL)
+               {
+                       struct RttKey* tableKey= malloc(sizeof(*tableKey));
+
+                       graph= constructAnalysisGraphEval(syncState->graphsDir, rttKey);
+                       memcpy(tableKey, rttKey, sizeof(*tableKey));
+                       g_hash_table_insert(analysisData->graphs, tableKey, graph);
+               }
+
+               hitBin(&graph->hrttBins, *rtt / 2);
+       }
+
        exchangeRtt= g_hash_table_lookup(analysisData->stats->exchangeRtt,
                rttKey);
 
@@ -629,8 +657,10 @@ static GArray* finalizeAnalysisEval(SyncState* const syncState)
 
        if (syncState->graphsStream && analysisData->graphs)
        {
-               writeGraphFiles(syncState);
-               destroyGraphs(syncState);
+               g_hash_table_foreach(analysisData->graphs, &ghfWriteGraph, &(struct
+                               WriteGraphInfo) {.rttInfo= analysisData->rttInfo,
+                       .graphsStream= syncState->graphsStream});
+               g_hash_table_destroy(analysisData->graphs);
                analysisData->graphs= NULL;
        }
 
@@ -1005,134 +1035,122 @@ static void gfSumSquares(gpointer data, gpointer userData)
 }
 
 
+/*
+ * Update a struct Bins according to a new value
+ *
+ * Args:
+ *   bins:         the structure containing bins to build a histrogram
+ *   value:        the new value
+ */
+static void hitBin(struct Bins* const bins, const double value)
+{
+       unsigned int binN= binNum(value);
+
+       if (binN < bins->min)
+       {
+               bins->min= binN;
+       }
+       else if (binN > bins->max)
+       {
+               bins->max= binN;
+       }
+
+       bins->total++;
+
+       bins->bin[binN]++;
+}
+
+
 /*
  * Figure out the bin in a histogram to which a value belongs.
  *
  * This uses exponentially sized bins that go from 0 to infinity.
  *
  * Args:
- *   value:        the value, must be >=0, or else expect the unexpected
- *                 (floating point exception)
+ *   value:        in the range -INFINITY to INFINITY
+ *
+ * Returns:
+ *   The number of the bin in a struct Bins.bin
  */
 static unsigned int binNum(const double value)
 {
-       if (value == 0)
+       if (value <= 0)
        {
                return 0;
        }
+       else if (value < binEnd(1))
+       {
+               return 1;
+       }
+       else if (value >= binStart(BIN_NB - 1))
+       {
+               return BIN_NB - 1;
+       }
        else
        {
-               double result= floor(log(value) / log(binBase)) + (binNb - 1);
-
-               if (result < 0.)
-               {
-                       return 0.;
-               }
-               else
-               {
-                       return result;
-               }
+               return floor(log(value) / log(binBase)) + BIN_NB + 1;
        }
 }
 
 
 /*
- * Figure out the start of the interval of a bin in a histogram. The starting
- * value is included in the interval.
+ * Figure out the start of the interval of a bin in a histogram. See struct
+ * Bins.
  *
  * This uses exponentially sized bins that go from 0 to infinity.
  *
  * Args:
  *   binNum:       bin number
+ *
+ * Return:
+ *   The start of the interval, this value is included in the interval (except
+ *   for -INFINITY, naturally)
  */
 static double binStart(const unsigned int binNum)
 {
-       g_assert(binNum < binNb);
+       g_assert_cmpuint(binNum, <, BIN_NB);
 
        if (binNum == 0)
        {
-               return 0;
+               return -INFINITY;
+       }
+       else if (binNum == 1)
+       {
+               return 0.;
        }
        else
        {
-               return pow(binBase, (double) binNum - (binNb - 1));
+               return pow(binBase, (double) binNum - BIN_NB + 1);
        }
 }
 
 
 /*
- * Figure out the end of the interval of a bin in a histogram. The end value
- * is not included in the interval.
+ * Figure out the end of the interval of a bin in a histogram. See struct
+ * Bins.
  *
  * This uses exponentially sized bins that go from 0 to infinity.
  *
  * Args:
  *   binNum:       bin number
+ *
+ * Return:
+ *   The end of the interval, this value is not included in the interval
  */
 static double binEnd(const unsigned int binNum)
 {
-       g_assert(binNum < binNb);
+       g_assert_cmpuint(binNum, <, BIN_NB);
 
-       if (binNum < binNb)
+       if (binNum == 0)
        {
-               return pow(binBase, (double) binNum - (binNb - 2));
+               return 0.;
+       }
+       else if (binNum < BIN_NB - 1)
+       {
+               return pow(binBase, (double) binNum - BIN_NB + 2);
        }
        else
        {
                return INFINITY;
        }
 }
-
-
-/*
- * Write the analysis-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 writeAnalysisGraphsPlotsEval(SyncState* const syncState, const
-       unsigned int i, const unsigned int j)
-{
-       fprintf(syncState->graphsStream,
-               "\t\"analysis_eval_hrtt-%2$03d_and_%1$03d.data\" "
-                       "title \"RTT/2\" with boxes linetype 1 linewidth 3 "
-                       "linecolor rgb \"black\" fill transparent solid 0.75, \\\n"
-               /*"\t\"analysis_eval_tt-%1$03d_to_%2$03d.data\" "
-                       "title \"%1$u to %2$u\" with boxes linetype 1 linewidth 3 "
-                       "linecolor rgb \"black\" fill transparent solid 0.5, \\\n"
-               "\t\"analysis_eval_tt-%2$03d_to_%1$03d.data\" "
-                       "title \"%2$u to %1$u\" with boxes linetype 1 linewidth 3 "
-                       "linecolor rgb \"black\" fill transparent solid 0.25, \\\n"*/
-                       , i, j);
-       /*
-       fprintf(syncState->graphsStream,
-               "\t\"analysis_eval_hrtt-%2$03d_and_%1$03d.data\" "
-                       "title \"RTT/2\" with linespoints linetype 1 linewidth 3 "
-                       "linecolor rgb \"black\", \\\n"
-               "\t\"analysis_eval_tt-%1$03d_to_%2$03d.data\" "
-                       "title \"%1$u to %2$u\" with linespoints linetype 1 linewidth 3 "
-                       "linecolor rgb \"gray70\", \\\n"
-               "\t\"analysis_eval_tt-%2$03d_to_%1$03d.data\" "
-                       "title \"%2$u to %1$u\" with linespoints linetype 1 linewidth 3 "
-                       "linecolor rgb \"gray40\", \\\n", i, j);
-*/
-}
-
-
-/*
- * Write the analysis-specific options 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 writeAnalysisGraphsOptionsEval(SyncState* const syncState, const
-       unsigned int i, const unsigned int j)
-{
-       fprintf(syncState->graphsStream,
-               "set xlabel \"Message Latency (s)\"\n"
-               "set ylabel \"Proportion of messages per second\"\n");
-}
index 120bdc67c46a9c12162b9601806fda4ac2c00eb9..d30fb1ef59883bad4d5b8789844909b1bba316dc 100644 (file)
@@ -42,48 +42,51 @@ typedef struct
        double broadcastDiffSum;
        unsigned int broadcastNb;
 
+       // MessageStats messageStats[traceNb][traceNb]
        MessageStats** messageStats;
+
        /* double* exchangeRtt[RttKey]
         * For this table, saddr and daddr are swapped as necessary such that
         * saddr < daddr */
        GHashTable* exchangeRtt;
 } AnalysisStatsEval;
 
+
+#define BIN_NB 1001
+struct Bins
+{
+       // index of min and max bins that are != 0
+       uint32_t min, max;
+       // sum of all bins
+       uint32_t total;
+       /* bin[0]: underflow ]-INFINITY..0[
+        * bin[1]: [0..1e-6[
+        * rest defined exponentially, see binStart()
+        * bin[BIN_NB - 1]: overflow [1..INFINITY[ */
+       uint32_t bin[BIN_NB];
+};
+
+
 typedef struct
 {
-       /* FILE* ttPoints[row][col] where
-        *   row= outE->traceNum
-        *   col= inE->traceNum
-        *
-        * This array contains file pointers to files where "trip times" (message
-        * latency) histogram values are outputted. Each trace-pair has two files,
-        * one for each message direction. The elements on the diagonal are not
-        * initialized.
-        */
-       FILE*** ttPoints;
-
-       // uint32_t ttBinsArray[row][col][binNum];
-       // Row and col have the same structure as ttPoints
-       uint32_t*** ttBinsArray;
-       // uint32_t ttBinsTotal[row][col];
-       // Row and col have the same structure as ttPoints
-       uint32_t** ttBinsTotal;
-
-       /* FILE* hrttPoints[traceNum][traceNum] where
-        *   row > col, other elements are not initialized
-        *
-        * This array contains file pointers to files where half round trip times
-        * (evaluated from exchanges) histogram values are outputted.
-        */
-       FILE*** hrttPoints;
-
-       // uint32_t hrttBinsArray[row][col][binNum];
-       // Row and col have the same structure as hrttPoints
-       uint32_t*** hrttBinsArray;
-       // uint32_t hrttBinsTotal[row][col];
-       // Row and col have the same structure as hrttPoints
-       uint32_t** hrttBinsTotal;
-} AnalysisGraphsEval;
+        /* File pointers to files where "trip times" (message latency) histogram
+         * values are outputted. Each host-pair has two files, one for each
+         * message direction. As for traces, the host with the smallest address
+         * is considered to be the reference for the direction of messages (ie.
+         * messages from the host with the lowest address to the host with the
+         * largest address are "sent"). */
+       FILE* ttSendPoints;
+       FILE* ttRecvPoints;
+
+       struct Bins ttSendBins;
+       struct Bins ttRecvBins;
+
+       /* File pointers to files where half round trip times (evaluated from
+        * exchanges) histogram values are outputted. */
+       FILE* hrttPoints;
+
+       struct Bins hrttBins;
+} AnalysisGraphEval;
 
 typedef struct
 {
@@ -91,7 +94,10 @@ typedef struct
        GHashTable* rttInfo;
 
        AnalysisStatsEval* stats;
-       AnalysisGraphsEval* graphs;
+       /* AnalysisGraphsEval* graphs[RttKey];
+        * For this table, saddr and daddr are swapped as necessary such that
+        * saddr < daddr */
+       GHashTable* graphs;
 } AnalysisDataEval;
 
 #endif
index 4523ec530ec5e7b00a46200decfd959194643ba0..2735f22f22de9f8fc93937478619def45be0380d 100644 (file)
@@ -356,8 +356,10 @@ void gfGraphFunctionCall(gpointer data, gpointer user_data)
 {
        SyncState* parallelSS= data;
        struct GraphAggregate* aggregate= user_data;
-       void (*graphFunction)(struct _SyncState*, const unsigned int, const
-               unsigned int)= (void*) data + (size_t) aggregate->offset;
+       typedef void (*GraphFunction)(struct _SyncState*, const unsigned int,
+               const unsigned int);
+       GraphFunction graphFunction= *(GraphFunction*)((void*)
+               parallelSS->matchingModule + (size_t) aggregate->offset);
 
        if (graphFunction != NULL)
        {
index 48a2be5884eb695d6e467e3106be63ff57621e59..4a70154884a63a59ac703abecc95dca5753a6c76 100644 (file)
@@ -218,6 +218,10 @@ void syncTraceset(LttvTracesetContext* const traceSetContext)
                        g_error(strerror(errno));
                }
 
+               fprintf(syncState->graphsStream,
+                       "#!/usr/bin/gnuplot\n\n"
+                       "set terminal postscript eps color size 8in,6in\n");
+
                retval= chdir(cwd);
                if (retval == -1)
                {
@@ -281,10 +285,6 @@ void syncTraceset(LttvTracesetContext* const traceSetContext)
        // Write graphs file
        if (optionSyncGraphs.present)
        {
-               fprintf(syncState->graphsStream,
-                       "#!/usr/bin/gnuplot\n\n"
-                       "set terminal postscript eps color size 8in,6in\n");
-
                // Cover the upper triangular matrix, i is the reference node.
                for (i= 0; i < syncState->traceNb; i++)
                {
@@ -293,7 +293,8 @@ void syncTraceset(LttvTracesetContext* const traceSetContext)
                                long pos1, pos2, trunc;
 
                                fprintf(syncState->graphsStream,
-                                       "\nset output \"%03d-%03d.eps\"\n"
+                                       "\nreset\n"
+                                       "set output \"%03d-%03d.eps\"\n"
                                        "plot \\\n", i, j);
 
                                if (syncState->processingModule->writeProcessingGraphsPlots)
index 86d4a2aa710c7794e68029b4a52aff0de07d3f1e..8ac77fd9fb2188ddcc6c592d5a7b6fa46cbd04e3 100644 (file)
@@ -314,6 +314,10 @@ void setupSyncChain(LttvTracesetContext* const traceSetContext)
                        g_error(strerror(errno));
                }
 
+               fprintf(syncState->graphsStream,
+                       "#!/usr/bin/gnuplot\n\n"
+                       "set terminal postscript eps color size 8in,6in\n");
+
                retval= chdir(cwd);
                if (retval == -1)
                {
@@ -370,10 +374,6 @@ void teardownSyncChain(LttvTracesetContext* const traceSetContext)
        // Write graphs file
        if (optionEvalGraphs)
        {
-               fprintf(syncState->graphsStream,
-                       "#!/usr/bin/gnuplot\n\n"
-                       "set terminal postscript eps color size 8in,6in\n");
-
                // Cover the upper triangular matrix, i is the reference node.
                for (i= 0; i < syncState->traceNb; i++)
                {
@@ -382,10 +382,21 @@ void teardownSyncChain(LttvTracesetContext* const traceSetContext)
                                long pos1, pos2, trunc;
 
                                fprintf(syncState->graphsStream,
-                                       "\nset output \"%03d-%03d.eps\"\n"
+                                       "\nreset\n"
+                                       "set output \"%03d-%03d.eps\"\n"
                                        "plot \\\n", i, j);
                                pos1= ftell(syncState->graphsStream);
 
+                               if (syncState->processingModule->writeProcessingGraphsPlots)
+                               {
+                                       syncState->processingModule->writeProcessingGraphsPlots(syncState,
+                                               i, j);
+                               }
+                               if (syncState->matchingModule->writeMatchingGraphsPlots)
+                               {
+                                       syncState->matchingModule->writeMatchingGraphsPlots(syncState,
+                                               i, j);
+                               }
                                if (syncState->analysisModule->writeAnalysisGraphsPlots)
                                {
                                        syncState->analysisModule->writeAnalysisGraphsPlots(syncState,
@@ -419,6 +430,16 @@ void teardownSyncChain(LttvTracesetContext* const traceSetContext)
                                        "\nset output \"%1$03d-%2$03d.eps\"\n"
                                        "set title \"\"\n", i, j);
 
+                               if (syncState->processingModule->writeProcessingGraphsOptions)
+                               {
+                                       syncState->processingModule->writeProcessingGraphsOptions(syncState,
+                                               i, j);
+                               }
+                               if (syncState->matchingModule->writeMatchingGraphsOptions)
+                               {
+                                       syncState->matchingModule->writeMatchingGraphsOptions(syncState,
+                                               i, j);
+                               }
                                if (syncState->analysisModule->writeAnalysisGraphsOptions)
                                {
                                        syncState->analysisModule->writeAnalysisGraphsOptions(syncState,
This page took 0.035621 seconds and 4 git commands to generate.