Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Various hacks to unbench the logging to disk when run in SMPI
authorMartin Quinson <martin.quinson@loria.fr>
Thu, 9 Aug 2012 07:59:35 +0000 (09:59 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Thu, 9 Aug 2012 07:59:35 +0000 (09:59 +0200)
- 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

src/smpi/smpi_global.c
src/xbt/xbt_log_appender_file.c
src/xbt/xbt_main.c

index 4560524..fcaaf23 100644 (file)
@@ -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);
index 57038c1..8869cc2 100644 (file)
@@ -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 <stdio.h>
 
-/**
- * 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");
index 2ca0ed6..030dd34 100644 (file)
@@ -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;