Do not use __attribute__((constructor))
[lttv.git] / lttv / lttv / sync / event_analysis_linreg.c
index 8a7bd22777b977708e8065797e9f480fcd62c7c9..7011f96fb55aac14251553b8b228493e3ed11c18 100644 (file)
 #include "event_analysis_linreg.h"
 
 
-#ifndef g_info
-#define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
-#endif
-
-
 // Functions common to all analysis modules
 static void initAnalysisLinReg(SyncState* const syncState);
 static void destroyAnalysisLinReg(SyncState* const syncState);
 
-static void analyzeExchangeLinReg(SyncState* const syncState, Packet* const packet);
+static void analyzeExchangeLinReg(SyncState* const syncState, Exchange* const exchange);
 static GArray* finalizeAnalysisLinReg(SyncState* const syncState);
 static void printAnalysisStatsLinReg(SyncState* const syncState);
+static void writeAnalysisGraphsPlotsLinReg(SyncState* const syncState, const
+       unsigned int i, const unsigned int j);
 
 // Functions specific to this module
-static void registerAnalysisLinReg() __attribute__((constructor (101)));
-
 static void finalizeLSA(SyncState* const syncState);
 static void doGraphProcessing(SyncState* const syncState);
 static GArray* calculateFactors(SyncState* const syncState);
@@ -69,17 +64,19 @@ static AnalysisModule analysisModuleLinReg= {
        .name= "linreg",
        .initAnalysis= &initAnalysisLinReg,
        .destroyAnalysis= &destroyAnalysisLinReg,
-       .analyzePacket= NULL,
        .analyzeExchange= &analyzeExchangeLinReg,
        .finalizeAnalysis= &finalizeAnalysisLinReg,
        .printAnalysisStats= &printAnalysisStatsLinReg,
+       .graphFunctions= {
+               .writeTraceTraceForePlots= &writeAnalysisGraphsPlotsLinReg,
+       }
 };
 
 
 /*
  * Analysis module registering function
  */
-static void registerAnalysisLinReg()
+void registerAnalysisLinReg()
 {
        g_queue_push_tail(&analysisModules, &analysisModuleLinReg);
 }
@@ -166,47 +163,38 @@ static void destroyAnalysisLinReg(SyncState* const syncState)
 /*
  * Perform analysis on a series of event pairs.
  *
- * If one event pair is a packet, an exchange is composed of at least two
- * packets, one in each direction. There should be a non-negative minimum
- * "round trip time" (RTT) between the first and last event of the exchange.
- * This RTT should be as small as possible so these packets should be closely
- * related in time like a data packet and an acknowledgement packet. If the
- * events analyzed are such that the minimum RTT can be zero, there's nothing
- * gained in analyzing exchanges beyond what can already be figured out by
- * analyzing packets.
- *
- * An exchange can also consist of more than two packets, in case one packet
- * single handedly acknowledges many data packets.
- *
  * Args:
  *   syncState     container for synchronization data
- *   packet        structure containing the many events
+ *   exchange      structure containing the many events
  */
-static void analyzeExchangeLinReg(SyncState* const syncState, Packet* const packet)
+static void analyzeExchangeLinReg(SyncState* const syncState, Exchange* const exchange)
 {
        unsigned int ni, nj;
        double dji, eji;
        double timoy;
        Fit* fit;
-       Packet* ackedPacket;
+       Message* ackedMessage;
        AnalysisDataLinReg* analysisData;
 
-       g_debug("Synchronization calculation, ");
-       g_debug("%d acked packets - using last one, ",
-               g_queue_get_length(packet->acks));
+       g_debug("Synchronization calculation, "
+               "%d acked packets - using last one,",
+               g_queue_get_length(exchange->acks));
 
        analysisData= (AnalysisDataLinReg*) syncState->analysisData;
-       ackedPacket= g_queue_peek_tail(packet->acks);
+       ackedMessage= g_queue_peek_tail(exchange->acks);
 
        // Calculate the intermediate values for the
        // least-squares analysis
-       dji= ((double) ackedPacket->inE->tsc - (double) ackedPacket->outE->tsc +
-               (double) packet->outE->tsc - (double) packet->inE->tsc) / 2;
-       eji= fabs((double) ackedPacket->inE->tsc - (double) ackedPacket->outE->tsc
-               - (double) packet->outE->tsc + (double) packet->inE->tsc) / 2;
-       timoy= ((double) ackedPacket->outE->tsc + (double) packet->inE->tsc) / 2;
-       ni= ackedPacket->outE->traceNum;
-       nj= ackedPacket->inE->traceNum;
+       dji= ((double) ackedMessage->inE->cpuTime - (double) ackedMessage->outE->cpuTime
+               + (double) exchange->message->outE->cpuTime - (double)
+               exchange->message->inE->cpuTime) / 2;
+       eji= fabs((double) ackedMessage->inE->cpuTime - (double)
+               ackedMessage->outE->cpuTime - (double) exchange->message->outE->cpuTime +
+               (double) exchange->message->inE->cpuTime) / 2;
+       timoy= ((double) ackedMessage->outE->cpuTime + (double)
+               exchange->message->inE->cpuTime) / 2;
+       ni= ackedMessage->outE->traceNum;
+       nj= ackedMessage->inE->traceNum;
        fit= &analysisData->fitArray[nj][ni];
 
        fit->n++;
@@ -367,11 +355,11 @@ static void finalizeLSA(SyncState* const syncState)
                                                        pow(fit->sd, 2) * fit->st2 - 2 * fit->st * fit->sd
                                                        * fit->std) / delta) / (fit->n - 2));
 
