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 GArray
* 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_clear(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 identity factors
174 * syncState container for synchronization data.
177 * Factors[traceNb] identity factors for each trace
179 static GArray
* finalizeMatchingDistributor(SyncState
* const syncState
)
183 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
185 g_queue_foreach(matchingData
->distributedModules
, &gfFinalize
, NULL
);
187 factors
= g_array_sized_new(FALSE
, FALSE
, sizeof(Factors
),
189 g_array_set_size(factors
, syncState
->traceNb
);
190 for (i
= 0; i
< syncState
->traceNb
; i
++)
194 e
= &g_array_index(factors
, Factors
, i
);
204 * Call the distributed statistics functions (when they exist). Must be called
205 * after finalizeMatching.
208 * syncState container for synchronization data.
210 static void printMatchingStatsDistributor(SyncState
* const syncState
)
212 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
214 g_queue_foreach(matchingData
->distributedModules
, &gfPrintStats
, NULL
);
219 * Call the distributed graph lines functions (when they exist).
222 * syncState: container for synchronization data
223 * i: first trace number
224 * j: second trace number, garanteed to be larger than i
226 static void writeMatchingTraceTraceForePlotsDistributor(SyncState
* const
227 syncState
, const unsigned int i
, const unsigned int j
)
229 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
231 g_queue_foreach(matchingData
->distributedModules
, &gfGraphFunctionCall
,
232 &(struct GraphAggregate
) {offsetof(MatchingModule
,
233 graphFunctions
.writeTraceTraceForePlots
), i
, j
});
238 * Call the distributed graph lines functions (when they exist).
241 * syncState: container for synchronization data
242 * i: first trace number
243 * j: second trace number, garanteed to be larger than i
245 static void writeMatchingTraceTraceBackPlotsDistributor(SyncState
* const
246 syncState
, const unsigned int i
, const unsigned int j
)
248 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
250 g_queue_foreach(matchingData
->distributedModules
, &gfGraphFunctionCall
,
251 &(struct GraphAggregate
) {offsetof(MatchingModule
,
252 graphFunctions
.writeTraceTraceBackPlots
), i
, j
});
257 * Call the distributed graph lines functions (when they exist).
260 * syncState: container for synchronization data
261 * i: first trace number
262 * j: second trace number, garanteed to be larger than i
264 static void writeMatchingTraceTimeForePlotsDistributor(SyncState
* const
265 syncState
, const unsigned int i
, const unsigned int j
)
267 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
269 g_queue_foreach(matchingData
->distributedModules
, &gfGraphFunctionCall
,
270 &(struct GraphAggregate
) {offsetof(MatchingModule
,
271 graphFunctions
.writeTraceTimeForePlots
), i
, j
});
276 * Call the distributed graph lines functions (when they exist).
279 * syncState: container for synchronization data
280 * i: first trace number
281 * j: second trace number, garanteed to be larger than i
283 static void writeMatchingTraceTimeBackPlotsDistributor(SyncState
* const
284 syncState
, const unsigned int i
, const unsigned int j
)
286 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
288 g_queue_foreach(matchingData
->distributedModules
, &gfGraphFunctionCall
,
289 &(struct GraphAggregate
) {offsetof(MatchingModule
,
290 graphFunctions
.writeTraceTimeBackPlots
), i
, j
});
295 * Call the distributed graph options functions (when they exist).
298 * syncState: container for synchronization data
299 * i: first trace number
300 * j: second trace number, garanteed to be larger than i
302 static void writeMatchingTraceTraceOptionsDistributor(SyncState
* const syncState
,
303 const unsigned int i
, const unsigned int j
)
305 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
307 g_queue_foreach(matchingData
->distributedModules
, &gfGraphFunctionCall
,
308 &(struct GraphAggregate
) {offsetof(MatchingModule
,
309 graphFunctions
.writeTraceTraceOptions
), i
, j
});
314 * Call the distributed graph options functions (when they exist).
317 * syncState: container for synchronization data
318 * i: first trace number
319 * j: second trace number, garanteed to be larger than i
321 static void writeMatchingTraceTimeOptionsDistributor(SyncState
* const syncState
,
322 const unsigned int i
, const unsigned int j
)
324 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
326 g_queue_foreach(matchingData
->distributedModules
, &gfGraphFunctionCall
,
327 &(struct GraphAggregate
) {offsetof(MatchingModule
,
328 graphFunctions
.writeTraceTimeOptions
), i
, j
});
333 * A GFunc for g_queue_foreach()
335 * Add and initialize matching module
338 * data MatchingModule*, module to add
339 * user_data InitAggregate*
341 void gfInitModule(gpointer data
, gpointer user_data
)
343 SyncState
* parallelSS
;
344 struct InitAggregate
* aggregate
= user_data
;
345 MatchingModule
* matchingModule
= data
;
347 if (strcmp(matchingModule
->name
, matchingModuleDistributor
.name
) == 0)
352 parallelSS
= malloc(sizeof(SyncState
));
353 memcpy(parallelSS
, aggregate
->syncState
, sizeof(SyncState
));
354 g_queue_push_tail(aggregate
->matchingModules
, parallelSS
);
356 parallelSS
->matchingModule
= matchingModule
;
357 parallelSS
->matchingModule
->initMatching(parallelSS
);
362 * A GFunc for g_queue_foreach()
364 * Destroy and remove matching module
367 * data SyncState* containing the module to destroy
370 void gfDestroyModule(gpointer data
, gpointer user_data
)
372 SyncState
* parallelSS
= data
;
374 parallelSS
->matchingModule
->destroyMatching(parallelSS
);
380 * A GFunc for g_queue_foreach()
383 * data SyncState* containing the distributed matching module
384 * user_data Event* original event
386 void gfMatchEvent(gpointer data
, gpointer user_data
)
388 SyncState
* parallelSS
= data
;
389 const Event
* event
= user_data
;
392 if (parallelSS
->matchingModule
->canMatch
[event
->type
])
394 event
->copy(event
, &newEvent
);
395 parallelSS
->matchingModule
->matchEvent(parallelSS
, newEvent
);
401 * A GFunc for g_queue_foreach()
404 * data SyncState* containing the distributed matching module
407 void gfFinalize(gpointer data
, gpointer user_data
)
410 SyncState
* parallelSS
= data
;
412 factors
= parallelSS
->matchingModule
->finalizeMatching(parallelSS
);
413 g_array_free(factors
, TRUE
);
418 * A GFunc for g_queue_foreach()
421 * data SyncState* containing the distributed matching module
424 void gfPrintStats(gpointer data
, gpointer user_data
)
426 SyncState
* parallelSS
= data
;
428 if (parallelSS
->matchingModule
->printMatchingStats
!= NULL
)
430 parallelSS
->matchingModule
->printMatchingStats(parallelSS
);
436 * A GFunc for g_queue_foreach()
438 * Call a certain matching function
441 * data SyncState* containing the distributed matching module
444 void gfGraphFunctionCall(gpointer data
, gpointer user_data
)
446 SyncState
* parallelSS
= data
;
447 struct GraphAggregate
* aggregate
= user_data
;
448 typedef void (*GraphFunction
)(struct _SyncState
*, const unsigned int,
450 GraphFunction graphFunction
= *(GraphFunction
*)((void*)
451 parallelSS
->matchingModule
+ (size_t) aggregate
->offset
);
453 if (graphFunction
!= NULL
)
455 graphFunction(parallelSS
, aggregate
->i
, aggregate
->j
);