+
+
+/*
+ * Create and open files used to store message points to genereate
+ * graphs. Allocate and populate array to store file pointers.
+ *
+ * Args:
+ * syncState: container for synchronization data
+ */
+static void openGraphDataFiles(SyncState* const syncState)
+{
+ unsigned int i, j;
+ int retval;
+ char* cwd;
+ char name[29];
+ MatchingDataTCP* matchingData;
+
+ matchingData= (MatchingDataTCP*) syncState->matchingData;
+
+ cwd= changeToGraphsDir(syncState->graphsDir);
+
+ matchingData->messagePoints= malloc(syncState->traceNb * sizeof(FILE**));
+ for (i= 0; i < syncState->traceNb; i++)
+ {
+ matchingData->messagePoints[i]= malloc(syncState->traceNb *
+ sizeof(FILE*));
+ for (j= 0; j < syncState->traceNb; j++)
+ {
+ if (i != j)
+ {
+ retval= snprintf(name, sizeof(name),
+ "matching_tcp-%03u_to_%03u.data", j, i);
+ if (retval > sizeof(name) - 1)
+ {
+ name[sizeof(name) - 1]= '\0';
+ }
+ if ((matchingData->messagePoints[i][j]= fopen(name, "w")) ==
+ NULL)
+ {
+ g_error(strerror(errno));
+ }
+ }
+ }
+ }
+
+ retval= chdir(cwd);
+ if (retval == -1)
+ {
+ g_error(strerror(errno));
+ }
+ free(cwd);
+}
+
+
+/*
+ * Write a message point to a file used to generate graphs
+ *
+ * Args:
+ * stream: FILE*, file pointer where to write the point
+ * message: message for which to write the point
+ */
+static void writeMessagePoint(FILE* stream, const Message* const message)
+{
+ uint64_t x, y;
+
+ if (message->inE->traceNum < message->outE->traceNum)
+ {
+ // CA is inE->traceNum
+ x= message->inE->cpuTime;
+ y= message->outE->cpuTime;
+ }
+ else
+ {
+ // CA is outE->traceNum
+ x= message->outE->cpuTime;
+ y= message->inE->cpuTime;
+ }
+
+ fprintf(stream, "%20" PRIu64 " %20" PRIu64 "\n", x, y);
+}
+
+
+/*
+ * Close files used to store convex hull points to genereate graphs.
+ * Deallocate array to store file pointers.
+ *
+ * Args:
+ * syncState: container for synchronization data
+ */
+static void closeGraphDataFiles(SyncState* const syncState)
+{
+ unsigned int i, j;
+ MatchingDataTCP* matchingData;
+ int retval;
+
+ matchingData= (MatchingDataTCP*) syncState->matchingData;
+
+ if (matchingData->messagePoints == NULL)
+ {
+ return;
+ }
+
+ for (i= 0; i < syncState->traceNb; i++)
+ {
+ for (j= 0; j < syncState->traceNb; j++)
+ {
+ if (i != j)
+ {
+ retval= fclose(matchingData->messagePoints[i][j]);
+ if (retval != 0)
+ {
+ g_error(strerror(errno));
+ }
+ }
+ }
+ free(matchingData->messagePoints[i]);
+ }
+ free(matchingData->messagePoints);
+
+ matchingData->messagePoints= 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 writeMatchingGraphsPlotsTCPMessages(SyncState* const syncState,
+ const unsigned int i, const unsigned int j)
+{
+ fprintf(syncState->graphsStream,
+ "\t\"matching_tcp-%1$03d_to_%2$03d.data\" "
+ "title \"Sent messages\" with points linetype 4 "
+ "linecolor rgb \"#98fc66\" pointtype 9 pointsize 2, \\\n"
+ "\t\"matching_tcp-%2$03d_to_%1$03d.data\" "
+ "title \"Received messages\" with points linetype 4 "
+ "linecolor rgb \"#6699cc\" pointtype 11 pointsize 2, \\\n", i, j);
+}