1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2009 Benjamin Poirier <benjamin.poirier@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 #define _ISOC99_SOURCE
26 #include <arpa/inet.h>
29 #include <netinet/in.h>
34 #include <sys/socket.h>
38 #include "sync_chain.h"
39 #include "event_analysis_chull.h"
41 #include "event_analysis_eval.h"
44 struct WriteHistogramInfo
55 GArray
* iArray
, * jArray
, * aArray
;
59 // Functions common to all analysis modules
60 static void initAnalysisEval(SyncState
* const syncState
);
61 static void destroyAnalysisEval(SyncState
* const syncState
);
63 static void analyzeMessageEval(SyncState
* const syncState
, Message
* const
65 static void analyzeExchangeEval(SyncState
* const syncState
, Exchange
* const
67 static void analyzeBroadcastEval(SyncState
* const syncState
, Broadcast
* const
69 static GArray
* finalizeAnalysisEval(SyncState
* const syncState
);
70 static void printAnalysisStatsEval(SyncState
* const syncState
);
71 static void writeAnalysisTraceTimeBackPlotsEval(SyncState
* const syncState
,
72 const unsigned int i
, const unsigned int j
);
73 static void writeAnalysisTraceTimeForePlotsEval(SyncState
* const syncState
,
74 const unsigned int i
, const unsigned int j
);
75 static void writeAnalysisTraceTraceBackPlotsEval(SyncState
* const syncState
,
76 const unsigned int i
, const unsigned int j
);
77 static void writeAnalysisTraceTraceForePlotsEval(SyncState
* const syncState
,
78 const unsigned int i
, const unsigned int j
);
80 // Functions specific to this module
81 static guint
ghfRttKeyHash(gconstpointer key
);
82 static gboolean
gefRttKeyEqual(gconstpointer a
, gconstpointer b
);
83 static void gdnDestroyRttKey(gpointer data
);
84 static void gdnDestroyDouble(gpointer data
);
85 static void readRttInfo(GHashTable
* rttInfo
, FILE* rttFile
);
86 static void positionStream(FILE* stream
);
88 static void gfSum(gpointer data
, gpointer userData
);
89 static void gfSumSquares(gpointer data
, gpointer userData
);
90 static void ghfPrintExchangeRtt(gpointer key
, gpointer value
, gpointer
93 static void hitBin(struct Bins
* const bins
, const double value
);
94 static unsigned int binNum(const double value
) __attribute__((pure
));
95 static double binStart(const unsigned int binNum
) __attribute__((pure
));
96 static double binEnd(const unsigned int binNum
) __attribute__((pure
));
97 static uint32_t normalTotal(struct Bins
* const bins
) __attribute__((const));
99 static AnalysisHistogramEval
* constructAnalysisHistogramEval(const char* const
100 graphsDir
, const struct RttKey
* const rttKey
);
101 static void destroyAnalysisHistogramEval(AnalysisHistogramEval
* const
103 static void gdnDestroyAnalysisHistogramEval(gpointer data
);
104 static void ghfWriteHistogram(gpointer key
, gpointer value
, gpointer
106 static void dumpBinToFile(const struct Bins
* const bins
, FILE* const file
);
107 static void writeHistogram(FILE* graphsStream
, const struct RttKey
* rttKey
,
108 double* minRtt
, AnalysisHistogramEval
* const histogram
);
110 static void updateBounds(Bounds
** const bounds
, Event
* const e1
, Event
* const
113 static void finalizeAnalysisEvalLP(SyncState
* const syncState
);
114 // The next group of functions is only needed when computing synchronization
117 static glp_prob
* lpCreateProblem(GQueue
* const lowerHull
, GQueue
* const
119 static void gfLPAddRow(gpointer data
, gpointer user_data
);
120 static Factors
* calculateFactors(glp_prob
* const lp
, const int direction
);
121 static void calculateCompleteFactors(glp_prob
* const lp
, FactorsCHull
*
123 static FactorsCHull
** createAllFactors(const unsigned int traceNb
);
127 // initialized in registerAnalysisEval()
130 static AnalysisModule analysisModuleEval
= {
132 .initAnalysis
= &initAnalysisEval
,
133 .destroyAnalysis
= &destroyAnalysisEval
,
134 .analyzeMessage
= &analyzeMessageEval
,
135 .analyzeExchange
= &analyzeExchangeEval
,
136 .analyzeBroadcast
= &analyzeBroadcastEval
,
137 .finalizeAnalysis
= &finalizeAnalysisEval
,
138 .printAnalysisStats
= &printAnalysisStatsEval
,
140 .writeTraceTimeBackPlots
= &writeAnalysisTraceTimeBackPlotsEval
,
141 .writeTraceTimeForePlots
= &writeAnalysisTraceTimeForePlotsEval
,
142 .writeTraceTraceBackPlots
= &writeAnalysisTraceTraceBackPlotsEval
,
143 .writeTraceTraceForePlots
= &writeAnalysisTraceTraceForePlotsEval
,
147 static ModuleOption optionEvalRttFile
= {
148 .longName
= "eval-rtt-file",
149 .hasArg
= REQUIRED_ARG
,
150 .optionHelp
= "specify the file containing RTT information",
156 * Analysis module registering function
158 void registerAnalysisEval()
160 binBase
= exp10(6. / (BIN_NB
- 3));
162 g_queue_push_tail(&analysisModules
, &analysisModuleEval
);
163 g_queue_push_tail(&moduleOptions
, &optionEvalRttFile
);
168 * Analysis init function
170 * This function is called at the beginning of a synchronization run for a set
174 * syncState container for synchronization data.
176 static void initAnalysisEval(SyncState
* const syncState
)
178 AnalysisDataEval
* analysisData
;
181 analysisData
= malloc(sizeof(AnalysisDataEval
));
182 syncState
->analysisData
= analysisData
;
184 analysisData
->rttInfo
= g_hash_table_new_full(&ghfRttKeyHash
,
185 &gefRttKeyEqual
, &gdnDestroyRttKey
, &gdnDestroyDouble
);
186 if (optionEvalRttFile
.arg
)
191 rttStream
= fopen(optionEvalRttFile
.arg
, "r");
192 if (rttStream
== NULL
)
194 g_error(strerror(errno
));
197 readRttInfo(analysisData
->rttInfo
, rttStream
);
199 retval
= fclose(rttStream
);
202 g_error(strerror(errno
));
206 if (syncState
->stats
)
208 analysisData
->stats
= calloc(1, sizeof(AnalysisStatsEval
));
209 analysisData
->stats
->broadcastDiffSum
= 0.;
211 analysisData
->stats
->messageStats
= malloc(syncState
->traceNb
*
212 sizeof(MessageStats
*));
213 for (i
= 0; i
< syncState
->traceNb
; i
++)
215 analysisData
->stats
->messageStats
[i
]= calloc(syncState
->traceNb
,
216 sizeof(MessageStats
));
219 analysisData
->stats
->exchangeRtt
=
220 g_hash_table_new_full(&ghfRttKeyHash
, &gefRttKeyEqual
,
221 &gdnDestroyRttKey
, &gdnDestroyDouble
);
224 analysisData
->stats
->chFactorsArray
= NULL
;
225 analysisData
->stats
->lpFactorsArray
= NULL
;
229 if (syncState
->graphsStream
)
231 AnalysisGraphsEval
* graphs
= malloc(sizeof(AnalysisGraphsEval
));
233 analysisData
->graphs
= graphs
;
235 graphs
->histograms
= g_hash_table_new_full(&ghfRttKeyHash
,
236 &gefRttKeyEqual
, &gdnDestroyRttKey
,
237 &gdnDestroyAnalysisHistogramEval
);
239 graphs
->bounds
= malloc(syncState
->traceNb
* sizeof(Bounds
*));
240 for (i
= 0; i
< syncState
->traceNb
; i
++)
242 graphs
->bounds
[i
]= malloc(i
* sizeof(Bounds
));
243 for (j
= 0; j
< i
; j
++)
245 graphs
->bounds
[i
][j
].min
= UINT64_MAX
;
246 graphs
->bounds
[i
][j
].max
= 0;
252 graphs
->lpFactorsArray
= NULL
;
256 if (syncState
->stats
|| syncState
->graphsStream
)
260 analysisData
->chullSS
= malloc(sizeof(SyncState
));
261 memcpy(analysisData
->chullSS
, syncState
, sizeof(SyncState
));
262 analysisData
->chullSS
->stats
= false;
263 analysisData
->chullSS
->analysisData
= NULL
;
264 result
= g_queue_find_custom(&analysisModules
, "chull",
265 &gcfCompareAnalysis
);
266 analysisData
->chullSS
->analysisModule
= (AnalysisModule
*) result
->data
;
267 analysisData
->chullSS
->analysisModule
->initAnalysis(analysisData
->chullSS
);
273 * Create and open files used to store histogram points to generate graphs.
274 * Create data structures to store histogram points during analysis.
277 * graphsDir: folder where to write files
278 * rttKey: host pair, make sure saddr < daddr
280 static AnalysisHistogramEval
* constructAnalysisHistogramEval(const char* const
281 graphsDir
, const struct RttKey
* const rttKey
)
286 char name
[60], saddr
[16], daddr
[16];
287 AnalysisHistogramEval
* histogram
= calloc(1, sizeof(*histogram
));
290 const char* fileName
;
291 const char* host1
, *host2
;
293 {offsetof(AnalysisHistogramEval
, ttSendPoints
),
294 "analysis_eval_tt-%s_to_%s.data", saddr
, daddr
},
295 {offsetof(AnalysisHistogramEval
, ttRecvPoints
),
296 "analysis_eval_tt-%s_to_%s.data", daddr
, saddr
},
297 {offsetof(AnalysisHistogramEval
, hrttPoints
),
298 "analysis_eval_hrtt-%s_and_%s.data", saddr
, daddr
},
301 histogram
->ttSendBins
.min
= BIN_NB
- 1;
302 histogram
->ttRecvBins
.min
= BIN_NB
- 1;
303 histogram
->hrttBins
.min
= BIN_NB
- 1;
305 convertIP(saddr
, rttKey
->saddr
);
306 convertIP(daddr
, rttKey
->daddr
);
308 cwd
= changeToGraphsDir(graphsDir
);
310 for (i
= 0; i
< sizeof(loopValues
) / sizeof(*loopValues
); i
++)
312 retval
= snprintf(name
, sizeof(name
), loopValues
[i
].fileName
,
313 loopValues
[i
].host1
, loopValues
[i
].host2
);
314 if (retval
> sizeof(name
) - 1)
316 name
[sizeof(name
) - 1]= '\0';
318 if ((*(FILE**)((void*) histogram
+ loopValues
[i
].pointsOffset
)=
319 fopen(name
, "w")) == NULL
)
321 g_error(strerror(errno
));
328 g_error(strerror(errno
));
337 * Close files used to store histogram points to generate graphs.
340 * graphsDir: folder where to write files
341 * rttKey: host pair, make sure saddr < daddr
343 static void destroyAnalysisHistogramEval(AnalysisHistogramEval
* const
351 {offsetof(AnalysisHistogramEval
, ttSendPoints
)},
352 {offsetof(AnalysisHistogramEval
, ttRecvPoints
)},
353 {offsetof(AnalysisHistogramEval
, hrttPoints
)},
356 for (i
= 0; i
< sizeof(loopValues
) / sizeof(*loopValues
); i
++)
358 retval
= fclose(*(FILE**)((void*) histogram
+ loopValues
[i
].pointsOffset
));
361 g_error(strerror(errno
));
370 * A GDestroyNotify function for g_hash_table_new_full()
373 * data: AnalysisHistogramEval*
375 static void gdnDestroyAnalysisHistogramEval(gpointer data
)
377 destroyAnalysisHistogramEval(data
);
382 * A GHFunc for g_hash_table_foreach()
385 * key: RttKey* where saddr < daddr
386 * value: AnalysisHistogramEval*
387 * user_data struct WriteHistogramInfo*
389 static void ghfWriteHistogram(gpointer key
, gpointer value
, gpointer user_data
)
391 double* rtt1
, * rtt2
;
392 struct RttKey
* rttKey
= key
;
393 struct RttKey oppositeRttKey
= {.saddr
= rttKey
->daddr
, .daddr
=
395 AnalysisHistogramEval
* histogram
= value
;
396 struct WriteHistogramInfo
* info
= user_data
;
398 rtt1
= g_hash_table_lookup(info
->rttInfo
, rttKey
);
399 rtt2
= g_hash_table_lookup(info
->rttInfo
, &oppositeRttKey
);
405 else if (rtt2
!= NULL
)
407 rtt1
= MIN(rtt1
, rtt2
);
410 dumpBinToFile(&histogram
->ttSendBins
, histogram
->ttSendPoints
);
411 dumpBinToFile(&histogram
->ttRecvBins
, histogram
->ttRecvPoints
);
412 dumpBinToFile(&histogram
->hrttBins
, histogram
->hrttPoints
);
413 writeHistogram(info
->graphsStream
, rttKey
, rtt1
, histogram
);
418 * Write the content of one bin in a histogram point file
421 * bin: array of values that make up a histogram
422 * file: FILE*, write to this file
424 static void dumpBinToFile(const struct Bins
* const bins
, FILE* const file
)
428 // The first and last bins are skipped, see struct Bins
429 for (i
= 1; i
< BIN_NB
- 1; i
++)
431 if (bins
->bin
[i
] > 0)
433 fprintf(file
, "%20.9f %20.9f %20.9f\n", (binStart(i
) + binEnd(i
))
434 / 2., (double) bins
->bin
[i
] / ((binEnd(i
) - binStart(i
)) *
435 bins
->total
), binEnd(i
) - binStart(i
));
442 * Write the analysis-specific plot in the gnuplot script.
445 * graphsStream: write to this file
446 * rttKey: must be sorted such that saddr < daddr
447 * minRtt: if available, else NULL
448 * histogram: struct that contains the bins for the pair of traces
449 * identified by rttKey
451 static void writeHistogram(FILE* graphsStream
, const struct RttKey
* rttKey
,
452 double* minRtt
, AnalysisHistogramEval
* const histogram
)
454 char saddr
[16], daddr
[16];
456 convertIP(saddr
, rttKey
->saddr
);
457 convertIP(daddr
, rttKey
->daddr
);
459 fprintf(graphsStream
,
461 "set output \"histogram-%s-%s.eps\"\n"
463 "set xlabel \"Message Latency (s)\"\n"
464 "set ylabel \"Proportion of messages per second\"\n", saddr
, daddr
);
468 fprintf(graphsStream
,
469 "set arrow from %.9f, 0 rto 0, graph 1 "
470 "nohead linetype 3 linewidth 3 linecolor rgb \"black\"\n", *minRtt
474 if (normalTotal(&histogram
->ttSendBins
) ||
475 normalTotal(&histogram
->ttRecvBins
) ||
476 normalTotal(&histogram
->hrttBins
))
478 fprintf(graphsStream
, "plot \\\n");
480 if (normalTotal(&histogram
->hrttBins
))
482 fprintf(graphsStream
,
483 "\t\"analysis_eval_hrtt-%s_and_%s.data\" "
484 "title \"RTT/2\" with linespoints linetype 1 linewidth 2 "
485 "linecolor rgb \"black\" pointtype 6 pointsize 1,\\\n",
489 if (normalTotal(&histogram
->ttSendBins
))
491 fprintf(graphsStream
,
492 "\t\"analysis_eval_tt-%1$s_to_%2$s.data\" "
493 "title \"%1$s to %2$s\" with linespoints linetype 4 linewidth 2 "
494 "linecolor rgb \"gray60\" pointtype 6 pointsize 1,\\\n",
498 if (normalTotal(&histogram
->ttRecvBins
))
500 fprintf(graphsStream
,
501 "\t\"analysis_eval_tt-%1$s_to_%2$s.data\" "
502 "title \"%1$s to %2$s\" with linespoints linetype 4 linewidth 2 "
503 "linecolor rgb \"gray30\" pointtype 6 pointsize 1,\\\n",
507 // Remove the ",\\\n" from the last graph plot line
508 if (ftruncate(fileno(graphsStream
), ftell(graphsStream
) - 3) == -1)
510 g_error(strerror(errno
));
512 if (fseek(graphsStream
, 0, SEEK_END
) == -1)
514 g_error(strerror(errno
));
516 fprintf(graphsStream
, "\n");
522 * Analysis destroy function
524 * Free the analysis specific data structures
527 * syncState container for synchronization data.
529 static void destroyAnalysisEval(SyncState
* const syncState
)
532 AnalysisDataEval
* analysisData
;
534 analysisData
= (AnalysisDataEval
*) syncState
->analysisData
;
536 if (analysisData
== NULL
)
541 g_hash_table_destroy(analysisData
->rttInfo
);
543 if (syncState
->stats
)
545 AnalysisStatsEval
* stats
= analysisData
->stats
;
547 for (i
= 0; i
< syncState
->traceNb
; i
++)
549 free(stats
->messageStats
[i
]);
551 free(stats
->messageStats
);
553 g_hash_table_destroy(stats
->exchangeRtt
);
556 freeAllFactors(syncState
->traceNb
, stats
->chFactorsArray
);
557 freeAllFactors(syncState
->traceNb
, stats
->lpFactorsArray
);
563 if (syncState
->graphsStream
)
565 AnalysisGraphsEval
* graphs
= analysisData
->graphs
;
567 if (graphs
->histograms
)
569 g_hash_table_destroy(graphs
->histograms
);
572 for (i
= 0; i
< syncState
->traceNb
; i
++)
574 free(graphs
->bounds
[i
]);
576 free(graphs
->bounds
);
579 for (i
= 0; i
< syncState
->traceNb
; i
++)
583 for (j
= 0; j
< i
; j
++)
585 // There seems to be a memory leak in glpk, valgrind reports a
586 // loss (reachable) even if the problem is deleted
587 glp_delete_prob(graphs
->lps
[i
][j
]);
589 free(graphs
->lps
[i
]);
593 if (!syncState
->stats
)
595 freeAllFactors(syncState
->traceNb
, graphs
->lpFactorsArray
);
602 if (syncState
->stats
|| syncState
->graphsStream
)
604 analysisData
->chullSS
->analysisModule
->destroyAnalysis(analysisData
->chullSS
);
605 free(analysisData
->chullSS
);
608 free(syncState
->analysisData
);
609 syncState
->analysisData
= NULL
;
614 * Perform analysis on an event pair.
616 * Check if there is message inversion or messages that are too fast.
619 * syncState container for synchronization data
620 * message structure containing the events
622 static void analyzeMessageEval(SyncState
* const syncState
, Message
* const
625 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
626 MessageStats
* messageStats
;
629 struct RttKey rttKey
;
631 g_assert(message
->inE
->type
== TCP
);
633 if (syncState
->stats
)
636 &analysisData
->stats
->messageStats
[message
->outE
->traceNum
][message
->inE
->traceNum
];
637 messageStats
->total
++;
640 tt
= wallTimeSub(&message
->inE
->wallTime
, &message
->outE
->wallTime
);
643 if (syncState
->stats
)
645 messageStats
->inversionNb
++;
648 else if (syncState
->graphsStream
)
650 struct RttKey rttKey
= {
651 .saddr
=MIN(message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
,
652 message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
),
653 .daddr
=MAX(message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
,
654 message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
),
656 AnalysisHistogramEval
* histogram
=
657 g_hash_table_lookup(analysisData
->graphs
->histograms
, &rttKey
);
659 if (histogram
== NULL
)
661 struct RttKey
* tableKey
= malloc(sizeof(*tableKey
));
663 histogram
= constructAnalysisHistogramEval(syncState
->graphsDir
, &rttKey
);
664 memcpy(tableKey
, &rttKey
, sizeof(*tableKey
));
665 g_hash_table_insert(analysisData
->graphs
->histograms
, tableKey
, histogram
);
668 if (message
->inE
->event
.udpEvent
->datagramKey
->saddr
<
669 message
->inE
->event
.udpEvent
->datagramKey
->daddr
)
671 hitBin(&histogram
->ttSendBins
, tt
);
675 hitBin(&histogram
->ttRecvBins
, tt
);
679 if (syncState
->stats
)
682 message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
;
684 message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
;
685 rtt
= g_hash_table_lookup(analysisData
->rttInfo
, &rttKey
);
686 g_debug("rttInfo, looking up (%u, %u)->(%f)", rttKey
.saddr
,
687 rttKey
.daddr
, rtt
? *rtt
: NAN
);
691 g_debug("rttInfo, tt: %f rtt / 2: %f", tt
, *rtt
/ 2.);
694 messageStats
->tooFastNb
++;
699 messageStats
->noRTTInfoNb
++;
703 if (syncState
->graphsStream
)
705 updateBounds(analysisData
->graphs
->bounds
, message
->inE
,
709 if (syncState
->stats
|| syncState
->graphsStream
)
711 analysisData
->chullSS
->analysisModule
->analyzeMessage(analysisData
->chullSS
,
718 * Perform analysis on multiple messages
723 * syncState container for synchronization data
724 * exchange structure containing the messages
726 static void analyzeExchangeEval(SyncState
* const syncState
, Exchange
* const
729 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
730 Message
* m1
= g_queue_peek_tail(exchange
->acks
);
731 Message
* m2
= exchange
->message
;
732 struct RttKey
* rttKey
;
733 double* rtt
, * exchangeRtt
;
735 g_assert(m1
->inE
->type
== TCP
);
737 // (T2 - T1) - (T3 - T4)
738 rtt
= malloc(sizeof(double));
739 *rtt
= wallTimeSub(&m1
->inE
->wallTime
, &m1
->outE
->wallTime
) -
740 wallTimeSub(&m2
->outE
->wallTime
, &m2
->inE
->wallTime
);
742 rttKey
= malloc(sizeof(struct RttKey
));
744 MIN(m1
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
,
745 m1
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
);
747 MAX(m1
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
,
748 m1
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
);
750 if (syncState
->graphsStream
)
752 AnalysisHistogramEval
* histogram
=
753 g_hash_table_lookup(analysisData
->graphs
->histograms
, rttKey
);
755 if (histogram
== NULL
)
757 struct RttKey
* tableKey
= malloc(sizeof(*tableKey
));
759 histogram
= constructAnalysisHistogramEval(syncState
->graphsDir
,
761 memcpy(tableKey
, rttKey
, sizeof(*tableKey
));
762 g_hash_table_insert(analysisData
->graphs
->histograms
, tableKey
,
766 hitBin(&histogram
->hrttBins
, *rtt
/ 2);
769 if (syncState
->stats
)
771 exchangeRtt
= g_hash_table_lookup(analysisData
->stats
->exchangeRtt
,
776 if (*rtt
< *exchangeRtt
)
778 g_hash_table_replace(analysisData
->stats
->exchangeRtt
, rttKey
, rtt
);
788 g_hash_table_insert(analysisData
->stats
->exchangeRtt
, rttKey
, rtt
);
800 * Perform analysis on muliple events
802 * Sum the broadcast differential delays
805 * syncState container for synchronization data
806 * broadcast structure containing the events
808 static void analyzeBroadcastEval(SyncState
* const syncState
, Broadcast
* const
811 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
813 if (syncState
->stats
)
815 double sum
= 0, squaresSum
= 0;
818 g_queue_foreach(broadcast
->events
, &gfSum
, &sum
);
819 g_queue_foreach(broadcast
->events
, &gfSumSquares
, &squaresSum
);
821 analysisData
->stats
->broadcastNb
++;
822 // Because of numerical errors, this can at times be < 0
823 y
= squaresSum
/ g_queue_get_length(broadcast
->events
) - pow(sum
/
824 g_queue_get_length(broadcast
->events
), 2.);
827 analysisData
->stats
->broadcastDiffSum
+= sqrt(y
);
831 if (syncState
->graphsStream
)
835 unsigned int eventNb
= broadcast
->events
->length
;
837 events
= g_array_sized_new(FALSE
, FALSE
, sizeof(Event
*), eventNb
);
838 g_queue_foreach(broadcast
->events
, &gfAddEventToArray
, events
);
840 for (i
= 0; i
< eventNb
; i
++)
842 for (j
= 0; j
< eventNb
; j
++)
844 Event
* eventI
= g_array_index(events
, Event
*, i
), * eventJ
=
845 g_array_index(events
, Event
*, j
);
847 if (eventI
->traceNum
< eventJ
->traceNum
)
849 updateBounds(analysisData
->graphs
->bounds
, eventI
, eventJ
);
854 g_array_free(events
, TRUE
);
860 * Finalize the factor calculations. Since this module does not really
861 * calculate factors, identity factors are returned. Instead, histograms are
862 * written out and histogram structures are freed.
865 * syncState container for synchronization data.
868 * Factors[traceNb] identity factors for each trace
870 static GArray
* finalizeAnalysisEval(SyncState
* const syncState
)
874 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
876 if (syncState
->graphsStream
&& analysisData
->graphs
->histograms
)
878 g_hash_table_foreach(analysisData
->graphs
->histograms
,
879 &ghfWriteHistogram
, &(struct WriteHistogramInfo
) {.rttInfo
=
880 analysisData
->rttInfo
, .graphsStream
= syncState
->graphsStream
});
881 g_hash_table_destroy(analysisData
->graphs
->histograms
);
882 analysisData
->graphs
->histograms
= NULL
;
885 finalizeAnalysisEvalLP(syncState
);
887 factors
= g_array_sized_new(FALSE
, FALSE
, sizeof(Factors
),
889 g_array_set_size(factors
, syncState
->traceNb
);
890 for (i
= 0; i
< syncState
->traceNb
; i
++)
894 e
= &g_array_index(factors
, Factors
, i
);
904 * Print statistics related to analysis. Must be called after
908 * syncState container for synchronization data.
910 static void printAnalysisStatsEval(SyncState
* const syncState
)
912 AnalysisDataEval
* analysisData
;
913 unsigned int i
, j
, k
;
914 unsigned int totInversion
= 0, totTooFast
= 0, totNoInfo
= 0, totTotal
= 0;
917 if (!syncState
->stats
)
922 analysisData
= (AnalysisDataEval
*) syncState
->analysisData
;
924 printf("Synchronization evaluation analysis stats:\n");
925 if (analysisData
->stats
->broadcastNb
)
927 printf("\tsum of broadcast differential delays: %g\n",
928 analysisData
->stats
->broadcastDiffSum
);
929 printf("\taverage broadcast differential delay: %g\n",
930 analysisData
->stats
->broadcastDiffSum
/
931 analysisData
->stats
->broadcastNb
);
934 printf("\tIndividual evaluation:\n"
935 "\t\tTrace pair Inversions Too fast No RTT info Total\n");
937 for (i
= 0; i
< syncState
->traceNb
; i
++)
939 for (j
= i
+ 1; j
< syncState
->traceNb
; j
++)
941 MessageStats
* messageStats
;
949 for (k
= 0; k
< sizeof(loopValues
) / sizeof(*loopValues
); k
++)
952 &analysisData
->stats
->messageStats
[loopValues
[k
].t1
][loopValues
[k
].t2
];
954 printf("\t\t%3d - %-3d ", loopValues
[k
].t1
, loopValues
[k
].t2
);
955 printf("%u (%u%%)%n", messageStats
->inversionNb
, (unsigned
956 int) ceil((double) messageStats
->inversionNb
/
957 messageStats
->total
* 100), &charNb
);
958 printf("%*s", 17 - charNb
> 0 ? 17 - charNb
+ 1: 1, " ");
959 printf("%u (%u%%)%n", messageStats
->tooFastNb
, (unsigned int)
960 ceil((double) messageStats
->tooFastNb
/
961 messageStats
->total
* 100), &charNb
);
962 printf("%*s%-10u %u\n", 17 - charNb
> 0 ? 17 - charNb
+ 1:
963 1, " ", messageStats
->noRTTInfoNb
, messageStats
->total
);
965 totInversion
+= messageStats
->inversionNb
;
966 totTooFast
+= messageStats
->tooFastNb
;
967 totNoInfo
+= messageStats
->noRTTInfoNb
;
968 totTotal
+= messageStats
->total
;
973 printf("\t\t total ");
974 printf("%u (%u%%)%n", totInversion
, (unsigned int) ceil((double)
975 totInversion
/ totTotal
* 100), &charNb
);
976 printf("%*s", 17 - charNb
> 0 ? 17 - charNb
+ 1: 1, " ");
977 printf("%u (%u%%)%n", totTooFast
, (unsigned int) ceil((double) totTooFast
978 / totTotal
* 100), &charNb
);
979 printf("%*s%-10u %u\n", 17 - charNb
> 0 ? 17 - charNb
+ 1: 1, " ",
980 totNoInfo
, totTotal
);
982 printf("\tRound-trip times:\n"
983 "\t\tHost pair RTT from exchanges RTTs from file (ms)\n");
984 g_hash_table_foreach(analysisData
->stats
->exchangeRtt
,
985 &ghfPrintExchangeRtt
, analysisData
->rttInfo
);
988 printf("\tConvex hull factors comparisons:\n"
989 "\t\tTrace pair Factors type Differences (lp - chull)\n"
991 "\t\t Min Max Min Max\n");
993 for (i
= 0; i
< syncState
->traceNb
; i
++)
995 for (j
= 0; j
< i
; j
++)
997 FactorsCHull
* chFactors
= &analysisData
->stats
->chFactorsArray
[i
][j
];
998 FactorsCHull
* lpFactors
= &analysisData
->stats
->lpFactorsArray
[i
][j
];
1000 printf("\t\t%3d - %-3d ", i
, j
);
1001 if (lpFactors
->type
== chFactors
->type
)
1003 if (lpFactors
->type
== MIDDLE
)
1005 printf("%-13s %-10.4g %-10.4g %-10.4g %.4g\n",
1006 approxNames
[lpFactors
->type
],
1007 lpFactors
->min
->offset
- chFactors
->min
->offset
,
1008 lpFactors
->max
->offset
- chFactors
->max
->offset
,
1009 lpFactors
->min
->drift
- chFactors
->min
->drift
,
1010 lpFactors
->max
->drift
- chFactors
->max
->drift
);
1012 else if (lpFactors
->type
== ABSENT
)
1014 printf("%s\n", approxNames
[lpFactors
->type
]);
1019 printf("Different! %s and %s\n", approxNames
[lpFactors
->type
],
1020 approxNames
[chFactors
->type
]);
1029 * A GHFunc for g_hash_table_foreach()
1032 * key: RttKey* where saddr < daddr
1033 * value: double*, RTT estimated from exchanges
1034 * user_data GHashTable* rttInfo
1036 static void ghfPrintExchangeRtt(gpointer key
, gpointer value
, gpointer
1039 char addr1
[16], addr2
[16];
1040 struct RttKey
* rttKey1
= key
;
1041 struct RttKey rttKey2
= {rttKey1
->daddr
, rttKey1
->saddr
};
1042 double* fileRtt1
, *fileRtt2
;
1043 GHashTable
* rttInfo
= user_data
;
1045 convertIP(addr1
, rttKey1
->saddr
);
1046 convertIP(addr2
, rttKey1
->daddr
);
1048 fileRtt1
= g_hash_table_lookup(rttInfo
, rttKey1
);
1049 fileRtt2
= g_hash_table_lookup(rttInfo
, &rttKey2
);
1051 printf("\t\t(%15s, %-15s) %-18.3f ", addr1
, addr2
, *(double*) value
* 1e3
);
1053 if (fileRtt1
|| fileRtt2
)
1057 printf("%.3f", *fileRtt1
* 1e3
);
1059 if (fileRtt1
&& fileRtt2
)
1065 printf("%.3f", *fileRtt2
* 1e3
);
1077 * A GHashFunc for g_hash_table_new()
1080 * key struct RttKey*
1082 static guint
ghfRttKeyHash(gconstpointer key
)
1084 struct RttKey
* rttKey
;
1087 rttKey
= (struct RttKey
*) key
;
1099 * A GDestroyNotify function for g_hash_table_new_full()
1102 * data: struct RttKey*
1104 static void gdnDestroyRttKey(gpointer data
)
1111 * A GDestroyNotify function for g_hash_table_new_full()
1116 static void gdnDestroyDouble(gpointer data
)
1123 * A GEqualFunc for g_hash_table_new()
1129 * TRUE if both values are equal
1131 static gboolean
gefRttKeyEqual(gconstpointer a
, gconstpointer b
)
1133 const struct RttKey
* rkA
, * rkB
;
1135 rkA
= (struct RttKey
*) a
;
1136 rkB
= (struct RttKey
*) b
;
1138 if (rkA
->saddr
== rkB
->saddr
&& rkA
->daddr
== rkB
->daddr
)
1150 * Read a file contain minimum round trip time values and fill an array with
1151 * them. The file is formatted as such:
1152 * <host1 IP> <host2 IP> <RTT in milliseconds>
1153 * ip's should be in dotted quad format
1156 * rttInfo: double* rttInfo[RttKey], empty table, will be filled
1157 * rttStream: stream from which to read
1159 static void readRttInfo(GHashTable
* rttInfo
, FILE* rttStream
)
1165 positionStream(rttStream
);
1166 retval
= getline(&line
, &len
, rttStream
);
1167 while(!feof(rttStream
))
1169 struct RttKey
* rttKey
;
1170 char saddrDQ
[20], daddrDQ
[20];
1173 struct in_addr addr
;
1179 {saddrDQ
, offsetof(struct RttKey
, saddr
)},
1180 {daddrDQ
, offsetof(struct RttKey
, daddr
)}
1183 if (retval
== -1 && !feof(rttStream
))
1185 g_error(strerror(errno
));
1188 if (line
[retval
- 1] == '\n')
1190 line
[retval
- 1]= '\0';
1193 rtt
= malloc(sizeof(double));
1194 retval
= sscanf(line
, " %19s %19s %lf %c", saddrDQ
, daddrDQ
, rtt
,
1198 g_error(strerror(errno
));
1200 else if (retval
!= 3)
1202 g_error("Error parsing RTT file, line was '%s'", line
);
1205 rttKey
= malloc(sizeof(struct RttKey
));
1206 for (i
= 0; i
< sizeof(loopValues
) / sizeof(*loopValues
); i
++)
1208 retval
= inet_aton(loopValues
[i
].dq
, &addr
);
1211 g_error("Error converting address '%s'", loopValues
[i
].dq
);
1213 *(uint32_t*) ((void*) rttKey
+ loopValues
[i
].offset
)=
1218 g_debug("rttInfo, Inserting (%u, %u)->(%f)", rttKey
->saddr
,
1219 rttKey
->daddr
, *rtt
);
1220 g_hash_table_insert(rttInfo
, rttKey
, rtt
);
1222 positionStream(rttStream
);
1223 retval
= getline(&line
, &len
, rttStream
);
1234 * Advance stream over empty space, empty lines and lines that begin with '#'
1237 * stream: stream, at exit, will be over the first non-empty character
1238 * of a line of be at EOF
1240 static void positionStream(FILE* stream
)
1249 firstChar
= fgetc(stream
);
1250 if (firstChar
== (int) '#')
1252 retval
= getline(&line
, &len
, stream
);
1261 g_error(strerror(errno
));
1265 else if (firstChar
== (int) '\n' || firstChar
== (int) ' ' ||
1266 firstChar
== (int) '\t')
1268 else if (firstChar
== EOF
)
1277 retval
= ungetc(firstChar
, stream
);
1280 g_error("Error: ungetc()");
1292 * A GFunc for g_queue_foreach()
1295 * data Event*, a UDP broadcast event
1296 * user_data double*, the running sum
1299 * Adds the time of the event to the sum
1301 static void gfSum(gpointer data
, gpointer userData
)
1303 Event
* event
= (Event
*) data
;
1305 *(double*) userData
+= event
->wallTime
.seconds
+ event
->wallTime
.nanosec
/
1311 * A GFunc for g_queue_foreach()
1314 * data Event*, a UDP broadcast event
1315 * user_data double*, the running sum
1318 * Adds the square of the time of the event to the sum
1320 static void gfSumSquares(gpointer data
, gpointer userData
)
1322 Event
* event
= (Event
*) data
;
1324 *(double*) userData
+= pow(event
->wallTime
.seconds
+ event
->wallTime
.nanosec
1330 * Update a struct Bins according to a new value
1333 * bins: the structure containing bins to build a histrogram
1334 * value: the new value
1336 static void hitBin(struct Bins
* const bins
, const double value
)
1338 unsigned int binN
= binNum(value
);
1340 if (binN
< bins
->min
)
1344 else if (binN
> bins
->max
)
1356 * Figure out the bin in a histogram to which a value belongs.
1358 * This uses exponentially sized bins that go from 0 to infinity.
1361 * value: in the range -INFINITY to INFINITY
1364 * The number of the bin in a struct Bins.bin
1366 static unsigned int binNum(const double value
)
1372 else if (value
< binEnd(1))
1376 else if (value
>= binStart(BIN_NB
- 1))
1382 return floor(log(value
) / log(binBase
)) + BIN_NB
+ 1;
1388 * Figure out the start of the interval of a bin in a histogram. See struct
1391 * This uses exponentially sized bins that go from 0 to infinity.
1394 * binNum: bin number
1397 * The start of the interval, this value is included in the interval (except
1398 * for -INFINITY, naturally)
1400 static double binStart(const unsigned int binNum
)
1402 g_assert_cmpuint(binNum
, <, BIN_NB
);
1408 else if (binNum
== 1)
1414 return pow(binBase
, (double) binNum
- BIN_NB
+ 1);
1420 * Figure out the end of the interval of a bin in a histogram. See struct
1423 * This uses exponentially sized bins that go from 0 to infinity.
1426 * binNum: bin number
1429 * The end of the interval, this value is not included in the interval
1431 static double binEnd(const unsigned int binNum
)
1433 g_assert_cmpuint(binNum
, <, BIN_NB
);
1439 else if (binNum
< BIN_NB
- 1)
1441 return pow(binBase
, (double) binNum
- BIN_NB
+ 2);
1451 * Return the total number of elements in the "normal" bins (not underflow or
1455 * bins: the structure containing bins to build a histrogram
1457 static uint32_t normalTotal(struct Bins
* const bins
)
1459 return bins
->total
- bins
->bin
[0] - bins
->bin
[BIN_NB
- 1];
1463 /* Update the bounds between two traces
1466 * bounds: the array containing all the trace-pair bounds
1467 * e1, e2: the two related events
1469 static void updateBounds(Bounds
** const bounds
, Event
* const e1
, Event
* const
1472 unsigned int traceI
, traceJ
;
1473 uint64_t messageTime
;
1476 if (e1
->traceNum
< e2
->traceNum
)
1478 traceI
= e2
->traceNum
;
1479 traceJ
= e1
->traceNum
;
1480 messageTime
= e1
->cpuTime
;
1484 traceI
= e1
->traceNum
;
1485 traceJ
= e2
->traceNum
;
1486 messageTime
= e2
->cpuTime
;
1488 tpBounds
= &bounds
[traceI
][traceJ
];
1490 if (messageTime
< tpBounds
->min
)
1492 tpBounds
->min
= messageTime
;
1494 if (messageTime
> tpBounds
->max
)
1496 tpBounds
->max
= messageTime
;
1503 * Create the linear programming problem containing the constraints defined by
1504 * two half-hulls. The objective function and optimization directions are not
1508 * syncState: container for synchronization data
1509 * i: first trace number
1510 * j: second trace number, garanteed to be larger than i
1512 * A new glp_prob*, this problem must be freed by the caller with
1515 static glp_prob
* lpCreateProblem(GQueue
* const lowerHull
, GQueue
* const
1520 const double zeroD
= 0.;
1521 glp_prob
* lp
= glp_create_prob();
1522 unsigned int hullPointNb
= g_queue_get_length(lowerHull
) +
1523 g_queue_get_length(upperHull
);
1524 GArray
* iArray
= g_array_sized_new(FALSE
, FALSE
, sizeof(int), hullPointNb
+
1526 GArray
* jArray
= g_array_sized_new(FALSE
, FALSE
, sizeof(int), hullPointNb
+
1528 GArray
* aArray
= g_array_sized_new(FALSE
, FALSE
, sizeof(double),
1532 struct LPAddRowInfo rowInfo
;
1534 {lowerHull
, {lp
, GLP_UP
, iArray
, jArray
, aArray
}},
1535 {upperHull
, {lp
, GLP_LO
, iArray
, jArray
, aArray
}},
1538 // Create the LP problem
1539 glp_term_out(GLP_OFF
);
1540 glp_add_rows(lp
, hullPointNb
);
1541 glp_add_cols(lp
, 2);
1543 glp_set_col_name(lp
, 1, "a0");
1544 glp_set_col_bnds(lp
, 1, GLP_FR
, 0., 0.);
1545 glp_set_col_name(lp
, 2, "a1");
1546 glp_set_col_bnds(lp
, 2, GLP_LO
, 0., 0.);
1548 // Add row constraints
1549 g_array_append_val(iArray
, zero
);
1550 g_array_append_val(jArray
, zero
);
1551 g_array_append_val(aArray
, zeroD
);
1553 for (it
= 0; it
< sizeof(loopValues
) / sizeof(*loopValues
); it
++)
1555 g_queue_foreach(loopValues
[it
].hull
, &gfLPAddRow
,
1556 &loopValues
[it
].rowInfo
);
1559 g_assert_cmpuint(iArray
->len
, ==, jArray
->len
);
1560 g_assert_cmpuint(jArray
->len
, ==, aArray
->len
);
1561 g_assert_cmpuint(aArray
->len
- 1, ==, hullPointNb
* 2);
1563 glp_load_matrix(lp
, aArray
->len
- 1, &g_array_index(iArray
, int, 0),
1564 &g_array_index(jArray
, int, 0), &g_array_index(aArray
, double, 0));
1566 glp_scale_prob(lp
, GLP_SF_AUTO
);
1568 g_array_free(iArray
, TRUE
);
1569 g_array_free(jArray
, TRUE
);
1570 g_array_free(aArray
, TRUE
);
1577 * A GFunc for g_queue_foreach(). Add constraints and bounds for one row.
1580 * data Point*, synchronization point for which to add an LP row
1582 * user_data LPAddRowInfo*
1584 static void gfLPAddRow(gpointer data
, gpointer user_data
)
1587 struct LPAddRowInfo
* rowInfo
= user_data
;
1589 double constraints
[2];
1591 indexes
[0]= g_array_index(rowInfo
->iArray
, int, rowInfo
->iArray
->len
- 1) + 1;
1592 indexes
[1]= indexes
[0];
1594 if (rowInfo
->boundType
== GLP_UP
)
1596 glp_set_row_bnds(rowInfo
->lp
, indexes
[0], GLP_UP
, 0., p
->y
);
1598 else if (rowInfo
->boundType
== GLP_LO
)
1600 glp_set_row_bnds(rowInfo
->lp
, indexes
[0], GLP_LO
, p
->y
, 0.);
1604 g_assert_not_reached();
1607 g_array_append_vals(rowInfo
->iArray
, indexes
, 2);
1610 g_array_append_vals(rowInfo
->jArray
, indexes
, 2);
1612 constraints
[1]= p
->x
;
1613 g_array_append_vals(rowInfo
->aArray
, constraints
, 2);
1618 * Calculate min or max correction factors (as possible) using an LP problem.
1621 * lp: A linear programming problem with constraints and bounds
1623 * direction: The type of factors desired. Use GLP_MAX for max
1624 * approximation factors (a1, the drift or slope is the
1625 * largest) and GLP_MIN in the other case.
1628 * If the calculation was successful, a new Factors struct. Otherwise, NULL.
1629 * The calculation will fail if the hull assumptions are not respected.
1631 static Factors
* calculateFactors(glp_prob
* const lp
, const int direction
)
1636 glp_set_obj_coef(lp
, 1, 0.);
1637 glp_set_obj_coef(lp
, 2, 1.);
1639 glp_set_obj_dir(lp
, direction
);
1640 retval
= glp_simplex(lp
, NULL
);
1641 status
= glp_get_status(lp
);
1643 if (retval
== 0 && status
== GLP_OPT
)
1645 factors
= malloc(sizeof(Factors
));
1646 factors
->offset
= glp_get_col_prim(lp
, 1);
1647 factors
->drift
= glp_get_col_prim(lp
, 2);
1659 * Calculate min, max and approx correction factors (as possible) using an LP
1663 * lp: A linear programming problem with constraints and bounds
1667 * Please note that the approximation type may be MIDDLE, INCOMPLETE or
1668 * ABSENT. Unlike in analysis_chull, ABSENT is also used when the hulls do
1669 * not respect assumptions.
1671 static void calculateCompleteFactors(glp_prob
* const lp
, FactorsCHull
* factors
)
1673 factors
->min
= calculateFactors(lp
, GLP_MIN
);
1674 factors
->max
= calculateFactors(lp
, GLP_MAX
);
1676 if (factors
->min
&& factors
->max
)
1678 factors
->type
= MIDDLE
;
1679 calculateFactorsMiddle(factors
);
1681 else if (factors
->min
|| factors
->max
)
1683 factors
->type
= INCOMPLETE
;
1684 factors
->approx
= NULL
;
1688 factors
->type
= ABSENT
;
1689 factors
->approx
= NULL
;
1695 * Create and initialize an array like AnalysisStatsCHull.allFactors
1698 * traceNb: number of traces
1701 * A new array, which can be freed with freeAllFactors()
1703 static FactorsCHull
** createAllFactors(const unsigned int traceNb
)
1705 FactorsCHull
** factorsArray
;
1708 factorsArray
= malloc(traceNb
* sizeof(FactorsCHull
*));
1709 for (i
= 0; i
< traceNb
; i
++)
1711 factorsArray
[i
]= calloc((i
+ 1), sizeof(FactorsCHull
));
1713 factorsArray
[i
][i
].type
= EXACT
;
1714 factorsArray
[i
][i
].approx
= malloc(sizeof(Factors
));
1715 factorsArray
[i
][i
].approx
->drift
= 1.;
1716 factorsArray
[i
][i
].approx
->offset
= 0.;
1719 return factorsArray
;
1725 * Compute synchronization factors using a linear programming approach.
1726 * Compute the factors using analysis_chull. Compare the two.
1728 * When the solver library, glpk, is not available at build time, only compute
1729 * the factors using analysis_chull. This is to make sure that module runs its
1730 * finalize function so that its graph functions can be called later.
1733 * syncState: container for synchronization data
1735 static void finalizeAnalysisEvalLP(SyncState
* const syncState
)
1737 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
1740 AnalysisDataCHull
* chAnalysisData
= analysisData
->chullSS
->analysisData
;
1741 FactorsCHull
** lpFactorsArray
;
1743 if (!syncState
->stats
&& !syncState
->graphsStream
)
1748 /* Because of matching_distributor, this analysis may be called twice.
1749 * Only run it once */
1750 if ((syncState
->graphsStream
&& analysisData
->graphs
->lps
!= NULL
) ||
1751 (syncState
->stats
&& analysisData
->stats
->chFactorsArray
!= NULL
))
1756 lpFactorsArray
= createAllFactors(syncState
->traceNb
);
1758 if (syncState
->stats
)
1760 analysisData
->stats
->chFactorsArray
=
1761 calculateAllFactors(analysisData
->chullSS
);
1762 analysisData
->stats
->lpFactorsArray
= lpFactorsArray
;
1765 if (syncState
->graphsStream
)
1767 analysisData
->graphs
->lps
= malloc(syncState
->traceNb
*
1768 sizeof(glp_prob
**));
1769 for (i
= 0; i
< syncState
->traceNb
; i
++)
1771 analysisData
->graphs
->lps
[i
]= malloc(i
* sizeof(glp_prob
*));
1773 analysisData
->graphs
->lpFactorsArray
= lpFactorsArray
;
1776 for (i
= 0; i
< syncState
->traceNb
; i
++)
1778 for (j
= 0; j
< i
; j
++)
1782 // Create the LP problem
1783 lp
= lpCreateProblem(chAnalysisData
->hullArray
[i
][j
],
1784 chAnalysisData
->hullArray
[j
][i
]);
1786 // Use the LP problem to find the correction factors for this pair of
1788 calculateCompleteFactors(lp
, &lpFactorsArray
[i
][j
]);
1790 if (syncState
->graphsStream
)
1792 analysisData
->graphs
->lps
[i
][j
]= lp
;
1796 glp_delete_prob(lp
);
1802 g_array_free(analysisData
->chullSS
->analysisModule
->finalizeAnalysis(analysisData
->chullSS
),
1808 * Compute synchronization accuracy information using a linear programming
1809 * approach. Write the neccessary data files and plot lines in the gnuplot
1812 * When the solver library, glpk, is not available at build time nothing is
1813 * actually produced.
1816 * syncState: container for synchronization data
1817 * i: first trace number
1818 * j: second trace number, garanteed to be larger than i
1820 static void writeAnalysisTraceTimeBackPlotsEval(SyncState
* const syncState
,
1821 const unsigned int i
, const unsigned int j
)
1825 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
1826 AnalysisGraphsEval
* graphs
= analysisData
->graphs
;
1827 GQueue
*** hullArray
= ((AnalysisDataCHull
*)
1828 analysisData
->chullSS
->analysisData
)->hullArray
;
1829 FactorsCHull
* lpFactors
= &graphs
->lpFactorsArray
[j
][i
];
1830 glp_prob
* lp
= graphs
->lps
[j
][i
];
1832 if (lpFactors
->type
== MIDDLE
)
1839 unsigned int xBegin
, xEnd
;
1841 const unsigned int graphPointNb
= 1000;
1843 // Open the data file
1844 snprintf(fileName
, 40, "analysis_eval_accuracy-%03u_and_%03u.data", i
, j
);
1845 fileName
[sizeof(fileName
) - 1]= '\0';
1847 cwd
= changeToGraphsDir(syncState
->graphsDir
);
1849 if ((fp
= fopen(fileName
, "w")) == NULL
)
1851 g_error(strerror(errno
));
1853 fprintf(fp
, "#%-24s %-25s %-25s %-25s\n", "x", "middle", "min", "max");
1858 g_error(strerror(errno
));
1862 // Build the list of absisca values for the points in the accuracy graph
1863 g_assert_cmpuint(graphPointNb
, >=, 4);
1864 xValues
= malloc(graphPointNb
* sizeof(double));
1865 xValues
[0]= graphs
->bounds
[j
][i
].min
;
1866 xValues
[graphPointNb
- 1]= graphs
->bounds
[j
][i
].max
;
1867 xValues
[1]= MIN(((Point
*) g_queue_peek_head(hullArray
[i
][j
]))->x
,
1868 ((Point
*) g_queue_peek_head(hullArray
[j
][i
]))->x
);
1869 xValues
[graphPointNb
- 2]= MAX(((Point
*)
1870 g_queue_peek_tail(hullArray
[i
][j
]))->x
, ((Point
*)
1871 g_queue_peek_tail(hullArray
[j
][i
]))->x
);
1873 if (xValues
[0] == xValues
[1])
1881 if (xValues
[graphPointNb
- 2] == xValues
[graphPointNb
- 1])
1883 xEnd
= graphPointNb
- 1;
1887 xEnd
= graphPointNb
- 2;
1889 interval
= (xValues
[xEnd
] - xValues
[xBegin
]) / (graphPointNb
- 1);
1891 for (it
= xBegin
; it
<= xEnd
; it
++)
1893 xValues
[it
]= xValues
[xBegin
] + interval
* (it
- xBegin
);
1896 /* For each absisca value and each optimisation direction, solve the LP
1897 * and write a line in the data file */
1898 for (it
= 0; it
< graphPointNb
; it
++)
1901 int directions
[]= {GLP_MIN
, GLP_MAX
};
1903 glp_set_obj_coef(lp
, 1, 1.);
1904 glp_set_obj_coef(lp
, 2, xValues
[it
]);
1906 fprintf(fp
, "%25.9f %25.9f", xValues
[it
], lpFactors
->approx
->offset
1907 + lpFactors
->approx
->drift
* xValues
[it
]);
1908 for (it2
= 0; it2
< sizeof(directions
) / sizeof(*directions
); it2
++)
1912 glp_set_obj_dir(lp
, directions
[it2
]);
1913 retval
= glp_simplex(lp
, NULL
);
1914 status
= glp_get_status(lp
);
1916 g_assert(retval
== 0 && status
== GLP_OPT
);
1917 fprintf(fp
, " %25.9f", glp_get_obj_val(lp
));
1925 fprintf(syncState
->graphsStream
,
1926 "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
1927 "using 1:(($3 - $2) / clock_freq_%2$u):(($4 - $2) / clock_freq_%2$u) "
1928 "title \"Synchronization accuracy\" "
1929 "with filledcurves linewidth 2 linetype 1 "
1930 "linecolor rgb \"black\" fill solid 0.25 noborder, \\\n", i
,
1938 * Write the analysis-specific graph lines in the gnuplot script.
1940 * When the solver library, glpk, is not available at build time nothing is
1941 * actually produced.
1944 * syncState: container for synchronization data
1945 * i: first trace number
1946 * j: second trace number, garanteed to be larger than i
1948 static void writeAnalysisTraceTimeForePlotsEval(SyncState
* const syncState
,
1949 const unsigned int i
, const unsigned int j
)
1952 if (((AnalysisDataEval
*)
1953 syncState
->analysisData
)->graphs
->lpFactorsArray
[j
][i
].type
==
1956 fprintf(syncState
->graphsStream
,
1957 "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
1958 "using 1:(($3 - $2) / clock_freq_%2$u) notitle "
1959 "with lines linewidth 2 linetype 1 "
1960 "linecolor rgb \"gray60\", \\\n"
1961 "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
1962 "using 1:(($4 - $2) / clock_freq_%2$u) notitle "
1963 "with lines linewidth 2 linetype 1 "
1964 "linecolor rgb \"gray60\", \\\n", i
, j
);
1971 * Write the analysis-specific graph lines in the gnuplot script.
1974 * syncState: container for synchronization data
1975 * i: first trace number
1976 * j: second trace number, garanteed to be larger than i
1978 static void writeAnalysisTraceTraceBackPlotsEval(SyncState
* const syncState
,
1979 const unsigned int i
, const unsigned int j
)
1982 fprintf(syncState
->graphsStream
,
1983 "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
1985 "title \"Synchronization accuracy\" "
1986 "with filledcurves linewidth 2 linetype 1 "
1987 "linecolor rgb \"black\" fill solid 0.25 noborder, \\\n", i
, j
);
1993 * Write the analysis-specific graph lines in the gnuplot script.
1996 * syncState: container for synchronization data
1997 * i: first trace number
1998 * j: second trace number, garanteed to be larger than i
2000 static void writeAnalysisTraceTraceForePlotsEval(SyncState
* const syncState
,
2001 const unsigned int i
, const unsigned int j
)
2003 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
2005 analysisData
->chullSS
->analysisModule
->graphFunctions
.writeTraceTraceForePlots(analysisData
->chullSS
,