Perform factor reduction as a modular step
[lttv.git] / lttv / lttv / sync / event_matching_distributor.c
index 9eeaff7c441f0b9abff9038f600836097f0d7672..5df7cd4116641f7687d73ddf97da7d326e8007e6 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/>.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -52,20 +51,22 @@ static void destroyMatchingDistributor(SyncState* const syncState);
 
 static void matchEventDistributor(SyncState* const syncState, Event* const
        event);
-static GArray* finalizeMatchingDistributor(SyncState* const syncState);
+static AllFactors* finalizeMatchingDistributor(SyncState* const syncState);
 static void printMatchingStatsDistributor(SyncState* const syncState);
-static void writeMatchingTraceTracePlotsDistributor(SyncState* const
+static void writeMatchingTraceTraceForePlotsDistributor(SyncState* const
+       syncState, const unsigned int i, const unsigned int j);
+static void writeMatchingTraceTraceBackPlotsDistributor(SyncState* const
        syncState, const unsigned int i, const unsigned int j);
 static void writeMatchingTraceTraceOptionsDistributor(SyncState* const
        syncState, const unsigned int i, const unsigned int j);
-static void writeMatchingTraceTimePlotsDistributor(SyncState* const
+static void writeMatchingTraceTimeForePlotsDistributor(SyncState* const
+       syncState, const unsigned int i, const unsigned int j);
+static void writeMatchingTraceTimeBackPlotsDistributor(SyncState* const
        syncState, const unsigned int i, const unsigned int j);
 static void writeMatchingTraceTimeOptionsDistributor(SyncState* const
        syncState, const unsigned int i, const unsigned int j);
 
 // Functions specific to this module
-static void registerMatchingDistributor() __attribute__((constructor (101)));
-
 void gfInitModule(gpointer data, gpointer user_data);
 void gfDestroyModule(gpointer data, gpointer user_data);
 void gfMatchEvent(gpointer data, gpointer user_data);
@@ -84,9 +85,13 @@ static MatchingModule matchingModuleDistributor = {
        .finalizeMatching= &finalizeMatchingDistributor,
        .printMatchingStats= &printMatchingStatsDistributor,
        .graphFunctions= {
-               .writeTraceTracePlots= &writeMatchingTraceTracePlotsDistributor,
+               .writeTraceTraceForePlots=
+                       &writeMatchingTraceTraceForePlotsDistributor,
+               .writeTraceTraceBackPlots=
+                       &writeMatchingTraceTraceBackPlotsDistributor,
                .writeTraceTraceOptions= &writeMatchingTraceTraceOptionsDistributor,
-               .writeTraceTimePlots= &writeMatchingTraceTimePlotsDistributor,
+               .writeTraceTimeForePlots= &writeMatchingTraceTimeForePlotsDistributor,
+               .writeTraceTimeBackPlots= &writeMatchingTraceTimeBackPlotsDistributor,
                .writeTraceTimeOptions= &writeMatchingTraceTimeOptionsDistributor,
        },
 };
@@ -95,7 +100,7 @@ static MatchingModule matchingModuleDistributor = {
 /*
  * Matching module registering function
  */
-static void registerMatchingDistributor()
+void registerMatchingDistributor()
 {
        g_queue_push_tail(&matchingModules, &matchingModuleDistributor);
 }
@@ -139,7 +144,7 @@ static void destroyMatchingDistributor(SyncState* const syncState)
 
        g_queue_foreach(matchingData->distributedModules, &gfDestroyModule, NULL);
 
-       g_queue_clear(matchingData->distributedModules);
+       g_queue_free(matchingData->distributedModules);
        free(syncState->matchingData);
        syncState->matchingData= NULL;
 }
@@ -163,35 +168,21 @@ static void matchEventDistributor(SyncState* const syncState, Event* const event
 
 
 /*
- * Call the distributed finalization functions and return identity factors
+ * Call the distributed finalization functions and return absent factors
  *
  * Args:
  *   syncState     container for synchronization data.
  *
  * Returns:
- *   Factors[traceNb] identity factors for each trace
+ *   AllFactors*   synchronization factors for each trace pair
  */
-static GArray* finalizeMatchingDistributor(SyncState* const syncState)
+static AllFactors* finalizeMatchingDistributor(SyncState* const syncState)
 {
-       GArray* factors;
-       unsigned int i;
        MatchingDataDistributor* matchingData= syncState->matchingData;
 
        g_queue_foreach(matchingData->distributedModules, &gfFinalize, NULL);
 
-       factors= g_array_sized_new(FALSE, FALSE, sizeof(Factors),
-               syncState->traceNb);
-       g_array_set_size(factors, syncState->traceNb);
-       for (i= 0; i < syncState->traceNb; i++)
-       {
-               Factors* e;
-
-               e= &g_array_index(factors, Factors, i);
-               e->drift= 1.;
-               e->offset= 0.;
-       }
-
-       return factors;
+       return createAllFactors(syncState->traceNb);
 }
 
 
@@ -218,14 +209,52 @@ static void printMatchingStatsDistributor(SyncState* const syncState)
  *   i:            first trace number
  *   j:            second trace number, garanteed to be larger than i
  */
-static void writeMatchingTraceTracePlotsDistributor(SyncState* const
+static void writeMatchingTraceTraceForePlotsDistributor(SyncState* const
+       syncState, const unsigned int i, const unsigned int j)
+{
+       MatchingDataDistributor* matchingData= syncState->matchingData;
+
+       g_queue_foreach(matchingData->distributedModules, &gfGraphFunctionCall,
+               &(struct GraphAggregate) {offsetof(MatchingModule,
+                       graphFunctions.writeTraceTraceForePlots), i, j});
+}
+
+
+/*
+ * Call the distributed graph lines functions (when they exist).
+ *
+ * Args:
+ *   syncState:    container for synchronization data
+ *   i:            first trace number
+ *   j:            second trace number, garanteed to be larger than i
+ */
+static void writeMatchingTraceTraceBackPlotsDistributor(SyncState* const
+       syncState, const unsigned int i, const unsigned int j)
+{
+       MatchingDataDistributor* matchingData= syncState->matchingData;
+
+       g_queue_foreach(matchingData->distributedModules, &gfGraphFunctionCall,
+               &(struct GraphAggregate) {offsetof(MatchingModule,
+                       graphFunctions.writeTraceTraceBackPlots), i, j});
+}
+
+
+/*
+ * Call the distributed graph lines functions (when they exist).
+ *
+ * Args:
+ *   syncState:    container for synchronization data
+ *   i:            first trace number
+ *   j:            second trace number, garanteed to be larger than i
+ */
+static void writeMatchingTraceTimeForePlotsDistributor(SyncState* const
        syncState, const unsigned int i, const unsigned int j)
 {
        MatchingDataDistributor* matchingData= syncState->matchingData;
 
        g_queue_foreach(matchingData->distributedModules, &gfGraphFunctionCall,
                &(struct GraphAggregate) {offsetof(MatchingModule,
-                       graphFunctions.writeTraceTracePlots), i, j});
+                       graphFunctions.writeTraceTimeForePlots), i, j});
 }
 
 
@@ -237,14 +266,14 @@ static void writeMatchingTraceTracePlotsDistributor(SyncState* const
  *   i:            first trace number
  *   j:            second trace number, garanteed to be larger than i
  */
-static void writeMatchingTraceTimePlotsDistributor(SyncState* const
+static void writeMatchingTraceTimeBackPlotsDistributor(SyncState* const
        syncState, const unsigned int i, const unsigned int j)
 {
        MatchingDataDistributor* matchingData= syncState->matchingData;
 
        g_queue_foreach(matchingData->distributedModules, &gfGraphFunctionCall,
                &(struct GraphAggregate) {offsetof(MatchingModule,
-                       graphFunctions.writeTraceTimePlots), i, j});
+                       graphFunctions.writeTraceTimeBackPlots), i, j});
 }
 
 
@@ -363,11 +392,10 @@ void gfMatchEvent(gpointer data, gpointer user_data)
  */
 void gfFinalize(gpointer data, gpointer user_data)
 {
-       GArray* factors;
        SyncState* parallelSS= data;
 
-       factors= parallelSS->matchingModule->finalizeMatching(parallelSS);
-       g_array_free(factors, TRUE);
+       freeAllFactors(parallelSS->matchingModule->finalizeMatching(parallelSS),
+               parallelSS->traceNb);
 }
 
 
This page took 0.02499 seconds and 4 git commands to generate.