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,
20 #define _ISOC99_SOURCE
26 #include <arpa/inet.h>
29 #include <netinet/in.h>
34 #include <sys/socket.h>
38 #include "sync_chain.h"
39 #include "event_analysis_chull.h"
41 #include "event_analysis_eval.h"
44 struct WriteHistogramInfo
55 GArray
* iArray
, * jArray
, * aArray
;
59 // Functions common to all analysis modules
60 static void initAnalysisEval(SyncState
* const syncState
);
61 static void destroyAnalysisEval(SyncState
* const syncState
);
63 static void analyzeMessageEval(SyncState
* const syncState
, Message
* const
65 static void analyzeExchangeEval(SyncState
* const syncState
, Exchange
* const
67 static void analyzeBroadcastEval(SyncState
* const syncState
, Broadcast
* const
69 static GArray
* finalizeAnalysisEval(SyncState
* const syncState
);
70 static void printAnalysisStatsEval(SyncState
* const syncState
);
71 static void writeAnalysisTraceTimeBackPlotsEval(SyncState
* const syncState
,
72 const unsigned int i
, const unsigned int j
);
73 static void writeAnalysisTraceTimeForePlotsEval(SyncState
* const syncState
,
74 const unsigned int i
, const unsigned int j
);
75 static void writeAnalysisTraceTraceBackPlotsEval(SyncState
* const syncState
,
76 const unsigned int i
, const unsigned int j
);
77 static void writeAnalysisTraceTraceForePlotsEval(SyncState
* const syncState
,
78 const unsigned int i
, const unsigned int j
);
80 // Functions specific to this module
81 static void registerAnalysisEval() __attribute__((constructor (102)));
82 static guint
ghfRttKeyHash(gconstpointer key
);
83 static gboolean
gefRttKeyEqual(gconstpointer a
, gconstpointer b
);
84 static void gdnDestroyRttKey(gpointer data
);
85 static void gdnDestroyDouble(gpointer data
);
86 static void readRttInfo(GHashTable
* rttInfo
, FILE* rttFile
);
87 static void positionStream(FILE* stream
);
89 static void gfSum(gpointer data
, gpointer userData
);
90 static void gfSumSquares(gpointer data
, gpointer userData
);
91 static void ghfPrintExchangeRtt(gpointer key
, gpointer value
, gpointer
94 static void hitBin(struct Bins
* const bins
, const double value
);
95 static unsigned int binNum(const double value
) __attribute__((pure
));
96 static double binStart(const unsigned int binNum
) __attribute__((pure
));
97 static double binEnd(const unsigned int binNum
) __attribute__((pure
));
98 static uint32_t normalTotal(struct Bins
* const bins
) __attribute__((const));
100 static AnalysisHistogramEval
* constructAnalysisHistogramEval(const char* const
101 graphsDir
, const struct RttKey
* const rttKey
);
102 static void destroyAnalysisHistogramEval(AnalysisHistogramEval
* const
104 static void gdnDestroyAnalysisHistogramEval(gpointer data
);
105 static void ghfWriteHistogram(gpointer key
, gpointer value
, gpointer
107 static void dumpBinToFile(const struct Bins
* const bins
, FILE* const file
);
108 static void writeHistogram(FILE* graphsStream
, const struct RttKey
* rttKey
,
109 double* minRtt
, AnalysisHistogramEval
* const histogram
);
111 static void updateBounds(Bounds
** const bounds
, Event
* const e1
, Event
* const
114 static void finalizeAnalysisEvalLP(SyncState
* const syncState
);
115 // The next group of functions is only needed when computing synchronization
118 static glp_prob
* lpCreateProblem(GQueue
* const lowerHull
, GQueue
* const
120 static void gfLPAddRow(gpointer data
, gpointer user_data
);
121 static Factors
* calculateFactors(glp_prob
* const lp
, const int direction
);
122 static void calculateCompleteFactors(glp_prob
* const lp
, FactorsCHull
*
124 static FactorsCHull
** createAllFactors(const unsigned int traceNb
);
128 // initialized in registerAnalysisEval()
131 static AnalysisModule analysisModuleEval
= {
133 .initAnalysis
= &initAnalysisEval
,
134 .destroyAnalysis
= &destroyAnalysisEval
,
135 .analyzeMessage
= &analyzeMessageEval
,
136 .analyzeExchange
= &analyzeExchangeEval
,
137 .analyzeBroadcast
= &analyzeBroadcastEval
,
138 .finalizeAnalysis
= &finalizeAnalysisEval
,
139 .printAnalysisStats
= &printAnalysisStatsEval
,
141 .writeTraceTimeBackPlots
= &writeAnalysisTraceTimeBackPlotsEval
,
142 .writeTraceTimeForePlots
= &writeAnalysisTraceTimeForePlotsEval
,
143 .writeTraceTraceBackPlots
= &writeAnalysisTraceTraceBackPlotsEval
,
144 .writeTraceTraceForePlots
= &writeAnalysisTraceTraceForePlotsEval
,
148 static ModuleOption optionEvalRttFile
= {
149 .longName
= "eval-rtt-file",
150 .hasArg
= REQUIRED_ARG
,
151 .optionHelp
= "specify the file containing RTT information",
157 * Analysis module registering function
159 static void registerAnalysisEval()
161 binBase
= exp10(6. / (BIN_NB
- 3));
163 g_queue_push_tail(&analysisModules
, &analysisModuleEval
);
164 g_queue_push_tail(&moduleOptions
, &optionEvalRttFile
);
169 * Analysis init function
171 * This function is called at the beginning of a synchronization run for a set
175 * syncState container for synchronization data.
177 static void initAnalysisEval(SyncState
* const syncState
)
179 AnalysisDataEval
* analysisData
;
182 analysisData
= malloc(sizeof(AnalysisDataEval
));
183 syncState
->analysisData
= analysisData
;
185 analysisData
->rttInfo
= g_hash_table_new_full(&ghfRttKeyHash
,
186 &gefRttKeyEqual
, &gdnDestroyRttKey
, &gdnDestroyDouble
);
187 if (optionEvalRttFile
.arg
)
192 rttStream
= fopen(optionEvalRttFile
.arg
, "r");
193 if (rttStream
== NULL
)
195 g_error(strerror(errno
));
198 readRttInfo(analysisData
->rttInfo
, rttStream
);
200 retval
= fclose(rttStream
);
203 g_error(strerror(errno
));
207 if (syncState
->stats
)
209 analysisData
->stats
= calloc(1, sizeof(AnalysisStatsEval
));
210 analysisData
->stats
->broadcastDiffSum
= 0.;
212 analysisData
->stats
->messageStats
= malloc(syncState
->traceNb
*
213 sizeof(MessageStats
*));
214 for (i
= 0; i
< syncState
->traceNb
; i
++)
216 analysisData
->stats
->messageStats
[i
]= calloc(syncState
->traceNb
,
217 sizeof(MessageStats
));
220 analysisData
->stats
->exchangeRtt
=
221 g_hash_table_new_full(&ghfRttKeyHash
, &gefRttKeyEqual
,
222 &gdnDestroyRttKey
, &gdnDestroyDouble
);
225 analysisData
->stats
->chFactorsArray
= NULL
;
226 analysisData
->stats
->lpFactorsArray
= NULL
;
230 if (syncState
->graphsStream
)
232 AnalysisGraphsEval
* graphs
= malloc(sizeof(AnalysisGraphsEval
));
234 analysisData
->graphs
= graphs
;
236 graphs
->histograms
= g_hash_table_new_full(&ghfRttKeyHash
,
237 &gefRttKeyEqual
, &gdnDestroyRttKey
,
238 &gdnDestroyAnalysisHistogramEval
);
240 graphs
->bounds
= malloc(syncState
->traceNb
* sizeof(Bounds
*));
241 for (i
= 0; i
< syncState
->traceNb
; i
++)
243 graphs
->bounds
[i
]= malloc(i
* sizeof(Bounds
));
244 for (j
= 0; j
< i
; j
++)
246 graphs
->bounds
[i
][j
].min
= UINT64_MAX
;
247 graphs
->bounds
[i
][j
].max
= 0;
253 graphs
->lpFactorsArray
= NULL
;
257 if (syncState
->stats
|| syncState
->graphsStream
)
261 analysisData
->chullSS
= malloc(sizeof(SyncState
));
262 memcpy(analysisData
->chullSS
, syncState
, sizeof(SyncState
));
263 analysisData
->chullSS
->stats
= false;
264 analysisData
->chullSS
->analysisData
= NULL
;
265 result
= g_queue_find_custom(&analysisModules
, "chull",
266 &gcfCompareAnalysis
);
267 analysisData
->chullSS
->analysisModule
= (AnalysisModule
*) result
->data
;
268 analysisData
->chullSS
->analysisModule
->initAnalysis(analysisData
->chullSS
);
274 * Create and open files used to store histogram points to generate graphs.
275 * Create data structures to store histogram points during analysis.
278 * graphsDir: folder where to write files
279 * rttKey: host pair, make sure saddr < daddr
281 static AnalysisHistogramEval
* constructAnalysisHistogramEval(const char* const
282 graphsDir
, const struct RttKey
* const rttKey
)
287 char name
[60], saddr
[16], daddr
[16];
288 AnalysisHistogramEval
* histogram
= calloc(1, sizeof(*histogram
));
291 const char* fileName
;
292 const char* host1
, *host2
;
294 {offsetof(AnalysisHistogramEval
, ttSendPoints
),
295 "analysis_eval_tt-%s_to_%s.data", saddr
, daddr
},
296 {offsetof(AnalysisHistogramEval
, ttRecvPoints
),
297 "analysis_eval_tt-%s_to_%s.data", daddr
, saddr
},
298 {offsetof(AnalysisHistogramEval
, hrttPoints
),
299 "analysis_eval_hrtt-%s_and_%s.data", saddr
, daddr
},
302 histogram
->ttSendBins
.min
= BIN_NB
- 1;
303 histogram
->ttRecvBins
.min
= BIN_NB
- 1;
304 histogram
->hrttBins
.min
= BIN_NB
- 1;
306 convertIP(saddr
, rttKey
->saddr
);
307 convertIP(daddr
, rttKey
->daddr
);
309 cwd
= changeToGraphsDir(graphsDir
);
311 for (i
= 0; i
< sizeof(loopValues
) / sizeof(*loopValues
); i
++)
313 retval
= snprintf(name
, sizeof(name
), loopValues
[i
].fileName
,
314 loopValues
[i
].host1
, loopValues
[i
].host2
);
315 if (retval
> sizeof(name
) - 1)
317 name
[sizeof(name
) - 1]= '\0';
319 if ((*(FILE**)((void*) histogram
+ loopValues
[i
].pointsOffset
)=
320 fopen(name
, "w")) == NULL
)
322 g_error(strerror(errno
));
329 g_error(strerror(errno
));
338 * Close files used to store histogram points to generate graphs.
341 * graphsDir: folder where to write files
342 * rttKey: host pair, make sure saddr < daddr
344 static void destroyAnalysisHistogramEval(AnalysisHistogramEval
* const
352 {offsetof(AnalysisHistogramEval
, ttSendPoints
)},
353 {offsetof(AnalysisHistogramEval
, ttRecvPoints
)},
354 {offsetof(AnalysisHistogramEval
, hrttPoints
)},
357 for (i
= 0; i
< sizeof(loopValues
) / sizeof(*loopValues
); i
++)
359 retval
= fclose(*(FILE**)((void*) histogram
+ loopValues
[i
].pointsOffset
));
362 g_error(strerror(errno
));
371 * A GDestroyNotify function for g_hash_table_new_full()
374 * data: AnalysisHistogramEval*
376 static void gdnDestroyAnalysisHistogramEval(gpointer data
)
378 destroyAnalysisHistogramEval(data
);
383 * A GHFunc for g_hash_table_foreach()
386 * key: RttKey* where saddr < daddr
387 * value: AnalysisHistogramEval*
388 * user_data struct WriteHistogramInfo*
390 static void ghfWriteHistogram(gpointer key
, gpointer value
, gpointer user_data
)
392 double* rtt1
, * rtt2
;
393 struct RttKey
* rttKey
= key
;
394 struct RttKey oppositeRttKey
= {.saddr
= rttKey
->daddr
, .daddr
=
396 AnalysisHistogramEval
* histogram
= value
;
397 struct WriteHistogramInfo
* info
= user_data
;
399 rtt1
= g_hash_table_lookup(info
->rttInfo
, rttKey
);
400 rtt2
= g_hash_table_lookup(info
->rttInfo
, &oppositeRttKey
);
406 else if (rtt2
!= NULL
)
408 rtt1
= MIN(rtt1
, rtt2
);
411 dumpBinToFile(&histogram
->ttSendBins
, histogram
->ttSendPoints
);
412 dumpBinToFile(&histogram
->ttRecvBins
, histogram
->ttRecvPoints
);
413 dumpBinToFile(&histogram
->hrttBins
, histogram
->hrttPoints
);
414 writeHistogram(info
->graphsStream
, rttKey
, rtt1
, histogram
);
419 * Write the content of one bin in a histogram point file
422 * bin: array of values that make up a histogram
423 * file: FILE*, write to this file
425 static void dumpBinToFile(const struct Bins
* const bins
, FILE* const file
)
429 // The first and last bins are skipped, see struct Bins
430 for (i
= 1; i
< BIN_NB
- 1; i
++)
432 if (bins
->bin
[i
] > 0)
434 fprintf(file
, "%20.9f %20.9f %20.9f\n", (binStart(i
) + binEnd(i
))
435 / 2., (double) bins
->bin
[i
] / ((binEnd(i
) - binStart(i
)) *
436 bins
->total
), binEnd(i
) - binStart(i
));
443 * Write the analysis-specific plot in the gnuplot script.
446 * graphsStream: write to this file
447 * rttKey: must be sorted such that saddr < daddr
448 * minRtt: if available, else NULL
449 * histogram: struct that contains the bins for the pair of traces
450 * identified by rttKey
452 static void writeHistogram(FILE* graphsStream
, const struct RttKey
* rttKey
,
453 double* minRtt
, AnalysisHistogramEval
* const histogram
)
455 char saddr
[16], daddr
[16];
457 convertIP(saddr
, rttKey
->saddr
);
458 convertIP(daddr
, rttKey
->daddr
);
460 fprintf(graphsStream
,
462 "set output \"histogram-%s-%s.eps\"\n"
464 "set xlabel \"Message Latency (s)\"\n"
465 "set ylabel \"Proportion of messages per second\"\n", saddr
, daddr
);
469 fprintf(graphsStream
,
470 "set arrow from %.9f, 0 rto 0, graph 1 "
471 "nohead linetype 3 linewidth 3 linecolor rgb \"black\"\n", *minRtt
475 if (normalTotal(&histogram
->ttSendBins
) ||
476 normalTotal(&histogram
->ttRecvBins
) ||
477 normalTotal(&histogram
->hrttBins
))
479 fprintf(graphsStream
, "plot \\\n");
481 if (normalTotal(&histogram
->hrttBins
))
483 fprintf(graphsStream
,
484 "\t\"analysis_eval_hrtt-%s_and_%s.data\" "
485 "title \"RTT/2\" with linespoints linetype 1 linewidth 2 "
486 "linecolor rgb \"black\" pointtype 6 pointsize 1,\\\n",
490 if (normalTotal(&histogram
->ttSendBins
))
492 fprintf(graphsStream
,
493 "\t\"analysis_eval_tt-%1$s_to_%2$s.data\" "
494 "title \"%1$s to %2$s\" with linespoints linetype 4 linewidth 2 "
495 "linecolor rgb \"gray60\" pointtype 6 pointsize 1,\\\n",
499 if (normalTotal(&histogram
->ttRecvBins
))
501 fprintf(graphsStream
,
502 "\t\"analysis_eval_tt-%1$s_to_%2$s.data\" "
503 "title \"%1$s to %2$s\" with linespoints linetype 4 linewidth 2 "
504 "linecolor rgb \"gray30\" pointtype 6 pointsize 1,\\\n",
508 // Remove the ",\\\n" from the last graph plot line
509 if (ftruncate(fileno(graphsStream
), ftell(graphsStream
) - 3) == -1)
511 g_error(strerror(errno
));
513 if (fseek(graphsStream
, 0, SEEK_END
) == -1)
515 g_error(strerror(errno
));
517 fprintf(graphsStream
, "\n");
523 * Analysis destroy function
525 * Free the analysis specific data structures
528 * syncState container for synchronization data.
530 static void destroyAnalysisEval(SyncState
* const syncState
)
533 AnalysisDataEval
* analysisData
;
535 analysisData
= (AnalysisDataEval
*) syncState
->analysisData
;
537 if (analysisData
== NULL
)
542 g_hash_table_destroy(analysisData
->rttInfo
);
544 if (syncState
->stats
)
546 AnalysisStatsEval
* stats
= analysisData
->stats
;
548 for (i
= 0; i
< syncState
->traceNb
; i
++)
550 free(stats
->messageStats
[i
]);
552 free(stats
->messageStats
);
554 g_hash_table_destroy(stats
->exchangeRtt
);
557 freeAllFactors(syncState
->traceNb
, stats
->chFactorsArray
);
558 freeAllFactors(syncState
->traceNb
, stats
->lpFactorsArray
);
564 if (syncState
->graphsStream
)
566 AnalysisGraphsEval
* graphs
= analysisData
->graphs
;
568 if (graphs
->histograms
)
570 g_hash_table_destroy(graphs
->histograms
);
573 for (i
= 0; i
< syncState
->traceNb
; i
++)
575 free(graphs
->bounds
[i
]);
577 free(graphs
->bounds
);
580 for (i
= 0; i
< syncState
->traceNb
; i
++)
584 for (j
= 0; j
< i
; j
++)
586 // There seems to be a memory leak in glpk, valgrind reports a
587 // loss (reachable) even if the problem is deleted
588 glp_delete_prob(graphs
->lps
[i
][j
]);
590 free(graphs
->lps
[i
]);
594 if (!syncState
->stats
)
596 freeAllFactors(syncState
->traceNb
, graphs
->lpFactorsArray
);
603 if (syncState
->stats
|| syncState
->graphsStream
)
605 analysisData
->chullSS
->analysisModule
->destroyAnalysis(analysisData
->chullSS
);
606 free(analysisData
->chullSS
);
609 free(syncState
->analysisData
);
610 syncState
->analysisData
= NULL
;
615 * Perform analysis on an event pair.
617 * Check if there is message inversion or messages that are too fast.
620 * syncState container for synchronization data
621 * message structure containing the events
623 static void analyzeMessageEval(SyncState
* const syncState
, Message
* const
626 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
627 MessageStats
* messageStats
;
630 struct RttKey rttKey
;
632 g_assert(message
->inE
->type
== TCP
);
634 if (syncState
->stats
)
637 &analysisData
->stats
->messageStats
[message
->outE
->traceNum
][message
->inE
->traceNum
];
638 messageStats
->total
++;
641 tt
= wallTimeSub(&message
->inE
->wallTime
, &message
->outE
->wallTime
);
644 if (syncState
->stats
)
646 messageStats
->inversionNb
++;
649 else if (syncState
->graphsStream
)
651 struct RttKey rttKey
= {
652 .saddr
=MIN(message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
,
653 message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
),
654 .daddr
=MAX(message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
,
655 message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
),
657 AnalysisHistogramEval
* histogram
=
658 g_hash_table_lookup(analysisData
->graphs
->histograms
, &rttKey
);
660 if (histogram
== NULL
)
662 struct RttKey
* tableKey
= malloc(sizeof(*tableKey
));
664 histogram
= constructAnalysisHistogramEval(syncState
->graphsDir
, &rttKey
);
665 memcpy(tableKey
, &rttKey
, sizeof(*tableKey
));
666 g_hash_table_insert(analysisData
->graphs
->histograms
, tableKey
, histogram
);
669 if (message
->inE
->event
.udpEvent
->datagramKey
->saddr
<
670 message
->inE
->event
.udpEvent
->datagramKey
->daddr
)
672 hitBin(&histogram
->ttSendBins
, tt
);
676 hitBin(&histogram
->ttRecvBins
, tt
);
680 if (syncState
->stats
)
683 message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
;
685 message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
;
686 rtt
= g_hash_table_lookup(analysisData
->rttInfo
, &rttKey
);
687 g_debug("rttInfo, looking up (%u, %u)->(%f)", rttKey
.saddr
,
688 rttKey
.daddr
, rtt
? *rtt
: NAN
);
692 g_debug("rttInfo, tt: %f rtt / 2: %f", tt
, *rtt
/ 2.);
695 messageStats
->tooFastNb
++;
700 messageStats
->noRTTInfoNb
++;
704 if (syncState
->graphsStream
)
706 updateBounds(analysisData
->graphs
->bounds
, message
->inE
,
710 if (syncState
->stats
|| syncState
->graphsStream
)
712 analysisData
->chullSS
->analysisModule
->analyzeMessage(analysisData
->chullSS
,
719 * Perform analysis on multiple messages
724 * syncState container for synchronization data
725 * exchange structure containing the messages
727 static void analyzeExchangeEval(SyncState
* const syncState
, Exchange
* const
730 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
731 Message
* m1
= g_queue_peek_tail(exchange
->acks
);
732 Message
* m2
= exchange
->message
;
733 struct RttKey
* rttKey
;
734 double* rtt
, * exchangeRtt
;
736 g_assert(m1
->inE
->type
== TCP
);
738 // (T2 - T1) - (T3 - T4)
739 rtt
= malloc(sizeof(double));
740 *rtt
= wallTimeSub(&m1
->inE
->wallTime
, &m1
->outE
->wallTime
) -
741 wallTimeSub(&m2
->outE
->wallTime
, &m2
->inE
->wallTime
);
743 rttKey
= malloc(sizeof(struct RttKey
));
745 MIN(m1
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
,
746 m1
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
);
748 MAX(m1
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
,
749 m1
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
);
751 if (syncState
->graphsStream
)
753 AnalysisHistogramEval
* histogram
=
754 g_hash_table_lookup(analysisData
->graphs
->histograms
, rttKey
);
756 if (histogram
== NULL
)
758 struct RttKey
* tableKey
= malloc(sizeof(*tableKey
));
760 histogram
= constructAnalysisHistogramEval(syncState
->graphsDir
,
762 memcpy(tableKey
, rttKey
, sizeof(*tableKey
));
763 g_hash_table_insert(analysisData
->graphs
->histograms
, tableKey
,
767 hitBin(&histogram
->hrttBins
, *rtt
/ 2);
770 if (syncState
->stats
)
772 exchangeRtt
= g_hash_table_lookup(analysisData
->stats
->exchangeRtt
,
777 if (*rtt
< *exchangeRtt
)
779 g_hash_table_replace(analysisData
->stats
->exchangeRtt
, rttKey
, rtt
);
789 g_hash_table_insert(analysisData
->stats
->exchangeRtt
, rttKey
, rtt
);
801 * Perform analysis on muliple events
803 * Sum the broadcast differential delays
806 * syncState container for synchronization data
807 * broadcast structure containing the events
809 static void analyzeBroadcastEval(SyncState
* const syncState
, Broadcast
* const
812 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
814 if (syncState
->stats
)
816 double sum
= 0, squaresSum
= 0;
819 g_queue_foreach(broadcast
->events
, &gfSum
, &sum
);
820 g_queue_foreach(broadcast
->events
, &gfSumSquares
, &squaresSum
);
822 analysisData
->stats
->broadcastNb
++;
823 // Because of numerical errors, this can at times be < 0
824 y
= squaresSum
/ g_queue_get_length(broadcast
->events
) - pow(sum
/
825 g_queue_get_length(broadcast
->events
), 2.);
828 analysisData
->stats
->broadcastDiffSum
+= sqrt(y
);
832 if (syncState
->graphsStream
)
836 unsigned int eventNb
= broadcast
->events
->length
;
838 events
= g_array_sized_new(FALSE
, FALSE
, sizeof(Event
*), eventNb
);
839 g_queue_foreach(broadcast
->events
, &gfAddEventToArray
, events
);
841 for (i
= 0; i
< eventNb
; i
++)
843 for (j
= 0; j
< eventNb
; j
++)
845 Event
* eventI
= g_array_index(events
, Event
*, i
), * eventJ
=
846 g_array_index(events
, Event
*, j
);
848 if (eventI
->traceNum
< eventJ
->traceNum
)
850 updateBounds(analysisData
->graphs
->bounds
, eventI
, eventJ
);
855 g_array_free(events
, TRUE
);
861 * Finalize the factor calculations. Since this module does not really
862 * calculate factors, identity factors are returned. Instead, histograms are
863 * written out and histogram structures are freed.
866 * syncState container for synchronization data.
869 * Factors[traceNb] identity factors for each trace
871 static GArray
* finalizeAnalysisEval(SyncState
* const syncState
)
875 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
877 if (syncState
->graphsStream
&& analysisData
->graphs
->histograms
)
879 g_hash_table_foreach(analysisData
->graphs
->histograms
,
880 &ghfWriteHistogram
, &(struct WriteHistogramInfo
) {.rttInfo
=
881 analysisData
->rttInfo
, .graphsStream
= syncState
->graphsStream
});
882 g_hash_table_destroy(analysisData
->graphs
->histograms
);
883 analysisData
->graphs
->histograms
= NULL
;
886 finalizeAnalysisEvalLP(syncState
);
888 factors
= g_array_sized_new(FALSE
, FALSE
, sizeof(Factors
),
890 g_array_set_size(factors
, syncState
->traceNb
);
891 for (i
= 0; i
< syncState
->traceNb
; i
++)
895 e
= &g_array_index(factors
, Factors
, i
);
905 * Print statistics related to analysis. Must be called after
909 * syncState container for synchronization data.
911 static void printAnalysisStatsEval(SyncState
* const syncState
)
913 AnalysisDataEval
* analysisData
;
914 unsigned int i
, j
, k
;
915 unsigned int totInversion
= 0, totTooFast
= 0, totNoInfo
= 0, totTotal
= 0;
918 if (!syncState
->stats
)
923 analysisData
= (AnalysisDataEval
*) syncState
->analysisData
;
925 printf("Synchronization evaluation analysis stats:\n");
926 if (analysisData
->stats
->broadcastNb
)
928 printf("\tsum of broadcast differential delays: %g\n",
929 analysisData
->stats
->broadcastDiffSum
);
930 printf("\taverage broadcast differential delay: %g\n",
931 analysisData
->stats
->broadcastDiffSum
/
932 analysisData
->stats
->broadcastNb
);
935 printf("\tIndividual evaluation:\n"
936 "\t\tTrace pair Inversions Too fast No RTT info Total\n");
938 for (i
= 0; i
< syncState
->traceNb
; i
++)
940 for (j
= i
+ 1; j
< syncState
->traceNb
; j
++)
942 MessageStats
* messageStats
;
950 for (k
= 0; k
< sizeof(loopValues
) / sizeof(*loopValues
); k
++)
953 &analysisData
->stats
->messageStats
[loopValues
[k
].t1
][loopValues
[k
].t2
];
955 printf("\t\t%3d - %-3d ", loopValues
[k
].t1
, loopValues
[k
].t2
);
956 printf("%u (%u%%)%n", messageStats
->inversionNb
, (unsigned
957 int) ceil((double) messageStats
->inversionNb
/
958 messageStats
->total
* 100), &charNb
);
959 printf("%*s", 17 - charNb
> 0 ? 17 - charNb
+ 1: 1, " ");
960 printf("%u (%u%%)%n", messageStats
->tooFastNb
, (unsigned int)
961 ceil((double) messageStats
->tooFastNb
/
962 messageStats
->total
* 100), &charNb
);
963 printf("%*s%-10u %u\n", 17 - charNb
> 0 ? 17 - charNb
+ 1:
964 1, " ", messageStats
->noRTTInfoNb
, messageStats
->total
);
966 totInversion
+= messageStats
->inversionNb
;
967 totTooFast
+= messageStats
->tooFastNb
;
968 totNoInfo
+= messageStats
->noRTTInfoNb
;
969 totTotal
+= messageStats
->total
;
974 printf("\t\t total ");
975 printf("%u (%u%%)%n", totInversion
, (unsigned int) ceil((double)
976 totInversion
/ totTotal
* 100), &charNb
);
977 printf("%*s", 17 - charNb
> 0 ? 17 - charNb
+ 1: 1, " ");
978 printf("%u (%u%%)%n", totTooFast
, (unsigned int) ceil((double) totTooFast
979 / totTotal
* 100), &charNb
);
980 printf("%*s%-10u %u\n", 17 - charNb
> 0 ? 17 - charNb
+ 1: 1, " ",
981 totNoInfo
, totTotal
);
983 printf("\tRound-trip times:\n"
984 "\t\tHost pair RTT from exchanges RTTs from file (ms)\n");
985 g_hash_table_foreach(analysisData
->stats
->exchangeRtt
,
986 &ghfPrintExchangeRtt
, analysisData
->rttInfo
);
989 printf("\tConvex hull factors comparisons:\n"
990 "\t\tTrace pair Factors type Differences (lp - chull)\n"
992 "\t\t Min Max Min Max\n");
994 for (i
= 0; i
< syncState
->traceNb
; i
++)
996 for (j
= 0; j
< i
; j
++)
998 FactorsCHull
* chFactors
= &analysisData
->stats
->chFactorsArray
[i
][j
];
999 FactorsCHull
* lpFactors
= &analysisData
->stats
->lpFactorsArray
[i
][j
];
1001 printf("\t\t%3d - %-3d ", i
, j
);
1002 if (lpFactors
->type
== chFactors
->type
)
1004 if (lpFactors
->type
== MIDDLE
)
1006 printf("%-13s %-10.4g %-10.4g %-10.4g %.4g\n",
1007 approxNames
[lpFactors
->type
],
1008 lpFactors
->min
->offset
- chFactors
->min
->offset
,
1009 lpFactors
->max
->offset
- chFactors
->max
->offset
,
1010 lpFactors
->min
->drift
- chFactors
->min
->drift
,
1011 lpFactors
->max
->drift
- chFactors
->max
->drift
);
1013 else if (lpFactors
->type
== ABSENT
)
1015 printf("%s\n", approxNames
[lpFactors
->type
]);
1020 printf("Different! %s and %s\n", approxNames
[lpFactors
->type
],
1021 approxNames
[chFactors
->type
]);
1030 * A GHFunc for g_hash_table_foreach()
1033 * key: RttKey* where saddr < daddr
1034 * value: double*, RTT estimated from exchanges
1035 * user_data GHashTable* rttInfo
1037 static void ghfPrintExchangeRtt(gpointer key
, gpointer value
, gpointer
1040 char addr1
[16], addr2
[16];
1041 struct RttKey
* rttKey1
= key
;
1042 struct RttKey rttKey2
= {rttKey1
->daddr
, rttKey1
->saddr
};
1043 double* fileRtt1
, *fileRtt2
;
1044 GHashTable
* rttInfo
= user_data
;
1046 convertIP(addr1
, rttKey1
->saddr
);
1047 convertIP(addr2
, rttKey1
->daddr
);
1049 fileRtt1
= g_hash_table_lookup(rttInfo
, rttKey1
);
1050 fileRtt2
= g_hash_table_lookup(rttInfo
, &rttKey2
);
1052 printf("\t\t(%15s, %-15s) %-18.3f ", addr1
, addr2
, *(double*) value
* 1e3
);
1054 if (fileRtt1
|| fileRtt2
)
1058 printf("%.3f", *fileRtt1
* 1e3
);
1060 if (fileRtt1
&& fileRtt2
)
1066 printf("%.3f", *fileRtt2
* 1e3
);
1078 * A GHashFunc for g_hash_table_new()
1081 * key struct RttKey*
1083 static guint
ghfRttKeyHash(gconstpointer key
)
1085 struct RttKey
* rttKey
;
1088 rttKey
= (struct RttKey
*) key
;
1100 * A GDestroyNotify function for g_hash_table_new_full()
1103 * data: struct RttKey*
1105 static void gdnDestroyRttKey(gpointer data
)
1112 * A GDestroyNotify function for g_hash_table_new_full()
1117 static void gdnDestroyDouble(gpointer data
)
1124 * A GEqualFunc for g_hash_table_new()
1130 * TRUE if both values are equal
1132 static gboolean
gefRttKeyEqual(gconstpointer a
, gconstpointer b
)
1134 const struct RttKey
* rkA
, * rkB
;
1136 rkA
= (struct RttKey
*) a
;
1137 rkB
= (struct RttKey
*) b
;
1139 if (rkA
->saddr
== rkB
->saddr
&& rkA
->daddr
== rkB
->daddr
)
1151 * Read a file contain minimum round trip time values and fill an array with
1152 * them. The file is formatted as such:
1153 * <host1 IP> <host2 IP> <RTT in milliseconds>
1154 * ip's should be in dotted quad format
1157 * rttInfo: double* rttInfo[RttKey], empty table, will be filled
1158 * rttStream: stream from which to read
1160 static void readRttInfo(GHashTable
* rttInfo
, FILE* rttStream
)
1166 positionStream(rttStream
);
1167 retval
= getline(&line
, &len
, rttStream
);
1168 while(!feof(rttStream
))
1170 struct RttKey
* rttKey
;
1171 char saddrDQ
[20], daddrDQ
[20];
1174 struct in_addr addr
;
1180 {saddrDQ
, offsetof(struct RttKey
, saddr
)},
1181 {daddrDQ
, offsetof(struct RttKey
, daddr
)}
1184 if (retval
== -1 && !feof(rttStream
))
1186 g_error(strerror(errno
));
1189 if (line
[retval
- 1] == '\n')
1191 line
[retval
- 1]= '\0';
1194 rtt
= malloc(sizeof(double));
1195 retval
= sscanf(line
, " %19s %19s %lf %c", saddrDQ
, daddrDQ
, rtt
,
1199 g_error(strerror(errno
));
1201 else if (retval
!= 3)
1203 g_error("Error parsing RTT file, line was '%s'", line
);
1206 rttKey
= malloc(sizeof(struct RttKey
));
1207 for (i
= 0; i
< sizeof(loopValues
) / sizeof(*loopValues
); i
++)
1209 retval
= inet_aton(loopValues
[i
].dq
, &addr
);
1212 g_error("Error converting address '%s'", loopValues
[i
].dq
);
1214 *(uint32_t*) ((void*) rttKey
+ loopValues
[i
].offset
)=
1219 g_debug("rttInfo, Inserting (%u, %u)->(%f)", rttKey
->saddr
,
1220 rttKey
->daddr
, *rtt
);
1221 g_hash_table_insert(rttInfo
, rttKey
, rtt
);
1223 positionStream(rttStream
);
1224 retval
= getline(&line
, &len
, rttStream
);
1235 * Advance stream over empty space, empty lines and lines that begin with '#'
1238 * stream: stream, at exit, will be over the first non-empty character
1239 * of a line of be at EOF
1241 static void positionStream(FILE* stream
)
1250 firstChar
= fgetc(stream
);
1251 if (firstChar
== (int) '#')
1253 retval
= getline(&line
, &len
, stream
);
1262 g_error(strerror(errno
));
1266 else if (firstChar
== (int) '\n' || firstChar
== (int) ' ' ||
1267 firstChar
== (int) '\t')
1269 else if (firstChar
== EOF
)
1278 retval
= ungetc(firstChar
, stream
);
1281 g_error("Error: ungetc()");
1293 * A GFunc for g_queue_foreach()
1296 * data Event*, a UDP broadcast event
1297 * user_data double*, the running sum
1300 * Adds the time of the event to the sum
1302 static void gfSum(gpointer data
, gpointer userData
)
1304 Event
* event
= (Event
*) data
;
1306 *(double*) userData
+= event
->wallTime
.seconds
+ event
->wallTime
.nanosec
/
1312 * A GFunc for g_queue_foreach()
1315 * data Event*, a UDP broadcast event
1316 * user_data double*, the running sum
1319 * Adds the square of the time of the event to the sum
1321 static void gfSumSquares(gpointer data
, gpointer userData
)
1323 Event
* event
= (Event
*) data
;
1325 *(double*) userData
+= pow(event
->wallTime
.seconds
+ event
->wallTime
.nanosec
1331 * Update a struct Bins according to a new value
1334 * bins: the structure containing bins to build a histrogram
1335 * value: the new value
1337 static void hitBin(struct Bins
* const bins
, const double value
)
1339 unsigned int binN
= binNum(value
);
1341 if (binN
< bins
->min
)
1345 else if (binN
> bins
->max
)
1357 * Figure out the bin in a histogram to which a value belongs.
1359 * This uses exponentially sized bins that go from 0 to infinity.
1362 * value: in the range -INFINITY to INFINITY
1365 * The number of the bin in a struct Bins.bin
1367 static unsigned int binNum(const double value
)
1373 else if (value
< binEnd(1))
1377 else if (value
>= binStart(BIN_NB
- 1))
1383 return floor(log(value
) / log(binBase
)) + BIN_NB
+ 1;
1389 * Figure out the start of the interval of a bin in a histogram. See struct
1392 * This uses exponentially sized bins that go from 0 to infinity.
1395 * binNum: bin number
1398 * The start of the interval, this value is included in the interval (except
1399 * for -INFINITY, naturally)
1401 static double binStart(const unsigned int binNum
)
1403 g_assert_cmpuint(binNum
, <, BIN_NB
);
1409 else if (binNum
== 1)
1415 return pow(binBase
, (double) binNum
- BIN_NB
+ 1);
1421 * Figure out the end of the interval of a bin in a histogram. See struct
1424 * This uses exponentially sized bins that go from 0 to infinity.
1427 * binNum: bin number
1430 * The end of the interval, this value is not included in the interval
1432 static double binEnd(const unsigned int binNum
)
1434 g_assert_cmpuint(binNum
, <, BIN_NB
);
1440 else if (binNum
< BIN_NB
- 1)
1442 return pow(binBase
, (double) binNum
- BIN_NB
+ 2);
1452 * Return the total number of elements in the "normal" bins (not underflow or
1456 * bins: the structure containing bins to build a histrogram
1458 static uint32_t normalTotal(struct Bins
* const bins
)
1460 return bins
->total
- bins
->bin
[0] - bins
->bin
[BIN_NB
- 1];
1464 /* Update the bounds between two traces
1467 * bounds: the array containing all the trace-pair bounds
1468 * e1, e2: the two related events
1470 static void updateBounds(Bounds
** const bounds
, Event
* const e1
, Event
* const
1473 unsigned int traceI
, traceJ
;
1474 uint64_t messageTime
;
1477 if (e1
->traceNum
< e2
->traceNum
)
1479 traceI
= e2
->traceNum
;
1480 traceJ
= e1
->traceNum
;
1481 messageTime
= e1
->cpuTime
;
1485 traceI
= e1
->traceNum
;
1486 traceJ
= e2
->traceNum
;
1487 messageTime
= e2
->cpuTime
;
1489 tpBounds
= &bounds
[traceI
][traceJ
];
1491 if (messageTime
< tpBounds
->min
)
1493 tpBounds
->min
= messageTime
;
1495 if (messageTime
> tpBounds
->max
)
1497 tpBounds
->max
= messageTime
;
1504 * Create the linear programming problem containing the constraints defined by
1505 * two half-hulls. The objective function and optimization directions are not
1509 * syncState: container for synchronization data
1510 * i: first trace number
1511 * j: second trace number, garanteed to be larger than i
1513 * A new glp_prob*, this problem must be freed by the caller with
1516 static glp_prob
* lpCreateProblem(GQueue
* const lowerHull
, GQueue
* const
1521 const double zeroD
= 0.;
1522 glp_prob
* lp
= glp_create_prob();
1523 unsigned int hullPointNb
= g_queue_get_length(lowerHull
) +
1524 g_queue_get_length(upperHull
);
1525 GArray
* iArray
= g_array_sized_new(FALSE
, FALSE
, sizeof(int), hullPointNb
+
1527 GArray
* jArray
= g_array_sized_new(FALSE
, FALSE
, sizeof(int), hullPointNb
+
1529 GArray
* aArray
= g_array_sized_new(FALSE
, FALSE
, sizeof(double),
1533 struct LPAddRowInfo rowInfo
;
1535 {lowerHull
, {lp
, GLP_UP
, iArray
, jArray
, aArray
}},
1536 {upperHull
, {lp
, GLP_LO
, iArray
, jArray
, aArray
}},
1539 // Create the LP problem
1540 glp_term_out(GLP_OFF
);
1541 glp_add_rows(lp
, hullPointNb
);
1542 glp_add_cols(lp
, 2);
1544 glp_set_col_name(lp
, 1, "a0");
1545 glp_set_col_bnds(lp
, 1, GLP_FR
, 0., 0.);
1546 glp_set_col_name(lp
, 2, "a1");
1547 glp_set_col_bnds(lp
, 2, GLP_LO
, 0., 0.);
1549 // Add row constraints
1550 g_array_append_val(iArray
, zero
);
1551 g_array_append_val(jArray
, zero
);
1552 g_array_append_val(aArray
, zeroD
);
1554 for (it
= 0; it
< sizeof(loopValues
) / sizeof(*loopValues
); it
++)
1556 g_queue_foreach(loopValues
[it
].hull
, &gfLPAddRow
,
1557 &loopValues
[it
].rowInfo
);
1560 g_assert_cmpuint(iArray
->len
, ==, jArray
->len
);
1561 g_assert_cmpuint(jArray
->len
, ==, aArray
->len
);
1562 g_assert_cmpuint(aArray
->len
- 1, ==, hullPointNb
* 2);
1564 glp_load_matrix(lp
, aArray
->len
- 1, &g_array_index(iArray
, int, 0),
1565 &g_array_index(jArray
, int, 0), &g_array_index(aArray
, double, 0));
1567 glp_scale_prob(lp
, GLP_SF_AUTO
);
1569 g_array_free(iArray
, TRUE
);
1570 g_array_free(jArray
, TRUE
);
1571 g_array_free(aArray
, TRUE
);
1578 * A GFunc for g_queue_foreach(). Add constraints and bounds for one row.
1581 * data Point*, synchronization point for which to add an LP row
1583 * user_data LPAddRowInfo*
1585 static void gfLPAddRow(gpointer data
, gpointer user_data
)
1588 struct LPAddRowInfo
* rowInfo
= user_data
;
1590 double constraints
[2];
1592 indexes
[0]= g_array_index(rowInfo
->iArray
, int, rowInfo
->iArray
->len
- 1) + 1;
1593 indexes
[1]= indexes
[0];
1595 if (rowInfo
->boundType
== GLP_UP
)
1597 glp_set_row_bnds(rowInfo
->lp
, indexes
[0], GLP_UP
, 0., p
->y
);
1599 else if (rowInfo
->boundType
== GLP_LO
)
1601 glp_set_row_bnds(rowInfo
->lp
, indexes
[0], GLP_LO
, p
->y
, 0.);
1605 g_assert_not_reached();
1608 g_array_append_vals(rowInfo
->iArray
, indexes
, 2);
1611 g_array_append_vals(rowInfo
->jArray
, indexes
, 2);
1613 constraints
[1]= p
->x
;
1614 g_array_append_vals(rowInfo
->aArray
, constraints
, 2);
1619 * Calculate min or max correction factors (as possible) using an LP problem.
1622 * lp: A linear programming problem with constraints and bounds
1624 * direction: The type of factors desired. Use GLP_MAX for max
1625 * approximation factors (a1, the drift or slope is the
1626 * largest) and GLP_MIN in the other case.
1629 * If the calculation was successful, a new Factors struct. Otherwise, NULL.
1630 * The calculation will fail if the hull assumptions are not respected.
1632 static Factors
* calculateFactors(glp_prob
* const lp
, const int direction
)
1637 glp_set_obj_coef(lp
, 1, 0.);
1638 glp_set_obj_coef(lp
, 2, 1.);
1640 glp_set_obj_dir(lp
, direction
);
1641 retval
= glp_simplex(lp
, NULL
);
1642 status
= glp_get_status(lp
);
1644 if (retval
== 0 && status
== GLP_OPT
)
1646 factors
= malloc(sizeof(Factors
));
1647 factors
->offset
= glp_get_col_prim(lp
, 1);
1648 factors
->drift
= glp_get_col_prim(lp
, 2);
1660 * Calculate min, max and approx correction factors (as possible) using an LP
1664 * lp: A linear programming problem with constraints and bounds
1668 * Please note that the approximation type may be MIDDLE, INCOMPLETE or
1669 * ABSENT. Unlike in analysis_chull, ABSENT is also used when the hulls do
1670 * not respect assumptions.
1672 static void calculateCompleteFactors(glp_prob
* const lp
, FactorsCHull
* factors
)
1674 factors
->min
= calculateFactors(lp
, GLP_MIN
);
1675 factors
->max
= calculateFactors(lp
, GLP_MAX
);
1677 if (factors
->min
&& factors
->max
)
1679 factors
->type
= MIDDLE
;
1680 calculateFactorsMiddle(factors
);
1682 else if (factors
->min
|| factors
->max
)
1684 factors
->type
= INCOMPLETE
;
1685 factors
->approx
= NULL
;
1689 factors
->type
= ABSENT
;
1690 factors
->approx
= NULL
;
1696 * Create and initialize an array like AnalysisStatsCHull.allFactors
1699 * traceNb: number of traces
1702 * A new array, which can be freed with freeAllFactors()
1704 static FactorsCHull
** createAllFactors(const unsigned int traceNb
)
1706 FactorsCHull
** factorsArray
;
1709 factorsArray
= malloc(traceNb
* sizeof(FactorsCHull
*));
1710 for (i
= 0; i
< traceNb
; i
++)
1712 factorsArray
[i
]= calloc((i
+ 1), sizeof(FactorsCHull
));
1714 factorsArray
[i
][i
].type
= EXACT
;
1715 factorsArray
[i
][i
].approx
= malloc(sizeof(Factors
));
1716 factorsArray
[i
][i
].approx
->drift
= 1.;
1717 factorsArray
[i
][i
].approx
->offset
= 0.;
1720 return factorsArray
;
1726 * Compute synchronization factors using a linear programming approach.
1727 * Compute the factors using analysis_chull. Compare the two.
1729 * When the solver library, glpk, is not available at build time, only compute
1730 * the factors using analysis_chull. This is to make sure that module runs its
1731 * finalize function so that its graph functions can be called later.
1734 * syncState: container for synchronization data
1736 static void finalizeAnalysisEvalLP(SyncState
* const syncState
)
1738 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
1741 AnalysisDataCHull
* chAnalysisData
= analysisData
->chullSS
->analysisData
;
1742 FactorsCHull
** lpFactorsArray
;
1744 if (!syncState
->stats
&& !syncState
->graphsStream
)
1749 /* Because of matching_distributor, this analysis may be called twice.
1750 * Only run it once */
1751 if ((syncState
->graphsStream
&& analysisData
->graphs
->lps
!= NULL
) ||
1752 (syncState
->stats
&& analysisData
->stats
->chFactorsArray
!= NULL
))
1757 lpFactorsArray
= createAllFactors(syncState
->traceNb
);
1759 if (syncState
->stats
)
1761 analysisData
->stats
->chFactorsArray
=
1762 calculateAllFactors(analysisData
->chullSS
);
1763 analysisData
->stats
->lpFactorsArray
= lpFactorsArray
;
1766 if (syncState
->graphsStream
)
1768 analysisData
->graphs
->lps
= malloc(syncState
->traceNb
*
1769 sizeof(glp_prob
**));
1770 for (i
= 0; i
< syncState
->traceNb
; i
++)
1772 analysisData
->graphs
->lps
[i
]= malloc(i
* sizeof(glp_prob
*));
1774 analysisData
->graphs
->lpFactorsArray
= lpFactorsArray
;
1777 for (i
= 0; i
< syncState
->traceNb
; i
++)
1779 for (j
= 0; j
< i
; j
++)
1783 // Create the LP problem
1784 lp
= lpCreateProblem(chAnalysisData
->hullArray
[i
][j
],
1785 chAnalysisData
->hullArray
[j
][i
]);
1787 // Use the LP problem to find the correction factors for this pair of
1789 calculateCompleteFactors(lp
, &lpFactorsArray
[i
][j
]);
1791 if (syncState
->graphsStream
)
1793 analysisData
->graphs
->lps
[i
][j
]= lp
;
1797 glp_delete_prob(lp
);
1803 g_array_free(analysisData
->chullSS
->analysisModule
->finalizeAnalysis(analysisData
->chullSS
),
1809 * Compute synchronization accuracy information using a linear programming
1810 * approach. Write the neccessary data files and plot lines in the gnuplot
1813 * When the solver library, glpk, is not available at build time nothing is
1814 * actually produced.
1817 * syncState: container for synchronization data
1818 * i: first trace number
1819 * j: second trace number, garanteed to be larger than i
1821 static void writeAnalysisTraceTimeBackPlotsEval(SyncState
* const syncState
,
1822 const unsigned int i
, const unsigned int j
)
1826 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
1827 AnalysisGraphsEval
* graphs
= analysisData
->graphs
;
1828 GQueue
*** hullArray
= ((AnalysisDataCHull
*)
1829 analysisData
->chullSS
->analysisData
)->hullArray
;
1830 FactorsCHull
* lpFactors
= &graphs
->lpFactorsArray
[j
][i
];
1831 glp_prob
* lp
= graphs
->lps
[j
][i
];
1833 if (lpFactors
->type
== MIDDLE
)
1840 unsigned int xBegin
, xEnd
;
1842 const unsigned int graphPointNb
= 1000;
1844 // Open the data file
1845 snprintf(fileName
, 40, "analysis_eval_accuracy-%03u_and_%03u.data", i
, j
);
1846 fileName
[sizeof(fileName
) - 1]= '\0';
1848 cwd
= changeToGraphsDir(syncState
->graphsDir
);
1850 if ((fp
= fopen(fileName
, "w")) == NULL
)
1852 g_error(strerror(errno
));
1854 fprintf(fp
, "#%-24s %-25s %-25s %-25s\n", "x", "middle", "min", "max");
1859 g_error(strerror(errno
));
1863 // Build the list of absisca values for the points in the accuracy graph
1864 g_assert_cmpuint(graphPointNb
, >=, 4);
1865 xValues
= malloc(graphPointNb
* sizeof(double));
1866 xValues
[0]= graphs
->bounds
[j
][i
].min
;
1867 xValues
[graphPointNb
- 1]= graphs
->bounds
[j
][i
].max
;
1868 xValues
[1]= MIN(((Point
*) g_queue_peek_head(hullArray
[i
][j
]))->x
,
1869 ((Point
*) g_queue_peek_head(hullArray
[j
][i
]))->x
);
1870 xValues
[graphPointNb
- 2]= MAX(((Point
*)
1871 g_queue_peek_tail(hullArray
[i
][j
]))->x
, ((Point
*)
1872 g_queue_peek_tail(hullArray
[j
][i
]))->x
);
1874 if (xValues
[0] == xValues
[1])
1882 if (xValues
[graphPointNb
- 2] == xValues
[graphPointNb
- 1])
1884 xEnd
= graphPointNb
- 1;
1888 xEnd
= graphPointNb
- 2;
1890 interval
= (xValues
[xEnd
] - xValues
[xBegin
]) / (graphPointNb
- 1);
1892 for (it
= xBegin
; it
<= xEnd
; it
++)
1894 xValues
[it
]= xValues
[xBegin
] + interval
* (it
- xBegin
);
1897 /* For each absisca value and each optimisation direction, solve the LP
1898 * and write a line in the data file */
1899 for (it
= 0; it
< graphPointNb
; it
++)
1902 int directions
[]= {GLP_MIN
, GLP_MAX
};
1904 glp_set_obj_coef(lp
, 1, 1.);
1905 glp_set_obj_coef(lp
, 2, xValues
[it
]);
1907 fprintf(fp
, "%25.9f %25.9f", xValues
[it
], lpFactors
->approx
->offset
1908 + lpFactors
->approx
->drift
* xValues
[it
]);
1909 for (it2
= 0; it2
< sizeof(directions
) / sizeof(*directions
); it2
++)
1913 glp_set_obj_dir(lp
, directions
[it2
]);
1914 retval
= glp_simplex(lp
, NULL
);
1915 status
= glp_get_status(lp
);
1917 g_assert(retval
== 0 && status
== GLP_OPT
);
1918 fprintf(fp
, " %25.9f", glp_get_obj_val(lp
));
1926 fprintf(syncState
->graphsStream
,
1927 "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
1928 "using 1:(($3 - $2) / clock_freq_%2$u):(($4 - $2) / clock_freq_%2$u) "
1929 "title \"Synchronization accuracy\" "
1930 "with filledcurves linewidth 2 linetype 1 "
1931 "linecolor rgb \"black\" fill solid 0.25 noborder, \\\n", i
,
1939 * Write the analysis-specific graph lines in the gnuplot script.
1941 * When the solver library, glpk, is not available at build time nothing is
1942 * actually produced.
1945 * syncState: container for synchronization data
1946 * i: first trace number
1947 * j: second trace number, garanteed to be larger than i
1949 static void writeAnalysisTraceTimeForePlotsEval(SyncState
* const syncState
,
1950 const unsigned int i
, const unsigned int j
)
1953 if (((AnalysisDataEval
*)
1954 syncState
->analysisData
)->graphs
->lpFactorsArray
[j
][i
].type
==
1957 fprintf(syncState
->graphsStream
,
1958 "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
1959 "using 1:(($3 - $2) / clock_freq_%2$u) notitle "
1960 "with lines linewidth 2 linetype 1 "
1961 "linecolor rgb \"gray60\", \\\n"
1962 "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
1963 "using 1:(($4 - $2) / clock_freq_%2$u) notitle "
1964 "with lines linewidth 2 linetype 1 "
1965 "linecolor rgb \"gray60\", \\\n", i
, j
);
1972 * Write the analysis-specific graph lines in the gnuplot script.
1975 * syncState: container for synchronization data
1976 * i: first trace number
1977 * j: second trace number, garanteed to be larger than i
1979 static void writeAnalysisTraceTraceBackPlotsEval(SyncState
* const syncState
,
1980 const unsigned int i
, const unsigned int j
)
1983 fprintf(syncState
->graphsStream
,
1984 "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
1986 "title \"Synchronization accuracy\" "
1987 "with filledcurves linewidth 2 linetype 1 "
1988 "linecolor rgb \"black\" fill solid 0.25 noborder, \\\n", i
, j
);
1994 * Write the analysis-specific graph lines in the gnuplot script.
1997 * syncState: container for synchronization data
1998 * i: first trace number
1999 * j: second trace number, garanteed to be larger than i
2001 static void writeAnalysisTraceTraceForePlotsEval(SyncState
* const syncState
,
2002 const unsigned int i
, const unsigned int j
)
2004 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
2006 analysisData
->chullSS
->analysisModule
->graphFunctions
.writeTraceTraceForePlots(analysisData
->chullSS
,