Set the correction factors in the sync_chain
[lttv.git] / lttv / lttv / sync / event_analysis_linreg.c
index 10dc8d78de9af947d6fb2c06dd057f14a9b9e11e..bda898740f4cf8d7ccb965e97fee3e0a46bc2f35 100644 (file)
@@ -1,19 +1,18 @@
 /* This file is part of the Linux Trace Toolkit viewer
- * Copyright (C) 2009 Benjamin Poirier <benjamin.poirier@polymtl.ca>
+ * Copyright (C) 2009, 2010 Benjamin Poirier <benjamin.poirier@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License Version 2 as
- * published by the Free Software Foundation;
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at
+ * your option) any later version.
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- * MA 02111-1307, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 // for INFINITY in math.h
 #include <stdio.h>
 #include <stdlib.h>
 
-#include "sync_chain_lttv.h"
+#include "sync_chain.h"
 
 #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);
@@ -44,12 +38,10 @@ static void destroyAnalysisLinReg(SyncState* const syncState);
 static void analyzeExchangeLinReg(SyncState* const syncState, Exchange* const exchange);
 static GArray* finalizeAnalysisLinReg(SyncState* const syncState);
 static void printAnalysisStatsLinReg(SyncState* const syncState);
-static void writeAnalysisGraphsPlotsLinReg(FILE* stream, SyncState* const
-       syncState, const unsigned int i, const unsigned int j);
+static void writeAnalysisGraphsPlotsLinReg(SyncState* const syncState, const
+       unsigned int i, const unsigned int j);
 
 // Functions specific to this module
-static void registerAnalysisLinReg() __attribute__((constructor (102)));
-
 static void finalizeLSA(SyncState* const syncState);
 static void doGraphProcessing(SyncState* const syncState);
 static GArray* calculateFactors(SyncState* const syncState);
@@ -71,20 +63,19 @@ static AnalysisModule analysisModuleLinReg= {
        .name= "linreg",
        .initAnalysis= &initAnalysisLinReg,
        .destroyAnalysis= &destroyAnalysisLinReg,
-       .analyzeMessage= NULL,
        .analyzeExchange= &analyzeExchangeLinReg,
-       .analyzeBroadcast= NULL,
        .finalizeAnalysis= &finalizeAnalysisLinReg,
        .printAnalysisStats= &printAnalysisStatsLinReg,
-       .writeAnalysisGraphsPlots= &writeAnalysisGraphsPlotsLinReg,
-       .writeAnalysisGraphsOptions= NULL,
+       .graphFunctions= {
+               .writeTraceTraceForePlots= &writeAnalysisGraphsPlotsLinReg,
+       }
 };
 
 
 /*
  * Analysis module registering function
  */
-static void registerAnalysisLinReg()
+void registerAnalysisLinReg()
 {
        g_queue_push_tail(&analysisModules, &analysisModuleLinReg);
 }
@@ -184,8 +175,8 @@ static void analyzeExchangeLinReg(SyncState* const syncState, Exchange* const ex
        Message* ackedMessage;
        AnalysisDataLinReg* analysisData;
 
-       g_debug("Synchronization calculation, ");
-       g_debug("%d acked packets - using last one, ",
+       g_debug("Synchronization calculation, "
+               "%d acked packets - using last one,",
                g_queue_get_length(exchange->acks));
 
        analysisData= (AnalysisDataLinReg*) syncState->analysisData;
@@ -193,14 +184,14 @@ static void analyzeExchangeLinReg(SyncState* const syncState, Exchange* const ex
 
        // Calculate the intermediate values for the
        // least-squares analysis
-       dji= ((double) ackedMessage->inE->time - (double) ackedMessage->outE->time
-               + (double) exchange->message->outE->time - (double)
-               exchange->message->inE->time) / 2;
-       eji= fabs((double) ackedMessage->inE->time - (double)
-               ackedMessage->outE->time - (double) exchange->message->outE->time +
-               (double) exchange->message->inE->time) / 2;
-       timoy= ((double) ackedMessage->outE->time + (double)
-               exchange->message->inE->time) / 2;
+       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];
@@ -363,11 +354,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));
                        }
                }
@@ -404,7 +395,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);
 
@@ -412,12 +403,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);
@@ -427,11 +417,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("new reference");
                                graph->errorSum= errorSum;
                                free(graph->previousVertex);
                                graph->previousVertex= previousVertex;
@@ -444,7 +434,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;
@@ -548,7 +538,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;
@@ -566,7 +556,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++)
        {
@@ -583,7 +572,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)
                {
@@ -611,7 +600,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);
@@ -745,13 +733,12 @@ static gint gcfGraphTraceCompare(gconstpointer a, gconstpointer b)
  * Write the analysis-specific graph lines in the gnuplot script.
  *
  * Args:
- *   stream:       stream where to write the data
  *   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(FILE* stream, SyncState* const syncState,
-       const unsigned int i, const unsigned int j)
+void writeAnalysisGraphsPlotsLinReg(SyncState* const syncState, const unsigned
+       int i, const unsigned int j)
 {
        AnalysisDataLinReg* analysisData;
        Fit* fit;
@@ -759,7 +746,7 @@ void writeAnalysisGraphsPlotsLinReg(FILE* stream, SyncState* const syncState,
        analysisData= (AnalysisDataLinReg*) syncState->analysisData;
        fit= &analysisData->fitArray[j][i];
 
-       fprintf(stream,
+       fprintf(syncState->graphsStream,
                "\t%7g + %7g * x "
                "title \"Linreg conversion\" with lines "
                "linecolor rgb \"gray60\" linetype 1, \\\n",
This page took 0.0273 seconds and 4 git commands to generate.