1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2009, 2010 Benjamin Poirier <benjamin.poirier@polymtl.ca>
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 2.1 of the License, or (at
7 * your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
12 * License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "event_analysis.h"
27 #include "sync_chain.h"
29 #include "event_matching_distributor.h"
35 GQueue
* matchingModules
;
41 /* Offset whithin Matching module of the field* containing the function
48 // Functions common to all matching modules
49 static void initMatchingDistributor(SyncState
* const syncState
);
50 static void destroyMatchingDistributor(SyncState
* const syncState
);
52 static void matchEventDistributor(SyncState
* const syncState
, Event
* const
54 static AllFactors
* finalizeMatchingDistributor(SyncState
* const syncState
);
55 static void printMatchingStatsDistributor(SyncState
* const syncState
);
56 static void writeMatchingTraceTraceForePlotsDistributor(SyncState
* const
57 syncState
, const unsigned int i
, const unsigned int j
);
58 static void writeMatchingTraceTraceBackPlotsDistributor(SyncState
* const
59 syncState
, const unsigned int i
, const unsigned int j
);
60 static void writeMatchingTraceTraceOptionsDistributor(SyncState
* const
61 syncState
, const unsigned int i
, const unsigned int j
);
62 static void writeMatchingTraceTimeForePlotsDistributor(SyncState
* const
63 syncState
, const unsigned int i
, const unsigned int j
);
64 static void writeMatchingTraceTimeBackPlotsDistributor(SyncState
* const
65 syncState
, const unsigned int i
, const unsigned int j
);
66 static void writeMatchingTraceTimeOptionsDistributor(SyncState
* const
67 syncState
, const unsigned int i
, const unsigned int j
);
69 // Functions specific to this module
70 void gfInitModule(gpointer data
, gpointer user_data
);
71 void gfDestroyModule(gpointer data
, gpointer user_data
);
72 void gfMatchEvent(gpointer data
, gpointer user_data
);
73 void gfFinalize(gpointer data
, gpointer user_data
);
74 void gfPrintStats(gpointer data
, gpointer user_data
);
75 void gfGraphFunctionCall(gpointer data
, gpointer user_data
);
78 static MatchingModule matchingModuleDistributor
= {
82 .initMatching
= &initMatchingDistributor
,
83 .destroyMatching
= &destroyMatchingDistributor
,
84 .matchEvent
= &matchEventDistributor
,
85 .finalizeMatching
= &finalizeMatchingDistributor
,
86 .printMatchingStats
= &printMatchingStatsDistributor
,
88 .writeTraceTraceForePlots
=
89 &writeMatchingTraceTraceForePlotsDistributor
,
90 .writeTraceTraceBackPlots
=
91 &writeMatchingTraceTraceBackPlotsDistributor
,
92 .writeTraceTraceOptions
= &writeMatchingTraceTraceOptionsDistributor
,
93 .writeTraceTimeForePlots
= &writeMatchingTraceTimeForePlotsDistributor
,
94 .writeTraceTimeBackPlots
= &writeMatchingTraceTimeBackPlotsDistributor
,
95 .writeTraceTimeOptions
= &writeMatchingTraceTimeOptionsDistributor
,
101 * Matching module registering function
103 void registerMatchingDistributor()
105 g_queue_push_tail(&matchingModules
, &matchingModuleDistributor
);
110 * Matching init function
112 * This function is called at the beginning of a synchronization run for a set
115 * Build the list and initialize other matching Modules
118 * syncState container for synchronization data.
120 static void initMatchingDistributor(SyncState
* const syncState
)
122 MatchingDataDistributor
* matchingData
;
124 matchingData
= malloc(sizeof(MatchingDataDistributor
));
125 syncState
->matchingData
= matchingData
;
127 matchingData
->distributedModules
= g_queue_new();
128 g_queue_foreach(&matchingModules
, &gfInitModule
, &(struct InitAggregate
)
129 {syncState
, matchingData
->distributedModules
});
134 * Matching destroy function
136 * Destroy other modules and free the matching specific data structures
139 * syncState container for synchronization data.
141 static void destroyMatchingDistributor(SyncState
* const syncState
)
143 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
145 g_queue_foreach(matchingData
->distributedModules
, &gfDestroyModule
, NULL
);
147 g_queue_free(matchingData
->distributedModules
);
148 free(syncState
->matchingData
);
149 syncState
->matchingData
= NULL
;
155 * Copy event and distribute to matching modules
158 * syncState container for synchronization data.
159 * event new event to match
161 static void matchEventDistributor(SyncState
* const syncState
, Event
* const event
)
163 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
165 g_queue_foreach(matchingData
->distributedModules
, &gfMatchEvent
, event
);
166 event
->destroy(event
);
171 * Call the distributed finalization functions and return absent factors
174 * syncState container for synchronization data.
177 * AllFactors* synchronization factors for each trace pair
179 static AllFactors
* finalizeMatchingDistributor(SyncState
* const syncState
)
181 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
183 g_queue_foreach(matchingData
->distributedModules
, &gfFinalize
, NULL
);
185 return createAllFactors(syncState
->traceNb
);
190 * Call the distributed statistics functions (when they exist). Must be called
191 * after finalizeMatching.
194 * syncState container for synchronization data.
196 static void printMatchingStatsDistributor(SyncState
* const syncState
)
198 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
200 g_queue_foreach(matchingData
->distributedModules
, &gfPrintStats
, NULL
);
205 * Call the distributed graph lines functions (when they exist).
208 * syncState: container for synchronization data
209 * i: first trace number
210 * j: second trace number, garanteed to be larger than i
212 static void writeMatchingTraceTraceForePlotsDistributor(SyncState
* const
213 syncState
, const unsigned int i
, const unsigned int j
)
215 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
217 g_queue_foreach(matchingData
->distributedModules
, &gfGraphFunctionCall
,
218 &(struct GraphAggregate
) {offsetof(MatchingModule
,
219 graphFunctions
.writeTraceTraceForePlots
), i
, j
});
224 * Call the distributed graph lines functions (when they exist).
227 * syncState: container for synchronization data
228 * i: first trace number
229 * j: second trace number, garanteed to be larger than i
231 static void writeMatchingTraceTraceBackPlotsDistributor(SyncState
* const
232 syncState
, const unsigned int i
, const unsigned int j
)
234 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
236 g_queue_foreach(matchingData
->distributedModules
, &gfGraphFunctionCall
,
237 &(struct GraphAggregate
) {offsetof(MatchingModule
,
238 graphFunctions
.writeTraceTraceBackPlots
), i
, j
});
243 * Call the distributed graph lines functions (when they exist).
246 * syncState: container for synchronization data
247 * i: first trace number
248 * j: second trace number, garanteed to be larger than i
250 static void writeMatchingTraceTimeForePlotsDistributor(SyncState
* const
251 syncState
, const unsigned int i
, const unsigned int j
)
253 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
255 g_queue_foreach(matchingData
->distributedModules
, &gfGraphFunctionCall
,
256 &(struct GraphAggregate
) {offsetof(MatchingModule
,
257 graphFunctions
.writeTraceTimeForePlots
), i
, j
});
262 * Call the distributed graph lines functions (when they exist).
265 * syncState: container for synchronization data
266 * i: first trace number
267 * j: second trace number, garanteed to be larger than i
269 static void writeMatchingTraceTimeBackPlotsDistributor(SyncState
* const
270 syncState
, const unsigned int i
, const unsigned int j
)
272 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
274 g_queue_foreach(matchingData
->distributedModules
, &gfGraphFunctionCall
,
275 &(struct GraphAggregate
) {offsetof(MatchingModule
,
276 graphFunctions
.writeTraceTimeBackPlots
), i
, j
});
281 * Call the distributed graph options functions (when they exist).
284 * syncState: container for synchronization data
285 * i: first trace number
286 * j: second trace number, garanteed to be larger than i
288 static void writeMatchingTraceTraceOptionsDistributor(SyncState
* const syncState
,
289 const unsigned int i
, const unsigned int j
)
291 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
293 g_queue_foreach(matchingData
->distributedModules
, &gfGraphFunctionCall
,
294 &(struct GraphAggregate
) {offsetof(MatchingModule
,
295 graphFunctions
.writeTraceTraceOptions
), i
, j
});
300 * Call the distributed graph options functions (when they exist).
303 * syncState: container for synchronization data
304 * i: first trace number
305 * j: second trace number, garanteed to be larger than i
307 static void writeMatchingTraceTimeOptionsDistributor(SyncState
* const syncState
,
308 const unsigned int i
, const unsigned int j
)
310 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
312 g_queue_foreach(matchingData
->distributedModules
, &gfGraphFunctionCall
,
313 &(struct GraphAggregate
) {offsetof(MatchingModule
,
314 graphFunctions
.writeTraceTimeOptions
), i
, j
});
319 * A GFunc for g_queue_foreach()
321 * Add and initialize matching module
324 * data MatchingModule*, module to add
325 * user_data InitAggregate*
327 void gfInitModule(gpointer data
, gpointer user_data
)
329 SyncState
* parallelSS
;
330 struct InitAggregate
* aggregate
= user_data
;
331 MatchingModule
* matchingModule
= data
;
333 if (strcmp(matchingModule
->name
, matchingModuleDistributor
.name
) == 0)
338 parallelSS
= malloc(sizeof(SyncState
));
339 memcpy(parallelSS
, aggregate
->syncState
, sizeof(SyncState
));
340 g_queue_push_tail(aggregate
->matchingModules
, parallelSS
);
342 parallelSS
->matchingModule
= matchingModule
;
343 parallelSS
->matchingModule
->initMatching(parallelSS
);
348 * A GFunc for g_queue_foreach()
350 * Destroy and remove matching module
353 * data SyncState* containing the module to destroy
356 void gfDestroyModule(gpointer data
, gpointer user_data
)
358 SyncState
* parallelSS
= data
;
360 parallelSS
->matchingModule
->destroyMatching(parallelSS
);
366 * A GFunc for g_queue_foreach()
369 * data SyncState* containing the distributed matching module
370 * user_data Event* original event
372 void gfMatchEvent(gpointer data
, gpointer user_data
)
374 SyncState
* parallelSS
= data
;
375 const Event
* event
= user_data
;
378 if (parallelSS
->matchingModule
->canMatch
[event
->type
])
380 event
->copy(event
, &newEvent
);
381 parallelSS
->matchingModule
->matchEvent(parallelSS
, newEvent
);
387 * A GFunc for g_queue_foreach()
390 * data SyncState* containing the distributed matching module
393 void gfFinalize(gpointer data
, gpointer user_data
)
395 SyncState
* parallelSS
= data
;
397 freeAllFactors(parallelSS
->matchingModule
->finalizeMatching(parallelSS
),
398 parallelSS
->traceNb
);
403 * A GFunc for g_queue_foreach()
406 * data SyncState* containing the distributed matching module
409 void gfPrintStats(gpointer data
, gpointer user_data
)
411 SyncState
* parallelSS
= data
;
413 if (parallelSS
->matchingModule
->printMatchingStats
!= NULL
)
415 parallelSS
->matchingModule
->printMatchingStats(parallelSS
);
421 * A GFunc for g_queue_foreach()
423 * Call a certain matching function
426 * data SyncState* containing the distributed matching module
429 void gfGraphFunctionCall(gpointer data
, gpointer user_data
)
431 SyncState
* parallelSS
= data
;
432 struct GraphAggregate
* aggregate
= user_data
;
433 typedef void (*GraphFunction
)(struct _SyncState
*, const unsigned int,
435 GraphFunction graphFunction
= *(GraphFunction
*)((void*)
436 parallelSS
->matchingModule
+ (size_t) aggregate
->offset
);
438 if (graphFunction
!= NULL
)
440 graphFunction(parallelSS
, aggregate
->i
, aggregate
->j
);