Explorar o código

Add file monitoring number of events in a trace

Philippe SWARTVAGHER %!s(int64=5) %!d(string=hai) anos
pai
achega
4ff1c39709

+ 4 - 1
ChangeLog

@@ -1,6 +1,6 @@
 # StarPU --- Runtime system for heterogeneous multicore architectures.
 #
-# Copyright (C) 2012-2014,2016-2018                      Inria
+# Copyright (C) 2012-2014,2016-2018,2020                 Inria
 # Copyright (C) 2009-2020                                Université de Bordeaux
 # Copyright (C) 2010-2020                                CNRS
 #
@@ -28,6 +28,9 @@ New features:
   * New sched_tasks.rec trace file which monitors task scheduling push/pop actions
   * New STARPU_MPI_MEM_THROTTLE environment variable to throttle mpi
     submission according to memory use.
+  * New number_events.data trace file which monitors number of events in trace
+    files. This file can be parsed by the new script
+    starpu_fxt_number_events_to_names.py to convert event keys to event names.
 
 Small changes:
   * Use the S4U interface of Simgrid instead of xbt and MSG.

+ 6 - 0
configure.ac

@@ -2257,6 +2257,10 @@ fi
 AM_CONDITIONAL([STARPU_USE_AYUDAME1], [test "x$enable_ayudame1" = "xyes"])
 AM_CONDITIONAL([STARPU_USE_AYUDAME2], [test "x$enable_ayudame2" = "xyes"])
 
+
+STARPU_FXT_EVENT_DEFINES="`grep -E '#define\s+_STARPU_(MPI_)?FUT_' ${srcdir}/src/common/fxt.h ${srcdir}/mpi/src/starpu_mpi_fxt.h | grep 0x | grep -v 0x1 | cut -d : -f 2`"
+AC_SUBST([STARPU_FXT_EVENT_DEFINES])
+
 ###############################################################################
 #                                                                             #
 #                  Miscellaneous options for StarPU                           #
