1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2009 Benjamin Poirier <benjamin.poirier@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 #define _ISOC99_SOURCE
26 #include <arpa/inet.h>
29 #include <netinet/in.h>
34 #include <sys/socket.h>
38 #include "sync_chain.h"
39 #include "event_analysis_chull.h"
41 #include "event_analysis_eval.h"
44 struct WriteHistogramInfo
55 GArray
* iArray
, * jArray
, * aArray
;
59 // Functions common to all analysis modules
60 static void initAnalysisEval(SyncState
* const syncState
);
61 static void destroyAnalysisEval(SyncState
* const syncState
);
63 static void analyzeMessageEval(SyncState
* const syncState
, Message
* const
65 static void analyzeExchangeEval(SyncState
* const syncState
, Exchange
* const
67 static void analyzeBroadcastEval(SyncState
* const syncState
, Broadcast
* const
69 static GArray
* finalizeAnalysisEval(SyncState
* const syncState
);
70 static void printAnalysisStatsEval(SyncState
* const syncState
);
71 static void writeAnalysisTraceTimePlotsEval(SyncState
* const syncState
, const
72 unsigned int i
, const unsigned int j
);
73 static void writeAnalysisTraceTraceBackPlotsEval(SyncState
* const syncState
,
74 const unsigned int i
, const unsigned int j
);
75 static void writeAnalysisTraceTraceForePlotsEval(SyncState
* const syncState
,
76 const unsigned int i
, const unsigned int j
);
78 // Functions specific to this module
79 static void registerAnalysisEval() __attribute__((constructor (102)));
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 // The next group of functions is only needed when computing synchronization
115 static glp_prob
* lpCreateProblem(GQueue
* const lowerHull
, GQueue
* const
117 static void gfLPAddRow(gpointer data
, gpointer user_data
);
118 static Factors
* calculateFactors(glp_prob
* const lp
, const int direction
);
119 static void calculateCompleteFactors(glp_prob
* const lp
, FactorsCHull
*
121 static FactorsCHull
** createAllFactors(const unsigned int traceNb
);
122 static inline void finalizeAnalysisEvalLP(SyncState
* const syncState
);
124 static void finalizeAnalysisEvalLP(SyncState
* const syncState
);
128 // initialized in registerAnalysisEval()
131 static AnalysisModule analysisModuleEval
= {
133 .initAnalysis
= &initAnalysisEval
,
134 .destroyAnalysis
= &destroyAnalysisEval
,
135 .analyzeMessage
= &analyzeMessageEval
,
136 .analyzeExchange
= &analyzeExchangeEval
,
137 .analyzeBroadcast
= &analyzeBroadcastEval
,
138 .finalizeAnalysis
= &finalizeAnalysisEval
,
139 .printAnalysisStats
= &printAnalysisStatsEval
,
141 .writeTraceTimeBackPlots
= &writeAnalysisTraceTimePlotsEval
,
142 .writeTraceTraceBackPlots
= &writeAnalysisTraceTraceBackPlotsEval
,
143 .writeTraceTraceForePlots
= &writeAnalysisTraceTraceForePlotsEval
,
147 static ModuleOption optionEvalRttFile
= {
148 .longName
= "eval-rtt-file",
149 .hasArg
= REQUIRED_ARG
,
151 .optionHelp
= "specify the file containing RTT information",
157 * Analysis module registering function
159 static void registerAnalysisEval()
161 binBase
= exp10(6. / (BIN_NB
- 3));
163 g_queue_push_tail(&analysisModules
, &analysisModuleEval
);
164 g_queue_push_tail(&moduleOptions
, &optionEvalRttFile
);
169 * Analysis init function
171 * This function is called at the beginning of a synchronization run for a set
175 * syncState container for synchronization data.
177 static void initAnalysisEval(SyncState
* const syncState
)
179 AnalysisDataEval
* analysisData
;
182 analysisData
= malloc(sizeof(AnalysisDataEval
));
183 syncState
->analysisData
= analysisData
;
185 analysisData
->rttInfo
= g_hash_table_new_full(&ghfRttKeyHash
,
186 &gefRttKeyEqual
, &gdnDestroyRttKey
, &gdnDestroyDouble
);
187 if (optionEvalRttFile
.arg
)
192 rttStream
= fopen(optionEvalRttFile
.arg
, "r");
193 if (rttStream
== NULL
)
195 g_error(strerror(errno
));
198 readRttInfo(analysisData
->rttInfo
, rttStream
);
200 retval
= fclose(rttStream
);
203 g_error(strerror(errno
));
207 if (syncState
->stats
)
209 analysisData
->stats
= calloc(1, sizeof(AnalysisStatsEval
));
210 analysisData
->stats
->broadcastDiffSum
= 0.;
212 analysisData
->stats
->messageStats
= malloc(syncState
->traceNb
*
213 sizeof(MessageStats
*));
214 for (i
= 0; i
< syncState
->traceNb
; i
++)
216 analysisData
->stats
->messageStats
[i
]= calloc(syncState
->traceNb
,
217 sizeof(MessageStats
));
220 analysisData
->stats
->exchangeRtt
=
221 g_hash_table_new_full(&ghfRttKeyHash
, &gefRttKeyEqual
,
222 &gdnDestroyRttKey
, &gdnDestroyDouble
);
225 analysisData
->stats
->chFactorsArray
= NULL
;
226 analysisData
->stats
->lpFactorsArray
= NULL
;
230 if (syncState
->graphsStream
)
232 AnalysisGraphsEval
* graphs
= malloc(sizeof(AnalysisGraphsEval
));
234 analysisData
->graphs
= graphs
;
236 graphs
->histograms
= g_hash_table_new_full(&ghfRttKeyHash
,
237 &gefRttKeyEqual
, &gdnDestroyRttKey
,
238 &gdnDestroyAnalysisHistogramEval
);
240 graphs
->bounds
= malloc(syncState
->traceNb
* sizeof(Bounds
*));
241 for (i
= 0; i
< syncState
->traceNb
; i
++)
243 graphs
->bounds
[i
]= malloc(i
* sizeof(Bounds
));
244 for (j
= 0; j
< i
; j
++)
246 graphs
->bounds
[i
][j
].min
= UINT64_MAX
;
247 graphs
->bounds
[i
][j
].max
= 0;
253 graphs
->lpFactorsArray
= NULL
;
257 if (syncState
->stats
|| syncState
->graphsStream
)
261 analysisData
->chullSS
= malloc(sizeof(SyncState
));
262 memcpy(analysisData
->chullSS
, syncState
, sizeof(SyncState
));
263 analysisData
->chullSS
->stats
= false;
264 analysisData
->chullSS
->analysisData
= NULL
;
265 result
= g_queue_find_custom(&analysisModules
, "chull",
266 &gcfCompareAnalysis
);
267 analysisData
->chullSS
->analysisModule
= (AnalysisModule
*) result
->data
;
268 analysisData
->chullSS
->analysisModule
->initAnalysis(analysisData
->chullSS
);
274 * Create and open files used to store histogram points to generate graphs.
275 * Create data structures to store histogram points during analysis.
278 * graphsDir: folder where to write files
279 * rttKey: host pair, make sure saddr < daddr
281 static AnalysisHistogramEval
* constructAnalysisHistogramEval(const char* const
282 graphsDir
, const struct RttKey
* const rttKey
)
287 char name
[60], saddr
[16], daddr
[16];
288 AnalysisHistogramEval
* histogram
= calloc(1, sizeof(*histogram
));
291 const char* fileName
;
292 const char* host1
, *host2
;
294 {offsetof(AnalysisHistogramEval
, ttSendPoints
),
295 "analysis_eval_tt-%s_to_%s.data", saddr
, daddr
},
296 {offsetof(AnalysisHistogramEval
, ttRecvPoints
),
297 "analysis_eval_tt-%s_to_%s.data", daddr
, saddr
},
298 {offsetof(AnalysisHistogramEval
, hrttPoints
),
299 "analysis_eval_hrtt-%s_and_%s.data", saddr
, daddr
},
302 histogram
->ttSendBins
.min
= BIN_NB
- 1;
303 histogram
->ttRecvBins
.min
= BIN_NB
- 1;
304 histogram
->hrttBins
.min
= BIN_NB
- 1;
306 convertIP(saddr
, rttKey
->saddr
);
307 convertIP(daddr
, rttKey
->daddr
);
309 cwd
= changeToGraphDir(graphsDir
);
311 for (i
= 0; i
< sizeof(loopValues
) / sizeof(*loopValues
); i
++)
313 retval
= snprintf(name
, sizeof(name
), loopValues
[i
].fileName
,
314 loopValues
[i
].host1
, loopValues
[i
].host2
);
315 if (retval
> sizeof(name
) - 1)
317 name
[sizeof(name
) - 1]= '\0';
319 if ((*(FILE**)((void*) histogram
+ loopValues
[i
].pointsOffset
)=
320 fopen(name
, "w")) == NULL
)
322 g_error(strerror(errno
));
329 g_error(strerror(errno
));
338 * Close files used to store histogram points to generate graphs.
341 * graphsDir: folder where to write files
342 * rttKey: host pair, make sure saddr < daddr
344 static void destroyAnalysisHistogramEval(AnalysisHistogramEval
* const
352 {offsetof(AnalysisHistogramEval
, ttSendPoints
)},
353 {offsetof(AnalysisHistogramEval
, ttRecvPoints
)},
354 {offsetof(AnalysisHistogramEval
, hrttPoints
)},
357 for (i
= 0; i
< sizeof(loopValues
) / sizeof(*loopValues
); i
++)
359 retval
= fclose(*(FILE**)((void*) histogram
+ loopValues
[i
].pointsOffset
));
362 g_error(strerror(errno
));
371 * A GDestroyNotify function for g_hash_table_new_full()
374 * data: AnalysisHistogramEval*
376 static void gdnDestroyAnalysisHistogramEval(gpointer data
)
378 destroyAnalysisHistogramEval(data
);
383 * A GHFunc for g_hash_table_foreach()
386 * key: RttKey* where saddr < daddr
387 * value: AnalysisHistogramEval*
388 * user_data struct WriteHistogramInfo*
390 static void ghfWriteHistogram(gpointer key
, gpointer value
, gpointer user_data
)
392 double* rtt1
, * rtt2
;
393 struct RttKey
* rttKey
= key
;
394 struct RttKey oppositeRttKey
= {.saddr
= rttKey
->daddr
, .daddr
=
396 AnalysisHistogramEval
* histogram
= value
;
397 struct WriteHistogramInfo
* info
= user_data
;
399 rtt1
= g_hash_table_lookup(info
->rttInfo
, rttKey
);
400 rtt2
= g_hash_table_lookup(info
->rttInfo
, &oppositeRttKey
);
406 else if (rtt2
!= NULL
)
408 rtt1
= MIN(rtt1
, rtt2
);
411 dumpBinToFile(&histogram
->ttSendBins
, histogram
->ttSendPoints
);
412 dumpBinToFile(&histogram
->ttRecvBins
, histogram
->ttRecvPoints
);
413 dumpBinToFile(&histogram
->hrttBins
, histogram
->hrttPoints
);
414 writeHistogram(info
->graphsStream
, rttKey
, rtt1
, histogram
);
419 * Write the content of one bin in a histogram point file
422 * bin: array of values that make up a histogram
423 * file: FILE*, write to this file
425 static void dumpBinToFile(const struct Bins
* const bins
, FILE* const file
)
429 // The first and last bins are skipped, see struct Bins
430 for (i
= 1; i
< BIN_NB
- 1; i
++)
432 if (bins
->bin
[i
] > 0)
434 fprintf(file
, "%20.9f %20.9f %20.9f\n", (binStart(i
) + binEnd(i
))
435 / 2., (double) bins
->bin
[i
] / ((binEnd(i
) - binStart(i
)) *
436 bins
->total
), binEnd(i
) - binStart(i
));
443 * Write the analysis-specific plot in the gnuplot script.
446 * graphsStream: write to this file
447 * rttKey: must be sorted such that saddr < daddr
448 * minRtt: if available, else NULL
449 * histogram: struct that contains the bins for the pair of traces
450 * identified by rttKey
452 static void writeHistogram(FILE* graphsStream
, const struct RttKey
* rttKey
,
453 double* minRtt
, AnalysisHistogramEval
* const histogram
)
455 char saddr
[16], daddr
[16];
457 convertIP(saddr
, rttKey
->saddr
);
458 convertIP(daddr
, rttKey
->daddr
);
460 fprintf(graphsStream
,
462 "set output \"histogram-%s-%s.eps\"\n"
464 "set xlabel \"Message Latency (s)\"\n"
465 "set ylabel \"Proportion of messages per second\"\n", saddr
, daddr
);
469 fprintf(graphsStream
,
470 "set arrow from %.9f, 0 rto 0, graph 1 "
471 "nohead linetype 3 linewidth 3 linecolor rgb \"black\"\n", *minRtt
475 if (normalTotal(&histogram
->ttSendBins
) ||
476 normalTotal(&histogram
->ttRecvBins
) ||
477 normalTotal(&histogram
->hrttBins
))
479 fprintf(graphsStream
, "plot \\\n");
481 if (normalTotal(&histogram
->hrttBins
))
483 fprintf(graphsStream
,
484 "\t\"analysis_eval_hrtt-%s_and_%s.data\" "
485 "title \"RTT/2\" with linespoints linetype 1 linewidth 2 "
486 "linecolor rgb \"black\" pointtype 6 pointsize 1,\\\n",
490 if (normalTotal(&histogram
->ttSendBins
))
492 fprintf(graphsStream
,
493 "\t\"analysis_eval_tt-%1$s_to_%2$s.data\" "
494 "title \"%1$s to %2$s\" with linespoints linetype 4 linewidth 2 "
495 "linecolor rgb \"gray60\" pointtype 6 pointsize 1,\\\n",
499 if (normalTotal(&histogram
->ttRecvBins
))
501 fprintf(graphsStream
,
502 "\t\"analysis_eval_tt-%1$s_to_%2$s.data\" "
503 "title \"%1$s to %2$s\" with linespoints linetype 4 linewidth 2 "
504 "linecolor rgb \"gray30\" pointtype 6 pointsize 1,\\\n",
508 // Remove the ",\\\n" from the last graph plot line
509 if (ftruncate(fileno(graphsStream
), ftell(graphsStream
) - 3) == -1)
511 g_error(strerror(errno
));
513 if (fseek(graphsStream
, 0, SEEK_END
) == -1)
515 g_error(strerror(errno
));
517 fprintf(graphsStream
, "\n");
523 * Analysis destroy function
525 * Free the analysis specific data structures
528 * syncState container for synchronization data.
530 static void destroyAnalysisEval(SyncState
* const syncState
)
533 AnalysisDataEval
* analysisData
;
535 analysisData
= (AnalysisDataEval
*) syncState
->analysisData
;
537 if (analysisData
== NULL
)
542 g_hash_table_destroy(analysisData
->rttInfo
);
544 if (syncState
->stats
)
546 AnalysisStatsEval
* stats
= analysisData
->stats
;
548 for (i
= 0; i
< syncState
->traceNb
; i
++)
550 free(stats
->messageStats
[i
]);
552 free(stats
->messageStats
);
554 g_hash_table_destroy(stats
->exchangeRtt
);
557 freeAllFactors(syncState
->traceNb
, stats
->chFactorsArray
);
558 freeAllFactors(syncState
->traceNb
, stats
->lpFactorsArray
);
564 if (syncState
->graphsStream
)
566 AnalysisGraphsEval
* graphs
= analysisData
->graphs
;
568 if (graphs
->histograms
)
570 g_hash_table_destroy(graphs
->histograms
);
573 for (i
= 0; i
< syncState
->traceNb
; i
++)
575 free(graphs
->bounds
[i
]);
577 free(graphs
->bounds
);
580 for (i
= 0; i
< syncState
->traceNb
; i
++)
582 for (j
= 0; j
< i
; j
++)
584 // There seems to be a memory leak in glpk, valgrind reports a
585 // loss 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
=
626 &analysisData
->stats
->messageStats
[message
->outE
->traceNum
][message
->inE
->traceNum
];
629 struct RttKey rttKey
;
631 g_assert(message
->inE
->type
== TCP
);
633 if (syncState
->stats
)
635 messageStats
->total
++;
638 tt
= wallTimeSub(&message
->inE
->wallTime
, &message
->outE
->wallTime
);
641 if (syncState
->stats
)
643 messageStats
->inversionNb
++;
646 else if (syncState
->graphsStream
)
648 struct RttKey rttKey
= {
649 .saddr
=MIN(message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
,
650 message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
),
651 .daddr
=MAX(message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
,
652 message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
),
654 AnalysisHistogramEval
* histogram
=
655 g_hash_table_lookup(analysisData
->graphs
->histograms
, &rttKey
);
657 if (histogram
== NULL
)
659 struct RttKey
* tableKey
= malloc(sizeof(*tableKey
));
661 histogram
= constructAnalysisHistogramEval(syncState
->graphsDir
, &rttKey
);
662 memcpy(tableKey
, &rttKey
, sizeof(*tableKey
));
663 g_hash_table_insert(analysisData
->graphs
->histograms
, tableKey
, histogram
);
666 if (message
->inE
->event
.udpEvent
->datagramKey
->saddr
<
667 message
->inE
->event
.udpEvent
->datagramKey
->daddr
)
669 hitBin(&histogram
->ttSendBins
, tt
);
673 hitBin(&histogram
->ttRecvBins
, tt
);
677 if (syncState
->stats
)
680 message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
;
682 message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
;
683 rtt
= g_hash_table_lookup(analysisData
->rttInfo
, &rttKey
);
684 g_debug("rttInfo, looking up (%u, %u)->(%f)", rttKey
.saddr
,
685 rttKey
.daddr
, rtt
? *rtt
: NAN
);
689 g_debug("rttInfo, tt: %f rtt / 2: %f", tt
, *rtt
/ 2.);
692 messageStats
->tooFastNb
++;
697 messageStats
->noRTTInfoNb
++;
701 if (syncState
->graphsStream
)
703 updateBounds(analysisData
->graphs
->bounds
, message
->inE
,
707 if (syncState
->stats
|| syncState
->graphsStream
)
709 analysisData
->chullSS
->analysisModule
->analyzeMessage(analysisData
->chullSS
,
716 * Perform analysis on multiple messages
721 * syncState container for synchronization data
722 * exchange structure containing the messages
724 static void analyzeExchangeEval(SyncState
* const syncState
, Exchange
* const
727 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
728 Message
* m1
= g_queue_peek_tail(exchange
->acks
);
729 Message
* m2
= exchange
->message
;
730 struct RttKey
* rttKey
;
731 double* rtt
, * exchangeRtt
;
733 g_assert(m1
->inE
->type
== TCP
);
735 // (T2 - T1) - (T3 - T4)
736 rtt
= malloc(sizeof(double));
737 *rtt
= wallTimeSub(&m1
->inE
->wallTime
, &m1
->outE
->wallTime
) -
738 wallTimeSub(&m2
->outE
->wallTime
, &m2
->inE
->wallTime
);
740 rttKey
= malloc(sizeof(struct RttKey
));
742 MIN(m1
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
,
743 m1
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
);
745 MAX(m1
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
,
746 m1
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
);
748 if (syncState
->graphsStream
)
750 AnalysisHistogramEval
* histogram
=
751 g_hash_table_lookup(analysisData
->graphs
->histograms
, rttKey
);
753 if (histogram
== NULL
)
755 struct RttKey
* tableKey
= malloc(sizeof(*tableKey
));
757 histogram
= constructAnalysisHistogramEval(syncState
->graphsDir
,
759 memcpy(tableKey
, rttKey
, sizeof(*tableKey
));
760 g_hash_table_insert(analysisData
->graphs
->histograms
, tableKey
,
764 hitBin(&histogram
->hrttBins
, *rtt
/ 2);
767 if (syncState
->stats
)
769 exchangeRtt
= g_hash_table_lookup(analysisData
->stats
->exchangeRtt
,
774 if (*rtt
< *exchangeRtt
)
776 g_hash_table_replace(analysisData
->stats
->exchangeRtt
, rttKey
, rtt
);
786 g_hash_table_insert(analysisData
->stats
->exchangeRtt
, rttKey
, rtt
);
798 * Perform analysis on muliple events
800 * Sum the broadcast differential delays
803 * syncState container for synchronization data
804 * broadcast structure containing the events
806 static void analyzeBroadcastEval(SyncState
* const syncState
, Broadcast
* const
809 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
811 if (syncState
->stats
)
813 double sum
= 0, squaresSum
= 0;
816 g_queue_foreach(broadcast
->events
, &gfSum
, &sum
);
817 g_queue_foreach(broadcast
->events
, &gfSumSquares
, &squaresSum
);
819 analysisData
->stats
->broadcastNb
++;
820 // Because of numerical errors, this can at times be < 0
821 y
= squaresSum
/ g_queue_get_length(broadcast
->events
) - pow(sum
/
822 g_queue_get_length(broadcast
->events
), 2.);
825 analysisData
->stats
->broadcastDiffSum
+= sqrt(y
);
829 if (syncState
->graphsStream
)
833 unsigned int eventNb
= broadcast
->events
->length
;
835 events
= g_array_sized_new(FALSE
, FALSE
, sizeof(Event
*), eventNb
);
836 g_queue_foreach(broadcast
->events
, &gfAddEventToArray
, events
);
838 for (i
= 0; i
< eventNb
; i
++)
840 for (j
= 0; j
< eventNb
; j
++)
842 Event
* eventI
= g_array_index(events
, Event
*, i
), * eventJ
=
843 g_array_index(events
, Event
*, j
);
845 if (eventI
->traceNum
< eventJ
->traceNum
)
847 updateBounds(analysisData
->graphs
->bounds
, eventI
, eventJ
);
852 g_array_free(events
, TRUE
);
858 * Finalize the factor calculations. Since this module does not really
859 * calculate factors, identity factors are returned. Instead, histograms are
860 * written out and histogram structures are freed.
863 * syncState container for synchronization data.
866 * Factors[traceNb] identity factors for each trace
868 static GArray
* finalizeAnalysisEval(SyncState
* const syncState
)
872 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
874 if (syncState
->graphsStream
&& analysisData
->graphs
->histograms
)
876 g_hash_table_foreach(analysisData
->graphs
->histograms
,
877 &ghfWriteHistogram
, &(struct WriteHistogramInfo
) {.rttInfo
=
878 analysisData
->rttInfo
, .graphsStream
= syncState
->graphsStream
});
879 g_hash_table_destroy(analysisData
->graphs
->histograms
);
880 analysisData
->graphs
->histograms
= NULL
;
883 finalizeAnalysisEvalLP(syncState
);
885 factors
= g_array_sized_new(FALSE
, FALSE
, sizeof(Factors
),
887 g_array_set_size(factors
, syncState
->traceNb
);
888 for (i
= 0; i
< syncState
->traceNb
; i
++)
892 e
= &g_array_index(factors
, Factors
, i
);
902 * Print statistics related to analysis. Must be called after
906 * syncState container for synchronization data.
908 static void printAnalysisStatsEval(SyncState
* const syncState
)
910 AnalysisDataEval
* analysisData
;
911 unsigned int i
, j
, k
;
912 unsigned int totInversion
= 0, totTooFast
= 0, totNoInfo
= 0, totTotal
= 0;
915 if (!syncState
->stats
)
920 analysisData
= (AnalysisDataEval
*) syncState
->analysisData
;
922 printf("Synchronization evaluation analysis stats:\n");
923 if (analysisData
->stats
->broadcastNb
)
925 printf("\tsum of broadcast differential delays: %g\n",
926 analysisData
->stats
->broadcastDiffSum
);
927 printf("\taverage broadcast differential delay: %g\n",
928 analysisData
->stats
->broadcastDiffSum
/
929 analysisData
->stats
->broadcastNb
);
932 printf("\tIndividual evaluation:\n"
933 "\t\tTrace pair Inversions Too fast No RTT info Total\n");
935 for (i
= 0; i
< syncState
->traceNb
; i
++)
937 for (j
= i
+ 1; j
< syncState
->traceNb
; j
++)
939 MessageStats
* messageStats
;
947 for (k
= 0; k
< sizeof(loopValues
) / sizeof(*loopValues
); k
++)
950 &analysisData
->stats
->messageStats
[loopValues
[k
].t1
][loopValues
[k
].t2
];
952 printf("\t\t%3d - %-3d ", loopValues
[k
].t1
, loopValues
[k
].t2
);
953 printf("%u (%u%%)%n", messageStats
->inversionNb
, (unsigned
954 int) ceil((double) messageStats
->inversionNb
/
955 messageStats
->total
* 100), &charNb
);
956 printf("%*s", 17 - charNb
> 0 ? 17 - charNb
+ 1: 1, " ");
957 printf("%u (%u%%)%n", messageStats
->tooFastNb
, (unsigned int)
958 ceil((double) messageStats
->tooFastNb
/
959 messageStats
->total
* 100), &charNb
);
960 printf("%*s%-10u %u\n", 17 - charNb
> 0 ? 17 - charNb
+ 1:
961 1, " ", messageStats
->noRTTInfoNb
, messageStats
->total
);
963 totInversion
+= messageStats
->inversionNb
;
964 totTooFast
+= messageStats
->tooFastNb
;
965 totNoInfo
+= messageStats
->noRTTInfoNb
;
966 totTotal
+= messageStats
->total
;
971 printf("\t\t total ");
972 printf("%u (%u%%)%n", totInversion
, (unsigned int) ceil((double)
973 totInversion
/ totTotal
* 100), &charNb
);
974 printf("%*s", 17 - charNb
> 0 ? 17 - charNb
+ 1: 1, " ");
975 printf("%u (%u%%)%n", totTooFast
, (unsigned int) ceil((double) totTooFast
976 / totTotal
* 100), &charNb
);
977 printf("%*s%-10u %u\n", 17 - charNb
> 0 ? 17 - charNb
+ 1: 1, " ",
978 totNoInfo
, totTotal
);
980 printf("\tRound-trip times:\n"
981 "\t\tHost pair RTT from exchanges RTTs from file (ms)\n");
982 g_hash_table_foreach(analysisData
->stats
->exchangeRtt
,
983 &ghfPrintExchangeRtt
, analysisData
->rttInfo
);
985 printf("\tConvex hull factors comparisons:\n"
986 "\t\tTrace pair Factors type Differences (lp - chull)\n"
988 "\t\t Min Max Min Max\n");
990 for (i
= 0; i
< syncState
->traceNb
; i
++)
992 for (j
= 0; j
< i
; j
++)
994 FactorsCHull
* chFactors
= &analysisData
->stats
->chFactorsArray
[i
][j
];
995 FactorsCHull
* lpFactors
= &analysisData
->stats
->lpFactorsArray
[i
][j
];
997 printf("\t\t%3d - %-3d ", i
, j
);
998 if (lpFactors
->type
== chFactors
->type
)
1000 if (lpFactors
->type
== MIDDLE
)
1002 printf("%-13s %-10.4g %-10.4g %-10.4g %.4g\n",
1003 approxNames
[lpFactors
->type
],
1004 lpFactors
->min
->offset
- chFactors
->min
->offset
,
1005 lpFactors
->max
->offset
- chFactors
->max
->offset
,
1006 lpFactors
->min
->drift
- chFactors
->min
->drift
,
1007 lpFactors
->max
->drift
- chFactors
->max
->drift
);
1009 else if (lpFactors
->type
== ABSENT
)
1011 printf("%s\n", approxNames
[lpFactors
->type
]);
1016 printf("Different! %s and %s\n", approxNames
[lpFactors
->type
],
1017 approxNames
[chFactors
->type
]);
1025 * A GHFunc for g_hash_table_foreach()
1028 * key: RttKey* where saddr < daddr
1029 * value: double*, RTT estimated from exchanges
1030 * user_data GHashTable* rttInfo
1032 static void ghfPrintExchangeRtt(gpointer key
, gpointer value
, gpointer
1035 char addr1
[16], addr2
[16];
1036 struct RttKey
* rttKey1
= key
;
1037 struct RttKey rttKey2
= {rttKey1
->daddr
, rttKey1
->saddr
};
1038 double* fileRtt1
, *fileRtt2
;
1039 GHashTable
* rttInfo
= user_data
;
1041 convertIP(addr1
, rttKey1
->saddr
);
1042 convertIP(addr2
, rttKey1
->daddr
);
1044 fileRtt1
= g_hash_table_lookup(rttInfo
, rttKey1
);
1045 fileRtt2
= g_hash_table_lookup(rttInfo
, &rttKey2
);
1047 printf("\t\t(%15s, %-15s) %-18.3f ", addr1
, addr2
, *(double*) value
* 1e3
);
1049 if (fileRtt1
|| fileRtt2
)
1053 printf("%.3f", *fileRtt1
* 1e3
);
1055 if (fileRtt1
&& fileRtt2
)
1061 printf("%.3f", *fileRtt2
* 1e3
);
1073 * A GHashFunc for g_hash_table_new()
1076 * key struct RttKey*
1078 static guint
ghfRttKeyHash(gconstpointer key
)
1080 struct RttKey
* rttKey
;
1083 rttKey
= (struct RttKey
*) key
;
1095 * A GDestroyNotify function for g_hash_table_new_full()
1098 * data: struct RttKey*
1100 static void gdnDestroyRttKey(gpointer data
)
1107 * A GDestroyNotify function for g_hash_table_new_full()
1112 static void gdnDestroyDouble(gpointer data
)
1119 * A GEqualFunc for g_hash_table_new()
1125 * TRUE if both values are equal
1127 static gboolean
gefRttKeyEqual(gconstpointer a
, gconstpointer b
)
1129 const struct RttKey
* rkA
, * rkB
;
1131 rkA
= (struct RttKey
*) a
;
1132 rkB
= (struct RttKey
*) b
;
1134 if (rkA
->saddr
== rkB
->saddr
&& rkA
->daddr
== rkB
->daddr
)
1146 * Read a file contain minimum round trip time values and fill an array with
1147 * them. The file is formatted as such:
1148 * <host1 IP> <host2 IP> <RTT in milliseconds>
1149 * ip's should be in dotted quad format
1152 * rttInfo: double* rttInfo[RttKey], empty table, will be filled
1153 * rttStream: stream from which to read
1155 static void readRttInfo(GHashTable
* rttInfo
, FILE* rttStream
)
1161 positionStream(rttStream
);
1162 retval
= getline(&line
, &len
, rttStream
);
1163 while(!feof(rttStream
))
1165 struct RttKey
* rttKey
;
1166 char saddrDQ
[20], daddrDQ
[20];
1169 struct in_addr addr
;
1175 {saddrDQ
, offsetof(struct RttKey
, saddr
)},
1176 {daddrDQ
, offsetof(struct RttKey
, daddr
)}
1179 if (retval
== -1 && !feof(rttStream
))
1181 g_error(strerror(errno
));
1184 if (line
[retval
- 1] == '\n')
1186 line
[retval
- 1]= '\0';
1189 rtt
= malloc(sizeof(double));
1190 retval
= sscanf(line
, " %19s %19s %lf %c", saddrDQ
, daddrDQ
, rtt
,
1194 g_error(strerror(errno
));
1196 else if (retval
!= 3)
1198 g_error("Error parsing RTT file, line was '%s'", line
);
1201 rttKey
= malloc(sizeof(struct RttKey
));
1202 for (i
= 0; i
< sizeof(loopValues
) / sizeof(*loopValues
); i
++)
1204 retval
= inet_aton(loopValues
[i
].dq
, &addr
);
1207 g_error("Error converting address '%s'", loopValues
[i
].dq
);
1209 *(uint32_t*) ((void*) rttKey
+ loopValues
[i
].offset
)=
1214 g_debug("rttInfo, Inserting (%u, %u)->(%f)", rttKey
->saddr
,
1215 rttKey
->daddr
, *rtt
);
1216 g_hash_table_insert(rttInfo
, rttKey
, rtt
);
1218 positionStream(rttStream
);
1219 retval
= getline(&line
, &len
, rttStream
);
1230 * Advance stream over empty space, empty lines and lines that begin with '#'
1233 * stream: stream, at exit, will be over the first non-empty character
1234 * of a line of be at EOF
1236 static void positionStream(FILE* stream
)
1245 firstChar
= fgetc(stream
);
1246 if (firstChar
== (int) '#')
1248 retval
= getline(&line
, &len
, stream
);
1257 g_error(strerror(errno
));
1261 else if (firstChar
== (int) '\n' || firstChar
== (int) ' ' ||
1262 firstChar
== (int) '\t')
1264 else if (firstChar
== EOF
)
1273 retval
= ungetc(firstChar
, stream
);
1276 g_error("Error: ungetc()");
1288 * A GFunc for g_queue_foreach()
1291 * data Event*, a UDP broadcast event
1292 * user_data double*, the running sum
1295 * Adds the time of the event to the sum
1297 static void gfSum(gpointer data
, gpointer userData
)
1299 Event
* event
= (Event
*) data
;
1301 *(double*) userData
+= event
->wallTime
.seconds
+ event
->wallTime
.nanosec
/
1307 * A GFunc for g_queue_foreach()
1310 * data Event*, a UDP broadcast event
1311 * user_data double*, the running sum
1314 * Adds the square of the time of the event to the sum
1316 static void gfSumSquares(gpointer data
, gpointer userData
)
1318 Event
* event
= (Event
*) data
;
1320 *(double*) userData
+= pow(event
->wallTime
.seconds
+ event
->wallTime
.nanosec
1326 * Update a struct Bins according to a new value
1329 * bins: the structure containing bins to build a histrogram
1330 * value: the new value
1332 static void hitBin(struct Bins
* const bins
, const double value
)
1334 unsigned int binN
= binNum(value
);
1336 if (binN
< bins
->min
)
1340 else if (binN
> bins
->max
)
1352 * Figure out the bin in a histogram to which a value belongs.
1354 * This uses exponentially sized bins that go from 0 to infinity.
1357 * value: in the range -INFINITY to INFINITY
1360 * The number of the bin in a struct Bins.bin
1362 static unsigned int binNum(const double value
)
1368 else if (value
< binEnd(1))
1372 else if (value
>= binStart(BIN_NB
- 1))
1378 return floor(log(value
) / log(binBase
)) + BIN_NB
+ 1;
1384 * Figure out the start of the interval of a bin in a histogram. See struct
1387 * This uses exponentially sized bins that go from 0 to infinity.
1390 * binNum: bin number
1393 * The start of the interval, this value is included in the interval (except
1394 * for -INFINITY, naturally)
1396 static double binStart(const unsigned int binNum
)
1398 g_assert_cmpuint(binNum
, <, BIN_NB
);
1404 else if (binNum
== 1)
1410 return pow(binBase
, (double) binNum
- BIN_NB
+ 1);
1416 * Figure out the end of the interval of a bin in a histogram. See struct
1419 * This uses exponentially sized bins that go from 0 to infinity.
1422 * binNum: bin number
1425 * The end of the interval, this value is not included in the interval
1427 static double binEnd(const unsigned int binNum
)
1429 g_assert_cmpuint(binNum
, <, BIN_NB
);
1435 else if (binNum
< BIN_NB
- 1)
1437 return pow(binBase
, (double) binNum
- BIN_NB
+ 2);
1447 * Return the total number of elements in the "normal" bins (not underflow or
1451 * bins: the structure containing bins to build a histrogram
1453 static uint32_t normalTotal(struct Bins
* const bins
)
1455 return bins
->total
- bins
->bin
[0] - bins
->bin
[BIN_NB
- 1];
1459 /* Update the bounds between two traces
1462 * bounds: the array containing all the trace-pair bounds
1463 * e1, e2: the two related events
1465 static void updateBounds(Bounds
** const bounds
, Event
* const e1
, Event
* const
1468 unsigned int traceI
, traceJ
;
1469 uint64_t messageTime
;
1472 if (e1
->traceNum
< e2
->traceNum
)
1474 traceI
= e2
->traceNum
;
1475 traceJ
= e1
->traceNum
;
1476 messageTime
= e1
->cpuTime
;
1480 traceI
= e1
->traceNum
;
1481 traceJ
= e2
->traceNum
;
1482 messageTime
= e2
->cpuTime
;
1484 tpBounds
= &bounds
[traceI
][traceJ
];
1486 if (messageTime
< tpBounds
->min
)
1488 tpBounds
->min
= messageTime
;
1490 if (messageTime
> tpBounds
->max
)
1492 tpBounds
->max
= messageTime
;
1499 * Create the linear programming problem containing the constraints defined by
1500 * two half-hulls. The objective function and optimization directions are not
1504 * syncState: container for synchronization data
1505 * i: first trace number
1506 * j: second trace number, garanteed to be larger than i
1508 * A new glp_prob*, this problem must be freed by the caller with
1511 static glp_prob
* lpCreateProblem(GQueue
* const lowerHull
, GQueue
* const
1516 const double zeroD
= 0.;
1517 glp_prob
* lp
= glp_create_prob();
1518 unsigned int hullPointNb
= g_queue_get_length(lowerHull
) +
1519 g_queue_get_length(upperHull
);
1520 GArray
* iArray
= g_array_sized_new(FALSE
, FALSE
, sizeof(int), hullPointNb
+
1522 GArray
* jArray
= g_array_sized_new(FALSE
, FALSE
, sizeof(int), hullPointNb
+
1524 GArray
* aArray
= g_array_sized_new(FALSE
, FALSE
, sizeof(double),
1528 struct LPAddRowInfo rowInfo
;
1530 {lowerHull
, {lp
, GLP_UP
, iArray
, jArray
, aArray
}},
1531 {upperHull
, {lp
, GLP_LO
, iArray
, jArray
, aArray
}},
1534 // Create the LP problem
1535 glp_term_out(GLP_OFF
);
1536 glp_add_rows(lp
, hullPointNb
);
1537 glp_add_cols(lp
, 2);
1539 glp_set_col_name(lp
, 1, "a0");
1540 glp_set_col_bnds(lp
, 1, GLP_FR
, 0., 0.);
1541 glp_set_col_name(lp
, 2, "a1");
1542 glp_set_col_bnds(lp
, 2, GLP_LO
, 0., 0.);
1544 // Add row constraints
1545 g_array_append_val(iArray
, zero
);
1546 g_array_append_val(jArray
, zero
);
1547 g_array_append_val(aArray
, zeroD
);
1549 for (it
= 0; it
< sizeof(loopValues
) / sizeof(*loopValues
); it
++)
1551 g_queue_foreach(loopValues
[it
].hull
, &gfLPAddRow
,
1552 &loopValues
[it
].rowInfo
);
1555 g_assert_cmpuint(iArray
->len
, ==, jArray
->len
);
1556 g_assert_cmpuint(jArray
->len
, ==, aArray
->len
);
1557 g_assert_cmpuint(aArray
->len
- 1, ==, hullPointNb
* 2);
1559 glp_load_matrix(lp
, aArray
->len
- 1, &g_array_index(iArray
, int, 0),
1560 &g_array_index(jArray
, int, 0), &g_array_index(aArray
, double, 0));
1562 glp_scale_prob(lp
, GLP_SF_AUTO
);
1564 g_array_free(iArray
, TRUE
);
1565 g_array_free(jArray
, TRUE
);
1566 g_array_free(aArray
, TRUE
);
1573 * A GFunc for g_queue_foreach(). Add constraints and bounds for one row.
1576 * data Point*, synchronization point for which to add an LP row
1578 * user_data LPAddRowInfo*
1580 static void gfLPAddRow(gpointer data
, gpointer user_data
)
1583 struct LPAddRowInfo
* rowInfo
= user_data
;
1585 double constraints
[2];
1587 indexes
[0]= g_array_index(rowInfo
->iArray
, int, rowInfo
->iArray
->len
- 1) + 1;
1588 indexes
[1]= indexes
[0];
1590 if (rowInfo
->boundType
== GLP_UP
)
1592 glp_set_row_bnds(rowInfo
->lp
, indexes
[0], GLP_UP
, 0., p
->y
);
1594 else if (rowInfo
->boundType
== GLP_LO
)
1596 glp_set_row_bnds(rowInfo
->lp
, indexes
[0], GLP_LO
, p
->y
, 0.);
1600 g_assert_not_reached();
1603 g_array_append_vals(rowInfo
->iArray
, indexes
, 2);
1606 g_array_append_vals(rowInfo
->jArray
, indexes
, 2);
1608 constraints
[1]= p
->x
;
1609 g_array_append_vals(rowInfo
->aArray
, constraints
, 2);
1614 * Calculate min or max correction factors (as possible) using an LP problem.
1617 * lp: A linear programming problem with constraints and bounds
1619 * direction: The type of factors desired. Use GLP_MAX for max
1620 * approximation factors (a1, the drift or slope is the
1621 * largest) and GLP_MIN in the other case.
1624 * If the calculation was successful, a new Factors struct. Otherwise, NULL.
1625 * The calculation will fail if the hull assumptions are not respected.
1627 static Factors
* calculateFactors(glp_prob
* const lp
, const int direction
)
1632 glp_set_obj_coef(lp
, 1, 0.);
1633 glp_set_obj_coef(lp
, 2, 1.);
1635 glp_set_obj_dir(lp
, direction
);
1636 retval
= glp_simplex(lp
, NULL
);
1637 status
= glp_get_status(lp
);
1639 if (retval
== 0 && status
== GLP_OPT
)
1641 factors
= malloc(sizeof(Factors
));
1642 factors
->offset
= glp_get_col_prim(lp
, 1);
1643 factors
->drift
= glp_get_col_prim(lp
, 2);
1655 * Calculate min, max and approx correction factors (as possible) using an LP
1659 * lp: A linear programming problem with constraints and bounds
1663 * Please note that the approximation type may be MIDDLE, INCOMPLETE or
1664 * ABSENT. Unlike in analysis_chull, ABSENT is also used when the hulls do
1665 * not respect assumptions.
1667 static void calculateCompleteFactors(glp_prob
* const lp
, FactorsCHull
* factors
)
1669 factors
->min
= calculateFactors(lp
, GLP_MIN
);
1670 factors
->max
= calculateFactors(lp
, GLP_MAX
);
1672 if (factors
->min
&& factors
->max
)
1674 factors
->type
= MIDDLE
;
1675 calculateFactorsMiddle(factors
);
1677 else if (factors
->min
|| factors
->max
)
1679 factors
->type
= INCOMPLETE
;
1680 factors
->approx
= NULL
;
1684 factors
->type
= ABSENT
;
1685 factors
->approx
= NULL
;
1691 * Create and initialize an array like AnalysisStatsCHull.allFactors
1694 * traceNb: number of traces
1697 * A new array, which can be freed with freeAllFactors()
1699 static FactorsCHull
** createAllFactors(const unsigned int traceNb
)
1701 FactorsCHull
** factorsArray
;
1704 factorsArray
= malloc(traceNb
* sizeof(FactorsCHull
*));
1705 for (i
= 0; i
< traceNb
; i
++)
1707 factorsArray
[i
]= calloc((i
+ 1), sizeof(FactorsCHull
));
1709 factorsArray
[i
][i
].type
= EXACT
;
1710 factorsArray
[i
][i
].approx
= malloc(sizeof(Factors
));
1711 factorsArray
[i
][i
].approx
->drift
= 1.;
1712 factorsArray
[i
][i
].approx
->offset
= 0.;
1715 return factorsArray
;
1721 * Compute synchronization factors using a linear programming approach.
1722 * Compute the factors using analysis_chull. Compare the two.
1724 * There are two definitions of this function. The empty one is used when the
1725 * solver library, glpk, is not available at build time. In that case, nothing
1726 * is actually produced.
1729 * syncState: container for synchronization data
1731 #ifndef HAVE_LIBGLPK
1732 static inline void finalizeAnalysisEvalLP(SyncState
* const syncState
)
1736 static void finalizeAnalysisEvalLP(SyncState
* const syncState
)
1739 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
1740 AnalysisDataCHull
* chAnalysisData
= analysisData
->chullSS
->analysisData
;
1741 FactorsCHull
** lpFactorsArray
= createAllFactors(syncState
->traceNb
);
1742 FactorsCHull
* lpFactors
;
1744 if (!syncState
->stats
&& !syncState
->graphsStream
)
1749 if ((syncState
->graphsStream
&& analysisData
->graphs
->lps
!= NULL
) ||
1750 (syncState
->stats
&& analysisData
->stats
->chFactorsArray
!= NULL
))
1755 if (syncState
->stats
)
1757 analysisData
->stats
->chFactorsArray
=
1758 calculateAllFactors(analysisData
->chullSS
);
1759 analysisData
->stats
->lpFactorsArray
= lpFactorsArray
;
1762 if (syncState
->graphsStream
)
1764 analysisData
->graphs
->lps
= malloc(syncState
->traceNb
*
1765 sizeof(glp_prob
**));
1766 for (i
= 0; i
< syncState
->traceNb
; i
++)
1768 analysisData
->graphs
->lps
[i
]= malloc(i
* sizeof(glp_prob
*));
1770 analysisData
->graphs
->lpFactorsArray
= lpFactorsArray
;
1773 for (i
= 0; i
< syncState
->traceNb
; i
++)
1775 for (j
= 0; j
< i
; j
++)
1779 // Create the LP problem
1780 lp
= lpCreateProblem(chAnalysisData
->hullArray
[i
][j
],
1781 chAnalysisData
->hullArray
[j
][i
]);
1783 // Use the LP problem to find the correction factors for this pair of
1785 calculateCompleteFactors(lp
, &lpFactorsArray
[i
][j
]);
1787 if (syncState
->graphsStream
)
1789 analysisData
->graphs
->lps
[i
][j
]= lp
;
1793 glp_delete_prob(lp
);
1794 destroyFactorsCHull(lpFactors
);
1799 g_array_free(analysisData
->chullSS
->analysisModule
->finalizeAnalysis(analysisData
->chullSS
),
1806 * Compute synchronization accuracy information using a linear programming
1807 * approach. Write the neccessary data files and plot lines in the gnuplot
1810 * There are two definitions of this function. The empty one is used when the
1811 * solver library, glpk, is not available at build time. In that case, nothing
1812 * is actually produced.
1815 * syncState: container for synchronization data
1816 * i: first trace number
1817 * j: second trace number, garanteed to be larger than i
1819 #ifndef HAVE_LIBGLPK
1820 static inline void writeAccuracyGraphs(SyncState
* const syncState
, const
1821 unsigned int i
, const unsigned int j
)
1825 static void writeAccuracyGraphs(SyncState
* const syncState
, const unsigned int
1826 i
, const unsigned int j
)
1829 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
1830 AnalysisGraphsEval
* graphs
= analysisData
->graphs
;
1831 GQueue
*** hullArray
= ((AnalysisDataCHull
*)
1832 analysisData
->chullSS
->analysisData
)->hullArray
;
1833 FactorsCHull
* lpFactors
= &graphs
->lpFactorsArray
[j
][i
];
1834 glp_prob
* lp
= graphs
->lps
[j
][i
];
1836 if (lpFactors
->type
== MIDDLE
)
1843 unsigned int xBegin
, xEnd
;
1845 const unsigned int graphPointNb
= 1000;
1847 // Open the data file
1848 snprintf(fileName
, 40, "analysis_eval_accuracy-%03u_and_%03u.data", i
, j
);
1849 fileName
[sizeof(fileName
) - 1]= '\0';
1851 cwd
= changeToGraphDir(syncState
->graphsDir
);
1853 if ((fp
= fopen(fileName
, "w")) == NULL
)
1855 g_error(strerror(errno
));
1857 fprintf(fp
, "#%-24s %-25s %-25s %-25s\n", "x", "middle", "min", "max");
1862 g_error(strerror(errno
));
1866 // Build the list of absisca values for the points in the accuracy graph
1867 g_assert_cmpuint(graphPointNb
, >=, 4);
1868 xValues
= malloc(graphPointNb
* sizeof(double));
1869 xValues
[0]= graphs
->bounds
[j
][i
].min
;
1870 xValues
[graphPointNb
- 1]= graphs
->bounds
[j
][i
].max
;
1871 xValues
[1]= MIN(((Point
*) g_queue_peek_head(hullArray
[i
][j
]))->x
,
1872 ((Point
*) g_queue_peek_head(hullArray
[j
][i
]))->x
);
1873 xValues
[graphPointNb
- 2]= MAX(((Point
*)
1874 g_queue_peek_tail(hullArray
[i
][j
]))->x
, ((Point
*)
1875 g_queue_peek_tail(hullArray
[j
][i
]))->x
);
1877 if (xValues
[0] == xValues
[1])
1885 if (xValues
[graphPointNb
- 2] == xValues
[graphPointNb
- 1])
1887 xEnd
= graphPointNb
- 1;
1891 xEnd
= graphPointNb
- 2;
1893 interval
= (xValues
[xEnd
] - xValues
[xBegin
]) / (graphPointNb
- 1);
1895 for (it
= xBegin
; it
<= xEnd
; it
++)
1897 xValues
[it
]= xValues
[xBegin
] + interval
* (it
- xBegin
);
1900 /* For each absisca value and each optimisation direction, solve the LP
1901 * and write a line in the data file */
1902 for (it
= 0; it
< graphPointNb
; it
++)
1905 int directions
[]= {GLP_MIN
, GLP_MAX
};
1907 glp_set_obj_coef(lp
, 1, 1.);
1908 glp_set_obj_coef(lp
, 2, xValues
[it
]);
1910 fprintf(fp
, "%25.9f %25.9f", xValues
[it
], lpFactors
->approx
->offset
1911 + lpFactors
->approx
->drift
* xValues
[it
]);
1912 for (it2
= 0; it2
< sizeof(directions
) / sizeof(*directions
); it2
++)
1916 glp_set_obj_dir(lp
, directions
[it2
]);
1917 retval
= glp_simplex(lp
, NULL
);
1918 status
= glp_get_status(lp
);
1920 g_assert(retval
== 0 && status
== GLP_OPT
);
1921 fprintf(fp
, " %25.9f", glp_get_obj_val(lp
));
1929 fprintf(syncState
->graphsStream
,
1930 "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
1931 "using 1:(($3 - $2) / clock_freq_%2$u):(($4 - $2) / clock_freq_%2$u) "
1932 "title \"Synchronization accuracy\" "
1933 "with filledcurves linewidth 2 linetype 1 "
1934 "linecolor rgb \"black\" fill solid 0.25 noborder, \\\n", i
,
1942 * Write the analysis-specific graph lines in the gnuplot script.
1945 * syncState: container for synchronization data
1946 * i: first trace number
1947 * j: second trace number, garanteed to be larger than i
1949 static void writeAnalysisTraceTimePlotsEval(SyncState
* const syncState
, const
1950 unsigned int i
, const unsigned int j
)
1952 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
1953 AnalysisGraphsEval
* graphs
= analysisData
->graphs
;
1954 GQueue
*** hullArray
= ((AnalysisDataCHull
*)
1955 analysisData
->chullSS
->analysisData
)->hullArray
;
1957 printf("Between %u and %u:\n", i
, j
);
1958 printf("\tbounds min %llu max %llu\n", graphs
->bounds
[j
][i
].min
,
1959 graphs
->bounds
[j
][i
].max
);
1960 printf("\tnumber of points in lower half-hull %u upper half-hull %u\n",
1961 g_queue_get_length(hullArray
[j
][i
]),
1962 g_queue_get_length(hullArray
[i
][j
]));
1964 writeAccuracyGraphs(syncState
, i
, j
);
1969 * Write the analysis-specific graph lines in the gnuplot script.
1972 * syncState: container for synchronization data
1973 * i: first trace number
1974 * j: second trace number, garanteed to be larger than i
1976 static void writeAnalysisTraceTraceBackPlotsEval(SyncState
* const syncState
,
1977 const unsigned int i
, const unsigned int j
)
1980 fprintf(syncState
->graphsStream
,
1981 "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
1983 "title \"Synchronization accuracy\" "
1984 "with filledcurves linewidth 2 linetype 1 "
1985 "linecolor rgb \"black\" fill solid 0.25 noborder, \\\n", i
, j
);
1991 * Write the analysis-specific graph lines in the gnuplot script.
1994 * syncState: container for synchronization data
1995 * i: first trace number
1996 * j: second trace number, garanteed to be larger than i
1998 static void writeAnalysisTraceTraceForePlotsEval(SyncState
* const syncState
,
1999 const unsigned int i
, const unsigned int j
)
2001 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
2003 analysisData
->chullSS
->analysisModule
->graphFunctions
.writeTraceTraceForePlots(analysisData
->chullSS
,