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,
25 #include "sync_chain_lttv.h"
27 #include "event_analysis_eval.h"
30 // Functions common to all analysis modules
31 static void initAnalysisEval(SyncState
* const syncState
);
32 static void destroyAnalysisEval(SyncState
* const syncState
);
34 static void analyzeMessageEval(SyncState
* const syncState
, Message
* const
36 static void analyzeExchangeEval(SyncState
* const syncState
, Exchange
* const
38 static void analyzeBroadcastEval(SyncState
* const syncState
, Broadcast
* const
40 static GArray
* finalizeAnalysisEval(SyncState
* const syncState
);
41 static void printAnalysisStatsEval(SyncState
* const syncState
);
43 // Functions specific to this module
44 static void registerAnalysisEval() __attribute__((constructor (102)));
47 static AnalysisModule analysisModuleEval
= {
49 .initAnalysis
= &initAnalysisEval
,
50 .destroyAnalysis
= &destroyAnalysisEval
,
51 .analyzeMessage
= &analyzeMessageEval
,
52 .analyzeExchange
= &analyzeExchangeEval
,
53 .analyzeBroadcast
= &analyzeBroadcastEval
,
54 .finalizeAnalysis
= &finalizeAnalysisEval
,
55 .printAnalysisStats
= &printAnalysisStatsEval
,
56 .writeAnalysisGraphsPlots
= NULL
,
57 .writeAnalysisGraphsOptions
= NULL
,
62 * Analysis module registering function
64 static void registerAnalysisEval()
66 g_queue_push_tail(&analysisModules
, &analysisModuleEval
);
71 * Analysis init function
73 * This function is called at the beginning of a synchronization run for a set
77 * syncState container for synchronization data.
79 static void initAnalysisEval(SyncState
* const syncState
)
81 AnalysisDataEval
* analysisData
;
84 analysisData
= malloc(sizeof(AnalysisDataEval
));
85 syncState
->analysisData
= analysisData
;
87 //readRttInfo(&analysisData->rttInfo, optionEvalRttFile);
91 analysisData
->stats
= malloc(sizeof(AnalysisStatsEval
));
92 analysisData
->stats
->broadcastDiffSum
= 0.;
94 analysisData
->stats
->allStats
= malloc(syncState
->traceNb
*
95 sizeof(TracePairStats
*));
96 for (i
= 0; i
< syncState
->traceNb
; i
++)
98 analysisData
->stats
->allStats
[i
]= calloc(syncState
->traceNb
,
99 sizeof(TracePairStats
));
106 * Analysis destroy function
108 * Free the analysis specific data structures
111 * syncState container for synchronization data.
113 static void destroyAnalysisEval(SyncState
* const syncState
)
116 AnalysisDataEval
* analysisData
;
118 analysisData
= (AnalysisDataEval
*) syncState
->analysisData
;
120 if (analysisData
== NULL
|| analysisData
->rttInfo
== NULL
)
125 //g_hash_table_destroy(analysisData->rttInfo);
126 analysisData
->rttInfo
= NULL
;
128 if (syncState
->stats
)
130 for (i
= 0; i
< syncState
->traceNb
; i
++)
132 free(analysisData
->stats
->allStats
[i
]);
134 free(analysisData
->stats
->allStats
);
135 free(analysisData
->stats
);
138 free(syncState
->analysisData
);
139 syncState
->analysisData
= NULL
;
144 * Perform analysis on an event pair.
147 * syncState container for synchronization data
148 * message structure containing the events
150 static void analyzeMessageEval(SyncState
* const syncState
, Message
* const message
)
152 AnalysisDataEval
* analysisData
;
154 analysisData
= (AnalysisDataEval
*) syncState
->analysisData
;
159 * Perform analysis on multiple messages
162 * syncState container for synchronization data
163 * exchange structure containing the messages
165 static void analyzeExchangeEval(SyncState
* const syncState
, Exchange
* const exchange
)
167 AnalysisDataEval
* analysisData
;
169 analysisData
= (AnalysisDataEval
*) syncState
->analysisData
;
174 * Perform analysis on muliple events
177 * syncState container for synchronization data
178 * broadcast structure containing the events
180 static void analyzeBroadcastEval(SyncState
* const syncState
, Broadcast
* const broadcast
)
182 AnalysisDataEval
* analysisData
;
184 analysisData
= (AnalysisDataEval
*) syncState
->analysisData
;
189 * Finalize the factor calculations
191 * Since this module does not really calculate factors, identity factors are
195 * syncState container for synchronization data.
198 * Factors[traceNb] synchronization factors for each trace
200 static GArray
* finalizeAnalysisEval(SyncState
* const syncState
)
205 factors
= g_array_sized_new(FALSE
, FALSE
, sizeof(Factors
),
207 g_array_set_size(factors
, syncState
->traceNb
);
208 for (i
= 0; i
< syncState
->traceNb
; i
++)
212 e
= &g_array_index(factors
, Factors
, i
);
222 * Print statistics related to analysis. Must be called after
226 * syncState container for synchronization data.
228 static void printAnalysisStatsEval(SyncState
* const syncState
)
230 AnalysisDataEval
* analysisData
;
233 if (!syncState
->stats
)
238 analysisData
= (AnalysisDataEval
*) syncState
->analysisData
;
240 printf("Synchronization evaluation analysis stats:\n");
241 printf("\tsum of broadcast differential delays: %g\n",
242 analysisData
->stats
->broadcastDiffSum
);
244 printf("\tIndividual evaluation:\n"
245 "\t\tTrace pair Inversions Too fast (No RTT info)\n");
247 for (i
= 0; i
< syncState
->traceNb
; i
++)
249 for (j
= i
+ 1; j
< syncState
->traceNb
; j
++)
251 TracePairStats
* tpStats
;
252 const char* format
= "\t\t%3d - %-3d %-10u %-10u %u\n";
254 tpStats
= &analysisData
->stats
->allStats
[i
][j
];
256 printf(format
, i
, j
, tpStats
->inversionNb
, tpStats
->tooFastNb
,
257 tpStats
->noRTTInfoNb
);
259 tpStats
= &analysisData
->stats
->allStats
[j
][i
];
261 printf(format
, j
, i
, tpStats
->inversionNb
, tpStats
->tooFastNb
,
262 tpStats
->noRTTInfoNb
);