1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2009, 2010 Benjamin Poirier <benjamin.poirier@polymtl.ca>
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 2.1 of the License, or (at
7 * your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
12 * License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #define _ISOC99_SOURCE
25 #include <arpa/inet.h>
28 #include <netinet/in.h>
33 #include <sys/socket.h>
37 #include "sync_chain.h"
39 #include "event_analysis_eval.h"
42 struct WriteHistogramInfo
48 // Functions common to all analysis modules
49 static void initAnalysisEval(SyncState
* const syncState
);
50 static void destroyAnalysisEval(SyncState
* const syncState
);
52 static void analyzeMessageEval(SyncState
* const syncState
, Message
* const
54 static void analyzeExchangeEval(SyncState
* const syncState
, Exchange
* const
56 static void analyzeBroadcastEval(SyncState
* const syncState
, Broadcast
* const
58 static AllFactors
* finalizeAnalysisEval(SyncState
* const syncState
);
59 static void printAnalysisStatsEval(SyncState
* const syncState
);
61 // Functions specific to this module
62 static guint
ghfRttKeyHash(gconstpointer key
);
63 static gboolean
gefRttKeyEqual(gconstpointer a
, gconstpointer b
);
64 static void gdnDestroyRttKey(gpointer data
);
65 static void gdnDestroyDouble(gpointer data
);
66 static void readRttInfo(GHashTable
* rttInfo
, FILE* rttFile
);
67 static void positionStream(FILE* stream
);
69 static void gfSum(gpointer data
, gpointer userData
);
70 static void gfSumSquares(gpointer data
, gpointer userData
);
71 static void ghfPrintExchangeRtt(gpointer key
, gpointer value
, gpointer
74 static void hitBin(struct Bins
* const bins
, const double value
);
75 static unsigned int binNum(const double value
) __attribute__((pure
));
76 static double binStart(const unsigned int binNum
) __attribute__((pure
));
77 static double binEnd(const unsigned int binNum
) __attribute__((pure
));
78 static uint32_t normalTotal(struct Bins
* const bins
) __attribute__((const));
80 static AnalysisHistogramEval
* constructAnalysisHistogramEval(const char* const
81 graphsDir
, const struct RttKey
* const rttKey
);
82 static void destroyAnalysisHistogramEval(AnalysisHistogramEval
* const
84 static void gdnDestroyAnalysisHistogramEval(gpointer data
);
85 static void ghfWriteHistogram(gpointer key
, gpointer value
, gpointer
87 static void dumpBinToFile(const struct Bins
* const bins
, FILE* const file
);
88 static void writeHistogram(FILE* graphsStream
, const struct RttKey
* rttKey
,
89 double* minRtt
, AnalysisHistogramEval
* const histogram
);
91 static void updateBounds(Bounds
** const bounds
, Event
* const e1
, Event
* const
95 // initialized in registerAnalysisEval()
98 static AnalysisModule analysisModuleEval
= {
100 .initAnalysis
= &initAnalysisEval
,
101 .destroyAnalysis
= &destroyAnalysisEval
,
102 .analyzeMessage
= &analyzeMessageEval
,
103 .analyzeExchange
= &analyzeExchangeEval
,
104 .analyzeBroadcast
= &analyzeBroadcastEval
,
105 .finalizeAnalysis
= &finalizeAnalysisEval
,
106 .printAnalysisStats
= &printAnalysisStatsEval
,
110 static ModuleOption optionEvalRttFile
= {
111 .longName
= "eval-rtt-file",
112 .hasArg
= REQUIRED_ARG
,
113 .optionHelp
= "specify the file containing RTT information",
119 * Analysis module registering function
121 void registerAnalysisEval()
123 binBase
= exp10(6. / (BIN_NB
- 3));
125 g_queue_push_tail(&analysisModules
, &analysisModuleEval
);
126 g_queue_push_tail(&moduleOptions
, &optionEvalRttFile
);
131 * Analysis init function
133 * This function is called at the beginning of a synchronization run for a set
137 * syncState container for synchronization data.
139 static void initAnalysisEval(SyncState
* const syncState
)
141 AnalysisDataEval
* analysisData
;
144 analysisData
= malloc(sizeof(AnalysisDataEval
));
145 syncState
->analysisData
= analysisData
;
147 analysisData
->rttInfo
= g_hash_table_new_full(&ghfRttKeyHash
,
148 &gefRttKeyEqual
, &gdnDestroyRttKey
, &gdnDestroyDouble
);
149 if (optionEvalRttFile
.arg
)
154 rttStream
= fopen(optionEvalRttFile
.arg
, "r");
155 if (rttStream
== NULL
)
157 g_error(strerror(errno
));
160 readRttInfo(analysisData
->rttInfo
, rttStream
);
162 retval
= fclose(rttStream
);
165 g_error(strerror(errno
));
169 if (syncState
->stats
)
171 analysisData
->stats
= calloc(1, sizeof(AnalysisStatsEval
));
172 analysisData
->stats
->broadcastRangeMin
= INFINITY
;
173 analysisData
->stats
->broadcastRangeMax
= -INFINITY
;
175 analysisData
->stats
->messageStats
= malloc(syncState
->traceNb
*
176 sizeof(MessageStats
*));
177 for (i
= 0; i
< syncState
->traceNb
; i
++)
179 analysisData
->stats
->messageStats
[i
]= calloc(syncState
->traceNb
,
180 sizeof(MessageStats
));
183 analysisData
->stats
->exchangeRtt
=
184 g_hash_table_new_full(&ghfRttKeyHash
, &gefRttKeyEqual
,
185 &gdnDestroyRttKey
, &gdnDestroyDouble
);
188 if (syncState
->graphsStream
)
190 AnalysisGraphsEval
* graphs
= malloc(sizeof(AnalysisGraphsEval
));
192 analysisData
->graphs
= graphs
;
194 graphs
->histograms
= g_hash_table_new_full(&ghfRttKeyHash
,
195 &gefRttKeyEqual
, &gdnDestroyRttKey
,
196 &gdnDestroyAnalysisHistogramEval
);
198 graphs
->bounds
= malloc(syncState
->traceNb
* sizeof(Bounds
*));
199 for (i
= 0; i
< syncState
->traceNb
; i
++)
201 graphs
->bounds
[i
]= malloc(i
* sizeof(Bounds
));
202 for (j
= 0; j
< i
; j
++)
204 graphs
->bounds
[i
][j
].min
= UINT64_MAX
;
205 graphs
->bounds
[i
][j
].max
= 0;
213 * Create and open files used to store histogram points to generate graphs.
214 * Create data structures to store histogram points during analysis.
217 * graphsDir: folder where to write files
218 * rttKey: host pair, make sure saddr < daddr
220 static AnalysisHistogramEval
* constructAnalysisHistogramEval(const char* const
221 graphsDir
, const struct RttKey
* const rttKey
)
226 char name
[60], saddr
[16], daddr
[16];
227 AnalysisHistogramEval
* histogram
= calloc(1, sizeof(*histogram
));
230 const char* fileName
;
231 const char* host1
, *host2
;
233 {offsetof(AnalysisHistogramEval
, ttSendPoints
),
234 "analysis_eval_tt-%s_to_%s.data", saddr
, daddr
},
235 {offsetof(AnalysisHistogramEval
, ttRecvPoints
),
236 "analysis_eval_tt-%s_to_%s.data", daddr
, saddr
},
237 {offsetof(AnalysisHistogramEval
, hrttPoints
),
238 "analysis_eval_hrtt-%s_and_%s.data", saddr
, daddr
},
241 histogram
->ttSendBins
.min
= BIN_NB
- 1;
242 histogram
->ttRecvBins
.min
= BIN_NB
- 1;
243 histogram
->hrttBins
.min
= BIN_NB
- 1;
245 convertIP(saddr
, rttKey
->saddr
);
246 convertIP(daddr
, rttKey
->daddr
);
248 cwd
= changeToGraphsDir(graphsDir
);
250 for (i
= 0; i
< sizeof(loopValues
) / sizeof(*loopValues
); i
++)
252 retval
= snprintf(name
, sizeof(name
), loopValues
[i
].fileName
,
253 loopValues
[i
].host1
, loopValues
[i
].host2
);
254 if (retval
> sizeof(name
) - 1)
256 name
[sizeof(name
) - 1]= '\0';
258 if ((*(FILE**)((void*) histogram
+ loopValues
[i
].pointsOffset
)=
259 fopen(name
, "w")) == NULL
)
261 g_error(strerror(errno
));
268 g_error(strerror(errno
));
277 * Close files used to store histogram points to generate graphs.
280 * graphsDir: folder where to write files
281 * rttKey: host pair, make sure saddr < daddr
283 static void destroyAnalysisHistogramEval(AnalysisHistogramEval
* const
291 {offsetof(AnalysisHistogramEval
, ttSendPoints
)},
292 {offsetof(AnalysisHistogramEval
, ttRecvPoints
)},
293 {offsetof(AnalysisHistogramEval
, hrttPoints
)},
296 for (i
= 0; i
< sizeof(loopValues
) / sizeof(*loopValues
); i
++)
298 retval
= fclose(*(FILE**)((void*) histogram
+ loopValues
[i
].pointsOffset
));
301 g_error(strerror(errno
));
310 * A GDestroyNotify function for g_hash_table_new_full()
313 * data: AnalysisHistogramEval*
315 static void gdnDestroyAnalysisHistogramEval(gpointer data
)
317 destroyAnalysisHistogramEval(data
);
322 * A GHFunc for g_hash_table_foreach()
325 * key: RttKey* where saddr < daddr
326 * value: AnalysisHistogramEval*
327 * user_data struct WriteHistogramInfo*
329 static void ghfWriteHistogram(gpointer key
, gpointer value
, gpointer user_data
)
331 double* rtt1
, * rtt2
;
332 struct RttKey
* rttKey
= key
;
333 struct RttKey oppositeRttKey
= {.saddr
= rttKey
->daddr
, .daddr
=
335 AnalysisHistogramEval
* histogram
= value
;
336 struct WriteHistogramInfo
* info
= user_data
;
338 rtt1
= g_hash_table_lookup(info
->rttInfo
, rttKey
);
339 rtt2
= g_hash_table_lookup(info
->rttInfo
, &oppositeRttKey
);
345 else if (rtt2
!= NULL
)
347 rtt1
= MIN(rtt1
, rtt2
);
350 dumpBinToFile(&histogram
->ttSendBins
, histogram
->ttSendPoints
);
351 dumpBinToFile(&histogram
->ttRecvBins
, histogram
->ttRecvPoints
);
352 dumpBinToFile(&histogram
->hrttBins
, histogram
->hrttPoints
);
353 writeHistogram(info
->graphsStream
, rttKey
, rtt1
, histogram
);
358 * Write the content of one bin in a histogram point file
361 * bin: array of values that make up a histogram
362 * file: FILE*, write to this file
364 static void dumpBinToFile(const struct Bins
* const bins
, FILE* const file
)
368 // The first and last bins are skipped, see struct Bins
369 for (i
= 1; i
< BIN_NB
- 1; i
++)
371 if (bins
->bin
[i
] > 0)
373 fprintf(file
, "%20.9f %20.9f %20.9f\n", (binStart(i
) + binEnd(i
))
374 / 2., (double) bins
->bin
[i
] / ((binEnd(i
) - binStart(i
)) *
375 bins
->total
), binEnd(i
) - binStart(i
));
382 * Write the analysis-specific plot in the gnuplot script.
385 * graphsStream: write to this file
386 * rttKey: must be sorted such that saddr < daddr
387 * minRtt: if available, else NULL
388 * histogram: struct that contains the bins for the pair of traces
389 * identified by rttKey
391 static void writeHistogram(FILE* graphsStream
, const struct RttKey
* rttKey
,
392 double* minRtt
, AnalysisHistogramEval
* const histogram
)
394 char saddr
[16], daddr
[16];
396 convertIP(saddr
, rttKey
->saddr
);
397 convertIP(daddr
, rttKey
->daddr
);
399 fprintf(graphsStream
,
401 "set output \"histogram-%s-%s.eps\"\n"
403 "set xlabel \"Message Latency (s)\"\n"
404 "set ylabel \"Proportion of messages per second\"\n", saddr
, daddr
);
408 fprintf(graphsStream
,
409 "set arrow from %.9f, 0 rto 0, graph 1 "
410 "nohead linetype 3 linewidth 3 linecolor rgb \"black\"\n", *minRtt
414 if (normalTotal(&histogram
->ttSendBins
) ||
415 normalTotal(&histogram
->ttRecvBins
) ||
416 normalTotal(&histogram
->hrttBins
))
418 fprintf(graphsStream
, "plot \\\n");
420 if (normalTotal(&histogram
->hrttBins
))
422 fprintf(graphsStream
,
423 "\t\"analysis_eval_hrtt-%s_and_%s.data\" "
424 "title \"RTT/2\" with linespoints linetype 1 linewidth 2 "
425 "linecolor rgb \"black\" pointtype 6 pointsize 1,\\\n",
429 if (normalTotal(&histogram
->ttSendBins
))
431 fprintf(graphsStream
,
432 "\t\"analysis_eval_tt-%1$s_to_%2$s.data\" "
433 "title \"%1$s to %2$s\" with linespoints linetype 4 linewidth 2 "
434 "linecolor rgb \"gray60\" pointtype 6 pointsize 1,\\\n",
438 if (normalTotal(&histogram
->ttRecvBins
))
440 fprintf(graphsStream
,
441 "\t\"analysis_eval_tt-%1$s_to_%2$s.data\" "
442 "title \"%1$s to %2$s\" with linespoints linetype 4 linewidth 2 "
443 "linecolor rgb \"gray30\" pointtype 6 pointsize 1,\\\n",
447 // Remove the ",\\\n" from the last graph plot line
448 if (ftruncate(fileno(graphsStream
), ftell(graphsStream
) - 3) == -1)
450 g_error(strerror(errno
));
452 if (fseek(graphsStream
, 0, SEEK_END
) == -1)
454 g_error(strerror(errno
));
456 fprintf(graphsStream
, "\n");
462 * Analysis destroy function
464 * Free the analysis specific data structures
467 * syncState container for synchronization data.
469 static void destroyAnalysisEval(SyncState
* const syncState
)
472 AnalysisDataEval
* analysisData
;
474 analysisData
= (AnalysisDataEval
*) syncState
->analysisData
;
476 if (analysisData
== NULL
)
481 g_hash_table_destroy(analysisData
->rttInfo
);
483 if (syncState
->stats
)
485 AnalysisStatsEval
* stats
= analysisData
->stats
;
487 for (i
= 0; i
< syncState
->traceNb
; i
++)
489 free(stats
->messageStats
[i
]);
491 free(stats
->messageStats
);
493 g_hash_table_destroy(stats
->exchangeRtt
);
498 if (syncState
->graphsStream
)
500 AnalysisGraphsEval
* graphs
= analysisData
->graphs
;
502 if (graphs
->histograms
)
504 g_hash_table_destroy(graphs
->histograms
);
507 for (i
= 0; i
< syncState
->traceNb
; i
++)
509 free(graphs
->bounds
[i
]);
511 free(graphs
->bounds
);
516 free(syncState
->analysisData
);
517 syncState
->analysisData
= NULL
;
522 * Perform analysis on an event pair.
524 * Check if there is message inversion or messages that are too fast.
527 * syncState container for synchronization data
528 * message structure containing the events
530 static void analyzeMessageEval(SyncState
* const syncState
, Message
* const
533 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
534 MessageStats
* messageStats
;
537 struct RttKey rttKey
;
539 g_assert(message
->inE
->type
== TCP
);
541 if (syncState
->stats
)
544 &analysisData
->stats
->messageStats
[message
->outE
->traceNum
][message
->inE
->traceNum
];
545 messageStats
->total
++;
548 tt
= wallTimeSub(&message
->inE
->wallTime
, &message
->outE
->wallTime
);
551 if (syncState
->stats
)
553 messageStats
->inversionNb
++;
556 else if (syncState
->graphsStream
)
558 struct RttKey rttKey
= {
559 .saddr
=MIN(message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
,
560 message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
),
561 .daddr
=MAX(message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
,
562 message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
),
564 AnalysisHistogramEval
* histogram
=
565 g_hash_table_lookup(analysisData
->graphs
->histograms
, &rttKey
);
567 if (histogram
== NULL
)
569 struct RttKey
* tableKey
= malloc(sizeof(*tableKey
));
571 histogram
= constructAnalysisHistogramEval(syncState
->graphsDir
, &rttKey
);
572 memcpy(tableKey
, &rttKey
, sizeof(*tableKey
));
573 g_hash_table_insert(analysisData
->graphs
->histograms
, tableKey
, histogram
);
576 if (message
->inE
->event
.udpEvent
->datagramKey
->saddr
<
577 message
->inE
->event
.udpEvent
->datagramKey
->daddr
)
579 hitBin(&histogram
->ttSendBins
, tt
);
583 hitBin(&histogram
->ttRecvBins
, tt
);
587 if (syncState
->stats
)
590 message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
;
592 message
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
;
593 rtt
= g_hash_table_lookup(analysisData
->rttInfo
, &rttKey
);
594 g_debug("rttInfo, looking up (%u, %u)->(%f)", rttKey
.saddr
,
595 rttKey
.daddr
, rtt
? *rtt
: NAN
);
599 g_debug("rttInfo, tt: %f rtt / 2: %f", tt
, *rtt
/ 2.);
602 messageStats
->tooFastNb
++;
607 messageStats
->noRTTInfoNb
++;
611 if (syncState
->graphsStream
)
613 updateBounds(analysisData
->graphs
->bounds
, message
->inE
,
620 * Perform analysis on multiple messages
625 * syncState container for synchronization data
626 * exchange structure containing the messages
628 static void analyzeExchangeEval(SyncState
* const syncState
, Exchange
* const
631 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
632 Message
* m1
= g_queue_peek_tail(exchange
->acks
);
633 Message
* m2
= exchange
->message
;
634 struct RttKey
* rttKey
;
635 double* rtt
, * exchangeRtt
;
637 g_assert(m1
->inE
->type
== TCP
);
639 // (T2 - T1) - (T3 - T4)
640 rtt
= malloc(sizeof(double));
641 *rtt
= wallTimeSub(&m1
->inE
->wallTime
, &m1
->outE
->wallTime
) -
642 wallTimeSub(&m2
->outE
->wallTime
, &m2
->inE
->wallTime
);
644 rttKey
= malloc(sizeof(struct RttKey
));
646 MIN(m1
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
,
647 m1
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
);
649 MAX(m1
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.saddr
,
650 m1
->inE
->event
.tcpEvent
->segmentKey
->connectionKey
.daddr
);
652 if (syncState
->graphsStream
)
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
,
663 memcpy(tableKey
, rttKey
, sizeof(*tableKey
));
664 g_hash_table_insert(analysisData
->graphs
->histograms
, tableKey
,
668 hitBin(&histogram
->hrttBins
, *rtt
/ 2);
671 if (syncState
->stats
)
673 exchangeRtt
= g_hash_table_lookup(analysisData
->stats
->exchangeRtt
,
678 if (*rtt
< *exchangeRtt
)
680 g_hash_table_replace(analysisData
->stats
->exchangeRtt
, rttKey
, rtt
);
690 g_hash_table_insert(analysisData
->stats
->exchangeRtt
, rttKey
, rtt
);
702 * Perform analysis on muliple events
704 * Sum the broadcast differential delays
707 * syncState container for synchronization data
708 * broadcast structure containing the events
710 static void analyzeBroadcastEval(SyncState
* const syncState
, Broadcast
* const
713 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
715 if (syncState
->stats
)
717 double sum
= 0, squaresSum
= 0;
720 g_queue_foreach(broadcast
->events
, &gfSum
, &sum
);
721 g_queue_foreach(broadcast
->events
, &gfSumSquares
, &squaresSum
);
723 analysisData
->stats
->broadcastNb
++;
724 // Because of numerical errors, this can at times be < 0
725 y
= squaresSum
/ g_queue_get_length(broadcast
->events
) - pow(sum
/
726 g_queue_get_length(broadcast
->events
), 2.);
729 analysisData
->stats
->broadcastStdevSum
+= sqrt(y
);
732 if (syncState
->traceNb
== 2 && g_queue_get_length(broadcast
->events
)
738 e0
= g_queue_peek_head(broadcast
->events
);
739 e1
= g_queue_peek_tail(broadcast
->events
);
740 if (e0
->traceNum
> e1
->traceNum
)
749 dd
= wallTimeSub(&e1
->wallTime
, &e0
->wallTime
);
751 analysisData
->stats
->broadcastPairNb
++;
752 if (dd
< analysisData
->stats
->broadcastRangeMin
)
754 analysisData
->stats
->broadcastRangeMin
= dd
;
756 if (dd
> analysisData
->stats
->broadcastRangeMax
)
758 analysisData
->stats
->broadcastRangeMax
= dd
;
761 analysisData
->stats
->broadcastSum
+= dd
;
762 analysisData
->stats
->broadcastSumSquares
+= pow(dd
, 2);
766 if (syncState
->graphsStream
)
770 unsigned int eventNb
= broadcast
->events
->length
;
772 events
= g_array_sized_new(FALSE
, FALSE
, sizeof(Event
*), eventNb
);
773 g_queue_foreach(broadcast
->events
, &gfAddEventToArray
, events
);
775 for (i
= 0; i
< eventNb
; i
++)
777 for (j
= 0; j
< eventNb
; j
++)
779 Event
* eventI
= g_array_index(events
, Event
*, i
), * eventJ
=
780 g_array_index(events
, Event
*, j
);
782 if (eventI
->traceNum
< eventJ
->traceNum
)
784 updateBounds(analysisData
->graphs
->bounds
, eventI
, eventJ
);
789 g_array_free(events
, TRUE
);
795 * Finalize the factor calculations. Since this module does not really
796 * calculate factors, absent factors are returned. Instead, histograms are
797 * written out and histogram structures are freed.
800 * syncState container for synchronization data.
803 * AllFactors* synchronization factors for each trace pair
805 static AllFactors
* finalizeAnalysisEval(SyncState
* const syncState
)
807 AnalysisDataEval
* analysisData
= syncState
->analysisData
;
809 if (syncState
->graphsStream
&& analysisData
->graphs
->histograms
)
811 g_hash_table_foreach(analysisData
->graphs
->histograms
,
812 &ghfWriteHistogram
, &(struct WriteHistogramInfo
) {.rttInfo
=
813 analysisData
->rttInfo
, .graphsStream
= syncState
->graphsStream
});
814 g_hash_table_destroy(analysisData
->graphs
->histograms
);
815 analysisData
->graphs
->histograms
= NULL
;
818 return createAllFactors(syncState
->traceNb
);
823 * Print statistics related to analysis. Must be called after
827 * syncState container for synchronization data.
829 static void printAnalysisStatsEval(SyncState
* const syncState
)
831 AnalysisDataEval
* analysisData
;
832 unsigned int i
, j
, k
;
833 unsigned int totInversion
= 0, totTooFast
= 0, totNoInfo
= 0, totTotal
= 0;
836 if (!syncState
->stats
)
841 analysisData
= (AnalysisDataEval
*) syncState
->analysisData
;
843 printf("Synchronization evaluation analysis stats:\n");
844 if (analysisData
->stats
->broadcastNb
)
846 printf("\tBroadcast differential delay:\n");
847 printf("\t\tsum of standard deviations: %g\n",
848 analysisData
->stats
->broadcastStdevSum
);
849 printf("\t\taverage standard deviation: %g\n",
850 analysisData
->stats
->broadcastStdevSum
/
851 analysisData
->stats
->broadcastNb
);
853 if (syncState
->traceNb
== 2)
855 printf("\t\tdifferential delay range: [ %g .. %g ]\n",
856 analysisData
->stats
->broadcastRangeMin
,
857 analysisData
->stats
->broadcastRangeMax
);
858 printf("\t\tdifferential delay average: %g\n",
859 analysisData
->stats
->broadcastSum
/
860 analysisData
->stats
->broadcastPairNb
);
861 printf("\t\tdifferential delay standard deviation: %g\n",
862 sqrt(analysisData
->stats
->broadcastSumSquares
/
863 analysisData
->stats
->broadcastPairNb
-
864 pow(analysisData
->stats
->broadcastSum
/
865 analysisData
->stats
->broadcastPairNb
, 2)));
869 printf("\tIndividual evaluation:\n"
870 "\t\tTrace pair Inversions Too fast No RTT info Total\n");
872 for (i
= 0; i
< syncState
->traceNb
; i
++)
874 for (j
= i
+ 1; j
< syncState
->traceNb
; j
++)
876 MessageStats
* messageStats
;
884 for (k
= 0; k
< sizeof(loopValues
) / sizeof(*loopValues
); k
++)
887 &analysisData
->stats
->messageStats
[loopValues
[k
].t1
][loopValues
[k
].t2
];
889 printf("\t\t%3d - %-3d ", loopValues
[k
].t1
, loopValues
[k
].t2
);
890 printf("%u (%.2f%%)%n", messageStats
->inversionNb
, (double)
891 messageStats
->inversionNb
/ messageStats
->total
* 100,
893 printf("%*s", 17 - charNb
> 0 ? 17 - charNb
+ 1: 1, " ");
894 printf("%u (%.2f%%)%n", messageStats
->tooFastNb
, (double)
895 messageStats
->tooFastNb
/ messageStats
->total
* 100,
897 printf("%*s%-10u %u\n", 17 - charNb
> 0 ? 17 - charNb
+ 1:
898 1, " ", messageStats
->noRTTInfoNb
, messageStats
->total
);
900 totInversion
+= messageStats
->inversionNb
;
901 totTooFast
+= messageStats
->tooFastNb
;
902 totNoInfo
+= messageStats
->noRTTInfoNb
;
903 totTotal
+= messageStats
->total
;
908 printf("\t\t total ");
909 printf("%u (%.2f%%)%n", totInversion
, (double) totInversion
/ totTotal
*
911 printf("%*s", 17 - charNb
> 0 ? 17 - charNb
+ 1: 1, " ");
912 printf("%u (%.2f%%)%n", totTooFast
, (double) totTooFast
/ totTotal
* 100,
914 printf("%*s%-10u %u\n", 17 - charNb
> 0 ? 17 - charNb
+ 1: 1, " ",
915 totNoInfo
, totTotal
);
917 printf("\tRound-trip times:\n"
918 "\t\tHost pair RTT from exchanges RTTs from file (ms)\n");
919 g_hash_table_foreach(analysisData
->stats
->exchangeRtt
,
920 &ghfPrintExchangeRtt
, analysisData
->rttInfo
);
925 * A GHFunc for g_hash_table_foreach()
928 * key: RttKey* where saddr < daddr
929 * value: double*, RTT estimated from exchanges
930 * user_data GHashTable* rttInfo
932 static void ghfPrintExchangeRtt(gpointer key
, gpointer value
, gpointer
935 char addr1
[16], addr2
[16];
936 struct RttKey
* rttKey1
= key
;
937 struct RttKey rttKey2
= {rttKey1
->daddr
, rttKey1
->saddr
};
938 double* fileRtt1
, *fileRtt2
;
939 GHashTable
* rttInfo
= user_data
;
941 convertIP(addr1
, rttKey1
->saddr
);
942 convertIP(addr2
, rttKey1
->daddr
);
944 fileRtt1
= g_hash_table_lookup(rttInfo
, rttKey1
);
945 fileRtt2
= g_hash_table_lookup(rttInfo
, &rttKey2
);
947 printf("\t\t(%15s, %-15s) %-18.3f ", addr1
, addr2
, *(double*) value
* 1e3
);
949 if (fileRtt1
|| fileRtt2
)
953 printf("%.3f", *fileRtt1
* 1e3
);
955 if (fileRtt1
&& fileRtt2
)
961 printf("%.3f", *fileRtt2
* 1e3
);
973 * A GHashFunc for g_hash_table_new()
978 static guint
ghfRttKeyHash(gconstpointer key
)
980 struct RttKey
* rttKey
;
983 rttKey
= (struct RttKey
*) key
;
995 * A GDestroyNotify function for g_hash_table_new_full()
998 * data: struct RttKey*
1000 static void gdnDestroyRttKey(gpointer data
)
1007 * A GDestroyNotify function for g_hash_table_new_full()
1012 static void gdnDestroyDouble(gpointer data
)
1019 * A GEqualFunc for g_hash_table_new()
1025 * TRUE if both values are equal
1027 static gboolean
gefRttKeyEqual(gconstpointer a
, gconstpointer b
)
1029 const struct RttKey
* rkA
, * rkB
;
1031 rkA
= (struct RttKey
*) a
;
1032 rkB
= (struct RttKey
*) b
;
1034 if (rkA
->saddr
== rkB
->saddr
&& rkA
->daddr
== rkB
->daddr
)
1046 * Read a file contain minimum round trip time values and fill an array with
1047 * them. The file is formatted as such:
1048 * <host1 IP> <host2 IP> <RTT in milliseconds>
1049 * ip's should be in dotted quad format
1052 * rttInfo: double* rttInfo[RttKey], empty table, will be filled
1053 * rttStream: stream from which to read
1055 static void readRttInfo(GHashTable
* rttInfo
, FILE* rttStream
)
1061 positionStream(rttStream
);
1062 retval
= getline(&line
, &len
, rttStream
);
1063 while(!feof(rttStream
))
1065 struct RttKey
* rttKey
;
1066 char saddrDQ
[20], daddrDQ
[20];
1069 struct in_addr addr
;
1075 {saddrDQ
, offsetof(struct RttKey
, saddr
)},
1076 {daddrDQ
, offsetof(struct RttKey
, daddr
)}
1079 if (retval
== -1 && !feof(rttStream
))
1081 g_error(strerror(errno
));
1084 if (line
[retval
- 1] == '\n')
1086 line
[retval
- 1]= '\0';
1089 rtt
= malloc(sizeof(double));
1090 retval
= sscanf(line
, " %19s %19s %lf %c", saddrDQ
, daddrDQ
, rtt
,
1094 g_error(strerror(errno
));
1096 else if (retval
!= 3)
1098 g_error("Error parsing RTT file, line was '%s'", line
);
1101 rttKey
= malloc(sizeof(struct RttKey
));
1102 for (i
= 0; i
< sizeof(loopValues
) / sizeof(*loopValues
); i
++)
1104 retval
= inet_aton(loopValues
[i
].dq
, &addr
);
1107 g_error("Error converting address '%s'", loopValues
[i
].dq
);
1109 *(uint32_t*) ((void*) rttKey
+ loopValues
[i
].offset
)=
1114 g_debug("rttInfo, Inserting (%u, %u)->(%f)", rttKey
->saddr
,
1115 rttKey
->daddr
, *rtt
);
1116 g_hash_table_insert(rttInfo
, rttKey
, rtt
);
1118 positionStream(rttStream
);
1119 retval
= getline(&line
, &len
, rttStream
);
1130 * Advance stream over empty space, empty lines and lines that begin with '#'
1133 * stream: stream, at exit, will be over the first non-empty character
1134 * of a line of be at EOF
1136 static void positionStream(FILE* stream
)
1145 firstChar
= fgetc(stream
);
1146 if (firstChar
== (int) '#')
1148 retval
= getline(&line
, &len
, stream
);
1157 g_error(strerror(errno
));
1161 else if (firstChar
== (int) '\n' || firstChar
== (int) ' ' ||
1162 firstChar
== (int) '\t')
1164 else if (firstChar
== EOF
)
1173 retval
= ungetc(firstChar
, stream
);
1176 g_error("Error: ungetc()");
1188 * A GFunc for g_queue_foreach()
1191 * data Event*, a UDP broadcast event
1192 * user_data double*, the running sum
1195 * Adds the time of the event to the sum
1197 static void gfSum(gpointer data
, gpointer userData
)
1199 Event
* event
= (Event
*) data
;
1201 *(double*) userData
+= event
->wallTime
.seconds
+ event
->wallTime
.nanosec
/
1207 * A GFunc for g_queue_foreach()
1210 * data Event*, a UDP broadcast event
1211 * user_data double*, the running sum
1214 * Adds the square of the time of the event to the sum
1216 static void gfSumSquares(gpointer data
, gpointer userData
)
1218 Event
* event
= (Event
*) data
;
1220 *(double*) userData
+= pow(event
->wallTime
.seconds
+ event
->wallTime
.nanosec
1226 * Update a struct Bins according to a new value
1229 * bins: the structure containing bins to build a histrogram
1230 * value: the new value
1232 static void hitBin(struct Bins
* const bins
, const double value
)
1234 unsigned int binN
= binNum(value
);
1236 if (binN
< bins
->min
)
1240 else if (binN
> bins
->max
)
1252 * Figure out the bin in a histogram to which a value belongs.
1254 * This uses exponentially sized bins that go from 0 to infinity.
1257 * value: in the range -INFINITY to INFINITY
1260 * The number of the bin in a struct Bins.bin
1262 static unsigned int binNum(const double value
)
1268 else if (value
< binEnd(1))
1272 else if (value
>= binStart(BIN_NB
- 1))
1278 return floor(log(value
) / log(binBase
)) + BIN_NB
+ 1;
1284 * Figure out the start of the interval of a bin in a histogram. See struct
1287 * This uses exponentially sized bins that go from 0 to infinity.
1290 * binNum: bin number
1293 * The start of the interval, this value is included in the interval (except
1294 * for -INFINITY, naturally)
1296 static double binStart(const unsigned int binNum
)
1298 g_assert_cmpuint(binNum
, <, BIN_NB
);
1304 else if (binNum
== 1)
1310 return pow(binBase
, (double) binNum
- BIN_NB
+ 1);
1316 * Figure out the end of the interval of a bin in a histogram. See struct
1319 * This uses exponentially sized bins that go from 0 to infinity.
1322 * binNum: bin number
1325 * The end of the interval, this value is not included in the interval
1327 static double binEnd(const unsigned int binNum
)
1329 g_assert_cmpuint(binNum
, <, BIN_NB
);
1335 else if (binNum
< BIN_NB
- 1)
1337 return pow(binBase
, (double) binNum
- BIN_NB
+ 2);
1347 * Return the total number of elements in the "normal" bins (not underflow or
1351 * bins: the structure containing bins to build a histrogram
1353 static uint32_t normalTotal(struct Bins
* const bins
)
1355 return bins
->total
- bins
->bin
[0] - bins
->bin
[BIN_NB
- 1];
1359 /* Update the bounds between two traces
1362 * bounds: the array containing all the trace-pair bounds
1363 * e1, e2: the two related events
1365 static void updateBounds(Bounds
** const bounds
, Event
* const e1
, Event
* const
1368 unsigned int traceI
, traceJ
;
1369 uint64_t messageTime
;
1372 if (e1
->traceNum
< e2
->traceNum
)
1374 traceI
= e2
->traceNum
;
1375 traceJ
= e1
->traceNum
;
1376 messageTime
= e1
->cpuTime
;
1380 traceI
= e1
->traceNum
;
1381 traceJ
= e2
->traceNum
;
1382 messageTime
= e2
->cpuTime
;
1384 tpBounds
= &bounds
[traceI
][traceJ
];
1386 if (messageTime
< tpBounds
->min
)
1388 tpBounds
->min
= messageTime
;
1390 if (messageTime
> tpBounds
->max
)
1392 tpBounds
->max
= messageTime
;