From: Martin Quinson Date: Thu, 9 Aug 2012 07:59:35 +0000 (+0200) Subject: Various hacks to unbench the logging to disk when run in SMPI X-Git-Tag: v3_8~177^2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/e7d52b71aae78b9db6aab2f8628fe6906167282e Various hacks to unbench the logging to disk when run in SMPI - First use of weak symbols aliases in our source tree :-/ I hope it won't induce portability issues - Only very partially tested, sorry. Read: it compiles, that's all I know --- diff --git a/src/smpi/smpi_global.c b/src/smpi/smpi_global.c index 4560524357..fcaaf23411 100644 --- a/src/smpi/smpi_global.c +++ b/src/smpi/smpi_global.c @@ -15,8 +15,6 @@ #include "simix/smx_private.h" -XBT_LOG_NEW_CATEGORY(smpi, "All SMPI categories"); - XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_kernel, smpi, "Logging specific to SMPI (kernel)"); @@ -274,7 +272,8 @@ int MAIN__(void) } /* Connect log categories. See xbt/log.c */ - XBT_LOG_CONNECT(smpi); + XBT_LOG_CONNECT(smpi); /* Keep this line as soon as possible in this function: xbt_log_appender_file.c depends on it + DO NOT connect this in XBT or so, or it will be useless to xbt_log_appender_file.c */ XBT_LOG_CONNECT(smpi_base); XBT_LOG_CONNECT(smpi_bench); XBT_LOG_CONNECT(smpi_coll); diff --git a/src/xbt/xbt_log_appender_file.c b/src/xbt/xbt_log_appender_file.c index 57038c121a..8869cc21ec 100644 --- a/src/xbt/xbt_log_appender_file.c +++ b/src/xbt/xbt_log_appender_file.c @@ -1,39 +1,45 @@ -/* file_appender - a dumb log appender which simply prints to stdout */ +/* file_appender - a dumb log appender which simply prints to a file */ -/* Copyright (c) 2007-2011. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2007-2012. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ #include "xbt/sysdep.h" #include "xbt/log_private.h" +#include "smpi/private.h" // to access bench_begin/end. Not ultraclean, I confess #include -/** - * The root category's default logging function. - */ - -extern const char *xbt_log_priority_names[8]; - +static void append_file(xbt_log_appender_t this_, char *str) { + fputs(str, (FILE *) this_->data); +} -static void append_file(xbt_log_appender_t this_appender, char *str) -{ - fputs(str, (FILE *) (this_appender->data)); +static void smpi_append_file(xbt_log_appender_t this_, char *str) { + smpi_bench_end(); + fputs(str, (FILE *) this_->data); + smpi_bench_begin(); } -static void free_(xbt_log_appender_t this_) -{ +static void free_(xbt_log_appender_t this_) { if (this_->data != stderr) fclose(this_->data); } +void __smpi_bench_dont (void); // Stupid prototype +void __smpi_bench_dont (void) { /* I'm only a place-holder in case we link without SMPI */; } +void smpi_bench_begin(void) __attribute__ ((weak, alias ("__smpi_bench_dont"))); +void smpi_bench_end(void) __attribute__ ((weak, alias ("__smpi_bench_dont"))); -xbt_log_appender_t xbt_log_appender_file_new(char *arg) -{ +XBT_LOG_EXTERNAL_CATEGORY(smpi); // To detect if SMPI is inited + +xbt_log_appender_t xbt_log_appender_file_new(char *arg) { + xbt_log_appender_t res = xbt_new0(s_xbt_log_appender_t, 1); - res->do_append = append_file; + if (_XBT_LOGV(smpi).initialized) // HACK to detect if we run in SMPI mode. Relies on MAIN__ source disposition + res->do_append = smpi_append_file; + else + res->do_append = append_file; res->free_ = free_; if (arg) res->data = (void *) fopen(arg, "w"); diff --git a/src/xbt/xbt_main.c b/src/xbt/xbt_main.c index 2ca0ed635a..030dd348c4 100644 --- a/src/xbt/xbt_main.c +++ b/src/xbt/xbt_main.c @@ -23,6 +23,9 @@ XBT_LOG_NEW_CATEGORY(xbt, "All XBT categories (simgrid toolbox)"); XBT_LOG_NEW_DEFAULT_SUBCATEGORY(module, xbt, "module handling"); +XBT_LOG_NEW_CATEGORY(smpi, "All SMPI categories"); /* lives here even if that's a bit odd to solve linking issues: this is used in xbt_log_file_appender to detect whether SMPI is used (and thus whether we should unbench the writing to disk) */ + + char *xbt_binary_name = NULL; /* Mandatory to retrieve neat backtraces */ int xbt_initialized = 0;