Move some functions around to improve overall structure
[lttv.git] / lttv / modules / text / sync_chain_batch.c
index 731720c840d24414fd9ea8c325b07492f84476e9..c88b13c5962623fdf3491829d9e1c0bf4f91ae8a 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;
@@ -124,7 +123,7 @@ static void init()
                "synchronization points", "none", LTTV_OPT_NONE, &optionEvalGraphs,
                NULL, NULL);
 
-       retval= snprintf(graphsDir, sizeof(graphsDir), "graphs-%d", getpid());
+       retval= snprintf(graphsDir, sizeof(graphsDir), "eval-graphs-%d", getpid());
        if (retval > sizeof(graphsDir) - 1)
        {
                graphsDir[sizeof(graphsDir) - 1]= '\0';
@@ -296,60 +295,34 @@ void setupSyncChain(LttvTracesetContext* const traceSetContext)
 
        if (optionEvalGraphs)
        {
-               syncState->graphs= optionEvalGraphsDir;
+               // Create the graph directory right away in case the module initialization
+               // functions have something to write in it.
+               syncState->graphsDir= optionEvalGraphsDir;
+               syncState->graphsStream= createGraphsDir(syncState->graphsDir);
        }
        else
        {
-               syncState->graphs= NULL;
+               syncState->graphsStream= NULL;
+               syncState->graphsDir= NULL;
        }
 
-       syncState->processingData= NULL;
-       result= g_queue_find_custom(&processingModules, "LTTV-standard",
-               &gcfCompareProcessing);
-       syncState->processingModule= (ProcessingModule*) result->data;
-
-       tracesetChainState->graphsStream= NULL;
-       if (syncState->graphs &&
-               syncState->processingModule->writeProcessingGraphsPlots != NULL)
-       {
-               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);
-
-               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
-                               | S_IWOTH | S_IXOTH)) == -1)
-               {
-                       g_error(strerror(errno));
-               }
-               if ((tracesetChainState->graphsStream= fdopen(graphsFp, "w")) == NULL)
-               {
-                       g_error(strerror(errno));
-               }
-
-               retval= chdir(cwd);
-               if (retval == -1)
-               {
-                       g_error(strerror(errno));
-               }
-               free(cwd);
-       }
-
-       syncState->matchingData= NULL;
-       result= g_queue_find_custom(&matchingModules, "broadcast", &gcfCompareMatching);
-       syncState->matchingModule= (MatchingModule*) result->data;
-
        syncState->analysisData= NULL;
        result= g_queue_find_custom(&analysisModules, "eval",
                &gcfCompareAnalysis);
        syncState->analysisModule= (AnalysisModule*) result->data;
+       syncState->analysisModule->initAnalysis(syncState);
 
-       syncState->processingModule->initProcessing(syncState, traceSetContext);
+       syncState->matchingData= NULL;
+       result= g_queue_find_custom(&matchingModules, "distributor",
+               &gcfCompareMatching);
+       syncState->matchingModule= (MatchingModule*) result->data;
        syncState->matchingModule->initMatching(syncState);
-       syncState->analysisModule->initAnalysis(syncState);
+
+       syncState->processingData= NULL;
+       result= g_queue_find_custom(&processingModules, "LTTV-standard",
+               &gcfCompareProcessing);
+       syncState->processingModule= (ProcessingModule*) result->data;
+       syncState->processingModule->initProcessing(syncState, traceSetContext);
 }
 
 
@@ -365,6 +338,7 @@ void teardownSyncChain(LttvTracesetContext* const traceSetContext)
        SyncState* syncState;
        struct timeval endTime;
        struct rusage endUsage;
+       unsigned int i, j;
        int retval;
 
        tracesetChainState= g_hash_table_lookup(tracesetChainStates, traceSetContext);
@@ -373,58 +347,11 @@ void teardownSyncChain(LttvTracesetContext* const traceSetContext)
        syncState->processingModule->finalizeProcessing(syncState);
 
        // Write graphs file
-       if (tracesetChainState->graphsStream != NULL)
+       if (optionEvalGraphs)
        {
-               unsigned int i, j;
-
-               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 pos;
-
-                               fprintf(tracesetChainState->graphsStream,
-                                       "\nset output \"%03d-%03d.eps\"\n"
-                                       "plot \\\n", i, j);
-
-                               syncState->processingModule->writeProcessingGraphsPlots(tracesetChainState->graphsStream,
-                                       syncState, i, j);
-
-                               // Remove the ", \\\n" from the last graph plot line
-                               fflush(tracesetChainState->graphsStream);
-                               pos= ftell(tracesetChainState->graphsStream);
-                               if (ftruncate(fileno(tracesetChainState->graphsStream), pos - 4) == -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 key inside right bottom\n"
-                                       "set title \"\"\n"
-                                       "set xlabel \"Clock %1$u\"\n"
-                                       "set xtics nomirror\n"
-                                       "set ylabel \"Clock %2$u\"\n"
-                                       "set ytics nomirror\n", i, j);
-
-                               syncState->processingModule->writeProcessingGraphsOptions(tracesetChainState->graphsStream,
-                                       syncState, i, j);
-
-                               fprintf(tracesetChainState->graphsStream,
-                                       "replot\n");
-                       }
-               }
+               writeGraphsScript(syncState);
 
-               if (fclose(tracesetChainState->graphsStream) != 0)
+               if (fclose(syncState->graphsStream) != 0)
                {
                        g_error(strerror(errno));
                }
@@ -434,6 +361,27 @@ void teardownSyncChain(LttvTracesetContext* const traceSetContext)
        {
                syncState->processingModule->printProcessingStats(syncState);
        }
+       if (syncState->matchingModule->printMatchingStats != NULL)
+       {
+               syncState->matchingModule->printMatchingStats(syncState);
+       }
+       if (syncState->analysisModule->printAnalysisStats != NULL)
+       {
+               syncState->analysisModule->printAnalysisStats(syncState);
+       }
+
+       printf("Resulting synchronization factors:\n");
+    for (i= 0; i < syncState->traceNb; i++)
+    {
+        LttTrace* t;
+
+        t= traceSetContext->traces[i]->t;
+
+        printf("\ttrace %u drift= %g offset= %g (%f) start time= %ld.%09ld\n",
+            i, t->drift, t->offset, (double) tsc_to_uint64(t->freq_scale,
+                t->start_freq, t->offset) / NANOSECONDS_PER_SECOND,
+            t->start_time_from_tsc.tv_sec, t->start_time_from_tsc.tv_nsec);
+    }
 
        syncState->processingModule->destroyProcessing(syncState);
        if (syncState->matchingModule != NULL)
This page took 0.031367 seconds and 4 git commands to generate.