1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2009 Benjamin Poirier <benjamin.poirier@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27 #include "event_analysis.h"
28 #include "sync_chain.h"
30 #include "event_matching_distributor.h"
36 GQueue
* matchingModules
;
42 /* Offset whithin Matching module of the field* containing the function
49 // Functions common to all matching modules
50 static void initMatchingDistributor(SyncState
* const syncState
);
51 static void destroyMatchingDistributor(SyncState
* const syncState
);
53 static void matchEventDistributor(SyncState
* const syncState
, Event
* const
55 static GArray
* finalizeMatchingDistributor(SyncState
* const syncState
);
56 static void printMatchingStatsDistributor(SyncState
* const syncState
);
57 static void writeMatchingTraceTraceForePlotsDistributor(SyncState
* const
58 syncState
, const unsigned int i
, const unsigned int j
);
59 static void writeMatchingTraceTraceBackPlotsDistributor(SyncState
* const
60 syncState
, const unsigned int i
, const unsigned int j
);
61 static void writeMatchingTraceTraceOptionsDistributor(SyncState
* const
62 syncState
, const unsigned int i
, const unsigned int j
);
63 static void writeMatchingTraceTimeForePlotsDistributor(SyncState
* const
64 syncState
, const unsigned int i
, const unsigned int j
);
65 static void writeMatchingTraceTimeBackPlotsDistributor(SyncState
* const
66 syncState
, const unsigned int i
, const unsigned int j
);
67 static void writeMatchingTraceTimeOptionsDistributor(SyncState
* const
68 syncState
, const unsigned int i
, const unsigned int j
);
70 // Functions specific to this module
71 static void registerMatchingDistributor() __attribute__((constructor (101)));
73 void gfInitModule(gpointer data
, gpointer user_data
);
74 void gfDestroyModule(gpointer data
, gpointer user_data
);
75 void gfMatchEvent(gpointer data
, gpointer user_data
);
76 void gfFinalize(gpointer data
, gpointer user_data
);
77 void gfPrintStats(gpointer data
, gpointer user_data
);
78 void gfGraphFunctionCall(gpointer data
, gpointer user_data
);
81 static MatchingModule matchingModuleDistributor
= {
85 .initMatching
= &initMatchingDistributor
,
86 .destroyMatching
= &destroyMatchingDistributor
,
87 .matchEvent
= &matchEventDistributor
,
88 .finalizeMatching
= &finalizeMatchingDistributor
,
89 .printMatchingStats
= &printMatchingStatsDistributor
,
91 .writeTraceTraceForePlots
=
92 &writeMatchingTraceTraceForePlotsDistributor
,
93 .writeTraceTraceBackPlots
=
94 &writeMatchingTraceTraceBackPlotsDistributor
,
95 .writeTraceTraceOptions
= &writeMatchingTraceTraceOptionsDistributor
,
96 .writeTraceTimeForePlots
= &writeMatchingTraceTimeForePlotsDistributor
,
97 .writeTraceTimeBackPlots
= &writeMatchingTraceTimeBackPlotsDistributor
,
98 .writeTraceTimeOptions
= &writeMatchingTraceTimeOptionsDistributor
,
104 * Matching module registering function
106 static void registerMatchingDistributor()
108 g_queue_push_tail(&matchingModules
, &matchingModuleDistributor
);
113 * Matching init function
115 * This function is called at the beginning of a synchronization run for a set
118 * Build the list and initialize other matching Modules
121 * syncState container for synchronization data.
123 static void initMatchingDistributor(SyncState
* const syncState
)
125 MatchingDataDistributor
* matchingData
;
127 matchingData
= malloc(sizeof(MatchingDataDistributor
));
128 syncState
->matchingData
= matchingData
;
130 matchingData
->distributedModules
= g_queue_new();
131 g_queue_foreach(&matchingModules
, &gfInitModule
, &(struct InitAggregate
)
132 {syncState
, matchingData
->distributedModules
});
137 * Matching destroy function
139 * Destroy other modules and free the matching specific data structures
142 * syncState container for synchronization data.
144 static void destroyMatchingDistributor(SyncState
* const syncState
)
146 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
148 g_queue_foreach(matchingData
->distributedModules
, &gfDestroyModule
, NULL
);
150 g_queue_clear(matchingData
->distributedModules
);
151 free(syncState
->matchingData
);
152 syncState
->matchingData
= NULL
;
158 * Copy event and distribute to matching modules
161 * syncState container for synchronization data.
162 * event new event to match
164 static void matchEventDistributor(SyncState
* const syncState
, Event
* const event
)
166 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
168 g_queue_foreach(matchingData
->distributedModules
, &gfMatchEvent
, event
);
169 event
->destroy(event
);
174 * Call the distributed finalization functions and return identity factors
177 * syncState container for synchronization data.
180 * Factors[traceNb] identity factors for each trace
182 static GArray
* finalizeMatchingDistributor(SyncState
* const syncState
)
186 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
188 g_queue_foreach(matchingData
->distributedModules
, &gfFinalize
, NULL
);
190 factors
= g_array_sized_new(FALSE
, FALSE
, sizeof(Factors
),
192 g_array_set_size(factors
, syncState
->traceNb
);
193 for (i
= 0; i
< syncState
->traceNb
; i
++)
197 e
= &g_array_index(factors
, Factors
, i
);
207 * Call the distributed statistics functions (when they exist). Must be called
208 * after finalizeMatching.
211 * syncState container for synchronization data.
213 static void printMatchingStatsDistributor(SyncState
* const syncState
)
215 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
217 g_queue_foreach(matchingData
->distributedModules
, &gfPrintStats
, NULL
);
222 * Call the distributed graph lines functions (when they exist).
225 * syncState: container for synchronization data
226 * i: first trace number
227 * j: second trace number, garanteed to be larger than i
229 static void writeMatchingTraceTraceForePlotsDistributor(SyncState
* const
230 syncState
, const unsigned int i
, const unsigned int j
)
232 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
234 g_queue_foreach(matchingData
->distributedModules
, &gfGraphFunctionCall
,
235 &(struct GraphAggregate
) {offsetof(MatchingModule
,
236 graphFunctions
.writeTraceTraceForePlots
), i
, j
});
241 * Call the distributed graph lines functions (when they exist).
244 * syncState: container for synchronization data
245 * i: first trace number
246 * j: second trace number, garanteed to be larger than i
248 static void writeMatchingTraceTraceBackPlotsDistributor(SyncState
* const
249 syncState
, const unsigned int i
, const unsigned int j
)
251 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
253 g_queue_foreach(matchingData
->distributedModules
, &gfGraphFunctionCall
,
254 &(struct GraphAggregate
) {offsetof(MatchingModule
,
255 graphFunctions
.writeTraceTraceBackPlots
), i
, j
});
260 * Call the distributed graph lines functions (when they exist).
263 * syncState: container for synchronization data
264 * i: first trace number
265 * j: second trace number, garanteed to be larger than i
267 static void writeMatchingTraceTimeForePlotsDistributor(SyncState
* const
268 syncState
, const unsigned int i
, const unsigned int j
)
270 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
272 g_queue_foreach(matchingData
->distributedModules
, &gfGraphFunctionCall
,
273 &(struct GraphAggregate
) {offsetof(MatchingModule
,
274 graphFunctions
.writeTraceTimeForePlots
), i
, j
});
279 * Call the distributed graph lines functions (when they exist).
282 * syncState: container for synchronization data
283 * i: first trace number
284 * j: second trace number, garanteed to be larger than i
286 static void writeMatchingTraceTimeBackPlotsDistributor(SyncState
* const
287 syncState
, const unsigned int i
, const unsigned int j
)
289 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
291 g_queue_foreach(matchingData
->distributedModules
, &gfGraphFunctionCall
,
292 &(struct GraphAggregate
) {offsetof(MatchingModule
,
293 graphFunctions
.writeTraceTimeBackPlots
), i
, j
});
298 * Call the distributed graph options functions (when they exist).
301 * syncState: container for synchronization data
302 * i: first trace number
303 * j: second trace number, garanteed to be larger than i
305 static void writeMatchingTraceTraceOptionsDistributor(SyncState
* const syncState
,
306 const unsigned int i
, const unsigned int j
)
308 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
310 g_queue_foreach(matchingData
->distributedModules
, &gfGraphFunctionCall
,
311 &(struct GraphAggregate
) {offsetof(MatchingModule
,
312 graphFunctions
.writeTraceTraceOptions
), i
, j
});
317 * Call the distributed graph options functions (when they exist).
320 * syncState: container for synchronization data
321 * i: first trace number
322 * j: second trace number, garanteed to be larger than i
324 static void writeMatchingTraceTimeOptionsDistributor(SyncState
* const syncState
,
325 const unsigned int i
, const unsigned int j
)
327 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
329 g_queue_foreach(matchingData
->distributedModules
, &gfGraphFunctionCall
,
330 &(struct GraphAggregate
) {offsetof(MatchingModule
,
331 graphFunctions
.writeTraceTimeOptions
), i
, j
});
336 * A GFunc for g_queue_foreach()
338 * Add and initialize matching module
341 * data MatchingModule*, module to add
342 * user_data InitAggregate*
344 void gfInitModule(gpointer data
, gpointer user_data
)
346 SyncState
* parallelSS
;
347 struct InitAggregate
* aggregate
= user_data
;
348 MatchingModule
* matchingModule
= data
;
350 if (strcmp(matchingModule
->name
, matchingModuleDistributor
.name
) == 0)
355 parallelSS
= malloc(sizeof(SyncState
));
356 memcpy(parallelSS
, aggregate
->syncState
, sizeof(SyncState
));
357 g_queue_push_tail(aggregate
->matchingModules
, parallelSS
);
359 parallelSS
->matchingModule
= matchingModule
;
360 parallelSS
->matchingModule
->initMatching(parallelSS
);
365 * A GFunc for g_queue_foreach()
367 * Destroy and remove matching module
370 * data SyncState* containing the module to destroy
373 void gfDestroyModule(gpointer data
, gpointer user_data
)
375 SyncState
* parallelSS
= data
;
377 parallelSS
->matchingModule
->destroyMatching(parallelSS
);
383 * A GFunc for g_queue_foreach()
386 * data SyncState* containing the distributed matching module
387 * user_data Event* original event
389 void gfMatchEvent(gpointer data
, gpointer user_data
)
391 SyncState
* parallelSS
= data
;
392 const Event
* event
= user_data
;
395 if (parallelSS
->matchingModule
->canMatch
[event
->type
])
397 event
->copy(event
, &newEvent
);
398 parallelSS
->matchingModule
->matchEvent(parallelSS
, newEvent
);
404 * A GFunc for g_queue_foreach()
407 * data SyncState* containing the distributed matching module
410 void gfFinalize(gpointer data
, gpointer user_data
)
413 SyncState
* parallelSS
= data
;
415 factors
= parallelSS
->matchingModule
->finalizeMatching(parallelSS
);
416 g_array_free(factors
, TRUE
);
421 * A GFunc for g_queue_foreach()
424 * data SyncState* containing the distributed matching module
427 void gfPrintStats(gpointer data
, gpointer user_data
)
429 SyncState
* parallelSS
= data
;
431 if (parallelSS
->matchingModule
->printMatchingStats
!= NULL
)
433 parallelSS
->matchingModule
->printMatchingStats(parallelSS
);
439 * A GFunc for g_queue_foreach()
441 * Call a certain matching function
444 * data SyncState* containing the distributed matching module
447 void gfGraphFunctionCall(gpointer data
, gpointer user_data
)
449 SyncState
* parallelSS
= data
;
450 struct GraphAggregate
* aggregate
= user_data
;
451 typedef void (*GraphFunction
)(struct _SyncState
*, const unsigned int,
453 GraphFunction graphFunction
= *(GraphFunction
*)((void*)
454 parallelSS
->matchingModule
+ (size_t) aggregate
->offset
);
456 if (graphFunction
!= NULL
)
458 graphFunction(parallelSS
, aggregate
->i
, aggregate
->j
);