/* This file is part of the Linux Trace Toolkit viewer
- * Copyright (C) 2009 Benjamin Poirier <benjamin.poirier@polymtl.ca>
+ * Copyright (C) 2009, 2010 Benjamin Poirier <benjamin.poirier@polymtl.ca>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License Version 2 as
- * published by the Free Software Foundation;
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or (at
+ * your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- * MA 02111-1307, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE
broadcast);
static GArray* finalizeAnalysisEval(SyncState* const syncState);
static void printAnalysisStatsEval(SyncState* const syncState);
-static void writeAnalysisTraceTimePlotsEval(SyncState* const syncState, const
- unsigned int i, const unsigned int j);
-static void writeAnalysisTraceTracePlotsEval(SyncState* const syncState, const
- unsigned int i, const unsigned int j);
+static void writeAnalysisTraceTimeBackPlotsEval(SyncState* const syncState,
+ const unsigned int i, const unsigned int j);
+static void writeAnalysisTraceTimeForePlotsEval(SyncState* const syncState,
+ const unsigned int i, const unsigned int j);
+static void writeAnalysisTraceTraceBackPlotsEval(SyncState* const syncState,
+ const unsigned int i, const unsigned int j);
+static void writeAnalysisTraceTraceForePlotsEval(SyncState* const syncState,
+ const unsigned int i, const unsigned int j);
// Functions specific to this module
-static void registerAnalysisEval() __attribute__((constructor (102)));
static guint ghfRttKeyHash(gconstpointer key);
static gboolean gefRttKeyEqual(gconstpointer a, gconstpointer b);
static void gdnDestroyRttKey(gpointer data);
static void writeHistogram(FILE* graphsStream, const struct RttKey* rttKey,
double* minRtt, AnalysisHistogramEval* const histogram);
-static void updateBounds(Bounds** const bounds, Event* const e1, Event* const e2);
+static void updateBounds(Bounds** const bounds, Event* const e1, Event* const
+ e2);
+static void finalizeAnalysisEvalLP(SyncState* const syncState);
// The next group of functions is only needed when computing synchronization
// accuracy.
#ifdef HAVE_LIBGLPK
-static glp_prob* lpCreateProblem(GQueue* const lowerHull, GQueue* const upperHull);
+static glp_prob* lpCreateProblem(GQueue* const lowerHull, GQueue* const
+ upperHull);
static void gfLPAddRow(gpointer data, gpointer user_data);
static Factors* calculateFactors(glp_prob* const lp, const int direction);
-static void calculateCompleteFactors(glp_prob* const lp, FactorsCHull* factors);
+static void calculateCompleteFactors(glp_prob* const lp, FactorsCHull*
+ factors);
static FactorsCHull** createAllFactors(const unsigned int traceNb);
static inline void finalizeAnalysisEvalLP(SyncState* const syncState);
+static void gfAddAbsiscaToArray(gpointer data, gpointer user_data);
+static gint gcfCompareDouble(gconstpointer a, gconstpointer b);
#else
static void finalizeAnalysisEvalLP(SyncState* const syncState);
#endif
.finalizeAnalysis= &finalizeAnalysisEval,
.printAnalysisStats= &printAnalysisStatsEval,
.graphFunctions= {
- .writeTraceTimePlots= &writeAnalysisTraceTimePlotsEval,
- .writeTraceTracePlots= &writeAnalysisTraceTracePlotsEval,
+ .writeTraceTimeBackPlots= &writeAnalysisTraceTimeBackPlotsEval,
+ .writeTraceTimeForePlots= &writeAnalysisTraceTimeForePlotsEval,
+ .writeTraceTraceBackPlots= &writeAnalysisTraceTraceBackPlotsEval,
+ .writeTraceTraceForePlots= &writeAnalysisTraceTraceForePlotsEval,
}
};
static ModuleOption optionEvalRttFile= {
.longName= "eval-rtt-file",
.hasArg= REQUIRED_ARG,
- {.arg= NULL},
.optionHelp= "specify the file containing RTT information",
.argHelp= "FILE",
};
/*
* Analysis module registering function
*/
-static void registerAnalysisEval()
+void registerAnalysisEval()
{
binBase= exp10(6. / (BIN_NB - 3));
if (syncState->stats)
{
analysisData->stats= calloc(1, sizeof(AnalysisStatsEval));
- analysisData->stats->broadcastDiffSum= 0.;
+ analysisData->stats->broadcastRangeMin= INFINITY;
+ analysisData->stats->broadcastRangeMax= -INFINITY;
analysisData->stats->messageStats= malloc(syncState->traceNb *
sizeof(MessageStats*));
convertIP(saddr, rttKey->saddr);
convertIP(daddr, rttKey->daddr);
- cwd= changeToGraphDir(graphsDir);
+ cwd= changeToGraphsDir(graphsDir);
for (i= 0; i < sizeof(loopValues) / sizeof(*loopValues); i++)
{
*/
static void destroyAnalysisEval(SyncState* const syncState)
{
- unsigned int i, j;
+ unsigned int i;
AnalysisDataEval* analysisData;
analysisData= (AnalysisDataEval*) syncState->analysisData;
#ifdef HAVE_LIBGLPK
for (i= 0; i < syncState->traceNb; i++)
{
+ unsigned int j;
+
for (j= 0; j < i; j++)
{
// There seems to be a memory leak in glpk, valgrind reports a
- // loss even if the problem is deleted
+ // loss (reachable) even if the problem is deleted
glp_delete_prob(graphs->lps[i][j]);
}
free(graphs->lps[i]);
message)
{
AnalysisDataEval* analysisData= syncState->analysisData;
- MessageStats* messageStats=
- &analysisData->stats->messageStats[message->outE->traceNum][message->inE->traceNum];
+ MessageStats* messageStats;
double* rtt;
double tt;
struct RttKey rttKey;
if (syncState->stats)
{
+ messageStats=
+ &analysisData->stats->messageStats[message->outE->traceNum][message->inE->traceNum];
messageStats->total++;
}
g_queue_get_length(broadcast->events), 2.);
if (y > 0)
{
- analysisData->stats->broadcastDiffSum+= sqrt(y);
+ analysisData->stats->broadcastStdevSum+= sqrt(y);
+ }
+
+ if (syncState->traceNb == 2 && g_queue_get_length(broadcast->events)
+ == 2)
+ {
+ Event* e0, * e1;
+ double dd;
+
+ e0= g_queue_peek_head(broadcast->events);
+ e1= g_queue_peek_tail(broadcast->events);
+ if (e0->traceNum > e1->traceNum)
+ {
+ Event* tmp;
+
+ tmp= e0;
+ e0= e1;
+ e1= tmp;
+ }
+
+ dd= wallTimeSub(&e1->wallTime, &e0->wallTime);
+
+ analysisData->stats->broadcastPairNb++;
+ if (dd < analysisData->stats->broadcastRangeMin)
+ {
+ analysisData->stats->broadcastRangeMin= dd;
+ }
+ if (dd > analysisData->stats->broadcastRangeMax)
+ {
+ analysisData->stats->broadcastRangeMax= dd;
+ }
+
+ analysisData->stats->broadcastSum+= dd;
+ analysisData->stats->broadcastSumSquares+= pow(dd, 2);
}
}
printf("Synchronization evaluation analysis stats:\n");
if (analysisData->stats->broadcastNb)
{
- printf("\tsum of broadcast differential delays: %g\n",
- analysisData->stats->broadcastDiffSum);
- printf("\taverage broadcast differential delay: %g\n",
- analysisData->stats->broadcastDiffSum /
+ printf("\tBroadcast differential delay:\n");
+ printf("\t\tsum of standard deviations: %g\n",
+ analysisData->stats->broadcastStdevSum);
+ printf("\t\taverage standard deviation: %g\n",
+ analysisData->stats->broadcastStdevSum /
analysisData->stats->broadcastNb);
+
+ if (syncState->traceNb == 2)
+ {
+ printf("\t\tdifferential delay range: [ %g .. %g ]\n",
+ analysisData->stats->broadcastRangeMin,
+ analysisData->stats->broadcastRangeMax);
+ printf("\t\tdifferential delay average: %g\n",
+ analysisData->stats->broadcastSum /
+ analysisData->stats->broadcastPairNb);
+ printf("\t\tdifferential delay standard deviation: %g\n",
+ sqrt(analysisData->stats->broadcastSumSquares /
+ analysisData->stats->broadcastPairNb -
+ pow(analysisData->stats->broadcastSum /
+ analysisData->stats->broadcastPairNb, 2)));
+ }
}
printf("\tIndividual evaluation:\n"
&analysisData->stats->messageStats[loopValues[k].t1][loopValues[k].t2];
printf("\t\t%3d - %-3d ", loopValues[k].t1, loopValues[k].t2);
- printf("%u (%u%%)%n", messageStats->inversionNb, (unsigned
- int) ceil((double) messageStats->inversionNb /
- messageStats->total * 100), &charNb);
+ printf("%u (%.2f%%)%n", messageStats->inversionNb, (double)
+ messageStats->inversionNb / messageStats->total * 100,
+ &charNb);
printf("%*s", 17 - charNb > 0 ? 17 - charNb + 1: 1, " ");
- printf("%u (%u%%)%n", messageStats->tooFastNb, (unsigned int)
- ceil((double) messageStats->tooFastNb /
- messageStats->total * 100), &charNb);
+ printf("%u (%.2f%%)%n", messageStats->tooFastNb, (double)
+ messageStats->tooFastNb / messageStats->total * 100,
+ &charNb);
printf("%*s%-10u %u\n", 17 - charNb > 0 ? 17 - charNb + 1:
1, " ", messageStats->noRTTInfoNb, messageStats->total);
}
printf("\t\t total ");
- printf("%u (%u%%)%n", totInversion, (unsigned int) ceil((double)
- totInversion / totTotal * 100), &charNb);
+ printf("%u (%.2f%%)%n", totInversion, (double) totInversion / totTotal *
+ 100, &charNb);
printf("%*s", 17 - charNb > 0 ? 17 - charNb + 1: 1, " ");
- printf("%u (%u%%)%n", totTooFast, (unsigned int) ceil((double) totTooFast
- / totTotal * 100), &charNb);
+ printf("%u (%.2f%%)%n", totTooFast, (double) totTooFast / totTotal * 100,
+ &charNb);
printf("%*s%-10u %u\n", 17 - charNb > 0 ? 17 - charNb + 1: 1, " ",
totNoInfo, totTotal);
g_hash_table_foreach(analysisData->stats->exchangeRtt,
&ghfPrintExchangeRtt, analysisData->rttInfo);
+#ifdef HAVE_LIBGLPK
printf("\tConvex hull factors comparisons:\n"
"\t\tTrace pair Factors type Differences (lp - chull)\n"
"\t\t a0 a1\n"
}
}
}
+#endif
}
* bounds: the array containing all the trace-pair bounds
* e1, e2: the two related events
*/
-static void updateBounds(Bounds** const bounds, Event* const e1, Event* const e2)
+static void updateBounds(Bounds** const bounds, Event* const e1, Event* const
+ e2)
{
unsigned int traceI, traceJ;
uint64_t messageTime;
* A new glp_prob*, this problem must be freed by the caller with
* glp_delete_prob()
*/
-static glp_prob* lpCreateProblem(GQueue* const lowerHull, GQueue* const upperHull)
+static glp_prob* lpCreateProblem(GQueue* const lowerHull, GQueue* const
+ upperHull)
{
unsigned int it;
const int zero= 0;
// Create the LP problem
glp_term_out(GLP_OFF);
- glp_add_rows(lp, hullPointNb);
+ if (hullPointNb > 0)
+ {
+ glp_add_rows(lp, hullPointNb);
+ }
glp_add_cols(lp, 2);
glp_set_col_name(lp, 1, "a0");
return factorsArray;
}
+
+
+/*
+ * A GFunc for g_queue_foreach()
+ *
+ * Args:
+ * data Point*, a convex hull point
+ * user_data GArray*, an array of convex hull point absisca values, as
+ * double
+ */
+static void gfAddAbsiscaToArray(gpointer data, gpointer user_data)
+{
+ Point* p= data;
+ GArray* a= user_data;
+ double v= p->x;
+
+ g_array_append_val(a, v);
+}
+
+
+/*
+ * A GCompareFunc for g_array_sort()
+ *
+ * Args:
+ * a, b double*, absisca values
+ *
+ * Returns:
+ * "returns less than zero for first arg is less than second arg, zero for
+ * equal, greater zero if first arg is greater than second arg"
+ * - the great glib documentation
+ */
+static gint gcfCompareDouble(gconstpointer a, gconstpointer b)
+{
+ if (*(double*) a < *(double*) b)
+ {
+ return -1;
+ }
+ else if (*(double*) a > *(double*) b)
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
#endif
* Compute synchronization factors using a linear programming approach.
* Compute the factors using analysis_chull. Compare the two.
*
- * There are two definitions of this function. The empty one is used when the
- * solver library, glpk, is not available at build time. In that case, nothing
- * is actually produced.
+ * When the solver library, glpk, is not available at build time, only compute
+ * the factors using analysis_chull. This is to make sure that module runs its
+ * finalize function so that its graph functions can be called later.
*
* Args:
* syncState: container for synchronization data
*/
-#ifndef HAVE_LIBGLPK
-static inline void finalizeAnalysisEvalLP(SyncState* const syncState)
-{
-}
-#else
static void finalizeAnalysisEvalLP(SyncState* const syncState)
{
- unsigned int i, j;
AnalysisDataEval* analysisData= syncState->analysisData;
+#ifdef HAVE_LIBGLPK
+ unsigned int i, j;
AnalysisDataCHull* chAnalysisData= analysisData->chullSS->analysisData;
- FactorsCHull** lpFactorsArray= createAllFactors(syncState->traceNb);
- FactorsCHull* lpFactors;
+ FactorsCHull** lpFactorsArray;
if (!syncState->stats && !syncState->graphsStream)
{
return;
}
+ /* Because of matching_distributor, this analysis may be called twice.
+ * Only run it once */
if ((syncState->graphsStream && analysisData->graphs->lps != NULL) ||
(syncState->stats && analysisData->stats->chFactorsArray != NULL))
{
return;
}
+ lpFactorsArray= createAllFactors(syncState->traceNb);
+
if (syncState->stats)
{
analysisData->stats->chFactorsArray=
else
{
glp_delete_prob(lp);
- destroyFactorsCHull(lpFactors);
}
}
}
+#endif
g_array_free(analysisData->chullSS->analysisModule->finalizeAnalysis(analysisData->chullSS),
TRUE);
}
-#endif
/*
* approach. Write the neccessary data files and plot lines in the gnuplot
* script.
*
- * There are two definitions of this function. The empty one is used when the
- * solver library, glpk, is not available at build time. In that case, nothing
- * is actually produced.
+ * When the solver library, glpk, is not available at build time nothing is
+ * actually produced.
*
* Args:
* syncState: container for synchronization data
* i: first trace number
* j: second trace number, garanteed to be larger than i
*/
-#ifndef HAVE_LIBGLPK
-static inline void writeAccuracyGraphs(SyncState* const syncState, const unsigned int
- i, const unsigned int j)
-{
-}
-#else
-static void writeAccuracyGraphs(SyncState* const syncState, const unsigned int
- i, const unsigned int j)
+static void writeAnalysisTraceTimeBackPlotsEval(SyncState* const syncState,
+ const unsigned int i, const unsigned int j)
{
+#ifdef HAVE_LIBGLPK
unsigned int it;
AnalysisDataEval* analysisData= syncState->analysisData;
AnalysisGraphsEval* graphs= analysisData->graphs;
char* cwd;
char fileName[40];
FILE* fp;
- double* xValues;
- unsigned int xBegin, xEnd;
- double interval;
- const unsigned int graphPointNb= 1000;
+ GArray* xValues;
// Open the data file
snprintf(fileName, 40, "analysis_eval_accuracy-%03u_and_%03u.data", i, j);
fileName[sizeof(fileName) - 1]= '\0';
- cwd= changeToGraphDir(syncState->graphsDir);
+ cwd= changeToGraphsDir(syncState->graphsDir);
if ((fp= fopen(fileName, "w")) == NULL)
{
free(cwd);
// Build the list of absisca values for the points in the accuracy graph
- g_assert_cmpuint(graphPointNb, >=, 4);
- xValues= malloc(graphPointNb * sizeof(double));
- xValues[0]= graphs->bounds[j][i].min;
- xValues[graphPointNb - 1]= graphs->bounds[j][i].max;
- xValues[1]= MIN(((Point*) g_queue_peek_head(hullArray[i][j]))->x,
- ((Point*) g_queue_peek_head(hullArray[j][i]))->x);
- xValues[graphPointNb - 2]= MAX(((Point*)
- g_queue_peek_tail(hullArray[i][j]))->x, ((Point*)
- g_queue_peek_tail(hullArray[j][i]))->x);
-
- if (xValues[0] == xValues[1])
- {
- xBegin= 0;
- }
- else
- {
- xBegin= 1;
- }
- if (xValues[graphPointNb - 2] == xValues[graphPointNb - 1])
- {
- xEnd= graphPointNb - 1;
- }
- else
- {
- xEnd= graphPointNb - 2;
- }
- interval= (xValues[xEnd] - xValues[xBegin]) / (graphPointNb - 1);
+ xValues= g_array_sized_new(FALSE, FALSE, sizeof(double),
+ g_queue_get_length(hullArray[i][j]) +
+ g_queue_get_length(hullArray[j][i]));
- for (it= xBegin; it <= xEnd; it++)
- {
- xValues[it]= xValues[xBegin] + interval * (it - xBegin);
- }
+ g_queue_foreach(hullArray[i][j], &gfAddAbsiscaToArray, xValues);
+ g_queue_foreach(hullArray[j][i], &gfAddAbsiscaToArray, xValues);
+
+ g_array_sort(xValues, &gcfCompareDouble);
/* For each absisca value and each optimisation direction, solve the LP
* and write a line in the data file */
- for (it= 0; it < graphPointNb; it++)
+ for (it= 0; it < xValues->len; it++)
{
unsigned int it2;
int directions[]= {GLP_MIN, GLP_MAX};
-
glp_set_obj_coef(lp, 1, 1.);
- glp_set_obj_coef(lp, 2, xValues[it]);
+ glp_set_obj_coef(lp, 2, g_array_index(xValues, double, it));
- fprintf(fp, "%25.9f %25.9f", xValues[it], lpFactors->approx->offset
- + lpFactors->approx->drift * xValues[it]);
+ fprintf(fp, "%25.9f %25.9f", g_array_index(xValues, double, it),
+ lpFactors->approx->offset + lpFactors->approx->drift *
+ g_array_index(xValues, double, it));
for (it2= 0; it2 < sizeof(directions) / sizeof(*directions); it2++)
{
int status;
fprintf(fp, "\n");
}
- free(xValues);
+ g_array_free(xValues, TRUE);
fclose(fp);
fprintf(syncState->graphsStream,
"linecolor rgb \"black\" fill solid 0.25 noborder, \\\n", i,
j);
}
-}
#endif
+}
/*
* Write the analysis-specific graph lines in the gnuplot script.
*
+ * When the solver library, glpk, is not available at build time nothing is
+ * actually produced.
+ *
* Args:
* syncState: container for synchronization data
* i: first trace number
* j: second trace number, garanteed to be larger than i
*/
-static void writeAnalysisTraceTimePlotsEval(SyncState* const syncState, const
- unsigned int i, const unsigned int j)
+static void writeAnalysisTraceTimeForePlotsEval(SyncState* const syncState,
+ const unsigned int i, const unsigned int j)
{
- AnalysisDataEval* analysisData= syncState->analysisData;
- AnalysisGraphsEval* graphs= analysisData->graphs;
- GQueue*** hullArray= ((AnalysisDataCHull*)
- analysisData->chullSS->analysisData)->hullArray;
-
- printf("Between %u and %u:\n", i, j);
- printf("\tbounds min %llu max %llu\n", graphs->bounds[j][i].min,
- graphs->bounds[j][i].max);
- printf("\tnumber of points in lower half-hull %u upper half-hull %u\n",
- g_queue_get_length(hullArray[j][i]),
- g_queue_get_length(hullArray[i][j]));
-
- writeAccuracyGraphs(syncState, i, j);
+#ifdef HAVE_LIBGLPK
+ if (((AnalysisDataEval*)
+ syncState->analysisData)->graphs->lpFactorsArray[j][i].type ==
+ MIDDLE)
+ {
+ fprintf(syncState->graphsStream,
+ "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
+ "using 1:(($3 - $2) / clock_freq_%2$u) notitle "
+ "with lines linewidth 2 linetype 1 "
+ "linecolor rgb \"gray60\", \\\n"
+ "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
+ "using 1:(($4 - $2) / clock_freq_%2$u) notitle "
+ "with lines linewidth 2 linetype 1 "
+ "linecolor rgb \"gray60\", \\\n", i, j);
+ }
+#endif
}
-static void writeAnalysisTraceTracePlotsEval(SyncState* const syncState, const
- unsigned int i, const unsigned int j)
+/*
+ * Write the analysis-specific graph lines in the gnuplot script.
+ *
+ * Args:
+ * syncState: container for synchronization data
+ * i: first trace number
+ * j: second trace number, garanteed to be larger than i
+ */
+static void writeAnalysisTraceTraceBackPlotsEval(SyncState* const syncState,
+ const unsigned int i, const unsigned int j)
{
- AnalysisDataEval* analysisData= syncState->analysisData;
-
#ifdef HAVE_LIBGLPK
fprintf(syncState->graphsStream,
"\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "
"with filledcurves linewidth 2 linetype 1 "
"linecolor rgb \"black\" fill solid 0.25 noborder, \\\n", i, j);
#endif
+}
+
+
+/*
+ * Write the analysis-specific graph lines in the gnuplot script.
+ *
+ * Args:
+ * syncState: container for synchronization data
+ * i: first trace number
+ * j: second trace number, garanteed to be larger than i
+ */
+static void writeAnalysisTraceTraceForePlotsEval(SyncState* const syncState,
+ const unsigned int i, const unsigned int j)
+{
+ AnalysisDataEval* analysisData= syncState->analysisData;
- analysisData->chullSS->analysisModule->graphFunctions.writeTraceTracePlots(analysisData->chullSS,
+ analysisData->chullSS->analysisModule->graphFunctions.writeTraceTraceForePlots(analysisData->chullSS,
i, j);
}