Browse Source

When the "verbose" option is enabled, create a log file. Its content is filled
by the means of the "print_to_logfile" function which is thread safe.

Cédric Augonnet 16 years ago
parent
commit
95f9c1a844
6 changed files with 104 additions and 2 deletions
  1. 2 0
      src/Makefile.am
  2. 60 0
      src/core/debug.c
  3. 32 0
      src/core/debug.h
  4. 7 0
      src/core/workers.c
  5. 2 1
      src/drivers/core/driver_core.c
  6. 1 1
      src/drivers/cuda/driver_cuda.c

+ 2 - 0
src/Makefile.am

@@ -46,6 +46,7 @@ noinst_HEADERS = 						\
 	core/perfmodel/regression.h				\
 	core/perfmodel/regression.h				\
 	core/jobs.h						\
 	core/jobs.h						\
 	core/workers.h						\
 	core/workers.h						\
+	core/debug.h						\
 	datawizard/footprint.h					\
 	datawizard/footprint.h					\
 	datawizard/datawizard.h					\
 	datawizard/datawizard.h					\
 	datawizard/data_request.h				\
 	datawizard/data_request.h				\
@@ -88,6 +89,7 @@ libstarpu_la_SOURCES = 						\
 	common/timing.c						\
 	common/timing.c						\
 	core/jobs.c						\
 	core/jobs.c						\
 	core/workers.c						\
 	core/workers.c						\
+	core/debug.c						\
 	core/dependencies/tags.c				\
 	core/dependencies/tags.c				\
 	core/dependencies/htable.c				\
 	core/dependencies/htable.c				\
 	core/dependencies/data-concurrency.c			\
 	core/dependencies/data-concurrency.c			\

+ 60 - 0
src/core/debug.c

@@ -0,0 +1,60 @@
+/*
+ * StarPU
+ * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
+ *
+ * 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 Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#include <common/config.h>
+#include <core/debug.h>
+
+#ifdef VERBOSE
+/* we want a single writer at the same time to have a log that is readable */
+static pthread_mutex_t logfile_mutex = PTHREAD_MUTEX_INITIALIZER;
+static FILE *logfile;
+#endif
+
+void open_debug_logfile(void)
+{
+#ifdef VERBOSE
+	/* what is  the name of the file ? default = "starpu.log" */
+	char *logfile_name;
+	
+	logfile_name = getenv("LOGFILENAME");
+	if (!logfile_name)
+	{
+		logfile_name = "starpu.log";
+	}
+
+	logfile = fopen(logfile_name, "w+");
+	STARPU_ASSERT(logfile);
+#endif
+}
+
+void close_debug_logfile(void)
+{
+#ifdef VERBOSE
+	fclose(logfile);
+#endif
+}
+
+void print_to_logfile(const char *format, ...)
+{
+#ifdef VERBOSE
+	va_list args;
+	va_start(args, format);
+	pthread_mutex_lock(&logfile_mutex);
+	vfprintf(logfile, format, args);
+	pthread_mutex_unlock(&logfile_mutex);
+	va_end( args );
+#endif
+}

+ 32 - 0
src/core/debug.h

@@ -0,0 +1,32 @@
+/*
+ * StarPU
+ * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
+ *
+ * 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 Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#ifndef __DEBUG_H__
+#define __DEBUG_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+#include <common/config.h>
+#include <core/workers.h>
+
+void open_debug_logfile(void);
+void close_debug_logfile(void);
+
+void print_to_logfile(const char *format, ...);
+
+#endif // __DEBUG_H__

+ 7 - 0
src/core/workers.c

@@ -14,8 +14,11 @@
  * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  */
  */
 
 
+#include <stdlib.h>
+#include <stdio.h>
 #include <common/config.h>
 #include <common/config.h>
 #include <core/workers.h>
 #include <core/workers.h>
+#include <core/debug.h>
 
 
 /* XXX quick and dirty implementation for now ... */
 /* XXX quick and dirty implementation for now ... */
 pthread_key_t local_workers_key;
 pthread_key_t local_workers_key;
@@ -406,6 +409,8 @@ void starpu_init(struct starpu_conf *user_conf)
 #ifdef USE_FXT
 #ifdef USE_FXT
 	start_fxt_profiling();
 	start_fxt_profiling();
 #endif
 #endif
+	
+	open_debug_logfile();
 
 
 	timing_init();
 	timing_init();
 
 
@@ -604,4 +609,6 @@ void starpu_shutdown(void)
 	deinit_memory_nodes();
 	deinit_memory_nodes();
 
 
 	deinit_sched_policy(&config);
 	deinit_sched_policy(&config);
+
+	close_debug_logfile();
 }
 }

+ 2 - 1
src/drivers/core/driver_core.c

@@ -16,6 +16,7 @@
 
 
 #include <math.h>
 #include <math.h>
 
 
+#include <core/debug.h>
 #include "driver_core.h"
 #include "driver_core.h"
 #include <core/policies/sched_policy.h>
 #include <core/policies/sched_policy.h>
 
 
@@ -157,7 +158,7 @@ void *core_worker(void *arg)
 #endif
 #endif
 
 
 #ifdef VERBOSE
 #ifdef VERBOSE
-	fprintf(stderr, "CORE #%d error %le error/exec %le\n", core_arg->id, core_arg->jobq->total_computation_time_error,  core_arg->jobq->total_computation_time_error/core_arg->jobq->total_computation_time);
+	print_to_logfile("MODEL ERROR: CORE %d ERROR %le EXEC %le RATIO %le\n", core_arg->id, core_arg->jobq->total_computation_time_error, core_arg->jobq->total_computation_time, core_arg->jobq->total_computation_time_error/core_arg->jobq->total_computation_time);
 #endif
 #endif
 
 
 	TRACE_WORKER_TERMINATED(FUT_CORE_KEY);
 	TRACE_WORKER_TERMINATED(FUT_CORE_KEY);

+ 1 - 1
src/drivers/cuda/driver_cuda.c

@@ -417,7 +417,7 @@ void *cuda_worker(void *arg)
 #endif
 #endif
 
 
 #ifdef VERBOSE
 #ifdef VERBOSE
-	fprintf(stderr, "CUDA #%d error %le error/exec %le\n", args->id, args->jobq->total_computation_time_error, args->jobq->total_computation_time_error/args->jobq->total_computation_time );
+	print_to_logfile("MODEL ERROR: CUDA %d ERROR %le EXEC %le RATIO %le\n", args->id, args->jobq->total_computation_time_error, args->jobq->total_computation_time, args->jobq->total_computation_time_error/args->jobq->total_computation_time);
 #endif
 #endif
 
 
 	TRACE_WORKER_TERMINATED(FUT_CUDA_KEY);
 	TRACE_WORKER_TERMINATED(FUT_CUDA_KEY);