@@ -3488,6 +3492,7 @@ AC_CONFIG_COMMANDS([executable-scripts], [
   chmod +x tools/starpu_codelet_profile
   chmod +x tools/starpu_codelet_histo_profile
   chmod +x tools/starpu_mpi_comm_matrix.py
+  chmod +x tools/starpu_fxt_number_events_to_names.py
   chmod +x tools/starpu_workers_activity
   chmod +x tools/starpu_paje_draw_histogram
   chmod +x tools/starpu_paje_state_stats
@@ -3561,6 +3566,7 @@ AC_OUTPUT([
 	tools/starpu_codelet_profile
 	tools/starpu_codelet_histo_profile
 	tools/starpu_mpi_comm_matrix.py
+	tools/starpu_fxt_number_events_to_names.py
 	tools/starpu_workers_activity
 	tools/starpu_paje_draw_histogram
 	tools/starpu_paje_state_stats

+ 14 - 0
doc/doxygen/chapters/380_offline_performance_tools.doxy

@@ -288,6 +288,20 @@ same graph but with elapsed time between send and usage of a data by the sender.
 \image html trace_send_use.png
 \image latex trace_send_use.eps "" width=\textwidth
 
+
+\subsubsection NumberEvents Number of events in trace files
+
+When launched with the option <c>-number-events</c>, <c>starpu_fxt_tool</c> will
+produce a file named <c>number_events.data</c>. This file contains the number of
+events for each event type. Events are represented with their key. To convert
+event keys to event names, you can use the <c>starpu_fxt_number_events_to_names.py</c>
+script:
+
+\verbatim
+$ starpu_fxt_number_events_to_names.py number_events.data
+\endverbatim
+
+
 \subsection LimitingScopeTrace Limiting The Scope Of The Trace
 
 For computing statistics, it is useful to limit the trace to a given portion of

+ 1 - 0
include/starpu_fxt.h

@@ -68,6 +68,7 @@ struct starpu_fxt_options
 	char *data_path;
 	char *papi_path;
 	char *comms_path;
+	char *number_events_path;
 	char *anim_path;
 	char *states_path;
 

+ 47 - 0
src/debug/traces/starpu_fxt.c

@@ -62,6 +62,7 @@ static unsigned cpus_index = 0;
 static unsigned mic_index = 0;
 static unsigned mpi_ms_index = 0;
 static unsigned other_index = 0;
+static uint64_t* number_events = NULL;
 
 static unsigned long fut_keymask;
 
@@ -89,6 +90,7 @@ static FILE *papi_file;
 static FILE *trace_file;
 static FILE *comms_file;
 static FILE *sched_tasks_file;
+static FILE *number_events_file;
 
 struct data_parameter_info
 {
@@ -3485,6 +3487,13 @@ void _starpu_fxt_parse_new_file(char *filename_in, struct starpu_fxt_options *op
 			break;
 		}
 
+		if (number_events_file != NULL)
+		{
+			assert(number_events != NULL);
+			assert(ev.code <= FUT_SETUP_CODE);
+			number_events[ev.code]++;
+		}
+
 		switch (ev.code)
 		{
 			case _STARPU_FUT_WORKER_INIT_START:
@@ -4198,6 +4207,7 @@ void starpu_fxt_options_init(struct starpu_fxt_options *options)
 	options->dag_path = "dag.dot";
 	options->tasks_path = "tasks.rec";
 	options->comms_path = "comms.rec";
+	options->number_events_path = NULL;
 	options->data_path = "data.rec";
 	options->papi_path = "papi.rec";
 	options->anim_path = "trace.html";
@@ -4295,6 +4305,20 @@ void _starpu_fxt_comms_file_init(struct starpu_fxt_options *options)
 }
 
 static
+void _starpu_fxt_number_events_file_init(struct starpu_fxt_options *options)
+{
+	if (options->number_events_path)
+	{
+		number_events_file = fopen(options->number_events_path, "w+");
+
+		/* FUT_SETUP_CODE is the event with the maximal value */
+		number_events = calloc(FUT_SETUP_CODE+1, sizeof(uint64_t));
+	}
+	else
+		number_events_file = NULL;
+}
+
+static
 void _starpu_fxt_papi_file_init(struct starpu_fxt_options *options)
 {
 #ifdef STARPU_PAPI
@@ -4370,6 +4394,27 @@ void _starpu_fxt_comms_file_close(void)
 		fclose(comms_file);
 }
 
+static
+void _starpu_fxt_number_events_file_close(void)
+{
+	if (number_events_file)
+	{
+		assert(number_events != NULL);
+
+		fprintf(number_events_file, "# Use starpu_fxt_number_events_to_names.py to convert event keys to event names.\n");
+
+		for (int i = 0; i <= FUT_SETUP_CODE; i++)
+		{
+			if (number_events[i] > 0)
+				fprintf(number_events_file, "0x%x\t%lu\n", i, number_events[i]);
+		}
+
+		free(number_events);
+		number_events = NULL;
+
+		fclose(number_events_file);
+	}
+}
 
 static
 void _starpu_fxt_data_file_close(void)
@@ -4490,6 +4535,7 @@ void starpu_fxt_generate_trace(struct starpu_fxt_options *options)
 	_starpu_fxt_data_file_init(options);
 	_starpu_fxt_papi_file_init(options);
 	_starpu_fxt_comms_file_init(options);
+	_starpu_fxt_number_events_file_init(options);
 	_starpu_fxt_trace_file_init(options);
 
 	_starpu_fxt_paje_file_init(options);
@@ -4623,6 +4669,7 @@ void starpu_fxt_generate_trace(struct starpu_fxt_options *options)
 	_starpu_fxt_data_file_close();
 	_starpu_fxt_papi_file_close();
 	_starpu_fxt_comms_file_close();
+	_starpu_fxt_number_events_file_close();
 	_starpu_fxt_trace_file_close();
 
 	_starpu_fxt_dag_terminate();

+ 18 - 13
tools/Makefile.am

@@ -417,19 +417,20 @@ STARPU_TOOLS	+=			\
 	starpu_perfmodel_plot
 endif
 
-dist_bin_SCRIPTS +=			\
-	starpu_workers_activity		\
-	starpu_codelet_histo_profile	\
-	starpu_codelet_profile		\
-	starpu_mpi_comm_matrix.py	\
-	starpu_paje_draw_histogram	\
-	starpu_paje_draw_histogram.R	\
-	starpu_paje_summary		\
-	starpu_paje_summary.Rmd		\
-	starpu_mlr_analysis		\
-	starpu_mlr_analysis.Rmd		\
-	starpu_paje_state_stats		\
-	starpu_send_recv_data_use.py \
+dist_bin_SCRIPTS +=				\
+	starpu_workers_activity			\
+	starpu_codelet_histo_profile		\
+	starpu_codelet_profile			\
+	starpu_mpi_comm_matrix.py		\
+	starpu_fxt_number_events_to_names.py	\
+	starpu_paje_draw_histogram		\
+	starpu_paje_draw_histogram.R		\
+	starpu_paje_summary			\
+	starpu_paje_summary.Rmd			\
+	starpu_mlr_analysis			\
+	starpu_mlr_analysis.Rmd			\
+	starpu_paje_state_stats			\
+	starpu_send_recv_data_use.py 		\
 	starpu_trace_state_stats.py
 
 if STARPU_USE_AYUDAME2
@@ -475,6 +476,9 @@ starpu_codelet_histo_profile.1: starpu_codelet_histo_profile
 starpu_mpi_comm_matrix.1: starpu_mpi_comm_matrix.py
 	chmod +x $<
 	help2man --no-discard-stderr -N -n "Draw StarPU MPI communications matrix" --output=$@ ./$<
+starpu_fxt_number_events_to_names.1: starpu_fxt_number_events_to_names.py
+	chmod +x $<
+	help2man --no-discard-stderr -N -n "Count events in StarPU traces" --output=$@ ./$<
 starpu_paje_draw_histogram.1: starpu_paje_draw_histogram
 	chmod +x $<
 	help2man --no-discard-stderr -N -n "Draw StarPU trace histogram" --output=$@ ./$<
@@ -502,6 +506,7 @@ dist_man1_MANS =\
 	starpu_codelet_profile.1 \
 	starpu_codelet_histo_profile.1 \
 	starpu_mpi_comm_matrix.1 \
+	starpu_fxt_number_events_to_names.1 \
 	starpu_paje_draw_histogram.1 \
 	starpu_paje_state_stats.1
 

+ 93 - 0
tools/starpu_fxt_number_events_to_names.py.in

@@ -0,0 +1,93 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+# StarPU --- Runtime system for heterogeneous multicore architectures.
+#
+# Copyright (C) 2020                                      Inria
+#
+# StarPU 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.
+#
+# StarPU 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.
+#
+
+import sys
+
+"""
+STARPU_FXT_EVENT_DEFINES is generated by configure and is the output of
+the following command:
+grep -E "#define\s+_STARPU_(MPI_)?FUT_" src/common/fxt.h mpi/src/starpu_mpi_fxt.h | grep 0x | grep -v 0x1 | cut -d : -f 2
+"""
+
+fxt_codes_raw = """
+@STARPU_FXT_EVENT_DEFINES@
+"""
+
+PROGNAME=sys.argv[0]
+
+number_events_path = None
+
+def usage():
+    print("Convert event keys in number_events.data to event names")
+    print("")
+    print("Usage: %s <number_events.data path>" % PROGNAME)
+    print("")
+    print("Options:")
+    print("	-h, --help          display this help and exit")
+    print("	-v, --version       output version information and exit")
+    print("")
+    print("Report bugs to <@PACKAGE_BUGREPORT@>")
+    sys.exit(1)
+
+
+if len(sys.argv) == 2:
+    if sys.argv[1] == '-v' or sys.argv[1] == '--version':
+        print("%s (@PACKAGE_NAME@) @PACKAGE_VERSION@" % PROGNAME)
+        sys.exit(0)
+    elif sys.argv[1] == '-h' or sys.argv[1] == '--help':
+        usage()
+    else:
+        number_events_path = sys.argv[1]
+else:
+    usage()
+
+def man():
+    print("Sepecify file containing event stats")
+    sys.exit(1)
+
+
+
+
+# Process fxt_code_raw content to ease the conversion:
+fxt_codes = dict()
+for line in fxt_codes_raw.split("\n"):
+    elements = line.split()
+
+    if len(elements) == 3:
+        key = int(elements[2][2:], 16)
+        assert(key not in fxt_codes)
+
+        fxt_codes[key] = elements[1]
+
+
+# Convert content of the file:
+nb_events = 0
+
+with open(number_events_path, 'r') as f:
+    for line in f:
+        elements = line.split()
+        if len(elements) == 2:
+            key = int(elements[0][2:], 16)
+            nb = int(elements[1])
+            nb_events += nb
+            if key in fxt_codes:
+                print("%12d    %s" % (nb, fxt_codes[key]))
+            else:
+                print("%12d    %s" % (nb, elements[0]))
+
+print("       TOTAL:   %d" % nb_events)

+ 8 - 0
tools/starpu_fxt_tool.c

@@ -43,6 +43,7 @@ static void usage()
 	fprintf(stderr, "   -label-deps         add label on dependencies.\n");
 	fprintf(stderr, "   -memory-states      show detailed memory states of handles\n");
 	fprintf(stderr, "   -internal           show StarPU-internal tasks in DAG\n");
+	fprintf(stderr, "   -number-events      generate a file counting FxT events by type\n");
 	fprintf(stderr, "   -h, --help          display this help and exit\n");
 	fprintf(stderr, "   -v, --version       output version information and exit\n\n");
         fprintf(stderr, "Report bugs to <%s>.", PACKAGE_BUGREPORT);
@@ -90,6 +91,13 @@ static int parse_args(int argc, char **argv)
 			continue;
 		}
 
+		if (strcmp(argv[i], "-number-events") == 0)
+		{
+			options.number_events_path = "number_events.data";
+			reading_input_filenames = 0;
+			continue;
+		}
+
 		if (strcmp(argv[i], "-no-counter") == 0)
 		{
 			options.no_counter = 1;