1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2009, 2010 Benjamin Poirier <benjamin.poirier@polymtl.ca>
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.
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.
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/>.
19 #define _ISOC99_SOURCE
25 #include <arpa/inet.h>
28 #include <netinet/in.h>
33 #include <sys/socket.h>
37 #include "sync_chain.h"
38 #include "event_analysis_chull.h"
40 #include "event_analysis_eval.h"
43 struct WriteHistogramInfo
54 GArray
* iArray
, * jArray
, * aArray
;
58 // Functions common to all analysis modules
59 static void initAnalysisEval(SyncState
* const syncState
);
60 static void destroyAnalysisEval(SyncState
* const syncState
);
62 static void analyzeMessageEval(SyncState
* const syncState
, Message
* const
64 static void analyzeExchangeEval(SyncState
* const syncState
, Exchange
* const
66 static void analyzeBroadcastEval(SyncState
* const syncState
, Broadcast
* const
68 static AllFactors
* finalizeAnalysisEval(SyncState
* const syncState
);
69 static void printAnalysisStatsEval(SyncState
* const syncState
);
70 static void writeAnalysisTraceTimeBackPlotsEval(SyncState
* const syncState
,
71 const unsigned int i
, const unsigned int j
);
72 static void writeAnalysisTraceTimeForePlotsEval(SyncState
* const syncState
,
73 const unsigned int i
, const unsigned int j
);
74 static void writeAnalysisTraceTraceBackPlotsEval(SyncState
* const syncState
,
75 const unsigned int i
, const unsigned int j
);
76 static void writeAnalysisTraceTraceForePlotsEval(SyncState
* const syncState
,
77 const unsigned int i
, const unsigned int j
);
79 // Functions specific to this module
80 static guint
ghfRttKeyHash(gconstpointer key
);
81 static gboolean
gefRttKeyEqual(gconstpointer a
, gconstpointer b
);
82 static void gdnDestroyRttKey(gpointer data
);
83 static void gdnDestroyDouble(gpointer data
);
84 static void readRttInfo(GHashTable
* rttInfo
, FILE* rttFile
);
85 static void positionStream(FILE* stream
);
87 static void gfSum(gpointer data
, gpointer userData
);
88 static void gfSumSquares(gpointer data
, gpointer userData
);
89 static void ghfPrintExchangeRtt(gpointer key
, gpointer value
, gpointer
92 static void hitBin(struct Bins
* const bins
, const double value
);
93 static unsigned int binNum(const double value
) __attribute__((pure
));
94 static double binStart(const unsigned int binNum
) __attribute__((pure
));
95 static double binEnd(const unsigned int binNum
) __attribute__((pure
));
96 static uint32_t normalTotal(struct Bins
* const bins
) __attribute__((const));
98 static AnalysisHistogramEval
* constructAnalysisHistogramEval(const char* const
99 graphsDir
, const struct RttKey
* const rttKey
);
100 static void destroyAnalysisHistogramEval(AnalysisHistogramEval
* const
102 static void gdnDestroyAnalysisHistogramEval(gpointer data
);
103 static void ghfWriteHistogram(gpointer key
, gpointer value
, gpointer
105 static void dumpBinToFile(const struct Bins
* const bins
, FILE* const file
);
106 static void writeHistogram(FILE* graphsStream
, const struct RttKey
* rttKey
,
107 double* minRtt
, AnalysisHistogramEval
* const histogram
);
109 static void updateBounds(Bounds
** const bounds
, Event
* const e1
, Event
* const
112 static void finalizeAnalysisEvalLP(SyncState
* const syncState
);
113 // The next group of functions is only needed when computing synchronization
116 static glp_prob
* lpCreateProblem(GQueue
* const lowerHull
, GQueue
* const
118 static void gfLPAddRow(gpointer data
, gpointer user_data
);
119 static Factors
* calculateFactors(glp_prob
* const lp
, const int direction
);
120 static void calculateCompleteFactors(glp_prob
* const lp
, PairFactors
*
122 static inline void finalizeAnalysisEvalLP(SyncState
* const syncState
);
123 static void gfAddAbsiscaToArray(gpointer data
, gpointer user_data
);
124 static gint
gcfCompareDouble(gconstpointer a
, gconstpointer b
);
126 static void finalizeAnalysisEvalLP(SyncState
* const syncState
);
130 // initialized in registerAnalysisEval()
133 static AnalysisModule analysisModuleEval
= {
135 .initAnalysis
= &initAnalysisEval
,
136 .destroyAnalysis
= &destroyAnalysisEval
,
137 .analyzeMessage
= &analyzeMessageEval
,
138 .analyzeExchange
= &analyzeExchangeEval
,
139 .analyzeBroadcast
= &analyzeBroadcastEval
,
140 .finalizeAnalysis
= &finalizeAnalysisEval
,
141 .printAnalysisStats
= &printAnalysisStatsEval
,
143 .writeTraceTimeBackPlots
= &writeAnalysisTraceTimeBackPlotsEval
,
144 .writeTraceTimeForePlots
= &writeAnalysisTraceTimeForePlotsEval
,
145 .writeTraceTraceBackPlots
= &writeAnalysisTraceTraceBackPlotsEval
,
146 .writeTraceTraceForePlots
= &writeAnalysisTraceTraceForePlotsEval
,
150 static ModuleOption optionEvalRttFile
= {
151 .longName
= "eval-rtt-file",
152 .hasArg
= REQUIRED_ARG
,
153 .optionHelp
= "specify the file containing RTT information",
159 * Analysis module registering function
161 void registerAnalysisEval()
163 binBase
= exp10(6. / (BIN_NB
- 3));
165 g_queue_push_tail(&analysisModules
, &analysisModuleEval
);
166 g_queue_push_tail(&moduleOptions
, &optionEvalRttFile
);
171 * Analysis init function
173 * This function is called at the beginning of a synchronization run for a set
177 * syncState container for synchronization data.
179 static void initAnalysisEval(SyncState
* const syncState
)
181 AnalysisDataEval
* analysisData
;
184 analysisData
= malloc(sizeof(AnalysisDataEval
));
185 syncState
->analysisData
= analysisData
;
187 analysisData
->rttInfo
= g_hash_table_new_full(&ghfRttKeyHash
,
188 &gefRttKeyEqual
, &gdnDestroyRttKey
, &gdnDestroyDouble
);
189 if (optionEvalRttFile
.arg
)
194 rttStream
= fopen(optionEvalRttFile
.arg
, "r");
195 if (rttStream
== NULL
)
197 g_error(strerror(errno
));
200 readRttInfo(analysisData
->rttInfo
, rttStream
);
202 retval
= fclose(rttStream
);
205 g_error(strerror(errno
));
209 if (syncState
->stats
)
211 analysisData
->stats
= calloc(1, sizeof(AnalysisStatsEval
));
212 analysisData
->stats
->broadcastRangeMin
= INFINITY
;
213 analysisData
->stats
->broadcastRangeMax
= -INFINITY
;
215 analysisData
->stats
->messageStats
= malloc(syncState
->traceNb
*
216 sizeof(MessageStats
*));
217 for (i
= 0; i
< syncState
->traceNb
; i
++)
219 analysisData
->stats
->messageStats
[i
]= calloc(syncState
->traceNb
,
220 sizeof(MessageStats
));
223 analysisData
->stats
->exchangeRtt
=
224 g_hash_table_new_full(&ghfRttKeyHash
, &gefRttKeyEqual
,
225 &gdnDestroyRttKey
, &gdnDestroyDouble
);
228 analysisData
->stats
->chFactorsArray
= NULL
;
229 analysisData
->stats
->lpFactorsArray
= NULL
;
233 if (syncState
->graphsStream
)
235 AnalysisGraphsEval
* graphs
= malloc(sizeof(AnalysisGraphsEval
));
237 analysisData
->graphs
= graphs
;
239 graphs
->histograms
= g_hash_table_new_full(&ghfRttKeyHash
,
240 &gefRttKeyEqual
, &gdnDestroyRttKey
,
241 &gdnDestroyAnalysisHistogramEval
);
243 graphs
->bounds
= malloc(syncState
->traceNb
* sizeof(Bounds
*));
244 for (i
= 0; i
< syncState
->traceNb
; i
++)
246 graphs
->bounds
[i
]= malloc(i
* sizeof(Bounds
));
247 for (j
= 0; j
< i
; j
++)
249 graphs
->bounds
[i
][j
].min
= UINT64_MAX
;
250 graphs
->bounds
[i
][j
].max
= 0;
256 graphs
->lpFactorsArray
= NULL
;
260 if (syncState
->stats
|| syncState
->graphsStream
)
264 analysisData
->chullSS
= malloc(sizeof(SyncState
));
265 memcpy(analysisData
->chullSS
, syncState
, sizeof(SyncState
));
266 analysisData
->chullSS
->stats
= false;
267 analysisData
->chullSS
->analysisData
= NULL
;
268 result
= g_queue_find_custom(&analysisModules
, "chull",
269 &gcfCompareAnalysis
);
270 analysisData
->chullSS
->analysisModule
= (AnalysisModule
*) result
->data
;
271 analysisData
->chullSS
->analysisModule
->initAnalysis(analysisData
->chullSS
);
277 * Create and open files used to store histogram points to generate graphs.
278 * Create data structures to store histogram points during analysis.
281 * graphsDir: folder where to write files
282 * rttKey: host pair, make sure saddr < daddr
284 static AnalysisHistogramEval
* constructAnalysisHistogramEval(const char* const
285 graphsDir
, const struct RttKey
* const rttKey
)
290 char name
[60], saddr
[16], daddr
[16];
291 AnalysisHistogramEval
* histogram
= calloc(1, sizeof(*histogram
));
294 const char* fileName
;
295 const char* host1
, *host2
;
297 {offsetof(AnalysisHistogramEval
, ttSendPoints
),
298 "analysis_eval_tt-%s_to_%s.data", saddr
, daddr
},
299 {offsetof(AnalysisHistogramEval
, ttRecvPoints
),
300 "analysis_eval_tt-%s_to_%s.data", daddr
, saddr
},
301 {offsetof(AnalysisHistogramEval
, hrttPoints
),
302 "analysis_eval_hrtt-%s_and_%s.data", saddr
, daddr
},
305 histogram
->ttSendBins
.min
= BIN_NB
- 1;
306 histogram
->ttRecvBins
.min
= BIN_NB
- 1;
307 histogram
->hrttBins
.min
= BIN_NB
- 1;
309 convertIP(saddr
, rttKey
->saddr
);
310 convertIP(daddr
, rttKey
->daddr
);
312 cwd
= changeToGraphsDir(graphsDir
);
314 for (i
= 0; i
< sizeof(loopValues
) / sizeof(*loopValues
); i
++)
316 retval
= snprintf(name
, sizeof(name
), loopValues
[i
].fileName
,
317 loopValues
[i
].host1
, loopValues
[i
].host2
);
318 if (retval
> sizeof(name
) - 1)
320 name
[sizeof(name
) - 1]= '\0';
322 if ((*(FILE**)((void*) histogram
+ loopValues
[i
].pointsOffset
)=
323 fopen(name
, "w")) == NULL
)
325 g_error(strerror(errno
));
332 g_error(strerror(errno
));
341 * Close files used to store histogram points to generate graphs.
344 * graphsDir: folder where to write files
345 * rttKey: host pair, make sure saddr < daddr
347 static void destroyAnalysisHistogramEval(AnalysisHistogramEval
* const
355 {offsetof(AnalysisHistogramEval
, ttSendPoints
)},
356 {offsetof(AnalysisHistogramEval
, ttRecvPoints
)},
357 {offsetof(AnalysisHistogramEval
, hrttPoints
)},
360 for (i
= 0; i
< sizeof(loopValues
) / sizeof(*loopValues
); i
++)
362 retval
= fclose(*(FILE**)((void*) histogram
+ loopValues
[i
].pointsOffset
));
365 g_error(strerror(errno
));
374 * A GDestroyNotify function for g_hash_table_new_full()
377 * data: AnalysisHistogramEval*
379 static void gdnDestroyAnalysisHistogramEval(gpointer data
)
381 destroyAnalysisHistogramEval(data
);
386 * A GHFunc for g_hash_table_foreach()
389 * key: RttKey* where saddr < daddr
390 * value: AnalysisHistogramEval*
391 * user_data struct WriteHistogramInfo*
393 static void ghfWriteHistogram(gpointer key
, gpointer value
, gpointer user_data
)
395 double* rtt1
, * rtt2
;
396 struct RttKey
* rttKey
= key
;
397 struct RttKey oppositeRttKey
= {.saddr
= rttKey
->daddr
, .daddr
=
399 AnalysisHistogramEval
* histogram
= value
;
400 struct WriteHistogramInfo
* info
= user_data
;
402 rtt1
= g_hash_table_lookup(info
->rttInfo
, rttKey
);
403 rtt2
= g_hash_table_lookup(info
->rttInfo
, &oppositeRttKey
);
409 else if (rtt2
!= NULL
)
411 rtt1
= MIN(rtt1
, rtt2
);
414 dumpBinToFile(&histogram
->ttSendBins
, histogram
->ttSendPoints
);
415 dumpBinToFile(&histogram
->ttRecvBins
, histogram
->ttRecvPoints
);
416 dumpBinToFile(&histogram
->hrttBins
, histogram
->hrttPoints
);
417 writeHistogram(info
->graphsStream
, rttKey
, rtt1
, histogram
);
422 * Write the content of one bin in a histogram point file
425 * bin: array of values that make up a histogram
426 * file: FILE*, write to this file
428 static void dumpBinToFile(const struct Bins
* const bins
, FILE* const file
)
432 // The first and last bins are skipped, see struct Bins
433 for (i
= 1; i
< BIN_NB
- 1; i
++)
435 if (bins
->bin
[i
] > 0)
437 fprintf(file
, "%20.9f %20.9f %20.9f\n", (binStart(i
) + binEnd(i
))
438 / 2., (double) bins
->bin
[i
] / ((binEnd(i
) - binStart(i
)) *
439 bins
->total
), binEnd(i
) - binStart(i
));
446 * Write the analysis-specific plot in the gnuplot script.
449 * graphsStream: write to this file
450 * rttKey: must be sorted such that saddr < daddr
451 * minRtt: if available, else NULL
452 * histogram: struct that contains the bins for the pair of traces
453 * identified by rttKey
455 static void writeHistogram(FILE* graphsStream
, const struct RttKey
* rttKey
,
456 double* minRtt
, AnalysisHistogramEval
* const histogram
)
458 char saddr
[16], daddr
[16];
460 convertIP(saddr
, rttKey
->saddr
);
461 convertIP(daddr
, rttKey
->daddr
);
463 fprintf(graphsStream
,
465 "set output \"histogram-%s-%s.eps\"\n"
467 "set xlabel \"Message Latency (s)\"\n"
468 "set ylabel \"Proportion of messages per second\"\n", saddr
, daddr
);
472 fprintf(graphsStream
,
473 "set arrow from %.9f, 0 rto 0, graph 1 "
474 "nohead linetype 3 linewidth 3 linecolor rgb \"black\"\n", *minRtt
478 if (normalTotal(&histogram
->ttSendBins
) ||
479 normalTotal(&histogram
->ttRecvBins
) ||
480 normalTotal(&histogram
->hrttBins
))
482 fprintf(graphsStream
, "plot \\\n");
484 if (normalTotal(&histogram
->hrttBins
))
486 fprintf(graphsStream
,
487 "\t\"analysis_eval_hrtt-%s_and_%s.data\" "
488 "title \"RTT/2\" with linespoints linetype 1 linewidth 2 "
489 "linecolor rgb \"black\" pointtype 6 pointsize 1,\\\n",
493 if (normalTotal(&histogram
->ttSendBins
))
495 fprintf(graphsStream
,
496 "\t\"analysis_eval_tt-%1$s_to_%2$s.data\" "
497 "title \"%1$s to %2$s\" with linespoints linetype 4 linewidth 2 "
498 "linecolor rgb \"gray60\" pointtype 6 pointsize 1,\\\n",
502 if (normalTotal(&histogram
->ttRecvBins
))
504 fprintf(graphsStream
,
505 "\t\"analysis_eval_tt-%1$s_to_%2$s.data\" "
506 "title \"%1$s to %2$s\" with linespoints linetype 4 linewidth 2 "
507 "linecolor rgb \"gray30\" pointtype 6 pointsize 1,\\\n",
511 // Remove the ",\\\n" from the last graph plot line
512 if (ftruncate(fileno(graphsStream
), ftell(graphsStream
) - 3) == -1)
514 g_error(strerror(errno
));
516 if (fseek(graphsStream
, 0, SEEK_END
) == -1)
518 g_error(strerror(errno
));
520 fprintf(graphsStream
, "\n");
526 * Analysis destroy function
528 * Free the analysis specific data structures
531 * syncState container for synchronization data.
533 static void destroyAnalysisEval(SyncState
* const syncState
)
536 AnalysisDataEval
* analysisData
;
538 analysisData
= (AnalysisDataEval
*) syncState
->analysisData
;
540 if (analysisData
== NULL
)
545 g_hash_table_destroy(analysisData
->rttInfo
);
547 if (syncState
->stats
)
549 AnalysisStatsEval
* stats
= analysisData
->stats
;
551 for (i
= 0; i
< syncState
->traceNb
; i
++)
553 free(stats
->messageStats
[i
]);
555 free(stats
->messageStats
);
557 g_hash_table_destroy(stats
->exchangeRtt
);
560 freeAllFactors(stats
->chFactorsArray
);
561 freeAllFactors(stats
->lpFactorsArray
);
567 if (syncState
->graphsStream
)
569 AnalysisGraphsEval
* graphs
= analysisData
->graphs
;
571 if (graphs
->histograms
)
573 g_hash_table_destroy(graphs
->histograms
);
576 for (i
= 0; i
< syncState
->traceNb
; i
++)
578 free(graphs
->bounds
[i
]);
580 free(graphs
->bounds
);
583 for (i
= 0; i
< syncState
->traceNb
; i
++)
587 for (j
= 0; j
< i
; j
++)
589 // There seems to be a memory leak in glpk, valgrind reports a
590 // loss (reachable) even if the problem is deleted
591 glp_delete_prob(graphs
->lps
[i
][j
]);
593 free(graphs
->lps
[i
]);
597 if (!syncState
->stats
)
599 freeAllFactors(graphs
->lpFactorsArray
);
606 if (syncState
->stats
|| syncState
->graphsStream
)
608 analysisData
->chullSS
->analysisModule
->destroyAnalysis(analysisData
->chullSS
);
609 free(analysisData
->chullSS
);
612 free(syncState
->analysisData
);
613 syncState
->analysisData
= NULL
;
618 * Perform analysis on an event pair.
620 * Check if there is message inversion or messages that are too fast.
623 * syncState container for synchronization data
624 * message structure containing the events
626 static void analyzeMessageEval(SyncState
* const syncState
, Message
* const
629 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
630 MessageStats
* messageStats
;
633 struct RttKey rttKey
;
635 g_assert(message
->inE
->type
== TCP
);
637 if (syncState
->stats
)
640 &analysisData
->stats
->messageStats
[message
->outE
->traceNum
][message
->inE
->traceNum
];
641 messageStats
->total
++;
644 tt
= wallTimeSub(&message
->inE
->wallTime
, &message
->outE
->wallTime
);
647 if (syncState
->stats
)
649 messageStats
->inversionNb
++;
652 else if (syncState
->graphsStream
)
654 struct RttKey rttKey
= {
655 .saddr
=MIN(message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
,
656 message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
),
657 .daddr
=MAX(message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
,
658 message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
),
660 AnalysisHistogramEval
* histogram
=
661 g_hash_table_lookup(analysisData
->graphs
->histograms
, &rttKey
);
663 if (histogram
== NULL
)
665 struct RttKey
* tableKey
= malloc(sizeof(*tableKey
));
667 histogram
= constructAnalysisHistogramEval(syncState
->graphsDir
, &rttKey
);
668 memcpy(tableKey
, &rttKey
, sizeof(*tableKey
));
669 g_hash_table_insert(analysisData
->graphs
->histograms
, tableKey
, histogram
);
672 if (message
->inE
->event
.udpEvent
->datagramKey
->saddr
<
673 message
->inE
->event
.udpEvent
->datagramKey
->daddr
)
675 hitBin(&histogram
->ttSendBins
, tt
);
679 hitBin(&histogram
->ttRecvBins
, tt
);
683 if (syncState
->stats
)
686 message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
;
688 message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
;
689 rtt
= g_hash_table_lookup(analysisData
->rttInfo
, &rttKey
);
690 g_debug("rttInfo, looking up (%u, %u)->(%f)", rttKey
.saddr
,
691 rttKey
.daddr
, rtt
? *rtt
: NAN
);
695 g_debug("rttInfo, tt: %f rtt / 2: %f", tt
, *rtt
/ 2.);
698 messageStats
->tooFastNb
++;
703 messageStats
->noRTTInfoNb
++;
707 if (syncState
->graphsStream
)
709 updateBounds(analysisData
->graphs
->bounds
, message
->inE
,
713 if (syncState
->stats
|| syncState
->graphsStream
)
715 analysisData
->chullSS
->analysisModule
->analyzeMessage(analysisData
->chullSS
,
722 * Perform analysis on multiple messages
727 * syncState container for synchronization data
728 * exchange structure containing the messages
730 static void analyzeExchangeEval(SyncState
* const syncState
, Exchange
* const
733 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
734 Message
* m1
= g_queue_peek_tail(exchange
->acks
);
735 Message
* m2
= exchange
->message
;
736 struct RttKey
* rttKey
;
737 double* rtt
, * exchangeRtt
;
739 g_assert(m1
->inE
->type
== TCP
);
741 // (T2 - T1) - (T3 - T4)
742 rtt
= malloc(sizeof(double));
743 *rtt
= wallTimeSub(&m1
->inE
->wallTime
, &m1
->outE
->wallTime
) -
744 wallTimeSub(&m2
->outE
->wallTime
, &m2
->inE
->wallTime
);
746 rttKey
= malloc(sizeof(struct RttKey
));
748 MIN(m1
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
,
749 m1
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
);
751 MAX(m1
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
,
752 m1
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
);
754 if (syncState
->graphsStream
)
756 AnalysisHistogramEval
* histogram
=
757 g_hash_table_lookup(analysisData
->graphs
->histograms
, rttKey
);
759 if (histogram
== NULL
)
761 struct RttKey
* tableKey
= malloc(sizeof(*tableKey
));
763 histogram
= constructAnalysisHistogramEval(syncState
->graphsDir
,
765 memcpy(tableKey
, rttKey
, sizeof(*tableKey
));
766 g_hash_table_insert(analysisData
->graphs
->histograms
, tableKey
,
770 hitBin(&histogram
->hrttBins
, *rtt
/ 2);
773 if (syncState
->stats
)
775 exchangeRtt
= g_hash_table_lookup(analysisData
->stats
->exchangeRtt
,
780 if (*rtt
< *exchangeRtt
)
782 g_hash_table_replace(analysisData
->stats
->exchangeRtt
, rttKey
, rtt
);
792 g_hash_table_insert(analysisData
->stats
->exchangeRtt
, rttKey
, rtt
);
804 * Perform analysis on muliple events
806 * Sum the broadcast differential delays
809 * syncState container for synchronization data
810 * broadcast structure containing the events
812 static void analyzeBroadcastEval(SyncState
* const syncState
, Broadcast
* const
815 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
817 if (syncState
->stats
)
819 double sum
= 0, squaresSum
= 0;
822 g_queue_foreach(broadcast
->events
, &gfSum
, &sum
);
823 g_queue_foreach(broadcast
->events
, &gfSumSquares
, &squaresSum
);
825 analysisData
->stats
->broadcastNb
++;
826 // Because of numerical errors, this can at times be < 0
827 y
= squaresSum
/ g_queue_get_length(broadcast
->events
) - pow(sum
/
828 g_queue_get_length(broadcast
->events
), 2.);
831 analysisData
->stats
->broadcastStdevSum
+= sqrt(y
);
834 if (syncState
->traceNb
== 2 && g_queue_get_length(broadcast
->events
)
840 e0
= g_queue_peek_head(broadcast
->events
);
841 e1
= g_queue_peek_tail(broadcast
->events
);
842 if (e0
->traceNum
> e1
->traceNum
)
851 dd
= wallTimeSub(&e1
->wallTime
, &e0
->wallTime
);
853 analysisData
->stats
->broadcastPairNb
++;
854 if (dd
< analysisData
->stats
->broadcastRangeMin
)
856 analysisData
->stats
->broadcastRangeMin
= dd
;
858 if (dd
> analysisData
->stats
->broadcastRangeMax
)
860 analysisData
->stats
->broadcastRangeMax
= dd
;
863 analysisData
->stats
->broadcastSum
+= dd
;
864 analysisData
->stats
->broadcastSumSquares
+= pow(dd
, 2);
868 if (syncState
->graphsStream
)
872 unsigned int eventNb
= broadcast
->events
->length
;
874 events
= g_array_sized_new(FALSE
, FALSE
, sizeof(Event
*), eventNb
);
875 g_queue_foreach(broadcast
->events
, &gfAddEventToArray
, events
);
877 for (i
= 0; i
< eventNb
; i
++)
879 for (j
= 0; j
< eventNb
; j
++)
881 Event
* eventI
= g_array_index(events
, Event
*, i
), * eventJ
=
882 g_array_index(events
, Event
*, j
);
884 if (eventI
->traceNum
< eventJ
->traceNum
)
886 updateBounds(analysisData
->graphs
->bounds
, eventI
, eventJ
);
891 g_array_free(events
, TRUE
);
897 * Finalize the factor calculations. Since this module does not really
898 * calculate factors, absent factors are returned. Instead, histograms are
899 * written out and histogram structures are freed.
902 * syncState container for synchronization data.
905 * AllFactors* synchronization factors for each trace pair
907 static AllFactors
* finalizeAnalysisEval(SyncState
* const syncState
)
909 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
911 if (syncState
->graphsStream
&& analysisData
->graphs
->histograms
)
913 g_hash_table_foreach(analysisData
->graphs
->histograms
,
914 &ghfWriteHistogram
, &(struct WriteHistogramInfo
) {.rttInfo
=
915 analysisData
->rttInfo
, .graphsStream
= syncState
->graphsStream
});
916 g_hash_table_destroy(analysisData
->graphs
->histograms
);
917 analysisData
->graphs
->histograms
= NULL
;
920 finalizeAnalysisEvalLP(syncState
);
922 return createAllFactors(syncState
->traceNb
);
927 * Print statistics related to analysis. Must be called after
931 * syncState container for synchronization data.
933 static void printAnalysisStatsEval(SyncState
* const syncState
)
935 AnalysisDataEval
* analysisData
;
936 unsigned int i
, j
, k
;
937 unsigned int totInversion
= 0, totTooFast
= 0, totNoInfo
= 0, totTotal
= 0;
940 if (!syncState
->stats
)
945 analysisData
= (AnalysisDataEval
*) syncState
->analysisData
;
947 printf("Synchronization evaluation analysis stats:\n");
948 if (analysisData
->stats
->broadcastNb
)
950 printf("\tBroadcast differential delay:\n");
951 printf("\t\tsum of standard deviations: %g\n",
952 analysisData
->stats
->broadcastStdevSum
);
953 printf("\t\taverage standard deviation: %g\n",
954 analysisData
->stats
->broadcastStdevSum
/
955 analysisData
->stats
->broadcastNb
);
957 if (syncState
->traceNb
== 2)
959 printf("\t\tdifferential delay range: [ %g .. %g ]\n",
960 analysisData
->stats
->broadcastRangeMin
,
961 analysisData
->stats
->broadcastRangeMax
);
962 printf("\t\tdifferential delay average: %g\n",
963 analysisData
->stats
->broadcastSum
/
964 analysisData
->stats
->broadcastPairNb
);
965 printf("\t\tdifferential delay standard deviation: %g\n",
966 sqrt(analysisData
->stats
->broadcastSumSquares
/
967 analysisData
->stats
->broadcastPairNb
-
968 pow(analysisData
->stats
->broadcastSum
/
969 analysisData
->stats
->broadcastPairNb
, 2)));
973 printf("\tIndividual evaluation:\n"
974 "\t\tTrace pair Inversions Too fast No RTT info Total\n");
976 for (i
= 0; i
< syncState
->traceNb
; i
++)
978 for (j
= i
+ 1; j
< syncState
->traceNb
; j
++)
980 MessageStats
* messageStats
;
988 for (k
= 0; k
< sizeof(loopValues
) / sizeof(*loopValues
); k
++)
991 &analysisData
->stats
->messageStats
[loopValues
[k
].t1
][loopValues
[k
].t2
];
993 printf("\t\t%3d - %-3d ", loopValues
[k
].t1
, loopValues
[k
].t2
);
994 printf("%u (%.2f%%)%n", messageStats
->inversionNb
, (double)
995 messageStats
->inversionNb
/ messageStats
->total
* 100,
997 printf("%*s", 17 - charNb
> 0 ? 17 - charNb
+ 1: 1, " ");
998 printf("%u (%.2f%%)%n", messageStats
->tooFastNb
, (double)
999 messageStats
->tooFastNb
/ messageStats
->total
* 100,
1001 printf("%*s%-10u %u\n", 17 - charNb
> 0 ? 17 - charNb
+ 1:
1002 1, " ", messageStats
->noRTTInfoNb
, messageStats
->total
);
1004 totInversion
+= messageStats
->inversionNb
;
1005 totTooFast
+= messageStats
->tooFastNb
;
1006 totNoInfo
+= messageStats
->noRTTInfoNb
;
1007 totTotal
+= messageStats
->total
;
1012 printf("\t\t total ");
1013 printf("%u (%.2f%%)%n", totInversion
, (double) totInversion
/ totTotal
*
1015 printf("%*s", 17 - charNb
> 0 ? 17 - charNb
+ 1: 1, " ");
1016 printf("%u (%.2f%%)%n", totTooFast
, (double) totTooFast
/ totTotal
* 100,
1018 printf("%*s%-10u %u\n", 17 - charNb
> 0 ? 17 - charNb
+ 1: 1, " ",
1019 totNoInfo
, totTotal
);
1021 printf("\tRound-trip times:\n"
1022 "\t\tHost pair RTT from exchanges RTTs from file (ms)\n");
1023 g_hash_table_foreach(analysisData
->stats
->exchangeRtt
,
1024 &ghfPrintExchangeRtt
, analysisData
->rttInfo
);
1027 printf("\tConvex hull factors comparisons:\n"
1028 "\t\tTrace pair Factors type Differences (lp - chull)\n"
1030 "\t\t Min Max Min Max\n");
1032 for (i
= 0; i
< syncState
->traceNb
; i
++)
1034 for (j
= 0; j
< i
; j
++)
1036 PairFactors
* chFactors
=
1037 &analysisData
->stats
->chFactorsArray
->pairFactors
[i
][j
];
1038 PairFactors
* lpFactors
=
1039 &analysisData
->stats
->lpFactorsArray
->pairFactors
[i
][j
];
1041 printf("\t\t%3d - %-3d ", i
, j
);
1042 if (lpFactors
->type
== chFactors
->type
)
1044 if (lpFactors
->type
== ACCURATE
)
1046 printf("%-13s %-10.4g %-10.4g %-10.4g %.4g\n",
1047 approxNames
[lpFactors
->type
],
1048 lpFactors
->min
->offset
- chFactors
->min
->offset
,
1049 lpFactors
->max
->offset
- chFactors
->max
->offset
,
1050 lpFactors
->min
->drift
- chFactors
->min
->drift
,
1051 lpFactors
->max
->drift
- chFactors
->max
->drift
);
1053 else if (lpFactors
->type
== ABSENT
)
1055 printf("%s\n", approxNames
[lpFactors
->type
]);
1060 printf("Different! %s and %s\n", approxNames
[lpFactors
->type
],
1061 approxNames
[chFactors
->type
]);
1070 * A GHFunc for g_hash_table_foreach()
1073 * key: RttKey* where saddr < daddr
1074 * value: double*, RTT estimated from exchanges
1075 * user_data GHashTable* rttInfo
1077 static void ghfPrintExchangeRtt(gpointer key
, gpointer value
, gpointer
1080 char addr1
[16], addr2
[16];
1081 struct RttKey
* rttKey1
= key
;
1082 struct RttKey rttKey2
= {rttKey1
->daddr
, rttKey1
->saddr
};
1083 double* fileRtt1
, *fileRtt2
;
1084 GHashTable
* rttInfo
= user_data
;
1086 convertIP(addr1
, rttKey1
->saddr
);
1087 convertIP(addr2
, rttKey1
->daddr
);
1089 fileRtt1
= g_hash_table_lookup(rttInfo
, rttKey1
);
1090 fileRtt2
= g_hash_table_lookup(rttInfo
, &rttKey2
);
1092 printf("\t\t(%15s, %-15s) %-18.3f ", addr1
, addr2
, *(double*) value
* 1e3
);
1094 if (fileRtt1
|| fileRtt2
)
1098 printf("%.3f", *fileRtt1
* 1e3
);
1100 if (fileRtt1
&& fileRtt2
)
1106 printf("%.3f", *fileRtt2
* 1e3
);
1118 * A GHashFunc for g_hash_table_new()
1121 * key struct RttKey*
1123 static guint
ghfRttKeyHash(gconstpointer key
)
1125 struct RttKey
* rttKey
;
1128 rttKey
= (struct RttKey
*) key
;
1140 * A GDestroyNotify function for g_hash_table_new_full()
1143 * data: struct RttKey*
1145 static void gdnDestroyRttKey(gpointer data
)
1152 * A GDestroyNotify function for g_hash_table_new_full()
1157 static void gdnDestroyDouble(gpointer data
)
1164 * A GEqualFunc for g_hash_table_new()
1170 * TRUE if both values are equal
1172 static gboolean
gefRttKeyEqual(gconstpointer a
, gconstpointer b
)
1174 const struct RttKey
* rkA
, * rkB
;
1176 rkA
= (struct RttKey
*) a
;
1177 rkB
= (struct RttKey
*) b
;
1179 if (rkA
->saddr
== rkB
->saddr
&& rkA
->daddr
== rkB
->daddr
)
1191 * Read a file contain minimum round trip time values and fill an array with
1192 * them. The file is formatted as such:
1193 * <host1 IP> <host2 IP> <RTT in milliseconds>
1194 * ip's should be in dotted quad format
1197 * rttInfo: double* rttInfo[RttKey], empty table, will be filled
1198 * rttStream: stream from which to read
1200 static void readRttInfo(GHashTable
* rttInfo
, FILE* rttStream
)
1206 positionStream(rttStream
);
1207 retval
= getline(&line
, &len
, rttStream
);
1208 while(!feof(rttStream
))
1210 struct RttKey
* rttKey
;
1211 char saddrDQ
[20], daddrDQ
[20];
1214 struct in_addr addr
;
1220 {saddrDQ
, offsetof(struct RttKey
, saddr
)},
1221 {daddrDQ
, offsetof(struct RttKey
, daddr
)}
1224 if (retval
== -1 && !feof(rttStream
))
1226 g_error(strerror(errno
));
1229 if (line
[retval
- 1] == '\n')
1231 line
[retval
- 1]= '\0';
1234 rtt
= malloc(sizeof(double));
1235 retval
= sscanf(line
, " %19s %19s %lf %c", saddrDQ
, daddrDQ
, rtt
,
1239 g_error(strerror(errno
));
1241 else if (retval
!= 3)
1243 g_error("Error parsing RTT file, line was '%s'", line
);
1246 rttKey
= malloc(sizeof(struct RttKey
));
1247 for (i
= 0; i
< sizeof(loopValues
) / sizeof(*loopValues
); i
++)
1249 retval
= inet_aton(loopValues
[i
].dq
, &addr
);
1252 g_error("Error converting address '%s'", loopValues
[i
].dq
);
1254 *(uint32_t*) ((void*) rttKey
+ loopValues
[i
].offset
)=
1259 g_debug("rttInfo, Inserting (%u, %u)->(%f)", rttKey
->saddr
,
1260 rttKey
->daddr
, *rtt
);
1261 g_hash_table_insert(rttInfo
, rttKey
, rtt
);
1263 positionStream(rttStream
);
1264 retval
= getline(&line
, &len
, rttStream
);
1275 * Advance stream over empty space, empty lines and lines that begin with '#'
1278 * stream: stream, at exit, will be over the first non-empty character
1279 * of a line of be at EOF
1281 static void positionStream(FILE* stream
)
1290 firstChar
= fgetc(stream
);
1291 if (firstChar
== (int) '#')
1293 retval
= getline(&line
, &len
, stream
);
1302 g_error(strerror(errno
));
1306 else if (firstChar
== (int) '\n' || firstChar
== (int) ' ' ||
1307 firstChar
== (int) '\t')
1309 else if (firstChar
== EOF
)
1318 retval
= ungetc(firstChar
, stream
);
1321 g_error("Error: ungetc()");
1333 * A GFunc for g_queue_foreach()
1336 * data Event*, a UDP broadcast event
1337 * user_data double*, the running sum
1340 * Adds the time of the event to the sum
1342 static void gfSum(gpointer data
, gpointer userData
)
1344 Event
* event
= (Event
*) data
;
1346 *(double*) userData
+= event
->wallTime
.seconds
+ event
->wallTime
.nanosec
/
1352 * A GFunc for g_queue_foreach()
1355 * data Event*, a UDP broadcast event
1356 * user_data double*, the running sum
1359 * Adds the square of the time of the event to the sum
1361 static void gfSumSquares(gpointer data
, gpointer userData
)
1363 Event
* event
= (Event
*) data
;
1365 *(double*) userData
+= pow(event
->wallTime
.seconds
+ event
->wallTime
.nanosec
1371 * Update a struct Bins according to a new value
1374 * bins: the structure containing bins to build a histrogram
1375 * value: the new value
1377 static void hitBin(struct Bins
* const bins
, const double value
)
1379 unsigned int binN
= binNum(value
);
1381 if (binN
< bins
->min
)
1385 else if (binN
> bins
->max
)
1397 * Figure out the bin in a histogram to which a value belongs.
1399 * This uses exponentially sized bins that go from 0 to infinity.
1402 * value: in the range -INFINITY to INFINITY
1405 * The number of the bin in a struct Bins.bin
1407 static unsigned int binNum(const double value
)
1413 else if (value
< binEnd(1))
1417 else if (value
>= binStart(BIN_NB
- 1))
1423 return floor(log(value
) / log(binBase
)) + BIN_NB
+ 1;
1429 * Figure out the start of the interval of a bin in a histogram. See struct
1432 * This uses exponentially sized bins that go from 0 to infinity.
1435 * binNum: bin number
1438 * The start of the interval, this value is included in the interval (except
1439 * for -INFINITY, naturally)
1441 static double binStart(const unsigned int binNum
)
1443 g_assert_cmpuint(binNum
, <, BIN_NB
);
1449 else if (binNum
== 1)
1455 return pow(binBase
, (double) binNum
- BIN_NB
+ 1);
1461 * Figure out the end of the interval of a bin in a histogram. See struct
1464 * This uses exponentially sized bins that go from 0 to infinity.
1467 * binNum: bin number
1470 * The end of the interval, this value is not included in the interval
1472 static double binEnd(const unsigned int binNum
)
1474 g_assert_cmpuint(binNum
, <, BIN_NB
);
1480 else if (binNum
< BIN_NB
- 1)
1482 return pow(binBase
, (double) binNum
- BIN_NB
+ 2);
1492 * Return the total number of elements in the "normal" bins (not underflow or
1496 * bins: the structure containing bins to build a histrogram
1498 static uint32_t normalTotal(struct Bins
* const bins
)
1500 return bins
->total
- bins
->bin
[0] - bins
->bin
[BIN_NB
- 1];
1504 /* Update the bounds between two traces
1507 * bounds: the array containing all the trace-pair bounds
1508 * e1, e2: the two related events
1510 static void updateBounds(Bounds
** const bounds
, Event
* const e1
, Event
* const
1513 unsigned int traceI
, traceJ
;
1514 uint64_t messageTime
;
1517 if (e1
->traceNum
< e2
->traceNum
)
1519 traceI
= e2
->traceNum
;
1520 traceJ
= e1
->traceNum
;
1521 messageTime
= e1
->cpuTime
;
1525 traceI
= e1
->traceNum
;
1526 traceJ
= e2
->traceNum
;
1527 messageTime
= e2
->cpuTime
;
1529 tpBounds
= &bounds
[traceI
][traceJ
];
1531 if (messageTime
< tpBounds
->min
)
1533 tpBounds
->min
= messageTime
;
1535 if (messageTime
> tpBounds
->max
)
1537 tpBounds
->max
= messageTime
;
1544 * Create the linear programming problem containing the constraints defined by
1545 * two half-hulls. The objective function and optimization directions are not
1549 * syncState: container for synchronization data
1550 * i: first trace number
1551 * j: second trace number, garanteed to be larger than i
1553 * A new glp_prob*, this problem must be freed by the caller with
1556 static glp_prob
* lpCreateProblem(GQueue
* const lowerHull
, GQueue
* const
1561 const double zeroD
= 0.;
1562 glp_prob
* lp
= glp_create_prob();
1563 unsigned int hullPointNb
= g_queue_get_length(lowerHull
) +
1564 g_queue_get_length(upperHull
);
1565 GArray
* iArray
= g_array_sized_new(FALSE
, FALSE
, sizeof(int), hullPointNb
+
1567 GArray
* jArray
= g_array_sized_new(FALSE
, FALSE
, sizeof(int), hullPointNb
+
1569 GArray
* aArray
= g_array_sized_new(FALSE
, FALSE
, sizeof(double),
1573 struct LPAddRowInfo rowInfo
;
1575 {lowerHull
, {lp
, GLP_UP
, iArray
, jArray
, aArray
}},
1576 {upperHull
, {lp
, GLP_LO
, iArray
, jArray
, aArray
}},
1579 // Create the LP problem
1580 glp_term_out(GLP_OFF
);
1581 if (hullPointNb
> 0)
1583 glp_add_rows(lp
, hullPointNb
);
1585 glp_add_cols(lp
, 2);
1587 glp_set_col_name(lp
, 1, "a0");
1588 glp_set_col_bnds(lp
, 1, GLP_FR
, 0., 0.);
1589 glp_set_col_name(lp
, 2, "a1");
1590 glp_set_col_bnds(lp
, 2, GLP_LO
, 0., 0.);
1592 // Add row constraints
1593 g_array_append_val(iArray
, zero
);
1594 g_array_append_val(jArray
, zero
);
1595 g_array_append_val(aArray
, zeroD
);
1597 for (it
= 0; it
< sizeof(loopValues
) / sizeof(*loopValues
); it
++)
1599 g_queue_foreach(loopValues
[it
].hull
, &gfLPAddRow
,
1600 &loopValues
[it
].rowInfo
);
1603 g_assert_cmpuint(iArray
->len
, ==, jArray
->len
);
1604 g_assert_cmpuint(jArray
->len
, ==, aArray
->len
);
1605 g_assert_cmpuint(aArray
->len
- 1, ==, hullPointNb
* 2);
1607 glp_load_matrix(lp
, aArray
->len
- 1, &g_array_index(iArray
, int, 0),
1608 &g_array_index(jArray
, int, 0), &g_array_index(aArray
, double, 0));
1610 glp_scale_prob(lp
, GLP_SF_AUTO
);
1612 g_array_free(iArray
, TRUE
);
1613 g_array_free(jArray
, TRUE
);
1614 g_array_free(aArray
, TRUE
);
1621 * A GFunc for g_queue_foreach(). Add constraints and bounds for one row.
1624 * data Point*, synchronization point for which to add an LP row
1626 * user_data LPAddRowInfo*
1628 static void gfLPAddRow(gpointer data
, gpointer user_data
)
1631 struct LPAddRowInfo
* rowInfo
= user_data
;
1633 double constraints
[2];
1635 indexes
[0]= g_array_index(rowInfo
->iArray
, int, rowInfo
->iArray
->len
- 1) + 1;
1636 indexes
[1]= indexes
[0];
1638 if (rowInfo
->boundType
== GLP_UP
)
1640 glp_set_row_bnds(rowInfo
->lp
, indexes
[0], GLP_UP
, 0., p
->y
);
1642 else if (rowInfo
->boundType
== GLP_LO
)
1644 glp_set_row_bnds(rowInfo
->lp
, indexes
[0], GLP_LO
, p
->y
, 0.);
1648 g_assert_not_reached();
1651 g_array_append_vals(rowInfo
->iArray
, indexes
, 2);
1654 g_array_append_vals(rowInfo
->jArray
, indexes
, 2);
1656 constraints
[1]= p
->x
;
1657 g_array_append_vals(rowInfo
->aArray
, constraints
, 2);
1662 * Calculate min or max correction factors (as possible) using an LP problem.
1665 * lp: A linear programming problem with constraints and bounds
1667 * direction: The type of factors desired. Use GLP_MAX for max
1668 * approximation factors (a1, the drift or slope is the
1669 * largest) and GLP_MIN in the other case.
1672 * If the calculation was successful, a new Factors struct. Otherwise, NULL.
1673 * The calculation will fail if the hull assumptions are not respected.
1675 static Factors
* calculateFactors(glp_prob
* const lp
, const int direction
)
1680 glp_set_obj_coef(lp
, 1, 0.);
1681 glp_set_obj_coef(lp
, 2, 1.);
1683 glp_set_obj_dir(lp
, direction
);
1684 retval
= glp_simplex(lp
, NULL
);
1685 status
= glp_get_status(lp
);
1687 if (retval
== 0 && status
== GLP_OPT
)
1689 factors
= malloc(sizeof(Factors
));
1690 factors
->offset
= glp_get_col_prim(lp
, 1);
1691 factors
->drift
= glp_get_col_prim(lp
, 2);
1703 * Calculate min, max and approx correction factors (as possible) using an LP
1707 * lp: A linear programming problem with constraints and bounds
1711 * Please note that the approximation type may be ACCURATE, INCOMPLETE or
1712 * ABSENT. Unlike in analysis_chull, ABSENT is also used when the hulls do
1713 * not respect assumptions.
1715 static void calculateCompleteFactors(glp_prob
* const lp
, PairFactors
* factors
)
1717 factors
->min
= calculateFactors(lp
, GLP_MIN
);
1718 factors
->max
= calculateFactors(lp
, GLP_MAX
);
1720 if (factors
->min
&& factors
->max
)
1722 factors
->type
= ACCURATE
;
1723 calculateFactorsMiddle(factors
);
1725 else if (factors
->min
|| factors
->max
)
1727 factors
->type
= INCOMPLETE
;
1728 factors
->approx
= NULL
;
1732 factors
->type
= ABSENT
;
1733 factors
->approx
= NULL
;
1739 * A GFunc for g_queue_foreach()
1742 * data Point*, a convex hull point
1743 * user_data GArray*, an array of convex hull point absisca values, as
1746 static void gfAddAbsiscaToArray(gpointer data
, gpointer user_data
)
1749 GArray
* a
= user_data
;
1752 g_array_append_val(a
, v
);
1757 * A GCompareFunc for g_array_sort()
1760 * a, b double*, absisca values
1763 * "returns less than zero for first arg is less than second arg, zero for
1764 * equal, greater zero if first arg is greater than second arg"
1765 * - the great glib documentation
1767 static gint
gcfCompareDouble(gconstpointer a
, gconstpointer b
)
1769 if (*(double*) a
< *(double*) b
)
1773 else if (*(double*) a
> *(double*) b
)
1786 * Compute synchronization factors using a linear programming approach.
1787 * Compute the factors using analysis_chull. Compare the two.
1789 * When the solver library, glpk, is not available at build time, only compute
1790 * the factors using analysis_chull. This is to make sure that module runs its
1791 * finalize function so that its graph functions can be called later.
1794 * syncState: container for synchronization data
1796 static void finalizeAnalysisEvalLP(SyncState
* const syncState
)
1798 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
1801 AnalysisDataCHull
* chAnalysisData
= analysisData
->chullSS
->analysisData
;
1802 AllFactors
* lpFactorsArray
;
1804 if (!syncState
->stats
&& !syncState
->graphsStream
)
1809 /* Because of matching_distributor, this analysis may be called twice.
1810 * Only run it once */
1811 if ((syncState
->graphsStream
&& analysisData
->graphs
->lps
!= NULL
) ||
1812 (syncState
->stats
&& analysisData
->stats
->chFactorsArray
!= NULL
))
1817 lpFactorsArray
= createAllFactors(syncState
->traceNb
);
1819 if (syncState
->stats
)
1821 analysisData
->stats
->chFactorsArray
=
1822 calculateAllFactors(analysisData
->chullSS
);
1823 analysisData
->stats
->lpFactorsArray
= lpFactorsArray
;
1826 if (syncState
->graphsStream
)
1828 analysisData
->graphs
->lps
= malloc(syncState
->traceNb
*
1829 sizeof(glp_prob
**));
1830 for (i
= 0; i
< syncState
->traceNb
; i
++)
1832 analysisData
->graphs
->lps
[i
]= malloc(i
* sizeof(glp_prob
*));
1834 analysisData
->graphs
->lpFactorsArray
= lpFactorsArray
;
1837 for (i
= 0; i
< syncState
->traceNb
; i
++)
1839 for (j
= 0; j
< i
; j
++)
1843 // Create the LP problem
1844 lp
= lpCreateProblem(chAnalysisData
->hullArray
[i
][j
],
1845 chAnalysisData
->hullArray
[j
][i
]);
1847 // Use the LP problem to find the correction factors for this pair of
1849 calculateCompleteFactors(lp
, &lpFactorsArray
->pairFactors
[i
][j
]);
1851 if (syncState
->graphsStream
)
1853 analysisData
->graphs
->lps
[i
][j
]= lp
;
1857 glp_delete_prob(lp
);
1863 freeAllFactors(analysisData
->chullSS
->analysisModule
->finalizeAnalysis(analysisData
->chullSS
));
1868 * Compute synchronization accuracy information using a linear programming
1869 * approach. Write the neccessary data files and plot lines in the gnuplot
1872 * When the solver library, glpk, is not available at build time nothing is
1873 * actually produced.
1876 * syncState: container for synchronization data
1877 * i: first trace number
1878 * j: second trace number, garanteed to be larger than i
1880 static void writeAnalysisTraceTimeBackPlotsEval(SyncState
* const syncState
,
1881 const unsigned int i
, const unsigned int j
)
1885 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
1886 AnalysisGraphsEval
* graphs
= analysisData
->graphs
;
1887 GQueue
*** hullArray
= ((AnalysisDataCHull
*)
1888 analysisData
->chullSS
->analysisData
)->hullArray
;
1889 PairFactors
* lpFactors
= &graphs
->lpFactorsArray
->pairFactors
[j
][i
];
1890 glp_prob
* lp
= graphs
->lps
[j
][i
];
1892 if (lpFactors
->type
== ACCURATE
)
1900 // Open the data file
1901 snprintf(fileName
, 40, "analysis_eval_accuracy-%03u_and_%03u.data", i
, j
);
1902 fileName
[sizeof(fileName
) - 1]= '\0';
1904 cwd
= changeToGraphsDir(syncState
->graphsDir
);
1906 if ((fp
= fopen(fileName
, "w")) == NULL
)
1908 g_error(strerror(errno
));
1910 fprintf(fp
, "#%-24s %-25s %-25s %-25s\n", "x", "middle", "min", "max");
1915 g_error(strerror(errno
));
1919 // Build the list of absisca values for the points in the accuracy graph
1920 xValues
= g_array_sized_new(FALSE
, FALSE
, sizeof(double),
1921 g_queue_get_length(hullArray
[i
][j
]) +
1922 g_queue_get_length(hullArray
[j
][i
]));
1924 g_queue_foreach(hullArray
[i
][j
], &gfAddAbsiscaToArray
, xValues
);
1925 g_queue_foreach(hullArray
[j
][i
], &gfAddAbsiscaToArray
, xValues
);
1927 g_array_sort(xValues
, &gcfCompareDouble
);
1929 /* For each absisca value and each optimisation direction, solve the LP
1930 * and write a line in the data file */
1931 for (it
= 0; it
< xValues
->len
; it
++)
1934 int directions
[]= {GLP_MIN
, GLP_MAX
};
1935 glp_set_obj_coef(lp
, 1, 1.);
1936 glp_set_obj_coef(lp
, 2, g_array_index(xValues
, double, it
));
1938 fprintf(fp
, "%25.9f %25.9f", g_array_index(xValues
, double, it
),
1939 lpFactors
->approx
->offset
+ lpFactors
->approx
->drift
*
1940 g_array_index(xValues
, double, it
));
1941 for (it2
= 0; it2
< sizeof(directions
) / sizeof(*directions
); it2
++)
1945 glp_set_obj_dir(lp
, directions
[it2
]);
1946 retval
= glp_simplex(lp
, NULL
);
1947 status
= glp_get_status(lp
);
1949 g_assert(retval
== 0 && status
== GLP_OPT
);
1950 fprintf(fp
, " %25.9f", glp_get_obj_val(lp
));
1955 g_array_free(xValues
, TRUE
);
1958 fprintf(syncState
->graphsStream
,
1959 "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
1960 "using 1:(($3 - $2) / clock_freq_%2$u):(($4 - $2) / clock_freq_%2$u) "
1961 "title \"Synchronization accuracy\" "
1962 "with filledcurves linewidth 2 linetype 1 "
1963 "linecolor rgb \"black\" fill solid 0.25 noborder, \\\n", i
,
1971 * Write the analysis-specific graph lines in the gnuplot script.
1973 * When the solver library, glpk, is not available at build time nothing is
1974 * actually produced.
1977 * syncState: container for synchronization data
1978 * i: first trace number
1979 * j: second trace number, garanteed to be larger than i
1981 static void writeAnalysisTraceTimeForePlotsEval(SyncState
* const syncState
,
1982 const unsigned int i
, const unsigned int j
)
1985 if (((AnalysisDataEval
*)
1986 syncState
->analysisData
)->graphs
->lpFactorsArray
->pairFactors
[j
][i
].type
1989 fprintf(syncState
->graphsStream
,
1990 "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
1991 "using 1:(($3 - $2) / clock_freq_%2$u) notitle "
1992 "with lines linewidth 2 linetype 1 "
1993 "linecolor rgb \"gray60\", \\\n"
1994 "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
1995 "using 1:(($4 - $2) / clock_freq_%2$u) notitle "
1996 "with lines linewidth 2 linetype 1 "
1997 "linecolor rgb \"gray60\", \\\n", i
, j
);
2004 * Write the analysis-specific graph lines in the gnuplot script.
2007 * syncState: container for synchronization data
2008 * i: first trace number
2009 * j: second trace number, garanteed to be larger than i
2011 static void writeAnalysisTraceTraceBackPlotsEval(SyncState
* const syncState
,
2012 const unsigned int i
, const unsigned int j
)
2015 fprintf(syncState
->graphsStream
,
2016 "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
2018 "title \"Synchronization accuracy\" "
2019 "with filledcurves linewidth 2 linetype 1 "
2020 "linecolor rgb \"black\" fill solid 0.25 noborder, \\\n", i
, j
);
2026 * Write the analysis-specific graph lines in the gnuplot script.
2029 * syncState: container for synchronization data
2030 * i: first trace number
2031 * j: second trace number, garanteed to be larger than i
2033 static void writeAnalysisTraceTraceForePlotsEval(SyncState
* const syncState
,
2034 const unsigned int i
, const unsigned int j
)
2036 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
2038 analysisData
->chullSS
->analysisModule
->graphFunctions
.writeTraceTraceForePlots(analysisData
->chullSS
,