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 GArray
* 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
, FactorsCHull
*
122 static FactorsCHull
** createAllFactors(const unsigned int traceNb
);
126 // initialized in registerAnalysisEval()
129 static AnalysisModule analysisModuleEval
= {
131 .initAnalysis
= &initAnalysisEval
,
132 .destroyAnalysis
= &destroyAnalysisEval
,
133 .analyzeMessage
= &analyzeMessageEval
,
134 .analyzeExchange
= &analyzeExchangeEval
,
135 .analyzeBroadcast
= &analyzeBroadcastEval
,
136 .finalizeAnalysis
= &finalizeAnalysisEval
,
137 .printAnalysisStats
= &printAnalysisStatsEval
,
139 .writeTraceTimeBackPlots
= &writeAnalysisTraceTimeBackPlotsEval
,
140 .writeTraceTimeForePlots
= &writeAnalysisTraceTimeForePlotsEval
,
141 .writeTraceTraceBackPlots
= &writeAnalysisTraceTraceBackPlotsEval
,
142 .writeTraceTraceForePlots
= &writeAnalysisTraceTraceForePlotsEval
,
146 static ModuleOption optionEvalRttFile
= {
147 .longName
= "eval-rtt-file",
148 .hasArg
= REQUIRED_ARG
,
149 .optionHelp
= "specify the file containing RTT information",
155 * Analysis module registering function
157 void registerAnalysisEval()
159 binBase
= exp10(6. / (BIN_NB
- 3));
161 g_queue_push_tail(&analysisModules
, &analysisModuleEval
);
162 g_queue_push_tail(&moduleOptions
, &optionEvalRttFile
);
167 * Analysis init function
169 * This function is called at the beginning of a synchronization run for a set
173 * syncState container for synchronization data.
175 static void initAnalysisEval(SyncState
* const syncState
)
177 AnalysisDataEval
* analysisData
;
180 analysisData
= malloc(sizeof(AnalysisDataEval
));
181 syncState
->analysisData
= analysisData
;
183 analysisData
->rttInfo
= g_hash_table_new_full(&ghfRttKeyHash
,
184 &gefRttKeyEqual
, &gdnDestroyRttKey
, &gdnDestroyDouble
);
185 if (optionEvalRttFile
.arg
)
190 rttStream
= fopen(optionEvalRttFile
.arg
, "r");
191 if (rttStream
== NULL
)
193 g_error(strerror(errno
));
196 readRttInfo(analysisData
->rttInfo
, rttStream
);
198 retval
= fclose(rttStream
);
201 g_error(strerror(errno
));
205 if (syncState
->stats
)
207 analysisData
->stats
= calloc(1, sizeof(AnalysisStatsEval
));
208 analysisData
->stats
->broadcastDiffSum
= 0.;
210 analysisData
->stats
->messageStats
= malloc(syncState
->traceNb
*
211 sizeof(MessageStats
*));
212 for (i
= 0; i
< syncState
->traceNb
; i
++)
214 analysisData
->stats
->messageStats
[i
]= calloc(syncState
->traceNb
,
215 sizeof(MessageStats
));
218 analysisData
->stats
->exchangeRtt
=
219 g_hash_table_new_full(&ghfRttKeyHash
, &gefRttKeyEqual
,
220 &gdnDestroyRttKey
, &gdnDestroyDouble
);
223 analysisData
->stats
->chFactorsArray
= NULL
;
224 analysisData
->stats
->lpFactorsArray
= NULL
;
228 if (syncState
->graphsStream
)
230 AnalysisGraphsEval
* graphs
= malloc(sizeof(AnalysisGraphsEval
));
232 analysisData
->graphs
= graphs
;
234 graphs
->histograms
= g_hash_table_new_full(&ghfRttKeyHash
,
235 &gefRttKeyEqual
, &gdnDestroyRttKey
,
236 &gdnDestroyAnalysisHistogramEval
);
238 graphs
->bounds
= malloc(syncState
->traceNb
* sizeof(Bounds
*));
239 for (i
= 0; i
< syncState
->traceNb
; i
++)
241 graphs
->bounds
[i
]= malloc(i
* sizeof(Bounds
));
242 for (j
= 0; j
< i
; j
++)
244 graphs
->bounds
[i
][j
].min
= UINT64_MAX
;
245 graphs
->bounds
[i
][j
].max
= 0;
251 graphs
->lpFactorsArray
= NULL
;
255 if (syncState
->stats
|| syncState
->graphsStream
)
259 analysisData
->chullSS
= malloc(sizeof(SyncState
));
260 memcpy(analysisData
->chullSS
, syncState
, sizeof(SyncState
));
261 analysisData
->chullSS
->stats
= false;
262 analysisData
->chullSS
->analysisData
= NULL
;
263 result
= g_queue_find_custom(&analysisModules
, "chull",
264 &gcfCompareAnalysis
);
265 analysisData
->chullSS
->analysisModule
= (AnalysisModule
*) result
->data
;
266 analysisData
->chullSS
->analysisModule
->initAnalysis(analysisData
->chullSS
);
272 * Create and open files used to store histogram points to generate graphs.
273 * Create data structures to store histogram points during analysis.
276 * graphsDir: folder where to write files
277 * rttKey: host pair, make sure saddr < daddr
279 static AnalysisHistogramEval
* constructAnalysisHistogramEval(const char* const
280 graphsDir
, const struct RttKey
* const rttKey
)
285 char name
[60], saddr
[16], daddr
[16];
286 AnalysisHistogramEval
* histogram
= calloc(1, sizeof(*histogram
));
289 const char* fileName
;
290 const char* host1
, *host2
;
292 {offsetof(AnalysisHistogramEval
, ttSendPoints
),
293 "analysis_eval_tt-%s_to_%s.data", saddr
, daddr
},
294 {offsetof(AnalysisHistogramEval
, ttRecvPoints
),
295 "analysis_eval_tt-%s_to_%s.data", daddr
, saddr
},
296 {offsetof(AnalysisHistogramEval
, hrttPoints
),
297 "analysis_eval_hrtt-%s_and_%s.data", saddr
, daddr
},
300 histogram
->ttSendBins
.min
= BIN_NB
- 1;
301 histogram
->ttRecvBins
.min
= BIN_NB
- 1;
302 histogram
->hrttBins
.min
= BIN_NB
- 1;
304 convertIP(saddr
, rttKey
->saddr
);
305 convertIP(daddr
, rttKey
->daddr
);
307 cwd
= changeToGraphsDir(graphsDir
);
309 for (i
= 0; i
< sizeof(loopValues
) / sizeof(*loopValues
); i
++)
311 retval
= snprintf(name
, sizeof(name
), loopValues
[i
].fileName
,
312 loopValues
[i
].host1
, loopValues
[i
].host2
);
313 if (retval
> sizeof(name
) - 1)
315 name
[sizeof(name
) - 1]= '\0';
317 if ((*(FILE**)((void*) histogram
+ loopValues
[i
].pointsOffset
)=
318 fopen(name
, "w")) == NULL
)
320 g_error(strerror(errno
));
327 g_error(strerror(errno
));
336 * Close files used to store histogram points to generate graphs.
339 * graphsDir: folder where to write files
340 * rttKey: host pair, make sure saddr < daddr
342 static void destroyAnalysisHistogramEval(AnalysisHistogramEval
* const
350 {offsetof(AnalysisHistogramEval
, ttSendPoints
)},
351 {offsetof(AnalysisHistogramEval
, ttRecvPoints
)},
352 {offsetof(AnalysisHistogramEval
, hrttPoints
)},
355 for (i
= 0; i
< sizeof(loopValues
) / sizeof(*loopValues
); i
++)
357 retval
= fclose(*(FILE**)((void*) histogram
+ loopValues
[i
].pointsOffset
));
360 g_error(strerror(errno
));
369 * A GDestroyNotify function for g_hash_table_new_full()
372 * data: AnalysisHistogramEval*
374 static void gdnDestroyAnalysisHistogramEval(gpointer data
)
376 destroyAnalysisHistogramEval(data
);
381 * A GHFunc for g_hash_table_foreach()
384 * key: RttKey* where saddr < daddr
385 * value: AnalysisHistogramEval*
386 * user_data struct WriteHistogramInfo*
388 static void ghfWriteHistogram(gpointer key
, gpointer value
, gpointer user_data
)
390 double* rtt1
, * rtt2
;
391 struct RttKey
* rttKey
= key
;
392 struct RttKey oppositeRttKey
= {.saddr
= rttKey
->daddr
, .daddr
=
394 AnalysisHistogramEval
* histogram
= value
;
395 struct WriteHistogramInfo
* info
= user_data
;
397 rtt1
= g_hash_table_lookup(info
->rttInfo
, rttKey
);
398 rtt2
= g_hash_table_lookup(info
->rttInfo
, &oppositeRttKey
);
404 else if (rtt2
!= NULL
)
406 rtt1
= MIN(rtt1
, rtt2
);
409 dumpBinToFile(&histogram
->ttSendBins
, histogram
->ttSendPoints
);
410 dumpBinToFile(&histogram
->ttRecvBins
, histogram
->ttRecvPoints
);
411 dumpBinToFile(&histogram
->hrttBins
, histogram
->hrttPoints
);
412 writeHistogram(info
->graphsStream
, rttKey
, rtt1
, histogram
);
417 * Write the content of one bin in a histogram point file
420 * bin: array of values that make up a histogram
421 * file: FILE*, write to this file
423 static void dumpBinToFile(const struct Bins
* const bins
, FILE* const file
)
427 // The first and last bins are skipped, see struct Bins
428 for (i
= 1; i
< BIN_NB
- 1; i
++)
430 if (bins
->bin
[i
] > 0)
432 fprintf(file
, "%20.9f %20.9f %20.9f\n", (binStart(i
) + binEnd(i
))
433 / 2., (double) bins
->bin
[i
] / ((binEnd(i
) - binStart(i
)) *
434 bins
->total
), binEnd(i
) - binStart(i
));
441 * Write the analysis-specific plot in the gnuplot script.
444 * graphsStream: write to this file
445 * rttKey: must be sorted such that saddr < daddr
446 * minRtt: if available, else NULL
447 * histogram: struct that contains the bins for the pair of traces
448 * identified by rttKey
450 static void writeHistogram(FILE* graphsStream
, const struct RttKey
* rttKey
,
451 double* minRtt
, AnalysisHistogramEval
* const histogram
)
453 char saddr
[16], daddr
[16];
455 convertIP(saddr
, rttKey
->saddr
);
456 convertIP(daddr
, rttKey
->daddr
);
458 fprintf(graphsStream
,
460 "set output \"histogram-%s-%s.eps\"\n"
462 "set xlabel \"Message Latency (s)\"\n"
463 "set ylabel \"Proportion of messages per second\"\n", saddr
, daddr
);
467 fprintf(graphsStream
,
468 "set arrow from %.9f, 0 rto 0, graph 1 "
469 "nohead linetype 3 linewidth 3 linecolor rgb \"black\"\n", *minRtt
473 if (normalTotal(&histogram
->ttSendBins
) ||
474 normalTotal(&histogram
->ttRecvBins
) ||
475 normalTotal(&histogram
->hrttBins
))
477 fprintf(graphsStream
, "plot \\\n");
479 if (normalTotal(&histogram
->hrttBins
))
481 fprintf(graphsStream
,
482 "\t\"analysis_eval_hrtt-%s_and_%s.data\" "
483 "title \"RTT/2\" with linespoints linetype 1 linewidth 2 "
484 "linecolor rgb \"black\" pointtype 6 pointsize 1,\\\n",
488 if (normalTotal(&histogram
->ttSendBins
))
490 fprintf(graphsStream
,
491 "\t\"analysis_eval_tt-%1$s_to_%2$s.data\" "
492 "title \"%1$s to %2$s\" with linespoints linetype 4 linewidth 2 "
493 "linecolor rgb \"gray60\" pointtype 6 pointsize 1,\\\n",
497 if (normalTotal(&histogram
->ttRecvBins
))
499 fprintf(graphsStream
,
500 "\t\"analysis_eval_tt-%1$s_to_%2$s.data\" "
501 "title \"%1$s to %2$s\" with linespoints linetype 4 linewidth 2 "
502 "linecolor rgb \"gray30\" pointtype 6 pointsize 1,\\\n",
506 // Remove the ",\\\n" from the last graph plot line
507 if (ftruncate(fileno(graphsStream
), ftell(graphsStream
) - 3) == -1)
509 g_error(strerror(errno
));
511 if (fseek(graphsStream
, 0, SEEK_END
) == -1)
513 g_error(strerror(errno
));
515 fprintf(graphsStream
, "\n");
521 * Analysis destroy function
523 * Free the analysis specific data structures
526 * syncState container for synchronization data.
528 static void destroyAnalysisEval(SyncState
* const syncState
)
531 AnalysisDataEval
* analysisData
;
533 analysisData
= (AnalysisDataEval
*) syncState
->analysisData
;
535 if (analysisData
== NULL
)
540 g_hash_table_destroy(analysisData
->rttInfo
);
542 if (syncState
->stats
)
544 AnalysisStatsEval
* stats
= analysisData
->stats
;
546 for (i
= 0; i
< syncState
->traceNb
; i
++)
548 free(stats
->messageStats
[i
]);
550 free(stats
->messageStats
);
552 g_hash_table_destroy(stats
->exchangeRtt
);
555 freeAllFactors(syncState
->traceNb
, stats
->chFactorsArray
);
556 freeAllFactors(syncState
->traceNb
, stats
->lpFactorsArray
);
562 if (syncState
->graphsStream
)
564 AnalysisGraphsEval
* graphs
= analysisData
->graphs
;
566 if (graphs
->histograms
)
568 g_hash_table_destroy(graphs
->histograms
);
571 for (i
= 0; i
< syncState
->traceNb
; i
++)
573 free(graphs
->bounds
[i
]);
575 free(graphs
->bounds
);
578 for (i
= 0; i
< syncState
->traceNb
; i
++)
582 for (j
= 0; j
< i
; j
++)
584 // There seems to be a memory leak in glpk, valgrind reports a
585 // loss (reachable) even if the problem is deleted
586 glp_delete_prob(graphs
->lps
[i
][j
]);
588 free(graphs
->lps
[i
]);
592 if (!syncState
->stats
)
594 freeAllFactors(syncState
->traceNb
, graphs
->lpFactorsArray
);
601 if (syncState
->stats
|| syncState
->graphsStream
)
603 analysisData
->chullSS
->analysisModule
->destroyAnalysis(analysisData
->chullSS
);
604 free(analysisData
->chullSS
);
607 free(syncState
->analysisData
);
608 syncState
->analysisData
= NULL
;
613 * Perform analysis on an event pair.
615 * Check if there is message inversion or messages that are too fast.
618 * syncState container for synchronization data
619 * message structure containing the events
621 static void analyzeMessageEval(SyncState
* const syncState
, Message
* const
624 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
625 MessageStats
* messageStats
;
628 struct RttKey rttKey
;
630 g_assert(message
->inE
->type
== TCP
);
632 if (syncState
->stats
)
635 &analysisData
->stats
->messageStats
[message
->outE
->traceNum
][message
->inE
->traceNum
];
636 messageStats
->total
++;
639 tt
= wallTimeSub(&message
->inE
->wallTime
, &message
->outE
->wallTime
);
642 if (syncState
->stats
)
644 messageStats
->inversionNb
++;
647 else if (syncState
->graphsStream
)
649 struct RttKey rttKey
= {
650 .saddr
=MIN(message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
,
651 message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
),
652 .daddr
=MAX(message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
,
653 message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
),
655 AnalysisHistogramEval
* histogram
=
656 g_hash_table_lookup(analysisData
->graphs
->histograms
, &rttKey
);
658 if (histogram
== NULL
)
660 struct RttKey
* tableKey
= malloc(sizeof(*tableKey
));
662 histogram
= constructAnalysisHistogramEval(syncState
->graphsDir
, &rttKey
);
663 memcpy(tableKey
, &rttKey
, sizeof(*tableKey
));
664 g_hash_table_insert(analysisData
->graphs
->histograms
, tableKey
, histogram
);
667 if (message
->inE
->event
.udpEvent
->datagramKey
->saddr
<
668 message
->inE
->event
.udpEvent
->datagramKey
->daddr
)
670 hitBin(&histogram
->ttSendBins
, tt
);
674 hitBin(&histogram
->ttRecvBins
, tt
);
678 if (syncState
->stats
)
681 message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
;
683 message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
;
684 rtt
= g_hash_table_lookup(analysisData
->rttInfo
, &rttKey
);
685 g_debug("rttInfo, looking up (%u, %u)->(%f)", rttKey
.saddr
,
686 rttKey
.daddr
, rtt
? *rtt
: NAN
);
690 g_debug("rttInfo, tt: %f rtt / 2: %f", tt
, *rtt
/ 2.);
693 messageStats
->tooFastNb
++;
698 messageStats
->noRTTInfoNb
++;
702 if (syncState
->graphsStream
)
704 updateBounds(analysisData
->graphs
->bounds
, message
->inE
,
708 if (syncState
->stats
|| syncState
->graphsStream
)
710 analysisData
->chullSS
->analysisModule
->analyzeMessage(analysisData
->chullSS
,
717 * Perform analysis on multiple messages
722 * syncState container for synchronization data
723 * exchange structure containing the messages
725 static void analyzeExchangeEval(SyncState
* const syncState
, Exchange
* const
728 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
729 Message
* m1
= g_queue_peek_tail(exchange
->acks
);
730 Message
* m2
= exchange
->message
;
731 struct RttKey
* rttKey
;
732 double* rtt
, * exchangeRtt
;
734 g_assert(m1
->inE
->type
== TCP
);
736 // (T2 - T1) - (T3 - T4)
737 rtt
= malloc(sizeof(double));
738 *rtt
= wallTimeSub(&m1
->inE
->wallTime
, &m1
->outE
->wallTime
) -
739 wallTimeSub(&m2
->outE
->wallTime
, &m2
->inE
->wallTime
);
741 rttKey
= malloc(sizeof(struct RttKey
));
743 MIN(m1
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
,
744 m1
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
);
746 MAX(m1
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
,
747 m1
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
);
749 if (syncState
->graphsStream
)
751 AnalysisHistogramEval
* histogram
=
752 g_hash_table_lookup(analysisData
->graphs
->histograms
, rttKey
);
754 if (histogram
== NULL
)
756 struct RttKey
* tableKey
= malloc(sizeof(*tableKey
));
758 histogram
= constructAnalysisHistogramEval(syncState
->graphsDir
,
760 memcpy(tableKey
, rttKey
, sizeof(*tableKey
));
761 g_hash_table_insert(analysisData
->graphs
->histograms
, tableKey
,
765 hitBin(&histogram
->hrttBins
, *rtt
/ 2);
768 if (syncState
->stats
)
770 exchangeRtt
= g_hash_table_lookup(analysisData
->stats
->exchangeRtt
,
775 if (*rtt
< *exchangeRtt
)
777 g_hash_table_replace(analysisData
->stats
->exchangeRtt
, rttKey
, rtt
);
787 g_hash_table_insert(analysisData
->stats
->exchangeRtt
, rttKey
, rtt
);
799 * Perform analysis on muliple events
801 * Sum the broadcast differential delays
804 * syncState container for synchronization data
805 * broadcast structure containing the events
807 static void analyzeBroadcastEval(SyncState
* const syncState
, Broadcast
* const
810 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
812 if (syncState
->stats
)
814 double sum
= 0, squaresSum
= 0;
817 g_queue_foreach(broadcast
->events
, &gfSum
, &sum
);
818 g_queue_foreach(broadcast
->events
, &gfSumSquares
, &squaresSum
);
820 analysisData
->stats
->broadcastNb
++;
821 // Because of numerical errors, this can at times be < 0
822 y
= squaresSum
/ g_queue_get_length(broadcast
->events
) - pow(sum
/
823 g_queue_get_length(broadcast
->events
), 2.);
826 analysisData
->stats
->broadcastDiffSum
+= sqrt(y
);
830 if (syncState
->graphsStream
)
834 unsigned int eventNb
= broadcast
->events
->length
;
836 events
= g_array_sized_new(FALSE
, FALSE
, sizeof(Event
*), eventNb
);
837 g_queue_foreach(broadcast
->events
, &gfAddEventToArray
, events
);
839 for (i
= 0; i
< eventNb
; i
++)
841 for (j
= 0; j
< eventNb
; j
++)
843 Event
* eventI
= g_array_index(events
, Event
*, i
), * eventJ
=
844 g_array_index(events
, Event
*, j
);
846 if (eventI
->traceNum
< eventJ
->traceNum
)
848 updateBounds(analysisData
->graphs
->bounds
, eventI
, eventJ
);
853 g_array_free(events
, TRUE
);
859 * Finalize the factor calculations. Since this module does not really
860 * calculate factors, identity factors are returned. Instead, histograms are
861 * written out and histogram structures are freed.
864 * syncState container for synchronization data.
867 * Factors[traceNb] identity factors for each trace
869 static GArray
* finalizeAnalysisEval(SyncState
* const syncState
)
873 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
875 if (syncState
->graphsStream
&& analysisData
->graphs
->histograms
)
877 g_hash_table_foreach(analysisData
->graphs
->histograms
,
878 &ghfWriteHistogram
, &(struct WriteHistogramInfo
) {.rttInfo
=
879 analysisData
->rttInfo
, .graphsStream
= syncState
->graphsStream
});
880 g_hash_table_destroy(analysisData
->graphs
->histograms
);
881 analysisData
->graphs
->histograms
= NULL
;
884 finalizeAnalysisEvalLP(syncState
);
886 factors
= g_array_sized_new(FALSE
, FALSE
, sizeof(Factors
),
888 g_array_set_size(factors
, syncState
->traceNb
);
889 for (i
= 0; i
< syncState
->traceNb
; i
++)
893 e
= &g_array_index(factors
, Factors
, i
);
903 * Print statistics related to analysis. Must be called after
907 * syncState container for synchronization data.
909 static void printAnalysisStatsEval(SyncState
* const syncState
)
911 AnalysisDataEval
* analysisData
;
912 unsigned int i
, j
, k
;
913 unsigned int totInversion
= 0, totTooFast
= 0, totNoInfo
= 0, totTotal
= 0;
916 if (!syncState
->stats
)
921 analysisData
= (AnalysisDataEval
*) syncState
->analysisData
;
923 printf("Synchronization evaluation analysis stats:\n");
924 if (analysisData
->stats
->broadcastNb
)
926 printf("\tsum of broadcast differential delays: %g\n",
927 analysisData
->stats
->broadcastDiffSum
);
928 printf("\taverage broadcast differential delay: %g\n",
929 analysisData
->stats
->broadcastDiffSum
/
930 analysisData
->stats
->broadcastNb
);
933 printf("\tIndividual evaluation:\n"
934 "\t\tTrace pair Inversions Too fast No RTT info Total\n");
936 for (i
= 0; i
< syncState
->traceNb
; i
++)
938 for (j
= i
+ 1; j
< syncState
->traceNb
; j
++)
940 MessageStats
* messageStats
;
948 for (k
= 0; k
< sizeof(loopValues
) / sizeof(*loopValues
); k
++)
951 &analysisData
->stats
->messageStats
[loopValues
[k
].t1
][loopValues
[k
].t2
];
953 printf("\t\t%3d - %-3d ", loopValues
[k
].t1
, loopValues
[k
].t2
);
954 printf("%u (%u%%)%n", messageStats
->inversionNb
, (unsigned
955 int) ceil((double) messageStats
->inversionNb
/
956 messageStats
->total
* 100), &charNb
);
957 printf("%*s", 17 - charNb
> 0 ? 17 - charNb
+ 1: 1, " ");
958 printf("%u (%u%%)%n", messageStats
->tooFastNb
, (unsigned int)
959 ceil((double) messageStats
->tooFastNb
/
960 messageStats
->total
* 100), &charNb
);
961 printf("%*s%-10u %u\n", 17 - charNb
> 0 ? 17 - charNb
+ 1:
962 1, " ", messageStats
->noRTTInfoNb
, messageStats
->total
);
964 totInversion
+= messageStats
->inversionNb
;
965 totTooFast
+= messageStats
->tooFastNb
;
966 totNoInfo
+= messageStats
->noRTTInfoNb
;
967 totTotal
+= messageStats
->total
;
972 printf("\t\t total ");
973 printf("%u (%u%%)%n", totInversion
, (unsigned int) ceil((double)
974 totInversion
/ totTotal
* 100), &charNb
);
975 printf("%*s", 17 - charNb
> 0 ? 17 - charNb
+ 1: 1, " ");
976 printf("%u (%u%%)%n", totTooFast
, (unsigned int) ceil((double) totTooFast
977 / totTotal
* 100), &charNb
);
978 printf("%*s%-10u %u\n", 17 - charNb
> 0 ? 17 - charNb
+ 1: 1, " ",
979 totNoInfo
, totTotal
);
981 printf("\tRound-trip times:\n"
982 "\t\tHost pair RTT from exchanges RTTs from file (ms)\n");
983 g_hash_table_foreach(analysisData
->stats
->exchangeRtt
,
984 &ghfPrintExchangeRtt
, analysisData
->rttInfo
);
987 printf("\tConvex hull factors comparisons:\n"
988 "\t\tTrace pair Factors type Differences (lp - chull)\n"
990 "\t\t Min Max Min Max\n");
992 for (i
= 0; i
< syncState
->traceNb
; i
++)
994 for (j
= 0; j
< i
; j
++)
996 FactorsCHull
* chFactors
= &analysisData
->stats
->chFactorsArray
[i
][j
];
997 FactorsCHull
* lpFactors
= &analysisData
->stats
->lpFactorsArray
[i
][j
];
999 printf("\t\t%3d - %-3d ", i
, j
);
1000 if (lpFactors
->type
== chFactors
->type
)
1002 if (lpFactors
->type
== MIDDLE
)
1004 printf("%-13s %-10.4g %-10.4g %-10.4g %.4g\n",
1005 approxNames
[lpFactors
->type
],
1006 lpFactors
->min
->offset
- chFactors
->min
->offset
,
1007 lpFactors
->max
->offset
- chFactors
->max
->offset
,
1008 lpFactors
->min
->drift
- chFactors
->min
->drift
,
1009 lpFactors
->max
->drift
- chFactors
->max
->drift
);
1011 else if (lpFactors
->type
== ABSENT
)
1013 printf("%s\n", approxNames
[lpFactors
->type
]);
1018 printf("Different! %s and %s\n", approxNames
[lpFactors
->type
],
1019 approxNames
[chFactors
->type
]);
1028 * A GHFunc for g_hash_table_foreach()
1031 * key: RttKey* where saddr < daddr
1032 * value: double*, RTT estimated from exchanges
1033 * user_data GHashTable* rttInfo
1035 static void ghfPrintExchangeRtt(gpointer key
, gpointer value
, gpointer
1038 char addr1
[16], addr2
[16];
1039 struct RttKey
* rttKey1
= key
;
1040 struct RttKey rttKey2
= {rttKey1
->daddr
, rttKey1
->saddr
};
1041 double* fileRtt1
, *fileRtt2
;
1042 GHashTable
* rttInfo
= user_data
;
1044 convertIP(addr1
, rttKey1
->saddr
);
1045 convertIP(addr2
, rttKey1
->daddr
);
1047 fileRtt1
= g_hash_table_lookup(rttInfo
, rttKey1
);
1048 fileRtt2
= g_hash_table_lookup(rttInfo
, &rttKey2
);
1050 printf("\t\t(%15s, %-15s) %-18.3f ", addr1
, addr2
, *(double*) value
* 1e3
);
1052 if (fileRtt1
|| fileRtt2
)
1056 printf("%.3f", *fileRtt1
* 1e3
);
1058 if (fileRtt1
&& fileRtt2
)
1064 printf("%.3f", *fileRtt2
* 1e3
);
1076 * A GHashFunc for g_hash_table_new()
1079 * key struct RttKey*
1081 static guint
ghfRttKeyHash(gconstpointer key
)
1083 struct RttKey
* rttKey
;
1086 rttKey
= (struct RttKey
*) key
;
1098 * A GDestroyNotify function for g_hash_table_new_full()
1101 * data: struct RttKey*
1103 static void gdnDestroyRttKey(gpointer data
)
1110 * A GDestroyNotify function for g_hash_table_new_full()
1115 static void gdnDestroyDouble(gpointer data
)
1122 * A GEqualFunc for g_hash_table_new()
1128 * TRUE if both values are equal
1130 static gboolean
gefRttKeyEqual(gconstpointer a
, gconstpointer b
)
1132 const struct RttKey
* rkA
, * rkB
;
1134 rkA
= (struct RttKey
*) a
;
1135 rkB
= (struct RttKey
*) b
;
1137 if (rkA
->saddr
== rkB
->saddr
&& rkA
->daddr
== rkB
->daddr
)
1149 * Read a file contain minimum round trip time values and fill an array with
1150 * them. The file is formatted as such:
1151 * <host1 IP> <host2 IP> <RTT in milliseconds>
1152 * ip's should be in dotted quad format
1155 * rttInfo: double* rttInfo[RttKey], empty table, will be filled
1156 * rttStream: stream from which to read
1158 static void readRttInfo(GHashTable
* rttInfo
, FILE* rttStream
)
1164 positionStream(rttStream
);
1165 retval
= getline(&line
, &len
, rttStream
);
1166 while(!feof(rttStream
))
1168 struct RttKey
* rttKey
;
1169 char saddrDQ
[20], daddrDQ
[20];
1172 struct in_addr addr
;
1178 {saddrDQ
, offsetof(struct RttKey
, saddr
)},
1179 {daddrDQ
, offsetof(struct RttKey
, daddr
)}
1182 if (retval
== -1 && !feof(rttStream
))
1184 g_error(strerror(errno
));
1187 if (line
[retval
- 1] == '\n')
1189 line
[retval
- 1]= '\0';
1192 rtt
= malloc(sizeof(double));
1193 retval
= sscanf(line
, " %19s %19s %lf %c", saddrDQ
, daddrDQ
, rtt
,
1197 g_error(strerror(errno
));
1199 else if (retval
!= 3)
1201 g_error("Error parsing RTT file, line was '%s'", line
);
1204 rttKey
= malloc(sizeof(struct RttKey
));
1205 for (i
= 0; i
< sizeof(loopValues
) / sizeof(*loopValues
); i
++)
1207 retval
= inet_aton(loopValues
[i
].dq
, &addr
);
1210 g_error("Error converting address '%s'", loopValues
[i
].dq
);
1212 *(uint32_t*) ((void*) rttKey
+ loopValues
[i
].offset
)=
1217 g_debug("rttInfo, Inserting (%u, %u)->(%f)", rttKey
->saddr
,
1218 rttKey
->daddr
, *rtt
);
1219 g_hash_table_insert(rttInfo
, rttKey
, rtt
);
1221 positionStream(rttStream
);
1222 retval
= getline(&line
, &len
, rttStream
);
1233 * Advance stream over empty space, empty lines and lines that begin with '#'
1236 * stream: stream, at exit, will be over the first non-empty character
1237 * of a line of be at EOF
1239 static void positionStream(FILE* stream
)
1248 firstChar
= fgetc(stream
);
1249 if (firstChar
== (int) '#')
1251 retval
= getline(&line
, &len
, stream
);
1260 g_error(strerror(errno
));
1264 else if (firstChar
== (int) '\n' || firstChar
== (int) ' ' ||
1265 firstChar
== (int) '\t')
1267 else if (firstChar
== EOF
)
1276 retval
= ungetc(firstChar
, stream
);
1279 g_error("Error: ungetc()");
1291 * A GFunc for g_queue_foreach()
1294 * data Event*, a UDP broadcast event
1295 * user_data double*, the running sum
1298 * Adds the time of the event to the sum
1300 static void gfSum(gpointer data
, gpointer userData
)
1302 Event
* event
= (Event
*) data
;
1304 *(double*) userData
+= event
->wallTime
.seconds
+ event
->wallTime
.nanosec
/
1310 * A GFunc for g_queue_foreach()
1313 * data Event*, a UDP broadcast event
1314 * user_data double*, the running sum
1317 * Adds the square of the time of the event to the sum
1319 static void gfSumSquares(gpointer data
, gpointer userData
)
1321 Event
* event
= (Event
*) data
;
1323 *(double*) userData
+= pow(event
->wallTime
.seconds
+ event
->wallTime
.nanosec
1329 * Update a struct Bins according to a new value
1332 * bins: the structure containing bins to build a histrogram
1333 * value: the new value
1335 static void hitBin(struct Bins
* const bins
, const double value
)
1337 unsigned int binN
= binNum(value
);
1339 if (binN
< bins
->min
)
1343 else if (binN
> bins
->max
)
1355 * Figure out the bin in a histogram to which a value belongs.
1357 * This uses exponentially sized bins that go from 0 to infinity.
1360 * value: in the range -INFINITY to INFINITY
1363 * The number of the bin in a struct Bins.bin
1365 static unsigned int binNum(const double value
)
1371 else if (value
< binEnd(1))
1375 else if (value
>= binStart(BIN_NB
- 1))
1381 return floor(log(value
) / log(binBase
)) + BIN_NB
+ 1;
1387 * Figure out the start of the interval of a bin in a histogram. See struct
1390 * This uses exponentially sized bins that go from 0 to infinity.
1393 * binNum: bin number
1396 * The start of the interval, this value is included in the interval (except
1397 * for -INFINITY, naturally)
1399 static double binStart(const unsigned int binNum
)
1401 g_assert_cmpuint(binNum
, <, BIN_NB
);
1407 else if (binNum
== 1)
1413 return pow(binBase
, (double) binNum
- BIN_NB
+ 1);
1419 * Figure out the end of the interval of a bin in a histogram. See struct
1422 * This uses exponentially sized bins that go from 0 to infinity.
1425 * binNum: bin number
1428 * The end of the interval, this value is not included in the interval
1430 static double binEnd(const unsigned int binNum
)
1432 g_assert_cmpuint(binNum
, <, BIN_NB
);
1438 else if (binNum
< BIN_NB
- 1)
1440 return pow(binBase
, (double) binNum
- BIN_NB
+ 2);
1450 * Return the total number of elements in the "normal" bins (not underflow or
1454 * bins: the structure containing bins to build a histrogram
1456 static uint32_t normalTotal(struct Bins
* const bins
)
1458 return bins
->total
- bins
->bin
[0] - bins
->bin
[BIN_NB
- 1];
1462 /* Update the bounds between two traces
1465 * bounds: the array containing all the trace-pair bounds
1466 * e1, e2: the two related events
1468 static void updateBounds(Bounds
** const bounds
, Event
* const e1
, Event
* const
1471 unsigned int traceI
, traceJ
;
1472 uint64_t messageTime
;
1475 if (e1
->traceNum
< e2
->traceNum
)
1477 traceI
= e2
->traceNum
;
1478 traceJ
= e1
->traceNum
;
1479 messageTime
= e1
->cpuTime
;
1483 traceI
= e1
->traceNum
;
1484 traceJ
= e2
->traceNum
;
1485 messageTime
= e2
->cpuTime
;
1487 tpBounds
= &bounds
[traceI
][traceJ
];
1489 if (messageTime
< tpBounds
->min
)
1491 tpBounds
->min
= messageTime
;
1493 if (messageTime
> tpBounds
->max
)
1495 tpBounds
->max
= messageTime
;
1502 * Create the linear programming problem containing the constraints defined by
1503 * two half-hulls. The objective function and optimization directions are not
1507 * syncState: container for synchronization data
1508 * i: first trace number
1509 * j: second trace number, garanteed to be larger than i
1511 * A new glp_prob*, this problem must be freed by the caller with
1514 static glp_prob
* lpCreateProblem(GQueue
* const lowerHull
, GQueue
* const
1519 const double zeroD
= 0.;
1520 glp_prob
* lp
= glp_create_prob();
1521 unsigned int hullPointNb
= g_queue_get_length(lowerHull
) +
1522 g_queue_get_length(upperHull
);
1523 GArray
* iArray
= g_array_sized_new(FALSE
, FALSE
, sizeof(int), hullPointNb
+
1525 GArray
* jArray
= g_array_sized_new(FALSE
, FALSE
, sizeof(int), hullPointNb
+
1527 GArray
* aArray
= g_array_sized_new(FALSE
, FALSE
, sizeof(double),
1531 struct LPAddRowInfo rowInfo
;
1533 {lowerHull
, {lp
, GLP_UP
, iArray
, jArray
, aArray
}},
1534 {upperHull
, {lp
, GLP_LO
, iArray
, jArray
, aArray
}},
1537 // Create the LP problem
1538 glp_term_out(GLP_OFF
);
1539 if (hullPointNb
> 0)
1541 glp_add_rows(lp
, hullPointNb
);
1543 glp_add_cols(lp
, 2);
1545 glp_set_col_name(lp
, 1, "a0");
1546 glp_set_col_bnds(lp
, 1, GLP_FR
, 0., 0.);
1547 glp_set_col_name(lp
, 2, "a1");
1548 glp_set_col_bnds(lp
, 2, GLP_LO
, 0., 0.);
1550 // Add row constraints
1551 g_array_append_val(iArray
, zero
);
1552 g_array_append_val(jArray
, zero
);
1553 g_array_append_val(aArray
, zeroD
);
1555 for (it
= 0; it
< sizeof(loopValues
) / sizeof(*loopValues
); it
++)
1557 g_queue_foreach(loopValues
[it
].hull
, &gfLPAddRow
,
1558 &loopValues
[it
].rowInfo
);
1561 g_assert_cmpuint(iArray
->len
, ==, jArray
->len
);
1562 g_assert_cmpuint(jArray
->len
, ==, aArray
->len
);
1563 g_assert_cmpuint(aArray
->len
- 1, ==, hullPointNb
* 2);
1565 glp_load_matrix(lp
, aArray
->len
- 1, &g_array_index(iArray
, int, 0),
1566 &g_array_index(jArray
, int, 0), &g_array_index(aArray
, double, 0));
1568 glp_scale_prob(lp
, GLP_SF_AUTO
);
1570 g_array_free(iArray
, TRUE
);
1571 g_array_free(jArray
, TRUE
);
1572 g_array_free(aArray
, TRUE
);
1579 * A GFunc for g_queue_foreach(). Add constraints and bounds for one row.
1582 * data Point*, synchronization point for which to add an LP row
1584 * user_data LPAddRowInfo*
1586 static void gfLPAddRow(gpointer data
, gpointer user_data
)
1589 struct LPAddRowInfo
* rowInfo
= user_data
;
1591 double constraints
[2];
1593 indexes
[0]= g_array_index(rowInfo
->iArray
, int, rowInfo
->iArray
->len
- 1) + 1;
1594 indexes
[1]= indexes
[0];
1596 if (rowInfo
->boundType
== GLP_UP
)
1598 glp_set_row_bnds(rowInfo
->lp
, indexes
[0], GLP_UP
, 0., p
->y
);
1600 else if (rowInfo
->boundType
== GLP_LO
)
1602 glp_set_row_bnds(rowInfo
->lp
, indexes
[0], GLP_LO
, p
->y
, 0.);
1606 g_assert_not_reached();
1609 g_array_append_vals(rowInfo
->iArray
, indexes
, 2);
1612 g_array_append_vals(rowInfo
->jArray
, indexes
, 2);
1614 constraints
[1]= p
->x
;
1615 g_array_append_vals(rowInfo
->aArray
, constraints
, 2);
1620 * Calculate min or max correction factors (as possible) using an LP problem.
1623 * lp: A linear programming problem with constraints and bounds
1625 * direction: The type of factors desired. Use GLP_MAX for max
1626 * approximation factors (a1, the drift or slope is the
1627 * largest) and GLP_MIN in the other case.
1630 * If the calculation was successful, a new Factors struct. Otherwise, NULL.
1631 * The calculation will fail if the hull assumptions are not respected.
1633 static Factors
* calculateFactors(glp_prob
* const lp
, const int direction
)
1638 glp_set_obj_coef(lp
, 1, 0.);
1639 glp_set_obj_coef(lp
, 2, 1.);
1641 glp_set_obj_dir(lp
, direction
);
1642 retval
= glp_simplex(lp
, NULL
);
1643 status
= glp_get_status(lp
);
1645 if (retval
== 0 && status
== GLP_OPT
)
1647 factors
= malloc(sizeof(Factors
));
1648 factors
->offset
= glp_get_col_prim(lp
, 1);
1649 factors
->drift
= glp_get_col_prim(lp
, 2);
1661 * Calculate min, max and approx correction factors (as possible) using an LP
1665 * lp: A linear programming problem with constraints and bounds
1669 * Please note that the approximation type may be MIDDLE, INCOMPLETE or
1670 * ABSENT. Unlike in analysis_chull, ABSENT is also used when the hulls do
1671 * not respect assumptions.
1673 static void calculateCompleteFactors(glp_prob
* const lp
, FactorsCHull
* factors
)
1675 factors
->min
= calculateFactors(lp
, GLP_MIN
);
1676 factors
->max
= calculateFactors(lp
, GLP_MAX
);
1678 if (factors
->min
&& factors
->max
)
1680 factors
->type
= MIDDLE
;
1681 calculateFactorsMiddle(factors
);
1683 else if (factors
->min
|| factors
->max
)
1685 factors
->type
= INCOMPLETE
;
1686 factors
->approx
= NULL
;
1690 factors
->type
= ABSENT
;
1691 factors
->approx
= NULL
;
1697 * Create and initialize an array like AnalysisStatsCHull.allFactors
1700 * traceNb: number of traces
1703 * A new array, which can be freed with freeAllFactors()
1705 static FactorsCHull
** createAllFactors(const unsigned int traceNb
)
1707 FactorsCHull
** factorsArray
;
1710 factorsArray
= malloc(traceNb
* sizeof(FactorsCHull
*));
1711 for (i
= 0; i
< traceNb
; i
++)
1713 factorsArray
[i
]= calloc((i
+ 1), sizeof(FactorsCHull
));
1715 factorsArray
[i
][i
].type
= EXACT
;
1716 factorsArray
[i
][i
].approx
= malloc(sizeof(Factors
));
1717 factorsArray
[i
][i
].approx
->drift
= 1.;
1718 factorsArray
[i
][i
].approx
->offset
= 0.;
1721 return factorsArray
;
1727 * Compute synchronization factors using a linear programming approach.
1728 * Compute the factors using analysis_chull. Compare the two.
1730 * When the solver library, glpk, is not available at build time, only compute
1731 * the factors using analysis_chull. This is to make sure that module runs its
1732 * finalize function so that its graph functions can be called later.
1735 * syncState: container for synchronization data
1737 static void finalizeAnalysisEvalLP(SyncState
* const syncState
)
1739 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
1742 AnalysisDataCHull
* chAnalysisData
= analysisData
->chullSS
->analysisData
;
1743 FactorsCHull
** lpFactorsArray
;
1745 if (!syncState
->stats
&& !syncState
->graphsStream
)
1750 /* Because of matching_distributor, this analysis may be called twice.
1751 * Only run it once */
1752 if ((syncState
->graphsStream
&& analysisData
->graphs
->lps
!= NULL
) ||
1753 (syncState
->stats
&& analysisData
->stats
->chFactorsArray
!= NULL
))
1758 lpFactorsArray
= createAllFactors(syncState
->traceNb
);
1760 if (syncState
->stats
)
1762 analysisData
->stats
->chFactorsArray
=
1763 calculateAllFactors(analysisData
->chullSS
);
1764 analysisData
->stats
->lpFactorsArray
= lpFactorsArray
;
1767 if (syncState
->graphsStream
)
1769 analysisData
->graphs
->lps
= malloc(syncState
->traceNb
*
1770 sizeof(glp_prob
**));
1771 for (i
= 0; i
< syncState
->traceNb
; i
++)
1773 analysisData
->graphs
->lps
[i
]= malloc(i
* sizeof(glp_prob
*));
1775 analysisData
->graphs
->lpFactorsArray
= lpFactorsArray
;
1778 for (i
= 0; i
< syncState
->traceNb
; i
++)
1780 for (j
= 0; j
< i
; j
++)
1784 // Create the LP problem
1785 lp
= lpCreateProblem(chAnalysisData
->hullArray
[i
][j
],
1786 chAnalysisData
->hullArray
[j
][i
]);
1788 // Use the LP problem to find the correction factors for this pair of
1790 calculateCompleteFactors(lp
, &lpFactorsArray
[i
][j
]);
1792 if (syncState
->graphsStream
)
1794 analysisData
->graphs
->lps
[i
][j
]= lp
;
1798 glp_delete_prob(lp
);
1804 g_array_free(analysisData
->chullSS
->analysisModule
->finalizeAnalysis(analysisData
->chullSS
),
1810 * Compute synchronization accuracy information using a linear programming
1811 * approach. Write the neccessary data files and plot lines in the gnuplot
1814 * When the solver library, glpk, is not available at build time nothing is
1815 * actually produced.
1818 * syncState: container for synchronization data
1819 * i: first trace number
1820 * j: second trace number, garanteed to be larger than i
1822 static void writeAnalysisTraceTimeBackPlotsEval(SyncState
* const syncState
,
1823 const unsigned int i
, const unsigned int j
)
1827 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
1828 AnalysisGraphsEval
* graphs
= analysisData
->graphs
;
1829 GQueue
*** hullArray
= ((AnalysisDataCHull
*)
1830 analysisData
->chullSS
->analysisData
)->hullArray
;
1831 FactorsCHull
* lpFactors
= &graphs
->lpFactorsArray
[j
][i
];
1832 glp_prob
* lp
= graphs
->lps
[j
][i
];
1834 if (lpFactors
->type
== MIDDLE
)
1841 unsigned int xBegin
, xEnd
;
1843 const unsigned int graphPointNb
= 1000;
1845 // Open the data file
1846 snprintf(fileName
, 40, "analysis_eval_accuracy-%03u_and_%03u.data", i
, j
);
1847 fileName
[sizeof(fileName
) - 1]= '\0';
1849 cwd
= changeToGraphsDir(syncState
->graphsDir
);
1851 if ((fp
= fopen(fileName
, "w")) == NULL
)
1853 g_error(strerror(errno
));
1855 fprintf(fp
, "#%-24s %-25s %-25s %-25s\n", "x", "middle", "min", "max");
1860 g_error(strerror(errno
));
1864 // Build the list of absisca values for the points in the accuracy graph
1865 g_assert_cmpuint(graphPointNb
, >=, 4);
1866 xValues
= malloc(graphPointNb
* sizeof(double));
1867 xValues
[0]= graphs
->bounds
[j
][i
].min
;
1868 xValues
[graphPointNb
- 1]= graphs
->bounds
[j
][i
].max
;
1869 xValues
[1]= MIN(((Point
*) g_queue_peek_head(hullArray
[i
][j
]))->x
,
1870 ((Point
*) g_queue_peek_head(hullArray
[j
][i
]))->x
);
1871 xValues
[graphPointNb
- 2]= MAX(((Point
*)
1872 g_queue_peek_tail(hullArray
[i
][j
]))->x
, ((Point
*)
1873 g_queue_peek_tail(hullArray
[j
][i
]))->x
);
1875 if (xValues
[0] == xValues
[1])
1883 if (xValues
[graphPointNb
- 2] == xValues
[graphPointNb
- 1])
1885 xEnd
= graphPointNb
- 1;
1889 xEnd
= graphPointNb
- 2;
1891 interval
= (xValues
[xEnd
] - xValues
[xBegin
]) / (graphPointNb
- 1);
1893 for (it
= xBegin
; it
<= xEnd
; it
++)
1895 xValues
[it
]= xValues
[xBegin
] + interval
* (it
- xBegin
);
1898 /* For each absisca value and each optimisation direction, solve the LP
1899 * and write a line in the data file */
1900 for (it
= 0; it
< graphPointNb
; it
++)
1903 int directions
[]= {GLP_MIN
, GLP_MAX
};
1905 glp_set_obj_coef(lp
, 1, 1.);
1906 glp_set_obj_coef(lp
, 2, xValues
[it
]);
1908 fprintf(fp
, "%25.9f %25.9f", xValues
[it
], lpFactors
->approx
->offset
1909 + lpFactors
->approx
->drift
* xValues
[it
]);
1910 for (it2
= 0; it2
< sizeof(directions
) / sizeof(*directions
); it2
++)
1914 glp_set_obj_dir(lp
, directions
[it2
]);
1915 retval
= glp_simplex(lp
, NULL
);
1916 status
= glp_get_status(lp
);
1918 g_assert(retval
== 0 && status
== GLP_OPT
);
1919 fprintf(fp
, " %25.9f", glp_get_obj_val(lp
));
1927 fprintf(syncState
->graphsStream
,
1928 "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
1929 "using 1:(($3 - $2) / clock_freq_%2$u):(($4 - $2) / clock_freq_%2$u) "
1930 "title \"Synchronization accuracy\" "
1931 "with filledcurves linewidth 2 linetype 1 "
1932 "linecolor rgb \"black\" fill solid 0.25 noborder, \\\n", i
,
1940 * Write the analysis-specific graph lines in the gnuplot script.
1942 * When the solver library, glpk, is not available at build time nothing is
1943 * actually produced.
1946 * syncState: container for synchronization data
1947 * i: first trace number
1948 * j: second trace number, garanteed to be larger than i
1950 static void writeAnalysisTraceTimeForePlotsEval(SyncState
* const syncState
,
1951 const unsigned int i
, const unsigned int j
)
1954 if (((AnalysisDataEval
*)
1955 syncState
->analysisData
)->graphs
->lpFactorsArray
[j
][i
].type
==
1958 fprintf(syncState
->graphsStream
,
1959 "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
1960 "using 1:(($3 - $2) / clock_freq_%2$u) notitle "
1961 "with lines linewidth 2 linetype 1 "
1962 "linecolor rgb \"gray60\", \\\n"
1963 "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
1964 "using 1:(($4 - $2) / clock_freq_%2$u) notitle "
1965 "with lines linewidth 2 linetype 1 "
1966 "linecolor rgb \"gray60\", \\\n", i
, j
);
1973 * Write the analysis-specific graph lines in the gnuplot script.
1976 * syncState: container for synchronization data
1977 * i: first trace number
1978 * j: second trace number, garanteed to be larger than i
1980 static void writeAnalysisTraceTraceBackPlotsEval(SyncState
* const syncState
,
1981 const unsigned int i
, const unsigned int j
)
1984 fprintf(syncState
->graphsStream
,
1985 "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
1987 "title \"Synchronization accuracy\" "
1988 "with filledcurves linewidth 2 linetype 1 "
1989 "linecolor rgb \"black\" fill solid 0.25 noborder, \\\n", i
, j
);
1995 * Write the analysis-specific graph lines in the gnuplot script.
1998 * syncState: container for synchronization data
1999 * i: first trace number
2000 * j: second trace number, garanteed to be larger than i
2002 static void writeAnalysisTraceTraceForePlotsEval(SyncState
* const syncState
,
2003 const unsigned int i
, const unsigned int j
)
2005 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
2007 analysisData
->chullSS
->analysisModule
->graphFunctions
.writeTraceTraceForePlots(analysisData
->chullSS
,