Generate graphs of synchronization accuracy
[lttv.git] / lttv / modules / text / sync_chain_batch.c
index b3f873ca76eceeb4719f9022c39e472265c02b8c..55ec91056f6397c1b8e1e997204e072136165946 100644 (file)
@@ -54,7 +54,6 @@ struct TracesetChainState {
        SyncState* syncState;
        struct timeval startTime;
        struct rusage startUsage;
-       FILE* graphsStream;
 };
 
 static LttvHooks* before_traceset, * before_trace, * event_hook, * after_traceset;
@@ -295,23 +294,14 @@ void setupSyncChain(LttvTracesetContext* const traceSetContext)
        syncState->stats= true;
 
        if (optionEvalGraphs)
-       {
-               syncState->graphs= optionEvalGraphsDir;
-       }
-       else
-       {
-               syncState->graphs= NULL;
-       }
-
-       tracesetChainState->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= optionEvalGraphsDir;
+               cwd= changeToGraphDir(optionEvalGraphsDir);
 
                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
@@ -319,11 +309,15 @@ void setupSyncChain(LttvTracesetContext* const traceSetContext)
                {
                        g_error(strerror(errno));
                }
-               if ((tracesetChainState->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)
                {
@@ -331,6 +325,11 @@ void setupSyncChain(LttvTracesetContext* const traceSetContext)
                }
                free(cwd);
        }
+       else
+       {
+               syncState->graphsStream= NULL;
+               syncState->graphsDir= NULL;
+       }
 
        syncState->analysisData= NULL;
        result= g_queue_find_custom(&analysisModules, "eval",
@@ -373,71 +372,11 @@ void teardownSyncChain(LttvTracesetContext* const traceSetContext)
        syncState->processingModule->finalizeProcessing(syncState);
 
        // Write graphs file
-       if (tracesetChainState->graphsStream != NULL)
+       if (optionEvalGraphs)
        {
-               fprintf(tracesetChainState->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(tracesetChainState->graphsStream,
-                                       "\nset output \"%03d-%03d.eps\"\n"
-                                       "plot \\\n", i, j);
-                               pos1= ftell(tracesetChainState->graphsStream);
-
-                               if (syncState->analysisModule->writeAnalysisGraphsPlots)
-                               {
-                                       syncState->analysisModule->writeAnalysisGraphsPlots(tracesetChainState->graphsStream,
-                                               syncState, i, j);
-                               }
-
-                               fflush(tracesetChainState->graphsStream);
-                               pos2= ftell(tracesetChainState->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(tracesetChainState->graphsStream), trunc) == -1)
-                               {
-                                       g_error(strerror(errno));
-                               }
-                               if (fseek(tracesetChainState->graphsStream, 0, SEEK_END) == -1)
-                               {
-                                       g_error(strerror(errno));
-                               }
-
-                               fprintf(tracesetChainState->graphsStream,
-                                       "\nset output \"%1$03d-%2$03d.eps\"\n"
-                                       "set title \"\"\n", i, j);
-
-                               if (syncState->analysisModule->writeAnalysisGraphsOptions)
-                               {
-                                       syncState->analysisModule->writeAnalysisGraphsOptions(tracesetChainState->graphsStream,
-                                               syncState, i, j);
-                               }
-
-                               if (pos1 != pos2)
-                               {
-                                       fprintf(tracesetChainState->graphsStream, "replot\n");
-                               }
-                       }
-               }
+               writeGraphsScript(syncState);
 
-               if (fclose(tracesetChainState->graphsStream) != 0)
+               if (fclose(syncState->graphsStream) != 0)
                {
                        g_error(strerror(errno));
                }
This page took 0.024499 seconds and 4 git commands to generate.