Generate graphs of synchronization accuracy
[lttv.git] / lttv / lttv / sync / sync_chain_lttv.c
index 9b2b8fe26f378ebe0ac4adcb8354b971bbcd9d1a..43963798e5df60585c64f5880b406e2a333bdb3c 100644 (file)
@@ -169,8 +169,7 @@ void syncTraceset(LttvTracesetContext* const traceSetContext)
        struct timeval startTime, endTime;
        struct rusage startUsage, endUsage;
        GList* result;
-       FILE* graphsStream;
-       unsigned int i, j;
+       unsigned int i;
        int retval;
 
        if (!optionSync.present)
@@ -199,23 +198,14 @@ void syncTraceset(LttvTracesetContext* const traceSetContext)
        }
 
        if (optionSyncGraphs.present)
-       {
-               syncState->graphs= optionSyncGraphsDir.arg;
-       }
-       else
-       {
-               syncState->graphs= NULL;
-       }
-
-       graphsStream= NULL;
-       if (syncState->graphs)
        {
                char* cwd;
                int graphsFp;
 
                // Create the graph directory right away in case the module initialization
                // functions have something to write in it.
-               cwd= changeToGraphDir(syncState->graphs);
+               syncState->graphsDir= optionSyncGraphsDir.arg;
+               cwd= changeToGraphDir(optionSyncGraphsDir.arg);
 
                if ((graphsFp= open("graphs.gnu", O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR |
                                S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH
@@ -223,11 +213,15 @@ void syncTraceset(LttvTracesetContext* const traceSetContext)
                {
                        g_error(strerror(errno));
                }
-               if ((graphsStream= fdopen(graphsFp, "w")) == NULL)
+               if ((syncState->graphsStream= fdopen(graphsFp, "w")) == NULL)
                {
                        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)
                {
@@ -235,6 +229,11 @@ void syncTraceset(LttvTracesetContext* const traceSetContext)
                }
                free(cwd);
        }
+       else
+       {
+               syncState->graphsStream= NULL;
+               syncState->graphsDir= NULL;
+       }
 
        // Identify and initialize modules
        syncState->processingData= NULL;
@@ -284,90 +283,11 @@ void syncTraceset(LttvTracesetContext* const traceSetContext)
        syncState->processingModule->finalizeProcessing(syncState);
 
        // Write graphs file
-       if (graphsStream != NULL)
+       if (optionSyncGraphs.present)
        {
-               fprintf(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++)
-               {
-                       for (j= i + 1; j < syncState->traceNb; j++)
-                       {
-                               long pos1, pos2, trunc;
-
-                               fprintf(graphsStream,
-                                       "\nset output \"%03d-%03d.eps\"\n"
-                                       "plot \\\n", i, j);
-
-                               if (syncState->processingModule->writeProcessingGraphsPlots)
-                               {
-                                       syncState->processingModule->writeProcessingGraphsPlots(graphsStream,
-                                               syncState, i, j);
-                               }
-                               if (syncState->matchingModule->writeMatchingGraphsPlots)
-                               {
-                                       syncState->matchingModule->writeMatchingGraphsPlots(graphsStream,
-                                               syncState, i, j);
-                               }
-                               if (syncState->analysisModule->writeAnalysisGraphsPlots)
-                               {
-                                       syncState->analysisModule->writeAnalysisGraphsPlots(graphsStream,
-                                               syncState, i, j);
-                               }
-
-                               fflush(graphsStream);
-                               pos2= ftell(graphsStream);
-                               if (pos1 != pos2)
-                               {
-                                       // Remove the ", \\\n" from the last graph plot line
-                                       trunc= pos2 - 4;
-                               }
-                               else
-                               {
-                                       // Remove the "plot \\\n" line to avoid creating an invalid
-                                       // gnuplot script
-                                       trunc= pos2 - 7;
-                               }
-
-                               if (ftruncate(fileno(graphsStream), trunc) == -1)
-                               {
-                                       g_error(strerror(errno));
-                               }
-                               if (fseek(graphsStream, 0, SEEK_END) == -1)
-                               {
-                                       g_error(strerror(errno));
-                               }
-
-                               fprintf(graphsStream,
-                                       "\nset output \"%03d-%03d.eps\"\n"
-                                       "set title \"\"\n", i, j);
-
-                               if (syncState->processingModule->writeProcessingGraphsOptions)
-                               {
-                                       syncState->processingModule->writeProcessingGraphsOptions(graphsStream,
-                                               syncState, i, j);
-                               }
-                               if (syncState->matchingModule->writeMatchingGraphsOptions)
-                               {
-                                       syncState->matchingModule->writeMatchingGraphsOptions(graphsStream,
-                                               syncState, i, j);
-                               }
-                               if (syncState->analysisModule->writeAnalysisGraphsOptions)
-                               {
-                                       syncState->analysisModule->writeAnalysisGraphsOptions(graphsStream,
-                                               syncState, i, j);
-                               }
-
-                               if (pos1 != pos2)
-                               {
-                                       fprintf(graphsStream, "replot\n");
-                               }
-                       }
-               }
+               writeGraphsScript(syncState);
 
-               if (fclose(graphsStream) != 0)
+               if (fclose(syncState->graphsStream) != 0)
                {
                        g_error(strerror(errno));
                }
This page took 0.024478 seconds and 4 git commands to generate.