9ee0f47f08d2776d6f4923748088d420396ca9f1
[lttv.git] / lttv / lttv / sync / event_analysis_eval.c
1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2009 Benjamin Poirier <benjamin.poirier@polymtl.ca>
3 *
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;
7 *
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.
12 *
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,
16 * MA 02111-1307, USA.
17 */
18
19 #ifdef HAVE_CONFIG_H
20 #include <config.h>
21 #endif
22
23 #include <stdlib.h>
24
25 #include "sync_chain_lttv.h"
26
27 #include "event_analysis_eval.h"
28
29
30 // Functions common to all analysis modules
31 static void initAnalysisEval(SyncState* const syncState);
32 static void destroyAnalysisEval(SyncState* const syncState);
33
34 static void analyzeMessageEval(SyncState* const syncState, Message* const
35 message);
36 static void analyzeExchangeEval(SyncState* const syncState, Exchange* const
37 exchange);
38 static void analyzeBroadcastEval(SyncState* const syncState, Broadcast* const
39 broadcast);
40 static GArray* finalizeAnalysisEval(SyncState* const syncState);
41 static void printAnalysisStatsEval(SyncState* const syncState);
42
43 // Functions specific to this module
44 static void registerAnalysisEval() __attribute__((constructor (102)));
45
46
47 static AnalysisModule analysisModuleEval= {
48 .name= "eval",
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,
58 };
59
60
61 /*
62 * Analysis module registering function
63 */
64 static void registerAnalysisEval()
65 {
66 g_queue_push_tail(&analysisModules, &analysisModuleEval);
67 }
68
69
70 /*
71 * Analysis init function
72 *
73 * This function is called at the beginning of a synchronization run for a set
74 * of traces.
75 *
76 * Args:
77 * syncState container for synchronization data.
78 */
79 static void initAnalysisEval(SyncState* const syncState)
80 {
81 AnalysisDataEval* analysisData;
82 unsigned int i;
83
84 analysisData= malloc(sizeof(AnalysisDataEval));
85 syncState->analysisData= analysisData;
86
87 //readRttInfo(&analysisData->rttInfo, optionEvalRttFile);
88
89 if (syncState->stats)
90 {
91 analysisData->stats= malloc(sizeof(AnalysisStatsEval));
92 analysisData->stats->broadcastDiffSum= 0.;
93
94 analysisData->stats->allStats= malloc(syncState->traceNb *
95 sizeof(TracePairStats*));
96 for (i= 0; i < syncState->traceNb; i++)
97 {
98 analysisData->stats->allStats[i]= calloc(syncState->traceNb,
99 sizeof(TracePairStats));
100 }
101 }
102 }
103
104
105 /*
106 * Analysis destroy function
107 *
108 * Free the analysis specific data structures
109 *
110 * Args:
111 * syncState container for synchronization data.
112 */
113 static void destroyAnalysisEval(SyncState* const syncState)
114 {
115 unsigned int i;
116 AnalysisDataEval* analysisData;
117
118 analysisData= (AnalysisDataEval*) syncState->analysisData;
119
120 if (analysisData == NULL || analysisData->rttInfo == NULL)
121 {
122 return;
123 }
124
125 //g_hash_table_destroy(analysisData->rttInfo);
126 analysisData->rttInfo= NULL;
127
128 if (syncState->stats)
129 {
130 for (i= 0; i < syncState->traceNb; i++)
131 {
132 free(analysisData->stats->allStats[i]);
133 }
134 free(analysisData->stats->allStats);
135 free(analysisData->stats);
136 }
137
138 free(syncState->analysisData);
139 syncState->analysisData= NULL;
140 }
141
142
143 /*
144 * Perform analysis on an event pair.
145 *
146 * Args:
147 * syncState container for synchronization data
148 * message structure containing the events
149 */
150 static void analyzeMessageEval(SyncState* const syncState, Message* const message)
151 {
152 AnalysisDataEval* analysisData;
153
154 analysisData= (AnalysisDataEval*) syncState->analysisData;
155 }
156
157
158 /*
159 * Perform analysis on multiple messages
160 *
161 * Args:
162 * syncState container for synchronization data
163 * exchange structure containing the messages
164 */
165 static void analyzeExchangeEval(SyncState* const syncState, Exchange* const exchange)
166 {
167 AnalysisDataEval* analysisData;
168
169 analysisData= (AnalysisDataEval*) syncState->analysisData;
170 }
171
172
173 /*
174 * Perform analysis on muliple events
175 *
176 * Args:
177 * syncState container for synchronization data
178 * broadcast structure containing the events
179 */
180 static void analyzeBroadcastEval(SyncState* const syncState, Broadcast* const broadcast)
181 {
182 AnalysisDataEval* analysisData;
183
184 analysisData= (AnalysisDataEval*) syncState->analysisData;
185 }
186
187
188 /*
189 * Finalize the factor calculations
190 *
191 * Since this module does not really calculate factors, identity factors are
192 * returned.
193 *
194 * Args:
195 * syncState container for synchronization data.
196 *
197 * Returns:
198 * Factors[traceNb] synchronization factors for each trace
199 */
200 static GArray* finalizeAnalysisEval(SyncState* const syncState)
201 {
202 GArray* factors;
203 unsigned int i;
204
205 factors= g_array_sized_new(FALSE, FALSE, sizeof(Factors),
206 syncState->traceNb);
207 g_array_set_size(factors, syncState->traceNb);
208 for (i= 0; i < syncState->traceNb; i++)
209 {
210 Factors* e;
211
212 e= &g_array_index(factors, Factors, i);
213 e->drift= 1.;
214 e->offset= 0.;
215 }
216
217 return factors;
218 }
219
220
221 /*
222 * Print statistics related to analysis. Must be called after
223 * finalizeAnalysis.
224 *
225 * Args:
226 * syncState container for synchronization data.
227 */
228 static void printAnalysisStatsEval(SyncState* const syncState)
229 {
230 AnalysisDataEval* analysisData;
231 unsigned int i, j;
232
233 if (!syncState->stats)
234 {
235 return;
236 }
237
238 analysisData= (AnalysisDataEval*) syncState->analysisData;
239
240 printf("Synchronization evaluation analysis stats:\n");
241 printf("\tsum of broadcast differential delays: %g\n",
242 analysisData->stats->broadcastDiffSum);
243
244 printf("\tIndividual evaluation:\n"
245 "\t\tTrace pair Inversions Too fast (No RTT info)\n");
246
247 for (i= 0; i < syncState->traceNb; i++)
248 {
249 for (j= i + 1; j < syncState->traceNb; j++)
250 {
251 TracePairStats* tpStats;
252 const char* format= "\t\t%3d - %-3d %-10u %-10u %u\n";
253
254 tpStats= &analysisData->stats->allStats[i][j];
255
256 printf(format, i, j, tpStats->inversionNb, tpStats->tooFastNb,
257 tpStats->noRTTInfoNb);
258
259 tpStats= &analysisData->stats->allStats[j][i];
260
261 printf(format, j, i, tpStats->inversionNb, tpStats->tooFastNb,
262 tpStats->noRTTInfoNb);
263 }
264 }
265 }
This page took 0.034034 seconds and 3 git commands to generate.