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 void gfInitModule(gpointer data
, gpointer user_data
);
72 void gfDestroyModule(gpointer data
, gpointer user_data
);
73 void gfMatchEvent(gpointer data
, gpointer user_data
);
74 void gfFinalize(gpointer data
, gpointer user_data
);
75 void gfPrintStats(gpointer data
, gpointer user_data
);
76 void gfGraphFunctionCall(gpointer data
, gpointer user_data
);
79 static MatchingModule matchingModuleDistributor
= {
83 .initMatching
= &initMatchingDistributor
,
84 .destroyMatching
= &destroyMatchingDistributor
,
85 .matchEvent
= &matchEventDistributor
,
86 .finalizeMatching
= &finalizeMatchingDistributor
,
87 .printMatchingStats
= &printMatchingStatsDistributor
,
89 .writeTraceTraceForePlots
=
90 &writeMatchingTraceTraceForePlotsDistributor
,
91 .writeTraceTraceBackPlots
=
92 &writeMatchingTraceTraceBackPlotsDistributor
,
93 .writeTraceTraceOptions
= &writeMatchingTraceTraceOptionsDistributor
,
94 .writeTraceTimeForePlots
= &writeMatchingTraceTimeForePlotsDistributor
,
95 .writeTraceTimeBackPlots
= &writeMatchingTraceTimeBackPlotsDistributor
,
96 .writeTraceTimeOptions
= &writeMatchingTraceTimeOptionsDistributor
,
102 * Matching module registering function
104 void registerMatchingDistributor()
106 g_queue_push_tail(&matchingModules
, &matchingModuleDistributor
);
111 * Matching init function
113 * This function is called at the beginning of a synchronization run for a set
116 * Build the list and initialize other matching Modules
119 * syncState container for synchronization data.
121 static void initMatchingDistributor(SyncState
* const syncState
)
123 MatchingDataDistributor
* matchingData
;
125 matchingData
= malloc(sizeof(MatchingDataDistributor
));
126 syncState
->matchingData
= matchingData
;
128 matchingData
->distributedModules
= g_queue_new();
129 g_queue_foreach(&matchingModules
, &gfInitModule
, &(struct InitAggregate
)
130 {syncState
, matchingData
->distributedModules
});
135 * Matching destroy function
137 * Destroy other modules and free the matching specific data structures
140 * syncState container for synchronization data.
142 static void destroyMatchingDistributor(SyncState
* const syncState
)
144 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
146 g_queue_foreach(matchingData
->distributedModules
, &gfDestroyModule
, NULL
);
148 g_queue_clear(matchingData
->distributedModules
);
149 free(syncState
->matchingData
);
150 syncState
->matchingData
= NULL
;
156 * Copy event and distribute to matching modules
159 * syncState container for synchronization data.
160 * event new event to match
162 static void matchEventDistributor(SyncState
* const syncState
, Event
* const event
)
164 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
166 g_queue_foreach(matchingData
->distributedModules
, &gfMatchEvent
, event
);
167 event
->destroy(event
);
172 * Call the distributed finalization functions and return identity factors
175 * syncState container for synchronization data.
178 * Factors[traceNb] identity factors for each trace
180 static GArray
* finalizeMatchingDistributor(SyncState
* const syncState
)
184 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
186 g_queue_foreach(matchingData
->distributedModules
, &gfFinalize
, NULL
);
188 factors
= g_array_sized_new(FALSE
, FALSE
, sizeof(Factors
),
190 g_array_set_size(factors
, syncState
->traceNb
);
191 for (i
= 0; i
< syncState
->traceNb
; i
++)
195 e
= &g_array_index(factors
, Factors
, i
);
205 * Call the distributed statistics functions (when they exist). Must be called
206 * after finalizeMatching.
209 * syncState container for synchronization data.
211 static void printMatchingStatsDistributor(SyncState
* const syncState
)
213 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
215 g_queue_foreach(matchingData
->distributedModules
, &gfPrintStats
, NULL
);
220 * Call the distributed graph lines functions (when they exist).
223 * syncState: container for synchronization data
224 * i: first trace number
225 * j: second trace number, garanteed to be larger than i
227 static void writeMatchingTraceTraceForePlotsDistributor(SyncState
* const
228 syncState
, const unsigned int i
, const unsigned int j
)
230 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
232 g_queue_foreach(matchingData
->distributedModules
, &gfGraphFunctionCall
,
233 &(struct GraphAggregate
) {offsetof(MatchingModule
,
234 graphFunctions
.writeTraceTraceForePlots
), i
, j
});
239 * Call the distributed graph lines functions (when they exist).
242 * syncState: container for synchronization data
243 * i: first trace number
244 * j: second trace number, garanteed to be larger than i
246 static void writeMatchingTraceTraceBackPlotsDistributor(SyncState
* const
247 syncState
, const unsigned int i
, const unsigned int j
)
249 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
251 g_queue_foreach(matchingData
->distributedModules
, &gfGraphFunctionCall
,
252 &(struct GraphAggregate
) {offsetof(MatchingModule
,
253 graphFunctions
.writeTraceTraceBackPlots
), i
, j
});
258 * Call the distributed graph lines functions (when they exist).
261 * syncState: container for synchronization data
262 * i: first trace number
263 * j: second trace number, garanteed to be larger than i
265 static void writeMatchingTraceTimeForePlotsDistributor(SyncState
* const
266 syncState
, const unsigned int i
, const unsigned int j
)
268 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
270 g_queue_foreach(matchingData
->distributedModules
, &gfGraphFunctionCall
,
271 &(struct GraphAggregate
) {offsetof(MatchingModule
,
272 graphFunctions
.writeTraceTimeForePlots
), i
, j
});
277 * Call the distributed graph lines functions (when they exist).
280 * syncState: container for synchronization data
281 * i: first trace number
282 * j: second trace number, garanteed to be larger than i
284 static void writeMatchingTraceTimeBackPlotsDistributor(SyncState
* const
285 syncState
, const unsigned int i
, const unsigned int j
)
287 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
289 g_queue_foreach(matchingData
->distributedModules
, &gfGraphFunctionCall
,
290 &(struct GraphAggregate
) {offsetof(MatchingModule
,
291 graphFunctions
.writeTraceTimeBackPlots
), i
, j
});
296 * Call the distributed graph options functions (when they exist).
299 * syncState: container for synchronization data
300 * i: first trace number
301 * j: second trace number, garanteed to be larger than i
303 static void writeMatchingTraceTraceOptionsDistributor(SyncState
* const syncState
,
304 const unsigned int i
, const unsigned int j
)
306 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
308 g_queue_foreach(matchingData
->distributedModules
, &gfGraphFunctionCall
,
309 &(struct GraphAggregate
) {offsetof(MatchingModule
,
310 graphFunctions
.writeTraceTraceOptions
), i
, j
});
315 * Call the distributed graph options functions (when they exist).
318 * syncState: container for synchronization data
319 * i: first trace number
320 * j: second trace number, garanteed to be larger than i
322 static void writeMatchingTraceTimeOptionsDistributor(SyncState
* const syncState
,
323 const unsigned int i
, const unsigned int j
)
325 MatchingDataDistributor
* matchingData
= syncState
->matchingData
;
327 g_queue_foreach(matchingData
->distributedModules
, &gfGraphFunctionCall
,
328 &(struct GraphAggregate
) {offsetof(MatchingModule
,
329 graphFunctions
.writeTraceTimeOptions
), i
, j
});
334 * A GFunc for g_queue_foreach()
336 * Add and initialize matching module
339 * data MatchingModule*, module to add
340 * user_data InitAggregate*
342 void gfInitModule(gpointer data
, gpointer user_data
)
344 SyncState
* parallelSS
;
345 struct InitAggregate
* aggregate
= user_data
;
346 MatchingModule
* matchingModule
= data
;
348 if (strcmp(matchingModule
->name
, matchingModuleDistributor
.name
) == 0)
353 parallelSS
= malloc(sizeof(SyncState
));
354 memcpy(parallelSS
, aggregate
->syncState
, sizeof(SyncState
));
355 g_queue_push_tail(aggregate
->matchingModules
, parallelSS
);
357 parallelSS
->matchingModule
= matchingModule
;
358 parallelSS
->matchingModule
->initMatching(parallelSS
);
363 * A GFunc for g_queue_foreach()
365 * Destroy and remove matching module
368 * data SyncState* containing the module to destroy
371 void gfDestroyModule(gpointer data
, gpointer user_data
)
373 SyncState
* parallelSS
= data
;
375 parallelSS
->matchingModule
->destroyMatching(parallelSS
);
381 * A GFunc for g_queue_foreach()
384 * data SyncState* containing the distributed matching module
385 * user_data Event* original event
387 void gfMatchEvent(gpointer data
, gpointer user_data
)
389 SyncState
* parallelSS
= data
;
390 const Event
* event
= user_data
;
393 if (parallelSS
->matchingModule
->canMatch
[event
->type
])
395 event
->copy(event
, &newEvent
);
396 parallelSS
->matchingModule
->matchEvent(parallelSS
, newEvent
);
402 * A GFunc for g_queue_foreach()
405 * data SyncState* containing the distributed matching module
408 void gfFinalize(gpointer data
, gpointer user_data
)
411 SyncState
* parallelSS
= data
;
413 factors
= parallelSS
->matchingModule
->finalizeMatching(parallelSS
);
414 g_array_free(factors
, TRUE
);
419 * A GFunc for g_queue_foreach()
422 * data SyncState* containing the distributed matching module
425 void gfPrintStats(gpointer data
, gpointer user_data
)
427 SyncState
* parallelSS
= data
;
429 if (parallelSS
->matchingModule
->printMatchingStats
!= NULL
)
431 parallelSS
->matchingModule
->printMatchingStats(parallelSS
);
437 * A GFunc for g_queue_foreach()
439 * Call a certain matching function
442 * data SyncState* containing the distributed matching module
445 void gfGraphFunctionCall(gpointer data
, gpointer user_data
)
447 SyncState
* parallelSS
= data
;
448 struct GraphAggregate
* aggregate
= user_data
;
449 typedef void (*GraphFunction
)(struct _SyncState
*, const unsigned int,
451 GraphFunction graphFunction
= *(GraphFunction
*)((void*)
452 parallelSS
->matchingModule
+ (size_t) aggregate
->offset
);
454 if (graphFunction
!= NULL
)
456 graphFunction(parallelSS
, aggregate
->i
, aggregate
->j
);