-                               g_debug("[i= %u j= %u]\n", i, j);
-                               g_debug("n= %d st= %g st2= %g sd= %g sd2= %g std= %g\n",
+                               g_debug("[i= %u j= %u]", i, j);
+                               g_debug("n= %d st= %g st2= %g sd= %g sd2= %g std= %g",
                                        fit->n, fit->st, fit->st2, fit->sd, fit->sd2, fit->std);
-                               g_debug("xij= %g d0ij= %g e= %g\n", fit->x, fit->d0, fit->e);
-                               g_debug("(xji= %g d0ji= %g)\n", -fit->x / (1 + fit->x),
+                               g_debug("xij= %g d0ij= %g e= %g", fit->x, fit->d0, fit->e);
+                               g_debug("(xji= %g d0ji= %g)", -fit->x / (1 + fit->x),
                                        -fit->d0 / (1 + fit->x));
                        }
                }
@@ -408,7 +396,7 @@ static void doGraphProcessing(SyncState* const syncState)
                GList* result;
 
                // Perform shortest path search
-               g_debug("shortest path trace %d\ndistances: ", i);
+               g_debug("shortest path trace %ddistances: ", i);
                shortestPath(analysisData->fitArray, i, syncState->traceNb, distances,
                        previousVertex);
 
@@ -416,12 +404,11 @@ static void doGraphProcessing(SyncState* const syncState)
                {
                        g_debug("%g, ", distances[j]);
                }
-               g_debug("\npreviousVertex: ");
+               g_debug("previousVertex: ");
                for (j= 0; j < syncState->traceNb; j++)
                {
                        g_debug("%u, ", previousVertex[j]);
                }
-               g_debug("\n");
 
                // Group in graphs nodes that have exchanges
                errorSum= sumDistances(distances, syncState->traceNb);
@@ -431,11 +418,11 @@ static void doGraphProcessing(SyncState* const syncState)
                {
                        Graph* graph;
 
-                       g_debug("found graph\n");
+                       g_debug("found graph");
                        graph= (Graph*) result->data;
                        if (errorSum < graph->errorSum)
                        {
-                               g_debug("adding to graph\n");
+                               g_debug("adding to graph");
                                graph->errorSum= errorSum;
                                free(graph->previousVertex);
                                graph->previousVertex= previousVertex;
@@ -448,7 +435,7 @@ static void doGraphProcessing(SyncState* const syncState)
                {
                        Graph* newGraph;
 
-                       g_debug("creating new graph\n");
+                       g_debug("creating new graph");
                        newGraph= malloc(sizeof(Graph));
                        newGraph->errorSum= errorSum;
                        newGraph->previousVertex= previousVertex;
@@ -483,6 +470,7 @@ static GArray* calculateFactors(SyncState* const syncState)
        analysisData= (AnalysisDataLinReg*) syncState->analysisData;
        factors= g_array_sized_new(FALSE, FALSE, sizeof(Factors),
                syncState->traceNb);
+       g_array_set_size(factors, syncState->traceNb);
 
        // Calculate the resulting offset and drift between each trace and its
        // reference
@@ -551,7 +539,7 @@ static void shortestPath(Fit* const* const fitArray, const unsigned int
                visited[i]= false;
 
                fit= &fitArray[traceNum][i];
-               g_debug("fitArray[traceNum= %u][i= %u]->n = %u\n", traceNum, i, fit->n);
+               g_debug("fitArray[traceNum= %u][i= %u]->n = %u", traceNum, i, fit->n);
                if (fit->n > 0)
                {
                        distances[i]= fit->e;
@@ -569,7 +557,6 @@ static void shortestPath(Fit* const* const fitArray, const unsigned int
        {
                g_debug("(%d, %u, %g), ", visited[j], previousVertex[j], distances[j]);
        }
-       g_debug("\n");
 
        for (i= 0; i < traceNb - 2; i++)
        {
@@ -586,7 +573,7 @@ static void shortestPath(Fit* const* const fitArray, const unsigned int
                        }
                }
 
-               g_debug("v= %u dvMin= %g\n", v, dvMin);
+               g_debug("v= %u dvMin= %g", v, dvMin);
 
                if (dvMin != INFINITY)
                {
@@ -614,7 +601,6 @@ static void shortestPath(Fit* const* const fitArray, const unsigned int
                {
                        g_debug("(%d, %u, %g), ", visited[j], previousVertex[j], distances[j]);
                }
-               g_debug("\n");
        }
 
        free(visited);
@@ -743,3 +729,27 @@ static gint gcfGraphTraceCompare(gconstpointer a, gconstpointer b)
        }
 }
 
+
+/*
+ * Write the analysis-specific graph lines in the gnuplot script.
+ *
+ * Args:
+ *   syncState:    container for synchronization data
+ *   i:            first trace number, on the x axis
+ *   j:            second trace number, garanteed to be larger than i
+ */
+void writeAnalysisGraphsPlotsLinReg(SyncState* const syncState, const unsigned
+       int i, const unsigned int j)
+{
+       AnalysisDataLinReg* analysisData;
+       Fit* fit;
+
+       analysisData= (AnalysisDataLinReg*) syncState->analysisData;
+       fit= &analysisData->fitArray[j][i];
+
+       fprintf(syncState->graphsStream,
+               "\t%7g + %7g * x "
+               "title \"Linreg conversion\" with lines "
+               "linecolor rgb \"gray60\" linetype 1, \\\n",
+               fit->d0, 1. + fit->x);
+}
This page took 0.026696 seconds and 4 git commands to generate.