+
+ if (syncState->graphs)
+ {
+ binBase= exp10(6. / (binNb - 2));
+ analysisData->graphs= malloc(sizeof(AnalysisGraphsEval));
+ initGraphs(syncState);
+ }
+}
+
+
+/*
+ * 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.
+ *
+ * Args:
+ * syncState: container for synchronization data
+ */
+static void initGraphs(SyncState* const syncState)
+{
+ unsigned int i, j;
+ int retval;
+ char* cwd;
+ char name[36];
+ AnalysisDataEval* analysisData= syncState->analysisData;
+
+ cwd= changeToGraphDir(syncState->graphs);
+
+ 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++)
+ {
+ 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++)
+ {
+ 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));
+ }
+ }
+ }
+
+ 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++)
+ {
+ 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));
+ }
+ }
+
+ retval= chdir(cwd);
+ if (retval == -1)
+ {
+ g_error(strerror(errno));
+ }
+ free(cwd);
+}
+
+
+/*
+ * Write histogram points to all files to generate graphs.
+ *
+ * Args:
+ * syncState: container for synchronization data
+ */
+static void writeGraphFiles(SyncState* const syncState)
+{
+ unsigned int i, j;
+ AnalysisDataEval* analysisData= syncState->analysisData;
+
+ for (i= 0; i < syncState->traceNb; i++)
+ {
+ for (j= 0; j < syncState->traceNb; j++)
+ {
+ 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]);
+ }
+ }
+ }
+}
+
+
+/*
+ * 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*
+ */
+static void dumpBinToFile(const uint32_t* const bin, const uint32_t total,
+ FILE* const file)
+{
+ unsigned int i;
+
+ // Last bin is skipped because is continues till infinity
+ for (i= 0; i < binNb - 1; i++)
+ {
+ if (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));
+ }
+ }
+}
+
+
+/*
+ * Close files used to store histogram points to generate graphs. Deallocate
+ * arrays of file pointers and arrays used to store histogram points during
+ * analysis.
+ *
+ * Args:
+ * syncState: container for synchronization data
+ */
+static void destroyGraphs(SyncState* const syncState)
+{
+ unsigned int i, j;
+ AnalysisDataEval* analysisData= syncState->analysisData;
+ int retval;
+
+ 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));
+ }
+
+ 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);
+
+ for (i= 0; i < syncState->traceNb; i++)
+ {
+ 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]);
+ }
+ free(analysisData->graphs->hrttPoints);
+ free(analysisData->graphs->hrttBinsArray);
+ free(analysisData->graphs->hrttBinsTotal);
+
+ analysisData->graphs->ttPoints= NULL;