Browse Source

traces: specify directory in which to save trace files

Nathalie Furmento 4 years ago
parent
commit
a9e81c65e7

+ 2 - 0
include/starpu_fxt.h

@@ -131,7 +131,9 @@ void starpu_fxt_start_profiling(void);
    start recording it again, etc.
    start recording it again, etc.
 */
 */
 void starpu_fxt_stop_profiling(void);
 void starpu_fxt_stop_profiling(void);
+
 void starpu_fxt_write_data_trace(char *filename_in);
 void starpu_fxt_write_data_trace(char *filename_in);
+void starpu_fxt_write_data_trace_in_dir(char *filename_in, char *dir);
 
 
 /**
 /**
     Wrapper to get value of env variable STARPU_FXT_TRACE
     Wrapper to get value of env variable STARPU_FXT_TRACE

+ 17 - 7
src/debug/traces/starpu_fxt.c

@@ -4844,7 +4844,7 @@ struct starpu_data_trace_kernel
 
 
 static FILE *codelet_list;
 static FILE *codelet_list;
 
 
-static void write_task(struct parse_task pt)
+static void write_task(char *dir, struct parse_task pt)
 {
 {
 	struct starpu_data_trace_kernel *kernel;
 	struct starpu_data_trace_kernel *kernel;
 	char *codelet_name = pt.codelet_name;
 	char *codelet_name = pt.codelet_name;
@@ -4854,11 +4854,13 @@ static void write_task(struct parse_task pt)
 	{
 	{
 		_STARPU_MALLOC(kernel, sizeof(*kernel));
 		_STARPU_MALLOC(kernel, sizeof(*kernel));
 		kernel->name = strdup(codelet_name);
 		kernel->name = strdup(codelet_name);
+		char filename[256];
+		snprintf(filename, sizeof(filename), "%s/%s", dir, kernel->name);
 		//fprintf(stderr, "%s\n", kernel->name);
 		//fprintf(stderr, "%s\n", kernel->name);
-		kernel->file = fopen(codelet_name, "w+");
+		kernel->file = fopen(filename, "w+");
 		if(!kernel->file)
 		if(!kernel->file)
 		{
 		{
-			STARPU_ABORT_MSG("Failed to open '%s' (err %s)", codelet_name, strerror(errno));
+			STARPU_ABORT_MSG("Failed to open '%s' (err %s)", filename, strerror(errno));
 		}
 		}
 		HASH_ADD_STR(kernels, name, kernel);
 		HASH_ADD_STR(kernels, name, kernel);
 		fprintf(codelet_list, "%s\n", codelet_name);
 		fprintf(codelet_list, "%s\n", codelet_name);
@@ -4867,7 +4869,7 @@ static void write_task(struct parse_task pt)
 	fprintf(kernel->file, "%lf %u %u\n", time, pt.data_total, pt.workerid);
 	fprintf(kernel->file, "%lf %u %u\n", time, pt.data_total, pt.workerid);
 }
 }
 
 
-void starpu_fxt_write_data_trace(char *filename_in)
+void starpu_fxt_write_data_trace_in_dir(char *filename_in, char *dir)
 {
 {
 	int fd_in;
 	int fd_in;
 	fd_in = open(filename_in, O_RDONLY);
 	fd_in = open(filename_in, O_RDONLY);
@@ -4884,10 +4886,12 @@ void starpu_fxt_write_data_trace(char *filename_in)
 	        exit(-1);
 	        exit(-1);
 	}
 	}
 
 
-	codelet_list = fopen("codelet_list", "w+");
+	char filename_out[512];
+	snprintf(filename_out, sizeof(filename_out), "%s/codelet_list", dir);
+	codelet_list = fopen(filename_out, "w+");
 	if(!codelet_list)
 	if(!codelet_list)
 	{
 	{
-		STARPU_ABORT_MSG("Failed to open '%s' (err %s)", "codelet_list", strerror(errno));
+		STARPU_ABORT_MSG("Failed to open '%s' (err %s)", filename_out, strerror(errno));
 	}
 	}
 
 
 	fxt_blockev_t block;
 	fxt_blockev_t block;
@@ -4928,7 +4932,7 @@ void starpu_fxt_write_data_trace(char *filename_in)
 			workerid = ev.param[3];
 			workerid = ev.param[3];
 			assert(workerid != -1);
 			assert(workerid != -1);
 			tasks[workerid].exec_time = ev.time - tasks[workerid].exec_time;
 			tasks[workerid].exec_time = ev.time - tasks[workerid].exec_time;
-			write_task(tasks[workerid]);
+			write_task(dir, tasks[workerid]);
 			break;
 			break;
 
 
 		case _STARPU_FUT_DATA_LOAD:
 		case _STARPU_FUT_DATA_LOAD:
@@ -4974,4 +4978,10 @@ void starpu_fxt_write_data_trace(char *filename_in)
 	}
 	}
 
 
 }
 }
+
+void starpu_fxt_write_data_trace(char *filename_in)
+{
+	starpu_fxt_write_data_trace_in_dir(filename_in, ".");
+}
+
 #endif // STARPU_USE_FXT
 #endif // STARPU_USE_FXT

+ 32 - 13
tools/starpu_fxt_data_trace.c

@@ -32,13 +32,14 @@ static void usage()
         fprintf(stderr, "Options:\n");
         fprintf(stderr, "Options:\n");
 	fprintf(stderr, "   -h, --help          display this help and exit\n");
 	fprintf(stderr, "   -h, --help          display this help and exit\n");
 	fprintf(stderr, "   -v, --version       output version information and exit\n\n");
 	fprintf(stderr, "   -v, --version       output version information and exit\n\n");
+	fprintf(stderr, "   -d directory        where to save output files (by default current directory)\n");
 	fprintf(stderr, "    filename           specify the FxT trace input file.\n");
 	fprintf(stderr, "    filename           specify the FxT trace input file.\n");
 	fprintf(stderr, "    codeletX           specify the codelet name to profile (by default, all codelets are profiled)\n");
 	fprintf(stderr, "    codeletX           specify the codelet name to profile (by default, all codelets are profiled)\n");
         fprintf(stderr, "Report bugs to <%s>.", PACKAGE_BUGREPORT);
         fprintf(stderr, "Report bugs to <%s>.", PACKAGE_BUGREPORT);
         fprintf(stderr, "\n");
         fprintf(stderr, "\n");
 }
 }
 
 
-static int parse_args(int argc, char **argv)
+static int parse_args(int argc, char **argv, int *pos, char **directory)
 {
 {
 	int i;
 	int i;
 
 
@@ -62,30 +63,42 @@ static int parse_args(int argc, char **argv)
 		        fputs(PROGNAME " (" PACKAGE_NAME ") " PACKAGE_VERSION "\n", stderr);
 		        fputs(PROGNAME " (" PACKAGE_NAME ") " PACKAGE_VERSION "\n", stderr);
 			exit(EXIT_FAILURE);
 			exit(EXIT_FAILURE);
 		}
 		}
+
+		if (strcmp(argv[i], "-d") == 0)
+		{
+			free(*directory);
+			*directory = strdup(argv[++i]);
+			*pos += 2;
+			continue;
+		}
+
 	}
 	}
 	return 0;
 	return 0;
 }
 }
 
 
-static void write_gp(int argc, char **argv)
+static void write_gp(char *dir, int argc, char **argv)
 {
 {
-	FILE *codelet_list = fopen("codelet_list", "r");
+	char codelet_filename[256];
+	snprintf(codelet_filename, sizeof(codelet_filename), "%s/codelet_list", dir);
+	FILE *codelet_list = fopen(codelet_filename, "r");
 	if(!codelet_list)
 	if(!codelet_list)
 	{
 	{
-		perror("Error while opening codelet_list:");
+		STARPU_ABORT_MSG("Failed to open '%s' (err %s)", codelet_filename, strerror(errno));
 		exit(-1);
 		exit(-1);
 	}
 	}
 	char codelet_name[MAX_LINE_SIZE];
 	char codelet_name[MAX_LINE_SIZE];
-	const char *file_name = "data_trace.gp";
+	char file_name[256];
+	snprintf(file_name, sizeof(file_name), "%s/data_trace.gp", dir);
 	FILE *plt = fopen(file_name, "w+");
 	FILE *plt = fopen(file_name, "w+");
 	if(!plt)
 	if(!plt)
 	{
 	{
-		perror("Error while creating data_trace.gp:");
+		STARPU_ABORT_MSG("Failed to open '%s' (err %s)", file_name, strerror(errno));
 		exit(-1);
 		exit(-1);
 	}
 	}
 
 
 	fprintf(plt, "#!/usr/bin/gnuplot -persist\n\n");
 	fprintf(plt, "#!/usr/bin/gnuplot -persist\n\n");
 	fprintf(plt, "set term postscript eps enhanced color\n");
 	fprintf(plt, "set term postscript eps enhanced color\n");
-	fprintf(plt, "set output \"data_trace.eps\"\n");
+	fprintf(plt, "set output \"%s/data_trace.eps\"\n", dir);
 	fprintf(plt, "set title \"Data trace\"\n");
 	fprintf(plt, "set title \"Data trace\"\n");
 	fprintf(plt, "set logscale x\n");
 	fprintf(plt, "set logscale x\n");
 	fprintf(plt, "set logscale y\n");
 	fprintf(plt, "set logscale y\n");
@@ -125,7 +138,7 @@ static void write_gp(int argc, char **argv)
 		}
 		}
 		else
 		else
 		{
 		{
-			fprintf(plt, "\"%s\" using 2:1 with dots lw 1 title \"%s\"", codelet_name, codelet_name);
+			fprintf(plt, "\"%s/%s\" using 2:1 with dots lw 1 title \"%s\"", dir, codelet_name, codelet_name);
 		}
 		}
 	}
 	}
 	fprintf(plt, "\n");
 	fprintf(plt, "\n");
@@ -157,15 +170,21 @@ static void write_gp(int argc, char **argv)
 		perror("chmod");
 		perror("chmod");
 		STARPU_ABORT();
 		STARPU_ABORT();
 	}
 	}
-	fprintf(stdout, "Gnuplot file <data_trace.gp> has been successfully created.\n");
+	fprintf(stdout, "Gnuplot file <%s/data_trace.gp> has been successfully created.\n", dir);
 }
 }
 
 
 int main(int argc, char **argv)
 int main(int argc, char **argv)
 {
 {
-	int ret = parse_args(argc, argv);
-	if (ret) return ret;
-	starpu_fxt_write_data_trace(argv[1]);
-	write_gp(argc - 2, argv + 2);
+	char *directory = strdup(".");
+	int pos=0;
+	int ret = parse_args(argc, argv, &pos, &directory);
+	if (ret)
+	{
+		free(directory);
+		return ret;
+	}
+	starpu_fxt_write_data_trace_in_dir(argv[1+pos], directory);
+	write_gp(directory, argc - (2 + pos), argv + 2 + pos);
 	starpu_perfmodel_free_sampling();
 	starpu_perfmodel_free_sampling();
 	return 0;
 	return 0;
 }
 }

+ 2 - 2
tools/starpu_fxt_tool.c

@@ -170,14 +170,14 @@ static int parse_args(int argc, char **argv)
 		if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
 		if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
 		{
 		{
 			usage();
 			usage();
-			return EXIT_SUCCESS;
+			return 77;
 		}
 		}
 
 
 		if (strcmp(argv[i], "-v") == 0
 		if (strcmp(argv[i], "-v") == 0
 		 || strcmp(argv[i], "--version") == 0)
 		 || strcmp(argv[i], "--version") == 0)
 		{
 		{
 		        fputs(PROGNAME " (" PACKAGE_NAME ") " PACKAGE_VERSION "\n", stderr);
 		        fputs(PROGNAME " (" PACKAGE_NAME ") " PACKAGE_VERSION "\n", stderr);
-			return EXIT_SUCCESS;
+			return 77;
 		}
 		}
 
 
 		/* That's pretty dirty: if the reading_input_filenames flag is
 		/* That's pretty dirty: if the reading_input_filenames flag is

+ 20 - 6
tools/starpu_perfmodel_plot.c

@@ -78,13 +78,14 @@ static void usage()
 	fprintf(stderr, "   -i <Fxt files>      input FxT files generated by StarPU\n");
 	fprintf(stderr, "   -i <Fxt files>      input FxT files generated by StarPU\n");
 	fprintf(stderr, "   -lc                 display all combinations of a given model\n");
 	fprintf(stderr, "   -lc                 display all combinations of a given model\n");
         fprintf(stderr, "   -c <combination>    specify the combination (use the option -lc to list all combinations of a given model)\n");
         fprintf(stderr, "   -c <combination>    specify the combination (use the option -lc to list all combinations of a given model)\n");
+	fprintf(stderr, "   -o <directory>      specify directory in which to create output files (current directory by default)\n");
 	fprintf(stderr, "   -h, --help          display this help and exit\n");
 	fprintf(stderr, "   -h, --help          display this help and exit\n");
 	fprintf(stderr, "   -v, --version       output version information and exit\n\n");
 	fprintf(stderr, "   -v, --version       output version information and exit\n\n");
         fprintf(stderr, "Report bugs to <%s>.", PACKAGE_BUGREPORT);
         fprintf(stderr, "Report bugs to <%s>.", PACKAGE_BUGREPORT);
         fprintf(stderr, "\n");
         fprintf(stderr, "\n");
 }
 }
 
 
-static void parse_args(int argc, char **argv, struct _perfmodel_plot_options *options)
+static void parse_args(int argc, char **argv, struct _perfmodel_plot_options *options, char **directory)
 {
 {
 	int correct_usage = 0;
 	int correct_usage = 0;
 	memset(options, 0, sizeof(struct _perfmodel_plot_options));
 	memset(options, 0, sizeof(struct _perfmodel_plot_options));
@@ -114,6 +115,17 @@ static void parse_args(int argc, char **argv, struct _perfmodel_plot_options *op
 			continue;
 			continue;
 		}
 		}
 
 
+		if (strcmp(argv[i], "-o") == 0)
+		{
+			free(*directory);
+			*directory = strdup(argv[++i]);
+#ifdef STARPU_USE_FXT
+			options->fxt_options.dir = strdup(*directory);
+#endif
+			correct_usage = 1;
+			continue;
+		}
+
 		if (strcmp(argv[i], "-i") == 0)
 		if (strcmp(argv[i], "-i") == 0)
 		{
 		{
 			reading_input_filenames = 1;
 			reading_input_filenames = 1;
@@ -480,13 +492,14 @@ int main(int argc, char **argv)
 	struct starpu_perfmodel model = { .type = STARPU_PERFMODEL_INVALID };
 	struct starpu_perfmodel model = { .type = STARPU_PERFMODEL_INVALID };
 	char gnuplot_file_name[256];
 	char gnuplot_file_name[256];
 	struct _perfmodel_plot_options options;
 	struct _perfmodel_plot_options options;
+	char *directory = strdup("./");
 
 
 #if defined(_WIN32) && !defined(__CYGWIN__)
 #if defined(_WIN32) && !defined(__CYGWIN__)
 	WSADATA wsadata;
 	WSADATA wsadata;
 	WSAStartup(MAKEWORD(1,0), &wsadata);
 	WSAStartup(MAKEWORD(1,0), &wsadata);
 #endif
 #endif
 
 
-	parse_args(argc, argv, &options);
+	parse_args(argc, argv, &options, &directory);
 	starpu_perfmodel_initialize();
 	starpu_perfmodel_initialize();
 
 
 	if (options.directory)
 	if (options.directory)
@@ -525,7 +538,7 @@ int main(int argc, char **argv)
 			{
 			{
 				starpu_fxt_generate_trace(&options.fxt_options);
 				starpu_fxt_generate_trace(&options.fxt_options);
 
 
-				snprintf(options.data_file_name, sizeof(options.data_file_name), "starpu_%s.data", options.symbol);
+				snprintf(options.data_file_name, sizeof(options.data_file_name), "%s/starpu_%s.data", directory, options.symbol);
 
 
 				FILE *data_file = fopen(options.data_file_name, "w+");
 				FILE *data_file = fopen(options.data_file_name, "w+");
 				STARPU_ASSERT(data_file);
 				STARPU_ASSERT(data_file);
@@ -534,11 +547,11 @@ int main(int argc, char **argv)
 			}
 			}
 #endif
 #endif
 
 
-			snprintf(gnuplot_file_name, sizeof(gnuplot_file_name), "starpu_%s.gp", options.symbol);
-			snprintf(options.avg_file_name, sizeof(options.avg_file_name), "starpu_%s_avg.data", options.symbol);
+			snprintf(gnuplot_file_name, sizeof(gnuplot_file_name), "%s/starpu_%s.gp", directory, options.symbol);
+			snprintf(options.avg_file_name, sizeof(options.avg_file_name), "%s/starpu_%s_avg.data", directory, options.symbol);
 
 
 			FILE *gnuplot_file = fopen(gnuplot_file_name, "w+");
 			FILE *gnuplot_file = fopen(gnuplot_file_name, "w+");
-			STARPU_ASSERT(gnuplot_file);
+			STARPU_ASSERT_MSG(gnuplot_file, "Cannot create file <%s>\n", gnuplot_file_name);
 			display_selected_models(gnuplot_file, &model, &options);
 			display_selected_models(gnuplot_file, &model, &options);
 			fprintf(gnuplot_file,"\n");
 			fprintf(gnuplot_file,"\n");
 			fclose(gnuplot_file);
 			fclose(gnuplot_file);
@@ -563,5 +576,6 @@ int main(int argc, char **argv)
 		}
 		}
 	}
 	}
 	starpu_perfmodel_free_sampling();
 	starpu_perfmodel_free_sampling();
+	free(directory);
 	return ret;
 	return ret;
 }
 }

+ 38 - 31
tools/starpu_workers_activity.in

@@ -30,6 +30,7 @@ usage()
     echo "Options:"
     echo "Options:"
     echo "	-h, --help          display this help and exit"
     echo "	-h, --help          display this help and exit"
     echo "	-v, --version       output version information and exit"
     echo "	-v, --version       output version information and exit"
+    echo "      -d directory        where to save output files, by default current directory"
     echo ""
     echo ""
     echo "Report bugs to <@PACKAGE_BUGREPORT@>"
     echo "Report bugs to <@PACKAGE_BUGREPORT@>"
     exit 0
     exit 0
@@ -44,6 +45,12 @@ if [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ "$1" = "" ] ; then
     usage
     usage
 fi
 fi
 
 
+odir="."
+if [ "$1" == "-d" ]
+then
+    odir=$2
+    shift ; shift
+fi
 if [ ! -f $1 ] ; then
 if [ ! -f $1 ] ; then
     echo "Error. File <$1> not found"
     echo "Error. File <$1> not found"
     echo ""
     echo ""
@@ -54,11 +61,12 @@ fi
 inputfile_with_counters=$1
 inputfile_with_counters=$1
 
 
 # We extract the counters out of the input file
 # We extract the counters out of the input file
-inputfile=.$inputfile_with_counters.activity
-inputfile_cnt_ready=.$1.cnt_ready
-inputfile_cnt_submitted=.$1.cnt_submitted
-set_profiling_list=.$1.set_profiling_list
-names=.$1.names
+dir=$(dirname $1)
+inputfile=$dir/.$(basename $1).activity
+inputfile_cnt_ready=$dir/.$(basename $1).cnt_ready
+inputfile_cnt_submitted=$dir/.$(basename $1).cnt_submitted
+set_profiling_list=$dir/.$(basename $1).set_profiling_list
+names=$dir/.$(basename $1).names
 
 
 grep "^set_profiling" $inputfile_with_counters > $set_profiling_list
 grep "^set_profiling" $inputfile_with_counters > $set_profiling_list
 grep "0$" $set_profiling_list | cut -f 2 | sort -n > $set_profiling_list.disable
 grep "0$" $set_profiling_list | cut -f 2 | sort -n > $set_profiling_list.disable
@@ -82,32 +90,31 @@ total_heigth=$(echo "$heigth + ($heigth * $nworkers)"|bc -l)
 # In case 3 arguments are provided, the 2nd (resp. 3rd) indicates the start
 # In case 3 arguments are provided, the 2nd (resp. 3rd) indicates the start
 # (resp. the end) of the interval to be displayed.
 # (resp. the end) of the interval to be displayed.
 if [ $# -ge 3 ]; then
 if [ $# -ge 3 ]; then
-starttime=$2
-endtime=$3
-else
-#if profiling is explicitely enabled (resp. disabled) at some point, we set the
-# default start (rest. end) point when we enable (resp. disable) profiling for
-# the first time.
-profiling_enable_cnt=`wc -l $set_profiling_list.enable|sed -e "s/\(.*\) .*/\1/"`
-if [ $profiling_enable_cnt -ge 1 ]; then
-starttime=`head -1 $set_profiling_list.enable`
+    starttime=$2
+    endtime=$3
 else
 else
