Give more statistics about broadcast messages
[lttv.git] / lttv / lttv / sync / event_analysis_eval.c
CommitLineData
cdce23b3 1/* This file is part of the Linux Trace Toolkit viewer
277e5b53 2 * Copyright (C) 2009, 2010 Benjamin Poirier <benjamin.poirier@polymtl.ca>
cdce23b3 3 *
277e5b53
BP
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.
cdce23b3 8 *
277e5b53
BP
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.
cdce23b3 13 *
277e5b53
BP
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/>.
cdce23b3
BP
16 */
17
2bd4b3e4 18#define _GNU_SOURCE
d4721e1a 19#define _ISOC99_SOURCE
2bd4b3e4 20
cdce23b3
BP
21#ifdef HAVE_CONFIG_H
22#include <config.h>
23#endif
24
2bd4b3e4
BP
25#include <arpa/inet.h>
26#include <errno.h>
76be6fc2 27#include <math.h>
2bd4b3e4
BP
28#include <netinet/in.h>
29#include <stddef.h>
cdce23b3 30#include <stdlib.h>
2bd4b3e4
BP
31#include <stdio.h>
32#include <string.h>
33#include <sys/socket.h>
4ee223e5 34#include <unistd.h>
cdce23b3 35
2bd4b3e4
BP
36#include "lookup3.h"
37#include "sync_chain.h"
66eaf2eb 38#include "event_analysis_chull.h"
cdce23b3
BP
39
40#include "event_analysis_eval.h"
41
42
66eaf2eb 43struct WriteHistogramInfo
e072e1ab
BP
44{
45 GHashTable* rttInfo;
46 FILE* graphsStream;
47};
48
66eaf2eb
BP
49#ifdef HAVE_LIBGLPK
50struct LPAddRowInfo
51{
52 glp_prob* lp;
53 int boundType;
54 GArray* iArray, * jArray, * aArray;
55};
56#endif
e072e1ab 57
cdce23b3
BP
58// Functions common to all analysis modules
59static void initAnalysisEval(SyncState* const syncState);
60static void destroyAnalysisEval(SyncState* const syncState);
61
62static void analyzeMessageEval(SyncState* const syncState, Message* const
63 message);
64static void analyzeExchangeEval(SyncState* const syncState, Exchange* const
65 exchange);
66static void analyzeBroadcastEval(SyncState* const syncState, Broadcast* const
67 broadcast);
68static GArray* finalizeAnalysisEval(SyncState* const syncState);
69static void printAnalysisStatsEval(SyncState* const syncState);
c5571851
BP
70static void writeAnalysisTraceTimeBackPlotsEval(SyncState* const syncState,
71 const unsigned int i, const unsigned int j);
72static void writeAnalysisTraceTimeForePlotsEval(SyncState* const syncState,
73 const unsigned int i, const unsigned int j);
c6356aa7
BP
74static void writeAnalysisTraceTraceBackPlotsEval(SyncState* const syncState,
75 const unsigned int i, const unsigned int j);
76static void writeAnalysisTraceTraceForePlotsEval(SyncState* const syncState,
77 const unsigned int i, const unsigned int j);
cdce23b3
BP
78
79// Functions specific to this module
2bd4b3e4
BP
80static guint ghfRttKeyHash(gconstpointer key);
81static gboolean gefRttKeyEqual(gconstpointer a, gconstpointer b);
82static void gdnDestroyRttKey(gpointer data);
83static void gdnDestroyDouble(gpointer data);
84static void readRttInfo(GHashTable* rttInfo, FILE* rttFile);
85static void positionStream(FILE* stream);
cdce23b3 86
76be6fc2
BP
87static void gfSum(gpointer data, gpointer userData);
88static void gfSumSquares(gpointer data, gpointer userData);
66eaf2eb
BP
89static void ghfPrintExchangeRtt(gpointer key, gpointer value, gpointer
90 user_data);
76be6fc2 91
e072e1ab 92static void hitBin(struct Bins* const bins, const double value);
4ee223e5
BP
93static unsigned int binNum(const double value) __attribute__((pure));
94static double binStart(const unsigned int binNum) __attribute__((pure));
95static double binEnd(const unsigned int binNum) __attribute__((pure));
467066ee 96static uint32_t normalTotal(struct Bins* const bins) __attribute__((const));
4ee223e5 97
66eaf2eb 98static AnalysisHistogramEval* constructAnalysisHistogramEval(const char* const
e072e1ab 99 graphsDir, const struct RttKey* const rttKey);
66eaf2eb
BP
100static void destroyAnalysisHistogramEval(AnalysisHistogramEval* const
101 histogram);
102static void gdnDestroyAnalysisHistogramEval(gpointer data);
103static void ghfWriteHistogram(gpointer key, gpointer value, gpointer
104 user_data);
e072e1ab
BP
105static void dumpBinToFile(const struct Bins* const bins, FILE* const file);
106static void writeHistogram(FILE* graphsStream, const struct RttKey* rttKey,
66eaf2eb
BP
107 double* minRtt, AnalysisHistogramEval* const histogram);
108
c6356aa7
BP
109static void updateBounds(Bounds** const bounds, Event* const e1, Event* const
110 e2);
66eaf2eb 111
05a840df 112static void finalizeAnalysisEvalLP(SyncState* const syncState);
66eaf2eb
BP
113// The next group of functions is only needed when computing synchronization
114// accuracy.
115#ifdef HAVE_LIBGLPK
c6356aa7
BP
116static glp_prob* lpCreateProblem(GQueue* const lowerHull, GQueue* const
117 upperHull);
66eaf2eb
BP
118static void gfLPAddRow(gpointer data, gpointer user_data);
119static Factors* calculateFactors(glp_prob* const lp, const int direction);
c6356aa7
BP
120static void calculateCompleteFactors(glp_prob* const lp, FactorsCHull*
121 factors);
66eaf2eb 122static FactorsCHull** createAllFactors(const unsigned int traceNb);
66eaf2eb 123#endif
e072e1ab 124
4ee223e5 125
66eaf2eb 126// initialized in registerAnalysisEval()
4ee223e5 127double binBase;
cdce23b3
BP
128
129static AnalysisModule analysisModuleEval= {
130 .name= "eval",
131 .initAnalysis= &initAnalysisEval,
132 .destroyAnalysis= &destroyAnalysisEval,
133 .analyzeMessage= &analyzeMessageEval,
134 .analyzeExchange= &analyzeExchangeEval,
135 .analyzeBroadcast= &analyzeBroadcastEval,
136 .finalizeAnalysis= &finalizeAnalysisEval,
137 .printAnalysisStats= &printAnalysisStatsEval,
66eaf2eb 138 .graphFunctions= {
c5571851
BP
139 .writeTraceTimeBackPlots= &writeAnalysisTraceTimeBackPlotsEval,
140 .writeTraceTimeForePlots= &writeAnalysisTraceTimeForePlotsEval,
c6356aa7
BP
141 .writeTraceTraceBackPlots= &writeAnalysisTraceTraceBackPlotsEval,
142 .writeTraceTraceForePlots= &writeAnalysisTraceTraceForePlotsEval,
66eaf2eb 143 }
cdce23b3
BP
144};
145
2bd4b3e4
BP
146static ModuleOption optionEvalRttFile= {
147 .longName= "eval-rtt-file",
148 .hasArg= REQUIRED_ARG,
4ee223e5 149 .optionHelp= "specify the file containing RTT information",
2bd4b3e4
BP
150 .argHelp= "FILE",
151};
152
cdce23b3
BP
153
154/*
155 * Analysis module registering function
156 */
2f961b65 157void registerAnalysisEval()
cdce23b3 158{
66eaf2eb
BP
159 binBase= exp10(6. / (BIN_NB - 3));
160
cdce23b3 161 g_queue_push_tail(&analysisModules, &analysisModuleEval);
2bd4b3e4 162 g_queue_push_tail(&moduleOptions, &optionEvalRttFile);
cdce23b3
BP
163}
164
165
166/*
167 * Analysis init function
168 *
169 * This function is called at the beginning of a synchronization run for a set
170 * of traces.
171 *
172 * Args:
173 * syncState container for synchronization data.
174 */
175static void initAnalysisEval(SyncState* const syncState)
176{
177 AnalysisDataEval* analysisData;
66eaf2eb 178 unsigned int i, j;
cdce23b3
BP
179
180 analysisData= malloc(sizeof(AnalysisDataEval));
181 syncState->analysisData= analysisData;
182
2bd4b3e4
BP
183 analysisData->rttInfo= g_hash_table_new_full(&ghfRttKeyHash,
184 &gefRttKeyEqual, &gdnDestroyRttKey, &gdnDestroyDouble);
185 if (optionEvalRttFile.arg)
186 {
187 FILE* rttStream;
188 int retval;
189
190 rttStream= fopen(optionEvalRttFile.arg, "r");
191 if (rttStream == NULL)
192 {
193 g_error(strerror(errno));
194 }
195
196 readRttInfo(analysisData->rttInfo, rttStream);
197
198 retval= fclose(rttStream);
199 if (retval == EOF)
200 {
201 g_error(strerror(errno));
202 }
203 }
cdce23b3
BP
204
205 if (syncState->stats)
206 {
76be6fc2 207 analysisData->stats= calloc(1, sizeof(AnalysisStatsEval));
2849af52
BP
208 analysisData->stats->broadcastRangeMin= INFINITY;
209 analysisData->stats->broadcastRangeMax= -INFINITY;
cdce23b3 210
76be6fc2
BP
211 analysisData->stats->messageStats= malloc(syncState->traceNb *
212 sizeof(MessageStats*));
cdce23b3
BP
213 for (i= 0; i < syncState->traceNb; i++)
214 {
76be6fc2
BP
215 analysisData->stats->messageStats[i]= calloc(syncState->traceNb,
216 sizeof(MessageStats));
cdce23b3 217 }
d4721e1a
BP
218
219 analysisData->stats->exchangeRtt=
220 g_hash_table_new_full(&ghfRttKeyHash, &gefRttKeyEqual,
221 &gdnDestroyRttKey, &gdnDestroyDouble);
66eaf2eb
BP
222
223#ifdef HAVE_LIBGLPK
224 analysisData->stats->chFactorsArray= NULL;
225 analysisData->stats->lpFactorsArray= NULL;
226#endif
cdce23b3 227 }
4ee223e5 228
8d7d16dd 229 if (syncState->graphsStream)
4ee223e5 230 {
66eaf2eb
BP
231 AnalysisGraphsEval* graphs= malloc(sizeof(AnalysisGraphsEval));
232
233 analysisData->graphs= graphs;
234
235 graphs->histograms= g_hash_table_new_full(&ghfRttKeyHash,
236 &gefRttKeyEqual, &gdnDestroyRttKey,
237 &gdnDestroyAnalysisHistogramEval);
238
239 graphs->bounds= malloc(syncState->traceNb * sizeof(Bounds*));
240 for (i= 0; i < syncState->traceNb; i++)
241 {
242 graphs->bounds[i]= malloc(i * sizeof(Bounds));
243 for (j= 0; j < i; j++)
244 {
245 graphs->bounds[i][j].min= UINT64_MAX;
246 graphs->bounds[i][j].max= 0;
247 }
248 }
249
250#ifdef HAVE_LIBGLPK
251 graphs->lps= NULL;
252 graphs->lpFactorsArray= NULL;
253#endif
254 }
255
256 if (syncState->stats || syncState->graphsStream)
257 {
258 GList* result;
259
260 analysisData->chullSS= malloc(sizeof(SyncState));
261 memcpy(analysisData->chullSS, syncState, sizeof(SyncState));
262 analysisData->chullSS->stats= false;
263 analysisData->chullSS->analysisData= NULL;
264 result= g_queue_find_custom(&analysisModules, "chull",
265 &gcfCompareAnalysis);
266 analysisData->chullSS->analysisModule= (AnalysisModule*) result->data;
267 analysisData->chullSS->analysisModule->initAnalysis(analysisData->chullSS);
4ee223e5
BP
268 }
269}
270
271
272/*
e072e1ab
BP
273 * Create and open files used to store histogram points to generate graphs.
274 * Create data structures to store histogram points during analysis.
4ee223e5
BP
275 *
276 * Args:
e072e1ab
BP
277 * graphsDir: folder where to write files
278 * rttKey: host pair, make sure saddr < daddr
4ee223e5 279 */
66eaf2eb 280static AnalysisHistogramEval* constructAnalysisHistogramEval(const char* const
e072e1ab 281 graphsDir, const struct RttKey* const rttKey)
4ee223e5 282{
4ee223e5 283 int retval;
e072e1ab 284 unsigned int i;
4ee223e5 285 char* cwd;
e072e1ab 286 char name[60], saddr[16], daddr[16];
66eaf2eb 287 AnalysisHistogramEval* histogram= calloc(1, sizeof(*histogram));
e072e1ab
BP
288 const struct {
289 size_t pointsOffset;
290 const char* fileName;
291 const char* host1, *host2;
292 } loopValues[]= {
66eaf2eb
BP
293 {offsetof(AnalysisHistogramEval, ttSendPoints),
294 "analysis_eval_tt-%s_to_%s.data", saddr, daddr},
295 {offsetof(AnalysisHistogramEval, ttRecvPoints),
296 "analysis_eval_tt-%s_to_%s.data", daddr, saddr},
297 {offsetof(AnalysisHistogramEval, hrttPoints),
298 "analysis_eval_hrtt-%s_and_%s.data", saddr, daddr},
e072e1ab
BP
299 };
300
66eaf2eb
BP
301 histogram->ttSendBins.min= BIN_NB - 1;
302 histogram->ttRecvBins.min= BIN_NB - 1;
303 histogram->hrttBins.min= BIN_NB - 1;
e072e1ab
BP
304
305 convertIP(saddr, rttKey->saddr);
306 convertIP(daddr, rttKey->daddr);
307
1d597550 308 cwd= changeToGraphsDir(graphsDir);
e072e1ab
BP
309
310 for (i= 0; i < sizeof(loopValues) / sizeof(*loopValues); i++)
4ee223e5 311 {
e072e1ab
BP
312 retval= snprintf(name, sizeof(name), loopValues[i].fileName,
313 loopValues[i].host1, loopValues[i].host2);
314 if (retval > sizeof(name) - 1)
4ee223e5 315 {
e072e1ab 316 name[sizeof(name) - 1]= '\0';
4ee223e5 317 }
66eaf2eb 318 if ((*(FILE**)((void*) histogram + loopValues[i].pointsOffset)=
e072e1ab 319 fopen(name, "w")) == NULL)
4ee223e5 320 {
e072e1ab 321 g_error(strerror(errno));
4ee223e5
BP
322 }
323 }
324
325 retval= chdir(cwd);
326 if (retval == -1)
327 {
328 g_error(strerror(errno));
329 }
330 free(cwd);
e072e1ab 331
66eaf2eb 332 return histogram;
4ee223e5
BP
333}
334
335
336/*
e072e1ab 337 * Close files used to store histogram points to generate graphs.
4ee223e5
BP
338 *
339 * Args:
e072e1ab
BP
340 * graphsDir: folder where to write files
341 * rttKey: host pair, make sure saddr < daddr
4ee223e5 342 */
66eaf2eb
BP
343static void destroyAnalysisHistogramEval(AnalysisHistogramEval* const
344 histogram)
4ee223e5 345{
e072e1ab
BP
346 unsigned int i;
347 int retval;
348 const struct {
349 size_t pointsOffset;
350 } loopValues[]= {
66eaf2eb
BP
351 {offsetof(AnalysisHistogramEval, ttSendPoints)},
352 {offsetof(AnalysisHistogramEval, ttRecvPoints)},
353 {offsetof(AnalysisHistogramEval, hrttPoints)},
e072e1ab
BP
354 };
355
356 for (i= 0; i < sizeof(loopValues) / sizeof(*loopValues); i++)
4ee223e5 357 {
66eaf2eb 358 retval= fclose(*(FILE**)((void*) histogram + loopValues[i].pointsOffset));
e072e1ab 359 if (retval != 0)
4ee223e5 360 {
e072e1ab 361 g_error(strerror(errno));
4ee223e5
BP
362 }
363 }
66eaf2eb
BP
364
365 free(histogram);
4ee223e5
BP
366}
367
368
e072e1ab
BP
369/*
370 * A GDestroyNotify function for g_hash_table_new_full()
371 *
372 * Args:
66eaf2eb 373 * data: AnalysisHistogramEval*
e072e1ab 374 */
66eaf2eb 375static void gdnDestroyAnalysisHistogramEval(gpointer data)
e072e1ab 376{
66eaf2eb 377 destroyAnalysisHistogramEval(data);
e072e1ab
BP
378}
379
380
381/*
382 * A GHFunc for g_hash_table_foreach()
383 *
384 * Args:
385 * key: RttKey* where saddr < daddr
66eaf2eb
BP
386 * value: AnalysisHistogramEval*
387 * user_data struct WriteHistogramInfo*
e072e1ab 388 */
66eaf2eb 389static void ghfWriteHistogram(gpointer key, gpointer value, gpointer user_data)
e072e1ab
BP
390{
391 double* rtt1, * rtt2;
392 struct RttKey* rttKey= key;
393 struct RttKey oppositeRttKey= {.saddr= rttKey->daddr, .daddr=
394 rttKey->saddr};
66eaf2eb
BP
395 AnalysisHistogramEval* histogram= value;
396 struct WriteHistogramInfo* info= user_data;
e072e1ab
BP
397
398 rtt1= g_hash_table_lookup(info->rttInfo, rttKey);
399 rtt2= g_hash_table_lookup(info->rttInfo, &oppositeRttKey);
400
401 if (rtt1 == NULL)
402 {
403 rtt1= rtt2;
404 }
405 else if (rtt2 != NULL)
406 {
407 rtt1= MIN(rtt1, rtt2);
408 }
409
66eaf2eb
BP
410 dumpBinToFile(&histogram->ttSendBins, histogram->ttSendPoints);
411 dumpBinToFile(&histogram->ttRecvBins, histogram->ttRecvPoints);
412 dumpBinToFile(&histogram->hrttBins, histogram->hrttPoints);
413 writeHistogram(info->graphsStream, rttKey, rtt1, histogram);
e072e1ab
BP
414}
415
416
4ee223e5
BP
417/*
418 * Write the content of one bin in a histogram point file
419 *
420 * Args:
421 * bin: array of values that make up a histogram
e072e1ab 422 * file: FILE*, write to this file
4ee223e5 423 */
e072e1ab 424static void dumpBinToFile(const struct Bins* const bins, FILE* const file)
4ee223e5
BP
425{
426 unsigned int i;
427
e072e1ab
BP
428 // The first and last bins are skipped, see struct Bins
429 for (i= 1; i < BIN_NB - 1; i++)
4ee223e5 430 {
e072e1ab 431 if (bins->bin[i] > 0)
4ee223e5 432 {
e072e1ab
BP
433 fprintf(file, "%20.9f %20.9f %20.9f\n", (binStart(i) + binEnd(i))
434 / 2., (double) bins->bin[i] / ((binEnd(i) - binStart(i)) *
435 bins->total), binEnd(i) - binStart(i));
4ee223e5
BP
436 }
437 }
438}
439
440
441/*
e072e1ab 442 * Write the analysis-specific plot in the gnuplot script.
4ee223e5
BP
443 *
444 * Args:
e072e1ab
BP
445 * graphsStream: write to this file
446 * rttKey: must be sorted such that saddr < daddr
447 * minRtt: if available, else NULL
66eaf2eb 448 * histogram: struct that contains the bins for the pair of traces
467066ee 449 * identified by rttKey
4ee223e5 450 */
e072e1ab 451static void writeHistogram(FILE* graphsStream, const struct RttKey* rttKey,
66eaf2eb 452 double* minRtt, AnalysisHistogramEval* const histogram)
4ee223e5 453{
e072e1ab 454 char saddr[16], daddr[16];
4ee223e5 455
e072e1ab
BP
456 convertIP(saddr, rttKey->saddr);
457 convertIP(daddr, rttKey->daddr);
4ee223e5 458
e072e1ab 459 fprintf(graphsStream,
66eaf2eb 460 "\nreset\n"
e072e1ab
BP
461 "set output \"histogram-%s-%s.eps\"\n"
462 "set title \"\"\n"
463 "set xlabel \"Message Latency (s)\"\n"
464 "set ylabel \"Proportion of messages per second\"\n", saddr, daddr);
4ee223e5 465
e072e1ab 466 if (minRtt != NULL)
4ee223e5 467 {
e072e1ab
BP
468 fprintf(graphsStream,
469 "set arrow from %.9f, 0 rto 0, graph 1 "
467066ee
BP
470 "nohead linetype 3 linewidth 3 linecolor rgb \"black\"\n", *minRtt
471 / 2);
4ee223e5 472 }
4ee223e5 473
66eaf2eb
BP
474 if (normalTotal(&histogram->ttSendBins) ||
475 normalTotal(&histogram->ttRecvBins) ||
476 normalTotal(&histogram->hrttBins))
467066ee
BP
477 {
478 fprintf(graphsStream, "plot \\\n");
479
66eaf2eb 480 if (normalTotal(&histogram->hrttBins))
467066ee
BP
481 {
482 fprintf(graphsStream,
483 "\t\"analysis_eval_hrtt-%s_and_%s.data\" "
484 "title \"RTT/2\" with linespoints linetype 1 linewidth 2 "
485 "linecolor rgb \"black\" pointtype 6 pointsize 1,\\\n",
486 saddr, daddr);
487 }
488
66eaf2eb 489 if (normalTotal(&histogram->ttSendBins))
467066ee
BP
490 {
491 fprintf(graphsStream,
492 "\t\"analysis_eval_tt-%1$s_to_%2$s.data\" "
493 "title \"%1$s to %2$s\" with linespoints linetype 4 linewidth 2 "
494 "linecolor rgb \"gray60\" pointtype 6 pointsize 1,\\\n",
495 saddr, daddr);
496 }
497
66eaf2eb 498 if (normalTotal(&histogram->ttRecvBins))
467066ee
BP
499 {
500 fprintf(graphsStream,
501 "\t\"analysis_eval_tt-%1$s_to_%2$s.data\" "
502 "title \"%1$s to %2$s\" with linespoints linetype 4 linewidth 2 "
503 "linecolor rgb \"gray30\" pointtype 6 pointsize 1,\\\n",
504 daddr, saddr);
505 }
506
507 // Remove the ",\\\n" from the last graph plot line
508 if (ftruncate(fileno(graphsStream), ftell(graphsStream) - 3) == -1)
509 {
510 g_error(strerror(errno));
511 }
512 if (fseek(graphsStream, 0, SEEK_END) == -1)
513 {
514 g_error(strerror(errno));
515 }
516 fprintf(graphsStream, "\n");
517 }
cdce23b3
BP
518}
519
520
521/*
522 * Analysis destroy function
523 *
524 * Free the analysis specific data structures
525 *
526 * Args:
527 * syncState container for synchronization data.
528 */
529static void destroyAnalysisEval(SyncState* const syncState)
530{
05a840df 531 unsigned int i;
cdce23b3
BP
532 AnalysisDataEval* analysisData;
533
534 analysisData= (AnalysisDataEval*) syncState->analysisData;
535
66eaf2eb 536 if (analysisData == NULL)
cdce23b3
BP
537 {
538 return;
539 }
540
2bd4b3e4 541 g_hash_table_destroy(analysisData->rttInfo);
cdce23b3
BP
542
543 if (syncState->stats)
544 {
66eaf2eb
BP
545 AnalysisStatsEval* stats= analysisData->stats;
546
547 for (i= 0; i < syncState->traceNb; i++)
548 {
549 free(stats->messageStats[i]);
550 }
551 free(stats->messageStats);
552
553 g_hash_table_destroy(stats->exchangeRtt);
554
555#ifdef HAVE_LIBGLPK
556 freeAllFactors(syncState->traceNb, stats->chFactorsArray);
557 freeAllFactors(syncState->traceNb, stats->lpFactorsArray);
558#endif
559
560 free(stats);
561 }
562
563 if (syncState->graphsStream)
564 {
565 AnalysisGraphsEval* graphs= analysisData->graphs;
566
567 if (graphs->histograms)
568 {
569 g_hash_table_destroy(graphs->histograms);
570 }
571
cdce23b3
BP
572 for (i= 0; i < syncState->traceNb; i++)
573 {
66eaf2eb
BP
574 free(graphs->bounds[i]);
575 }
576 free(graphs->bounds);
577
578#ifdef HAVE_LIBGLPK
579 for (i= 0; i < syncState->traceNb; i++)
580 {
05a840df
BP
581 unsigned int j;
582
66eaf2eb
BP
583 for (j= 0; j < i; j++)
584 {
585 // There seems to be a memory leak in glpk, valgrind reports a
6ce8ceac 586 // loss (reachable) even if the problem is deleted
66eaf2eb
BP
587 glp_delete_prob(graphs->lps[i][j]);
588 }
589 free(graphs->lps[i]);
cdce23b3 590 }
66eaf2eb 591 free(graphs->lps);
d4721e1a 592
66eaf2eb
BP
593 if (!syncState->stats)
594 {
595 freeAllFactors(syncState->traceNb, graphs->lpFactorsArray);
596 }
597#endif
d4721e1a 598
66eaf2eb 599 free(graphs);
cdce23b3
BP
600 }
601
66eaf2eb 602 if (syncState->stats || syncState->graphsStream)
4ee223e5 603 {
66eaf2eb
BP
604 analysisData->chullSS->analysisModule->destroyAnalysis(analysisData->chullSS);
605 free(analysisData->chullSS);
4ee223e5
BP
606 }
607
cdce23b3
BP
608 free(syncState->analysisData);
609 syncState->analysisData= NULL;
610}
611
612
613/*
614 * Perform analysis on an event pair.
615 *
76be6fc2
BP
616 * Check if there is message inversion or messages that are too fast.
617 *
cdce23b3
BP
618 * Args:
619 * syncState container for synchronization data
620 * message structure containing the events
621 */
66eaf2eb
BP
622static void analyzeMessageEval(SyncState* const syncState, Message* const
623 message)
cdce23b3 624{
e072e1ab 625 AnalysisDataEval* analysisData= syncState->analysisData;
7e39acc6 626 MessageStats* messageStats;
d4721e1a 627 double* rtt;
76be6fc2
BP
628 double tt;
629 struct RttKey rttKey;
630
e072e1ab 631 g_assert(message->inE->type == TCP);
76be6fc2 632
66eaf2eb
BP
633 if (syncState->stats)
634 {
7e39acc6
BP
635 messageStats=
636 &analysisData->stats->messageStats[message->outE->traceNum][message->inE->traceNum];
66eaf2eb
BP
637 messageStats->total++;
638 }
76be6fc2
BP
639
640 tt= wallTimeSub(&message->inE->wallTime, &message->outE->wallTime);
641 if (tt <= 0)
642 {
66eaf2eb
BP
643 if (syncState->stats)
644 {
645 messageStats->inversionNb++;
646 }
76be6fc2 647 }
8d7d16dd 648 else if (syncState->graphsStream)
4ee223e5 649 {
e072e1ab
BP
650 struct RttKey rttKey= {
651 .saddr=MIN(message->inE->event.tcpEvent->segmentKey->connectionKey.saddr,
652 message->inE->event.tcpEvent->segmentKey->connectionKey.daddr),
653 .daddr=MAX(message->inE->event.tcpEvent->segmentKey->connectionKey.saddr,
654 message->inE->event.tcpEvent->segmentKey->connectionKey.daddr),
655 };
66eaf2eb
BP
656 AnalysisHistogramEval* histogram=
657 g_hash_table_lookup(analysisData->graphs->histograms, &rttKey);
e072e1ab 658
66eaf2eb 659 if (histogram == NULL)
e072e1ab
BP
660 {
661 struct RttKey* tableKey= malloc(sizeof(*tableKey));
662
66eaf2eb 663 histogram= constructAnalysisHistogramEval(syncState->graphsDir, &rttKey);
e072e1ab 664 memcpy(tableKey, &rttKey, sizeof(*tableKey));
66eaf2eb 665 g_hash_table_insert(analysisData->graphs->histograms, tableKey, histogram);
e072e1ab
BP
666 }
667
668 if (message->inE->event.udpEvent->datagramKey->saddr <
669 message->inE->event.udpEvent->datagramKey->daddr)
670 {
66eaf2eb 671 hitBin(&histogram->ttSendBins, tt);
e072e1ab
BP
672 }
673 else
674 {
66eaf2eb 675 hitBin(&histogram->ttRecvBins, tt);
e072e1ab 676 }
4ee223e5 677 }
76be6fc2 678
66eaf2eb 679 if (syncState->stats)
76be6fc2 680 {
66eaf2eb
BP
681 rttKey.saddr=
682 message->inE->event.tcpEvent->segmentKey->connectionKey.saddr;
683 rttKey.daddr=
684 message->inE->event.tcpEvent->segmentKey->connectionKey.daddr;
685 rtt= g_hash_table_lookup(analysisData->rttInfo, &rttKey);
686 g_debug("rttInfo, looking up (%u, %u)->(%f)", rttKey.saddr,
687 rttKey.daddr, rtt ? *rtt : NAN);
688
689 if (rtt)
76be6fc2 690 {
66eaf2eb
BP
691 g_debug("rttInfo, tt: %f rtt / 2: %f", tt, *rtt / 2.);
692 if (tt < *rtt / 2.)
693 {
694 messageStats->tooFastNb++;
695 }
696 }
697 else
698 {
699 messageStats->noRTTInfoNb++;
76be6fc2
BP
700 }
701 }
66eaf2eb
BP
702
703 if (syncState->graphsStream)
704 {
705 updateBounds(analysisData->graphs->bounds, message->inE,
706 message->outE);
707 }
708
709 if (syncState->stats || syncState->graphsStream)
76be6fc2 710 {
66eaf2eb
BP
711 analysisData->chullSS->analysisModule->analyzeMessage(analysisData->chullSS,
712 message);
76be6fc2 713 }
cdce23b3
BP
714}
715
716
717/*
718 * Perform analysis on multiple messages
719 *
76be6fc2
BP
720 * Measure the RTT
721 *
cdce23b3
BP
722 * Args:
723 * syncState container for synchronization data
724 * exchange structure containing the messages
725 */
66eaf2eb
BP
726static void analyzeExchangeEval(SyncState* const syncState, Exchange* const
727 exchange)
cdce23b3 728{
d4721e1a
BP
729 AnalysisDataEval* analysisData= syncState->analysisData;
730 Message* m1= g_queue_peek_tail(exchange->acks);
731 Message* m2= exchange->message;
732 struct RttKey* rttKey;
733 double* rtt, * exchangeRtt;
cdce23b3 734
e072e1ab
BP
735 g_assert(m1->inE->type == TCP);
736
d4721e1a
BP
737 // (T2 - T1) - (T3 - T4)
738 rtt= malloc(sizeof(double));
739 *rtt= wallTimeSub(&m1->inE->wallTime, &m1->outE->wallTime) -
740 wallTimeSub(&m2->outE->wallTime, &m2->inE->wallTime);
741
d4721e1a
BP
742 rttKey= malloc(sizeof(struct RttKey));
743 rttKey->saddr=
744 MIN(m1->inE->event.tcpEvent->segmentKey->connectionKey.saddr,
745 m1->inE->event.tcpEvent->segmentKey->connectionKey.daddr);
746 rttKey->daddr=
747 MAX(m1->inE->event.tcpEvent->segmentKey->connectionKey.saddr,
748 m1->inE->event.tcpEvent->segmentKey->connectionKey.daddr);
e072e1ab
BP
749
750 if (syncState->graphsStream)
751 {
66eaf2eb
BP
752 AnalysisHistogramEval* histogram=
753 g_hash_table_lookup(analysisData->graphs->histograms, rttKey);
e072e1ab 754
66eaf2eb 755 if (histogram == NULL)
e072e1ab
BP
756 {
757 struct RttKey* tableKey= malloc(sizeof(*tableKey));
758
66eaf2eb
BP
759 histogram= constructAnalysisHistogramEval(syncState->graphsDir,
760 rttKey);
e072e1ab 761 memcpy(tableKey, rttKey, sizeof(*tableKey));
66eaf2eb
BP
762 g_hash_table_insert(analysisData->graphs->histograms, tableKey,
763 histogram);
e072e1ab
BP
764 }
765
66eaf2eb 766 hitBin(&histogram->hrttBins, *rtt / 2);
e072e1ab
BP
767 }
768
66eaf2eb 769 if (syncState->stats)
d4721e1a 770 {
66eaf2eb
BP
771 exchangeRtt= g_hash_table_lookup(analysisData->stats->exchangeRtt,
772 rttKey);
773
774 if (exchangeRtt)
d4721e1a 775 {
66eaf2eb
BP
776 if (*rtt < *exchangeRtt)
777 {
778 g_hash_table_replace(analysisData->stats->exchangeRtt, rttKey, rtt);
779 }
780 else
781 {
782 free(rttKey);
783 free(rtt);
784 }
785 }
786 else
787 {
788 g_hash_table_insert(analysisData->stats->exchangeRtt, rttKey, rtt);
d4721e1a
BP
789 }
790 }
791 else
792 {
66eaf2eb
BP
793 free(rttKey);
794 free(rtt);
d4721e1a 795 }
cdce23b3
BP
796}
797
798
799/*
800 * Perform analysis on muliple events
801 *
76be6fc2
BP
802 * Sum the broadcast differential delays
803 *
cdce23b3
BP
804 * Args:
805 * syncState container for synchronization data
806 * broadcast structure containing the events
807 */
66eaf2eb
BP
808static void analyzeBroadcastEval(SyncState* const syncState, Broadcast* const
809 broadcast)
cdce23b3 810{
66eaf2eb 811 AnalysisDataEval* analysisData= syncState->analysisData;
76be6fc2 812
66eaf2eb 813 if (syncState->stats)
76be6fc2 814 {
66eaf2eb
BP
815 double sum= 0, squaresSum= 0;
816 double y;
cdce23b3 817
66eaf2eb
BP
818 g_queue_foreach(broadcast->events, &gfSum, &sum);
819 g_queue_foreach(broadcast->events, &gfSumSquares, &squaresSum);
76be6fc2 820
66eaf2eb
BP
821 analysisData->stats->broadcastNb++;
822 // Because of numerical errors, this can at times be < 0
823 y= squaresSum / g_queue_get_length(broadcast->events) - pow(sum /
824 g_queue_get_length(broadcast->events), 2.);
825 if (y > 0)
826 {
2849af52
BP
827 analysisData->stats->broadcastStdevSum+= sqrt(y);
828 }
829
830 if (syncState->traceNb == 2 && g_queue_get_length(broadcast->events)
831 == 2)
832 {
833 Event* e0, * e1;
834 double dd;
835
836 e0= g_queue_peek_head(broadcast->events);
837 e1= g_queue_peek_tail(broadcast->events);
838 if (e0->traceNum > e1->traceNum)
839 {
840 Event* tmp;
841
842 tmp= e0;
843 e0= e1;
844 e1= tmp;
845 }
846
847 dd= wallTimeSub(&e1->wallTime, &e0->wallTime);
848
849 analysisData->stats->broadcastPairNb++;
850 if (dd < analysisData->stats->broadcastRangeMin)
851 {
852 analysisData->stats->broadcastRangeMin= dd;
853 }
854 if (dd > analysisData->stats->broadcastRangeMax)
855 {
856 analysisData->stats->broadcastRangeMax= dd;
857 }
858
859 analysisData->stats->broadcastSum+= dd;
860 analysisData->stats->broadcastSumSquares+= pow(dd, 2);
66eaf2eb
BP
861 }
862 }
76be6fc2 863
66eaf2eb 864 if (syncState->graphsStream)
76be6fc2 865 {
66eaf2eb
BP
866 unsigned int i, j;
867 GArray* events;
868 unsigned int eventNb= broadcast->events->length;
869
870 events= g_array_sized_new(FALSE, FALSE, sizeof(Event*), eventNb);
871 g_queue_foreach(broadcast->events, &gfAddEventToArray, events);
872
873 for (i= 0; i < eventNb; i++)
874 {
875 for (j= 0; j < eventNb; j++)
876 {
877 Event* eventI= g_array_index(events, Event*, i), * eventJ=
878 g_array_index(events, Event*, j);
879
880 if (eventI->traceNum < eventJ->traceNum)
881 {
882 updateBounds(analysisData->graphs->bounds, eventI, eventJ);
883 }
884 }
885 }
886
887 g_array_free(events, TRUE);
76be6fc2 888 }
cdce23b3
BP
889}
890
891
892/*
66eaf2eb
BP
893 * Finalize the factor calculations. Since this module does not really
894 * calculate factors, identity factors are returned. Instead, histograms are
895 * written out and histogram structures are freed.
cdce23b3
BP
896 *
897 * Args:
898 * syncState container for synchronization data.
899 *
900 * Returns:
d4721e1a 901 * Factors[traceNb] identity factors for each trace
cdce23b3
BP
902 */
903static GArray* finalizeAnalysisEval(SyncState* const syncState)
904{
905 GArray* factors;
906 unsigned int i;
4ee223e5
BP
907 AnalysisDataEval* analysisData= syncState->analysisData;
908
66eaf2eb 909 if (syncState->graphsStream && analysisData->graphs->histograms)
4ee223e5 910 {
66eaf2eb
BP
911 g_hash_table_foreach(analysisData->graphs->histograms,
912 &ghfWriteHistogram, &(struct WriteHistogramInfo) {.rttInfo=
913 analysisData->rttInfo, .graphsStream= syncState->graphsStream});
914 g_hash_table_destroy(analysisData->graphs->histograms);
915 analysisData->graphs->histograms= NULL;
4ee223e5 916 }
cdce23b3 917
66eaf2eb
BP
918 finalizeAnalysisEvalLP(syncState);
919
cdce23b3
BP
920 factors= g_array_sized_new(FALSE, FALSE, sizeof(Factors),
921 syncState->traceNb);
922 g_array_set_size(factors, syncState->traceNb);
923 for (i= 0; i < syncState->traceNb; i++)
924 {
925 Factors* e;
926
927 e= &g_array_index(factors, Factors, i);
928 e->drift= 1.;
929 e->offset= 0.;
930 }
931
932 return factors;
933}
934
935
936/*
937 * Print statistics related to analysis. Must be called after
938 * finalizeAnalysis.
939 *
940 * Args:
941 * syncState container for synchronization data.
942 */
943static void printAnalysisStatsEval(SyncState* const syncState)
944{
945 AnalysisDataEval* analysisData;
f109919b
BP
946 unsigned int i, j, k;
947 unsigned int totInversion= 0, totTooFast= 0, totNoInfo= 0, totTotal= 0;
948 int charNb;
cdce23b3
BP
949
950 if (!syncState->stats)
951 {
952 return;
953 }
954
955 analysisData= (AnalysisDataEval*) syncState->analysisData;
956
957 printf("Synchronization evaluation analysis stats:\n");
ffa21cfd
BP
958 if (analysisData->stats->broadcastNb)
959 {
2849af52
BP
960 printf("\tBroadcast differential delay:\n");
961 printf("\t\tsum of standard deviations: %g\n",
962 analysisData->stats->broadcastStdevSum);
963 printf("\t\taverage standard deviation: %g\n",
964 analysisData->stats->broadcastStdevSum /
ffa21cfd 965 analysisData->stats->broadcastNb);
2849af52
BP
966
967 if (syncState->traceNb == 2)
968 {
969 printf("\t\tdifferential delay range: [ %g .. %g ]\n",
970 analysisData->stats->broadcastRangeMin,
971 analysisData->stats->broadcastRangeMax);
972 printf("\t\tdifferential delay average: %g\n",
973 analysisData->stats->broadcastSum /
974 analysisData->stats->broadcastPairNb);
975 printf("\t\tdifferential delay standard deviation: %g\n",
976 sqrt(analysisData->stats->broadcastSumSquares /
977 analysisData->stats->broadcastPairNb -
978 pow(analysisData->stats->broadcastSum /
979 analysisData->stats->broadcastPairNb, 2)));
980 }
ffa21cfd 981 }
cdce23b3
BP
982
983 printf("\tIndividual evaluation:\n"
f109919b 984 "\t\tTrace pair Inversions Too fast No RTT info Total\n");
cdce23b3
BP
985
986 for (i= 0; i < syncState->traceNb; i++)
987 {
988 for (j= i + 1; j < syncState->traceNb; j++)
989 {
76be6fc2 990 MessageStats* messageStats;
f109919b
BP
991 struct {
992 unsigned int t1, t2;
993 } loopValues[]= {
994 {i, j},
995 {j, i}
996 };
997
998 for (k= 0; k < sizeof(loopValues) / sizeof(*loopValues); k++)
999 {
1000 messageStats=
1001 &analysisData->stats->messageStats[loopValues[k].t1][loopValues[k].t2];
1002
1003 printf("\t\t%3d - %-3d ", loopValues[k].t1, loopValues[k].t2);
2849af52
BP
1004 printf("%u (%.2f%%)%n", messageStats->inversionNb, (double)
1005 messageStats->inversionNb / messageStats->total * 100,
1006 &charNb);
f109919b 1007 printf("%*s", 17 - charNb > 0 ? 17 - charNb + 1: 1, " ");
2849af52
BP
1008 printf("%u (%.2f%%)%n", messageStats->tooFastNb, (double)
1009 messageStats->tooFastNb / messageStats->total * 100,
1010 &charNb);
f109919b
BP
1011 printf("%*s%-10u %u\n", 17 - charNb > 0 ? 17 - charNb + 1:
1012 1, " ", messageStats->noRTTInfoNb, messageStats->total);
1013
1014 totInversion+= messageStats->inversionNb;
1015 totTooFast+= messageStats->tooFastNb;
1016 totNoInfo+= messageStats->noRTTInfoNb;
1017 totTotal+= messageStats->total;
1018 }
cdce23b3
BP
1019 }
1020 }
d4721e1a 1021
f109919b 1022 printf("\t\t total ");
2849af52
BP
1023 printf("%u (%.2f%%)%n", totInversion, (double) totInversion / totTotal *
1024 100, &charNb);
f109919b 1025 printf("%*s", 17 - charNb > 0 ? 17 - charNb + 1: 1, " ");
2849af52
BP
1026 printf("%u (%.2f%%)%n", totTooFast, (double) totTooFast / totTotal * 100,
1027 &charNb);
f109919b
BP
1028 printf("%*s%-10u %u\n", 17 - charNb > 0 ? 17 - charNb + 1: 1, " ",
1029 totNoInfo, totTotal);
1030
d4721e1a
BP
1031 printf("\tRound-trip times:\n"
1032 "\t\tHost pair RTT from exchanges RTTs from file (ms)\n");
1033 g_hash_table_foreach(analysisData->stats->exchangeRtt,
1034 &ghfPrintExchangeRtt, analysisData->rttInfo);
66eaf2eb 1035
05a840df 1036#ifdef HAVE_LIBGLPK
66eaf2eb
BP
1037 printf("\tConvex hull factors comparisons:\n"
1038 "\t\tTrace pair Factors type Differences (lp - chull)\n"
1039 "\t\t a0 a1\n"
1040 "\t\t Min Max Min Max\n");
1041
1042 for (i= 0; i < syncState->traceNb; i++)
1043 {
1044 for (j= 0; j < i; j++)
1045 {
1046 FactorsCHull* chFactors= &analysisData->stats->chFactorsArray[i][j];
1047 FactorsCHull* lpFactors= &analysisData->stats->lpFactorsArray[i][j];
1048
1049 printf("\t\t%3d - %-3d ", i, j);
1050 if (lpFactors->type == chFactors->type)
1051 {
1052 if (lpFactors->type == MIDDLE)
1053 {
1054 printf("%-13s %-10.4g %-10.4g %-10.4g %.4g\n",
1055 approxNames[lpFactors->type],
1056 lpFactors->min->offset - chFactors->min->offset,
1057 lpFactors->max->offset - chFactors->max->offset,
1058 lpFactors->min->drift - chFactors->min->drift,
1059 lpFactors->max->drift - chFactors->max->drift);
1060 }
1061 else if (lpFactors->type == ABSENT)
1062 {
1063 printf("%s\n", approxNames[lpFactors->type]);
1064 }
1065 }
1066 else
1067 {
1068 printf("Different! %s and %s\n", approxNames[lpFactors->type],
1069 approxNames[chFactors->type]);
1070 }
1071 }
1072 }
05a840df 1073#endif
d4721e1a
BP
1074}
1075
1076
1077/*
1078 * A GHFunc for g_hash_table_foreach()
1079 *
1080 * Args:
1081 * key: RttKey* where saddr < daddr
1082 * value: double*, RTT estimated from exchanges
1083 * user_data GHashTable* rttInfo
1084 */
66eaf2eb
BP
1085static void ghfPrintExchangeRtt(gpointer key, gpointer value, gpointer
1086 user_data)
d4721e1a
BP
1087{
1088 char addr1[16], addr2[16];
1089 struct RttKey* rttKey1= key;
1090 struct RttKey rttKey2= {rttKey1->daddr, rttKey1->saddr};
1091 double* fileRtt1, *fileRtt2;
1092 GHashTable* rttInfo= user_data;
1093
1094 convertIP(addr1, rttKey1->saddr);
1095 convertIP(addr2, rttKey1->daddr);
1096
1097 fileRtt1= g_hash_table_lookup(rttInfo, rttKey1);
1098 fileRtt2= g_hash_table_lookup(rttInfo, &rttKey2);
1099
1100 printf("\t\t(%15s, %-15s) %-18.3f ", addr1, addr2, *(double*) value * 1e3);
1101
1102 if (fileRtt1 || fileRtt2)
1103 {
1104 if (fileRtt1)
1105 {
1106 printf("%.3f", *fileRtt1 * 1e3);
1107 }
1108 if (fileRtt1 && fileRtt2)
1109 {
1110 printf(", ");
1111 }
1112 if (fileRtt2)
1113 {
1114 printf("%.3f", *fileRtt2 * 1e3);
1115 }
1116 }
1117 else
1118 {
1119 printf("-");
1120 }
1121 printf("\n");
cdce23b3 1122}
2bd4b3e4
BP
1123
1124
1125/*
1126 * A GHashFunc for g_hash_table_new()
1127 *
1128 * Args:
1129 * key struct RttKey*
1130 */
1131static guint ghfRttKeyHash(gconstpointer key)
1132{
1133 struct RttKey* rttKey;
1134 uint32_t a, b, c;
1135
1136 rttKey= (struct RttKey*) key;
1137
1138 a= rttKey->saddr;
1139 b= rttKey->daddr;
1140 c= 0;
1141 final(a, b, c);
1142
1143 return c;
1144}
1145
1146
1147/*
1148 * A GDestroyNotify function for g_hash_table_new_full()
1149 *
1150 * Args:
1151 * data: struct RttKey*
1152 */
1153static void gdnDestroyRttKey(gpointer data)
1154{
1155 free(data);
1156}
1157
1158
1159/*
1160 * A GDestroyNotify function for g_hash_table_new_full()
1161 *
1162 * Args:
1163 * data: double*
1164 */
1165static void gdnDestroyDouble(gpointer data)
1166{
1167 free(data);
1168}
1169
1170
1171/*
1172 * A GEqualFunc for g_hash_table_new()
1173 *
1174 * Args:
1175 * a, b RttKey*
1176 *
1177 * Returns:
1178 * TRUE if both values are equal
1179 */
1180static gboolean gefRttKeyEqual(gconstpointer a, gconstpointer b)
1181{
1182 const struct RttKey* rkA, * rkB;
1183
1184 rkA= (struct RttKey*) a;
1185 rkB= (struct RttKey*) b;
1186
1187 if (rkA->saddr == rkB->saddr && rkA->daddr == rkB->daddr)
1188 {
1189 return TRUE;
1190 }
1191 else
1192 {
1193 return FALSE;
1194 }
1195}
1196
1197
1198/*
1199 * Read a file contain minimum round trip time values and fill an array with
1200 * them. The file is formatted as such:
1201 * <host1 IP> <host2 IP> <RTT in milliseconds>
1202 * ip's should be in dotted quad format
1203 *
1204 * Args:
1205 * rttInfo: double* rttInfo[RttKey], empty table, will be filled
1206 * rttStream: stream from which to read
1207 */
1208static void readRttInfo(GHashTable* rttInfo, FILE* rttStream)
1209{
1210 char* line= NULL;
1211 size_t len;
1212 int retval;
1213
1214 positionStream(rttStream);
1215 retval= getline(&line, &len, rttStream);
1216 while(!feof(rttStream))
1217 {
1218 struct RttKey* rttKey;
1219 char saddrDQ[20], daddrDQ[20];
1220 double* rtt;
1221 char tmp;
1222 struct in_addr addr;
1223 unsigned int i;
1224 struct {
1225 char* dq;
1226 size_t offset;
1227 } loopValues[] = {
1228 {saddrDQ, offsetof(struct RttKey, saddr)},
1229 {daddrDQ, offsetof(struct RttKey, daddr)}
1230 };
1231
1232 if (retval == -1 && !feof(rttStream))
1233 {
1234 g_error(strerror(errno));
1235 }
1236
1237 if (line[retval - 1] == '\n')
1238 {
1239 line[retval - 1]= '\0';
1240 }
1241
1242 rtt= malloc(sizeof(double));
1243 retval= sscanf(line, " %19s %19s %lf %c", saddrDQ, daddrDQ, rtt,
1244 &tmp);
1245 if (retval == EOF)
1246 {
1247 g_error(strerror(errno));
1248 }
1249 else if (retval != 3)
1250 {
1251 g_error("Error parsing RTT file, line was '%s'", line);
1252 }
1253
1254 rttKey= malloc(sizeof(struct RttKey));
1255 for (i= 0; i < sizeof(loopValues) / sizeof(*loopValues); i++)
1256 {
1257 retval= inet_aton(loopValues[i].dq, &addr);
1258 if (retval == 0)
1259 {
1260 g_error("Error converting address '%s'", loopValues[i].dq);
1261 }
1262 *(uint32_t*) ((void*) rttKey + loopValues[i].offset)=
1263 addr.s_addr;
1264 }
1265
76be6fc2 1266 *rtt/= 1e3;
d4721e1a
BP
1267 g_debug("rttInfo, Inserting (%u, %u)->(%f)", rttKey->saddr,
1268 rttKey->daddr, *rtt);
2bd4b3e4
BP
1269 g_hash_table_insert(rttInfo, rttKey, rtt);
1270
1271 positionStream(rttStream);
1272 retval= getline(&line, &len, rttStream);
1273 }
1274
1275 if (line)
1276 {
1277 free(line);
1278 }
1279}
1280
1281
1282/*
1283 * Advance stream over empty space, empty lines and lines that begin with '#'
1284 *
1285 * Args:
1286 * stream: stream, at exit, will be over the first non-empty character
1287 * of a line of be at EOF
1288 */
1289static void positionStream(FILE* stream)
1290{
1291 int firstChar;
1292 ssize_t retval;
1293 char* line= NULL;
1294 size_t len;
1295
1296 do
1297 {
1298 firstChar= fgetc(stream);
1299 if (firstChar == (int) '#')
1300 {
1301 retval= getline(&line, &len, stream);
1302 if (retval == -1)
1303 {
1304 if (feof(stream))
1305 {
1306 goto outEof;
1307 }
1308 else
1309 {
1310 g_error(strerror(errno));
1311 }
1312 }
1313 }
1314 else if (firstChar == (int) '\n' || firstChar == (int) ' ' ||
1315 firstChar == (int) '\t')
1316 {}
1317 else if (firstChar == EOF)
1318 {
1319 goto outEof;
1320 }
1321 else
1322 {
1323 break;
1324 }
1325 } while (true);
1326 retval= ungetc(firstChar, stream);
1327 if (retval == EOF)
1328 {
1329 g_error("Error: ungetc()");
1330 }
1331
1332outEof:
1333 if (line)
1334 {
1335 free(line);
1336 }
1337}
76be6fc2
BP
1338
1339
1340/*
1341 * A GFunc for g_queue_foreach()
1342 *
1343 * Args:
1344 * data Event*, a UDP broadcast event
1345 * user_data double*, the running sum
1346 *
1347 * Returns:
1348 * Adds the time of the event to the sum
1349 */
1350static void gfSum(gpointer data, gpointer userData)
1351{
1352 Event* event= (Event*) data;
1353
1354 *(double*) userData+= event->wallTime.seconds + event->wallTime.nanosec /
1355 1e9;
1356}
1357
1358
1359/*
1360 * A GFunc for g_queue_foreach()
1361 *
1362 * Args:
1363 * data Event*, a UDP broadcast event
1364 * user_data double*, the running sum
1365 *
1366 * Returns:
1367 * Adds the square of the time of the event to the sum
1368 */
1369static void gfSumSquares(gpointer data, gpointer userData)
1370{
1371 Event* event= (Event*) data;
1372
1373 *(double*) userData+= pow(event->wallTime.seconds + event->wallTime.nanosec
1374 / 1e9, 2.);
1375}
4ee223e5
BP
1376
1377
e072e1ab
BP
1378/*
1379 * Update a struct Bins according to a new value
1380 *
1381 * Args:
1382 * bins: the structure containing bins to build a histrogram
1383 * value: the new value
1384 */
1385static void hitBin(struct Bins* const bins, const double value)
1386{
1387 unsigned int binN= binNum(value);
1388
1389 if (binN < bins->min)
1390 {
1391 bins->min= binN;
1392 }
1393 else if (binN > bins->max)
1394 {
1395 bins->max= binN;
1396 }
1397
1398 bins->total++;
1399
1400 bins->bin[binN]++;
1401}
1402
1403
4ee223e5
BP
1404/*
1405 * Figure out the bin in a histogram to which a value belongs.
1406 *
1407 * This uses exponentially sized bins that go from 0 to infinity.
1408 *
1409 * Args:
e072e1ab
BP
1410 * value: in the range -INFINITY to INFINITY
1411 *
1412 * Returns:
1413 * The number of the bin in a struct Bins.bin
4ee223e5
BP
1414 */
1415static unsigned int binNum(const double value)
1416{
e072e1ab 1417 if (value <= 0)
4ee223e5
BP
1418 {
1419 return 0;
1420 }
e072e1ab
BP
1421 else if (value < binEnd(1))
1422 {
1423 return 1;
1424 }
1425 else if (value >= binStart(BIN_NB - 1))
1426 {
1427 return BIN_NB - 1;
1428 }
4ee223e5
BP
1429 else
1430 {
e072e1ab 1431 return floor(log(value) / log(binBase)) + BIN_NB + 1;
4ee223e5
BP
1432 }
1433}
1434
1435
1436/*
e072e1ab
BP
1437 * Figure out the start of the interval of a bin in a histogram. See struct
1438 * Bins.
4ee223e5
BP
1439 *
1440 * This uses exponentially sized bins that go from 0 to infinity.
1441 *
1442 * Args:
1443 * binNum: bin number
e072e1ab
BP
1444 *
1445 * Return:
1446 * The start of the interval, this value is included in the interval (except
1447 * for -INFINITY, naturally)
4ee223e5
BP
1448 */
1449static double binStart(const unsigned int binNum)
1450{
e072e1ab 1451 g_assert_cmpuint(binNum, <, BIN_NB);
4ee223e5
BP
1452
1453 if (binNum == 0)
1454 {
e072e1ab
BP
1455 return -INFINITY;
1456 }
1457 else if (binNum == 1)
1458 {
1459 return 0.;
4ee223e5
BP
1460 }
1461 else
1462 {
e072e1ab 1463 return pow(binBase, (double) binNum - BIN_NB + 1);
4ee223e5
BP
1464 }
1465}
1466
1467
1468/*
e072e1ab
BP
1469 * Figure out the end of the interval of a bin in a histogram. See struct
1470 * Bins.
4ee223e5
BP
1471 *
1472 * This uses exponentially sized bins that go from 0 to infinity.
1473 *
1474 * Args:
1475 * binNum: bin number
e072e1ab
BP
1476 *
1477 * Return:
1478 * The end of the interval, this value is not included in the interval
4ee223e5
BP
1479 */
1480static double binEnd(const unsigned int binNum)
1481{
e072e1ab 1482 g_assert_cmpuint(binNum, <, BIN_NB);
4ee223e5 1483
e072e1ab 1484 if (binNum == 0)
4ee223e5 1485 {
e072e1ab
BP
1486 return 0.;
1487 }
1488 else if (binNum < BIN_NB - 1)
1489 {
1490 return pow(binBase, (double) binNum - BIN_NB + 2);
4ee223e5
BP
1491 }
1492 else
1493 {
1494 return INFINITY;
1495 }
1496}
467066ee
BP
1497
1498
1499/*
1500 * Return the total number of elements in the "normal" bins (not underflow or
1501 * overflow)
1502 *
1503 * Args:
1504 * bins: the structure containing bins to build a histrogram
1505 */
1506static uint32_t normalTotal(struct Bins* const bins)
1507{
1508 return bins->total - bins->bin[0] - bins->bin[BIN_NB - 1];
1509}
66eaf2eb
BP
1510
1511
1512/* Update the bounds between two traces
1513 *
1514 * Args:
1515 * bounds: the array containing all the trace-pair bounds
1516 * e1, e2: the two related events
1517 */
c6356aa7
BP
1518static void updateBounds(Bounds** const bounds, Event* const e1, Event* const
1519 e2)
66eaf2eb
BP
1520{
1521 unsigned int traceI, traceJ;
1522 uint64_t messageTime;
1523 Bounds* tpBounds;
1524
1525 if (e1->traceNum < e2->traceNum)
1526 {
1527 traceI= e2->traceNum;
1528 traceJ= e1->traceNum;
1529 messageTime= e1->cpuTime;
1530 }
1531 else
1532 {
1533 traceI= e1->traceNum;
1534 traceJ= e2->traceNum;
1535 messageTime= e2->cpuTime;
1536 }
1537 tpBounds= &bounds[traceI][traceJ];
1538
1539 if (messageTime < tpBounds->min)
1540 {
1541 tpBounds->min= messageTime;
1542 }
1543 if (messageTime > tpBounds->max)
1544 {
1545 tpBounds->max= messageTime;
1546 }
1547}
1548
1549
1550#ifdef HAVE_LIBGLPK
1551/*
1552 * Create the linear programming problem containing the constraints defined by
1553 * two half-hulls. The objective function and optimization directions are not
1554 * written.
1555 *
1556 * Args:
1557 * syncState: container for synchronization data
1558 * i: first trace number
1559 * j: second trace number, garanteed to be larger than i
1560 * Returns:
1561 * A new glp_prob*, this problem must be freed by the caller with
1562 * glp_delete_prob()
1563 */
c6356aa7
BP
1564static glp_prob* lpCreateProblem(GQueue* const lowerHull, GQueue* const
1565 upperHull)
66eaf2eb
BP
1566{
1567 unsigned int it;
1568 const int zero= 0;
1569 const double zeroD= 0.;
1570 glp_prob* lp= glp_create_prob();
1571 unsigned int hullPointNb= g_queue_get_length(lowerHull) +
1572 g_queue_get_length(upperHull);
1573 GArray* iArray= g_array_sized_new(FALSE, FALSE, sizeof(int), hullPointNb +
1574 1);
1575 GArray* jArray= g_array_sized_new(FALSE, FALSE, sizeof(int), hullPointNb +
1576 1);
1577 GArray* aArray= g_array_sized_new(FALSE, FALSE, sizeof(double),
1578 hullPointNb + 1);
1579 struct {
1580 GQueue* hull;
1581 struct LPAddRowInfo rowInfo;
1582 } loopValues[2]= {
1583 {lowerHull, {lp, GLP_UP, iArray, jArray, aArray}},
1584 {upperHull, {lp, GLP_LO, iArray, jArray, aArray}},
1585 };
1586
1587 // Create the LP problem
1588 glp_term_out(GLP_OFF);
dce9bf0c
BP
1589 if (hullPointNb > 0)
1590 {
1591 glp_add_rows(lp, hullPointNb);
1592 }
66eaf2eb
BP
1593 glp_add_cols(lp, 2);
1594
1595 glp_set_col_name(lp, 1, "a0");
1596 glp_set_col_bnds(lp, 1, GLP_FR, 0., 0.);
1597 glp_set_col_name(lp, 2, "a1");
1598 glp_set_col_bnds(lp, 2, GLP_LO, 0., 0.);
1599
1600 // Add row constraints
1601 g_array_append_val(iArray, zero);
1602 g_array_append_val(jArray, zero);
1603 g_array_append_val(aArray, zeroD);
1604
1605 for (it= 0; it < sizeof(loopValues) / sizeof(*loopValues); it++)
1606 {
1607 g_queue_foreach(loopValues[it].hull, &gfLPAddRow,
1608 &loopValues[it].rowInfo);
1609 }
1610
1611 g_assert_cmpuint(iArray->len, ==, jArray->len);
1612 g_assert_cmpuint(jArray->len, ==, aArray->len);
1613 g_assert_cmpuint(aArray->len - 1, ==, hullPointNb * 2);
1614
1615 glp_load_matrix(lp, aArray->len - 1, &g_array_index(iArray, int, 0),
1616 &g_array_index(jArray, int, 0), &g_array_index(aArray, double, 0));
1617
1618 glp_scale_prob(lp, GLP_SF_AUTO);
1619
1620 g_array_free(iArray, TRUE);
1621 g_array_free(jArray, TRUE);
1622 g_array_free(aArray, TRUE);
1623
1624 return lp;
1625}
1626
1627
1628/*
1629 * A GFunc for g_queue_foreach(). Add constraints and bounds for one row.
1630 *
1631 * Args:
1632 * data Point*, synchronization point for which to add an LP row
1633 * (a constraint)
1634 * user_data LPAddRowInfo*
1635 */
1636static void gfLPAddRow(gpointer data, gpointer user_data)
1637{
1638 Point* p= data;
1639 struct LPAddRowInfo* rowInfo= user_data;
1640 int indexes[2];
1641 double constraints[2];
1642
1643 indexes[0]= g_array_index(rowInfo->iArray, int, rowInfo->iArray->len - 1) + 1;
1644 indexes[1]= indexes[0];
1645
1646 if (rowInfo->boundType == GLP_UP)
1647 {
1648 glp_set_row_bnds(rowInfo->lp, indexes[0], GLP_UP, 0., p->y);
1649 }
1650 else if (rowInfo->boundType == GLP_LO)
1651 {
1652 glp_set_row_bnds(rowInfo->lp, indexes[0], GLP_LO, p->y, 0.);
1653 }
1654 else
1655 {
1656 g_assert_not_reached();
1657 }
1658
1659 g_array_append_vals(rowInfo->iArray, indexes, 2);
1660 indexes[0]= 1;
1661 indexes[1]= 2;
1662 g_array_append_vals(rowInfo->jArray, indexes, 2);
1663 constraints[0]= 1.;
1664 constraints[1]= p->x;
1665 g_array_append_vals(rowInfo->aArray, constraints, 2);
1666}
1667
1668
1669/*
1670 * Calculate min or max correction factors (as possible) using an LP problem.
1671 *
1672 * Args:
1673 * lp: A linear programming problem with constraints and bounds
1674 * initialized.
1675 * direction: The type of factors desired. Use GLP_MAX for max
1676 * approximation factors (a1, the drift or slope is the
1677 * largest) and GLP_MIN in the other case.
1678 *
1679 * Returns:
1680 * If the calculation was successful, a new Factors struct. Otherwise, NULL.
1681 * The calculation will fail if the hull assumptions are not respected.
1682 */
1683static Factors* calculateFactors(glp_prob* const lp, const int direction)
1684{
1685 int retval, status;
1686 Factors* factors;
1687
1688 glp_set_obj_coef(lp, 1, 0.);
1689 glp_set_obj_coef(lp, 2, 1.);
1690
1691 glp_set_obj_dir(lp, direction);
1692 retval= glp_simplex(lp, NULL);
1693 status= glp_get_status(lp);
1694
1695 if (retval == 0 && status == GLP_OPT)
1696 {
1697 factors= malloc(sizeof(Factors));
1698 factors->offset= glp_get_col_prim(lp, 1);
1699 factors->drift= glp_get_col_prim(lp, 2);
1700 }
1701 else
1702 {
1703 factors= NULL;
1704 }
1705
1706 return factors;
1707}
1708
1709
1710/*
1711 * Calculate min, max and approx correction factors (as possible) using an LP
1712 * problem.
1713 *
1714 * Args:
1715 * lp: A linear programming problem with constraints and bounds
1716 * initialized.
1717 *
1718 * Returns:
1719 * Please note that the approximation type may be MIDDLE, INCOMPLETE or
1720 * ABSENT. Unlike in analysis_chull, ABSENT is also used when the hulls do
1721 * not respect assumptions.
1722 */
1723static void calculateCompleteFactors(glp_prob* const lp, FactorsCHull* factors)
1724{
1725 factors->min= calculateFactors(lp, GLP_MIN);
1726 factors->max= calculateFactors(lp, GLP_MAX);
1727
1728 if (factors->min && factors->max)
1729 {
1730 factors->type= MIDDLE;
1731 calculateFactorsMiddle(factors);
1732 }
1733 else if (factors->min || factors->max)
1734 {
1735 factors->type= INCOMPLETE;
1736 factors->approx= NULL;
1737 }
1738 else
1739 {
1740 factors->type= ABSENT;
1741 factors->approx= NULL;
1742 }
1743}
1744
1745
1746/*
1747 * Create and initialize an array like AnalysisStatsCHull.allFactors
1748 *
1749 * Args:
1750 * traceNb: number of traces
1751 *
1752 * Returns:
1753 * A new array, which can be freed with freeAllFactors()
1754 */
1755static FactorsCHull** createAllFactors(const unsigned int traceNb)
1756{
1757 FactorsCHull** factorsArray;
1758 unsigned int i;
1759
1760 factorsArray= malloc(traceNb * sizeof(FactorsCHull*));
1761 for (i= 0; i < traceNb; i++)
1762 {
1763 factorsArray[i]= calloc((i + 1), sizeof(FactorsCHull));
1764
1765 factorsArray[i][i].type= EXACT;
1766 factorsArray[i][i].approx= malloc(sizeof(Factors));
1767 factorsArray[i][i].approx->drift= 1.;
1768 factorsArray[i][i].approx->offset= 0.;
1769 }
1770
1771 return factorsArray;
1772}
1773#endif
1774
1775
1776/*
1777 * Compute synchronization factors using a linear programming approach.
1778 * Compute the factors using analysis_chull. Compare the two.
1779 *
05a840df
BP
1780 * When the solver library, glpk, is not available at build time, only compute
1781 * the factors using analysis_chull. This is to make sure that module runs its
1782 * finalize function so that its graph functions can be called later.
66eaf2eb
BP
1783 *
1784 * Args:
1785 * syncState: container for synchronization data
1786 */
66eaf2eb
BP
1787static void finalizeAnalysisEvalLP(SyncState* const syncState)
1788{
66eaf2eb 1789 AnalysisDataEval* analysisData= syncState->analysisData;
05a840df
BP
1790#ifdef HAVE_LIBGLPK
1791 unsigned int i, j;
66eaf2eb 1792 AnalysisDataCHull* chAnalysisData= analysisData->chullSS->analysisData;
6ce8ceac 1793 FactorsCHull** lpFactorsArray;
66eaf2eb
BP
1794
1795 if (!syncState->stats && !syncState->graphsStream)
1796 {
1797 return;
1798 }
1799
6ce8ceac
BP
1800 /* Because of matching_distributor, this analysis may be called twice.
1801 * Only run it once */
66eaf2eb
BP
1802 if ((syncState->graphsStream && analysisData->graphs->lps != NULL) ||
1803 (syncState->stats && analysisData->stats->chFactorsArray != NULL))
1804 {
1805 return;
1806 }
1807
6ce8ceac
BP
1808 lpFactorsArray= createAllFactors(syncState->traceNb);
1809
66eaf2eb
BP
1810 if (syncState->stats)
1811 {
1812 analysisData->stats->chFactorsArray=
1813 calculateAllFactors(analysisData->chullSS);
1814 analysisData->stats->lpFactorsArray= lpFactorsArray;
1815 }
1816
1817 if (syncState->graphsStream)
1818 {
1819 analysisData->graphs->lps= malloc(syncState->traceNb *
1820 sizeof(glp_prob**));
1821 for (i= 0; i < syncState->traceNb; i++)
1822 {
1823 analysisData->graphs->lps[i]= malloc(i * sizeof(glp_prob*));
1824 }
1825 analysisData->graphs->lpFactorsArray= lpFactorsArray;
1826 }
1827
1828 for (i= 0; i < syncState->traceNb; i++)
1829 {
1830 for (j= 0; j < i; j++)
1831 {
1832 glp_prob* lp;
1833
1834 // Create the LP problem
1835 lp= lpCreateProblem(chAnalysisData->hullArray[i][j],
1836 chAnalysisData->hullArray[j][i]);
1837
1838 // Use the LP problem to find the correction factors for this pair of
1839 // traces
1840 calculateCompleteFactors(lp, &lpFactorsArray[i][j]);
1841
1842 if (syncState->graphsStream)
1843 {
1844 analysisData->graphs->lps[i][j]= lp;
1845 }
1846 else
1847 {
1848 glp_delete_prob(lp);
66eaf2eb
BP
1849 }
1850 }
1851 }
05a840df 1852#endif
66eaf2eb
BP
1853
1854 g_array_free(analysisData->chullSS->analysisModule->finalizeAnalysis(analysisData->chullSS),
1855 TRUE);
1856}
66eaf2eb
BP
1857
1858
1859/*
1860 * Compute synchronization accuracy information using a linear programming
1861 * approach. Write the neccessary data files and plot lines in the gnuplot
1862 * script.
1863 *
c5571851
BP
1864 * When the solver library, glpk, is not available at build time nothing is
1865 * actually produced.
66eaf2eb
BP
1866 *
1867 * Args:
1868 * syncState: container for synchronization data
1869 * i: first trace number
1870 * j: second trace number, garanteed to be larger than i
1871 */
c5571851
BP
1872static void writeAnalysisTraceTimeBackPlotsEval(SyncState* const syncState,
1873 const unsigned int i, const unsigned int j)
66eaf2eb 1874{
c5571851 1875#ifdef HAVE_LIBGLPK
66eaf2eb
BP
1876 unsigned int it;
1877 AnalysisDataEval* analysisData= syncState->analysisData;
1878 AnalysisGraphsEval* graphs= analysisData->graphs;
1879 GQueue*** hullArray= ((AnalysisDataCHull*)
1880 analysisData->chullSS->analysisData)->hullArray;
1881 FactorsCHull* lpFactors= &graphs->lpFactorsArray[j][i];
1882 glp_prob* lp= graphs->lps[j][i];
1883
1884 if (lpFactors->type == MIDDLE)
1885 {
1886 int retval;
1887 char* cwd;
1888 char fileName[40];
1889 FILE* fp;
1890 double* xValues;
1891 unsigned int xBegin, xEnd;
1892 double interval;
1893 const unsigned int graphPointNb= 1000;
1894
1895 // Open the data file
1896 snprintf(fileName, 40, "analysis_eval_accuracy-%03u_and_%03u.data", i, j);
1897 fileName[sizeof(fileName) - 1]= '\0';
1898
1d597550 1899 cwd= changeToGraphsDir(syncState->graphsDir);
66eaf2eb
BP
1900
1901 if ((fp= fopen(fileName, "w")) == NULL)
1902 {
1903 g_error(strerror(errno));
1904 }
1905 fprintf(fp, "#%-24s %-25s %-25s %-25s\n", "x", "middle", "min", "max");
1906
1907 retval= chdir(cwd);
1908 if (retval == -1)
1909 {
1910 g_error(strerror(errno));
1911 }
1912 free(cwd);
1913
1914 // Build the list of absisca values for the points in the accuracy graph
1915 g_assert_cmpuint(graphPointNb, >=, 4);
1916 xValues= malloc(graphPointNb * sizeof(double));
1917 xValues[0]= graphs->bounds[j][i].min;
1918 xValues[graphPointNb - 1]= graphs->bounds[j][i].max;
1919 xValues[1]= MIN(((Point*) g_queue_peek_head(hullArray[i][j]))->x,
1920 ((Point*) g_queue_peek_head(hullArray[j][i]))->x);
1921 xValues[graphPointNb - 2]= MAX(((Point*)
1922 g_queue_peek_tail(hullArray[i][j]))->x, ((Point*)
1923 g_queue_peek_tail(hullArray[j][i]))->x);
1924
1925 if (xValues[0] == xValues[1])
1926 {
1927 xBegin= 0;
1928 }
1929 else
1930 {
1931 xBegin= 1;
1932 }
1933 if (xValues[graphPointNb - 2] == xValues[graphPointNb - 1])
1934 {
1935 xEnd= graphPointNb - 1;
1936 }
1937 else
1938 {
1939 xEnd= graphPointNb - 2;
1940 }
1941 interval= (xValues[xEnd] - xValues[xBegin]) / (graphPointNb - 1);
1942
1943 for (it= xBegin; it <= xEnd; it++)
1944 {
1945 xValues[it]= xValues[xBegin] + interval * (it - xBegin);
1946 }
1947
1948 /* For each absisca value and each optimisation direction, solve the LP
1949 * and write a line in the data file */
1950 for (it= 0; it < graphPointNb; it++)
1951 {
1952 unsigned int it2;
1953 int directions[]= {GLP_MIN, GLP_MAX};
66eaf2eb
BP
1954 glp_set_obj_coef(lp, 1, 1.);
1955 glp_set_obj_coef(lp, 2, xValues[it]);
1956
2849af52
BP
1957 fprintf(fp, "%25.9f %25.9f", xValues[it],
1958 lpFactors->approx->offset + lpFactors->approx->drift *
1959 xValues[it]);
66eaf2eb
BP
1960 for (it2= 0; it2 < sizeof(directions) / sizeof(*directions); it2++)
1961 {
1962 int status;
1963
1964 glp_set_obj_dir(lp, directions[it2]);
1965 retval= glp_simplex(lp, NULL);
1966 status= glp_get_status(lp);
1967
1968 g_assert(retval == 0 && status == GLP_OPT);
1969 fprintf(fp, " %25.9f", glp_get_obj_val(lp));
1970 }
1971 fprintf(fp, "\n");
1972 }
1973
1974 free(xValues);
1975 fclose(fp);
1976
1977 fprintf(syncState->graphsStream,
1978 "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
1979 "using 1:(($3 - $2) / clock_freq_%2$u):(($4 - $2) / clock_freq_%2$u) "
1980 "title \"Synchronization accuracy\" "
1981 "with filledcurves linewidth 2 linetype 1 "
1982 "linecolor rgb \"black\" fill solid 0.25 noborder, \\\n", i,
1983 j);
1984 }
66eaf2eb 1985#endif
c5571851 1986}
66eaf2eb
BP
1987
1988
1989/*
1990 * Write the analysis-specific graph lines in the gnuplot script.
1991 *
c5571851
BP
1992 * When the solver library, glpk, is not available at build time nothing is
1993 * actually produced.
1994 *
66eaf2eb
BP
1995 * Args:
1996 * syncState: container for synchronization data
1997 * i: first trace number
1998 * j: second trace number, garanteed to be larger than i
1999 */
c5571851
BP
2000static void writeAnalysisTraceTimeForePlotsEval(SyncState* const syncState,
2001 const unsigned int i, const unsigned int j)
66eaf2eb 2002{
c5571851
BP
2003#ifdef HAVE_LIBGLPK
2004 if (((AnalysisDataEval*)
2005 syncState->analysisData)->graphs->lpFactorsArray[j][i].type ==
2006 MIDDLE)
2007 {
2008 fprintf(syncState->graphsStream,
2009 "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
2010 "using 1:(($3 - $2) / clock_freq_%2$u) notitle "
2011 "with lines linewidth 2 linetype 1 "
2012 "linecolor rgb \"gray60\", \\\n"
2013 "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
2014 "using 1:(($4 - $2) / clock_freq_%2$u) notitle "
2015 "with lines linewidth 2 linetype 1 "
2016 "linecolor rgb \"gray60\", \\\n", i, j);
2017 }
2018#endif
66eaf2eb
BP
2019}
2020
2021
c6356aa7
BP
2022/*
2023 * Write the analysis-specific graph lines in the gnuplot script.
2024 *
2025 * Args:
2026 * syncState: container for synchronization data
2027 * i: first trace number
2028 * j: second trace number, garanteed to be larger than i
2029 */
2030static void writeAnalysisTraceTraceBackPlotsEval(SyncState* const syncState,
2031 const unsigned int i, const unsigned int j)
66eaf2eb 2032{
66eaf2eb
BP
2033#ifdef HAVE_LIBGLPK
2034 fprintf(syncState->graphsStream,
2035 "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
2036 "using 1:3:4 "
2037 "title \"Synchronization accuracy\" "
2038 "with filledcurves linewidth 2 linetype 1 "
2039 "linecolor rgb \"black\" fill solid 0.25 noborder, \\\n", i, j);
2040#endif
c6356aa7
BP
2041}
2042
2043
2044/*
2045 * Write the analysis-specific graph lines in the gnuplot script.
2046 *
2047 * Args:
2048 * syncState: container for synchronization data
2049 * i: first trace number
2050 * j: second trace number, garanteed to be larger than i
2051 */
2052static void writeAnalysisTraceTraceForePlotsEval(SyncState* const syncState,
2053 const unsigned int i, const unsigned int j)
2054{
2055 AnalysisDataEval* analysisData= syncState->analysisData;
66eaf2eb 2056
c6356aa7 2057 analysisData->chullSS->analysisModule->graphFunctions.writeTraceTraceForePlots(analysisData->chullSS,
66eaf2eb
BP
2058 i, j);
2059}
This page took 0.125391 seconds and 4 git commands to generate.