-starttime=$(cut -f 2 $inputfile |sort -n|head -1)
-fi
-
-# TODO test if last disable > first enable
-
-profiling_disable_cnt=$(wc -l $set_profiling_list.disable|sed -e "s/\(.*\) .*/\1/")
-if [ $profiling_disable_cnt -ge 1 ]; then
-endtime=`tail -1 $set_profiling_list.disable`
-else
-endtime=$(cut -f 2 $inputfile |sort -n|tail -1)
-fi
-
-# The values in the file are in ms, we display seconds
-starttime=$(echo "$starttime * 0.001 "| bc -l)
-endtime=$(echo "$endtime * 0.001 "| bc -l)
-
+    #if profiling is explicitely enabled (resp. disabled) at some point, we set the
+    # default start (rest. end) point when we enable (resp. disable) profiling for
+    # the first time.
+    profiling_enable_cnt=`wc -l $set_profiling_list.enable|sed -e "s/\(.*\) .*/\1/"`
+    if [ $profiling_enable_cnt -ge 1 ]; then
+	starttime=`head -1 $set_profiling_list.enable`
+    else
+	starttime=$(cut -f 2 $inputfile |sort -n|head -1)
+    fi
+
+    # TODO test if last disable > first enable
+
+    profiling_disable_cnt=$(wc -l $set_profiling_list.disable|sed -e "s/\(.*\) .*/\1/")
+    if [ $profiling_disable_cnt -ge 1 ]; then
+	endtime=`tail -1 $set_profiling_list.disable`
+    else
+	endtime=$(cut -f 2 $inputfile |sort -n|tail -1)
+    fi
+
+    # The values in the file are in ms, we display seconds
+    starttime=$(echo "$starttime * 0.001 "| bc -l)
+    endtime=$(echo "$endtime * 0.001 "| bc -l)
 fi
 fi
 
 
 echo "START $starttime END $endtime"
 echo "START $starttime END $endtime"
@@ -115,7 +122,7 @@ echo "START $starttime END $endtime"
 # Gnuplot header
 # Gnuplot header
 cat > gnuplotcmd << EOF
 cat > gnuplotcmd << EOF
 set term postscript eps enhanced color
 set term postscript eps enhanced color
-set output "activity.eps"
+set output "$odir/activity.eps"
 set xrange [$starttime:$endtime]
 set xrange [$starttime:$endtime]
 set size $width,$total_heigth
 set size $width,$total_heigth
 set multiplot;
 set multiplot;