瀏覽代碼

tools/starpu_fxt_stats: generate man page, add options -v and -h, and really implement -o option

Nathalie Furmento 12 年之前
父節點
當前提交
c0e474271e
共有 2 個文件被更改,包括 102 次插入26 次删除
  1. 6 2
      tools/Makefile.am
  2. 96 24
      tools/starpu_fxt_stats.c

+ 6 - 2
tools/Makefile.am

@@ -125,7 +125,10 @@ starpu_codelet_histo_profile.1: starpu_codelet_histo_profile$(EXEEXT)
 
 if STARPU_USE_FXT
 starpu_fxt_tool.1: starpu_fxt_tool$(EXEEXT)
-	chmod +x starpu_fxt_tool$(EXEEXT)
+	chmod +x $<
+	help2man --no-discard-stderr -N --output=$@ ./$<
+starpu_fxt_stats.1: starpu_fxt_stats$(EXEEXT)
+	chmod +x $<
 	help2man --no-discard-stderr -N --output=$@ ./$<
 endif
 
@@ -140,7 +143,8 @@ dist_man1_MANS =\
 
 if STARPU_USE_FXT
 dist_man1_MANS +=\
-	starpu_fxt_tool.1
+	starpu_fxt_tool.1 \
+	starpu_fxt_stats.1
 endif
 
 clean-local:

+ 96 - 24
tools/starpu_fxt_stats.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2011, 2012  Centre National de la Recherche Scientifique
+ * Copyright (C) 2011, 2012, 2013  Centre National de la Recherche Scientifique
  *
  * 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
@@ -27,13 +27,70 @@
 
 #include <common/fxt.h>
 #include <common/list.h>
+#include <config.h>
 #include <starpu.h>
 
-
 static fxt_t fut;
 struct fxt_ev_64 ev;
 
-static uint64_t transfers[16][16]; 
+static uint64_t transfers[16][16];
+
+#define PROGNAME "starpu_fxt_stat"
+
+static void usage(char **argv)
+{
+	fprintf(stderr, "Parse the log generated by FxT\n\n");
+	fprintf(stderr, "Usage: %s [ options ]\n", PROGNAME);
+        fprintf(stderr, "\n");
+        fprintf(stderr, "Options:\n");
+	fprintf(stderr, "   -i <input file>     specify the input file.\n");
+        fprintf(stderr, "   -o <output file>    specify the output file\n");
+	fprintf(stderr, "   -h, --help          display this help and exit\n");
+	fprintf(stderr, "   -v, --version       output version information and exit\n\n");
+        fprintf(stderr, "Reports bugs to <"PACKAGE_BUGREPORT">.");
+        fprintf(stderr, "\n");
+}
+
+static void parse_args(int argc, char **argv, char **fin, char **fout)
+{
+	int i;
+
+	*fin = NULL;
+	*fout = NULL;
+	for (i = 1; i < argc; i++)
+	{
+		if (strcmp(argv[i], "-o") == 0)
+		{
+			*fout = argv[++i];
+			continue;
+		}
+
+		if (strcmp(argv[i], "-i") == 0)
+		{
+			*fin = argv[++i];
+			continue;
+		}
+
+		if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
+		{
+			usage(argv);
+			exit(EXIT_SUCCESS);
+		}
+
+		if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0)
+		{
+		        fputs(PROGNAME " (" PACKAGE_NAME ") " PACKAGE_VERSION "\n", stderr);
+			exit(EXIT_SUCCESS);
+		}
+	}
+
+	if (!*fin)
+	{
+		fprintf(stderr, "Incorrect usage, aborting\n");
+                usage(argv);
+		exit(77);
+	}
+}
 
 static void handle_data_copy(void)
 {
@@ -47,34 +104,45 @@ static void handle_data_copy(void)
 }
 
 /*
- * This program should be used to parse the log generated by FxT 
+ * This program should be used to parse the log generated by FxT
  */
 int main(int argc, char **argv)
 {
-	char *filename = NULL;
+	char *fin, *fout;
 	int ret;
-	int fd_in; 
+	int fd_in;
+	FILE *fd_out;
 
-	if (argc < 2) {
-	        fprintf(stderr, "Usage : %s input_filename [-o output_filename]\n", argv[0]);
-	        exit(77);
-	}
-	
-	filename = argv[1];
-	
+	parse_args(argc, argv, &fin, &fout);
 
-	fd_in = open(filename, O_RDONLY);
-	if (fd_in < 0) {
+	fd_in = open(fin, O_RDONLY);
+	if (fd_in < 0)
+	{
 	        perror("open failed :");
 	        exit(-1);
 	}
 
 	fut = fxt_fdopen(fd_in);
-	if (!fut) {
+	if (!fut)
+	{
 	        perror("fxt_fdopen :");
 	        exit(-1);
 	}
-	
+
+	if (!fout)
+	{
+		fd_out = stdout;
+	}
+	else
+	{
+		fd_out = fopen(fout, "w");
+		if (fd_out < 0)
+		{
+			perror("open failed :");
+			exit(-1);
+		}
+	}
+
 	fxt_blockev_t block;
 	block = fxt_blockev_enter(fut);
 
@@ -84,9 +152,11 @@ int main(int argc, char **argv)
 	double start_time = 10e30;
 	double end_time = -10e30;
 
-	while(1) {
+	while(1)
+	{
 		ret = fxt_next_ev(block, FXT_EV_TYPE_64, (struct fxt_ev *)&ev);
-		if (ret != FXT_EV_OK) {
+		if (ret != FXT_EV_OK)
+		{
 			fprintf(stderr, "no more block ...\n");
 			break;
 		}
@@ -96,7 +166,8 @@ int main(int argc, char **argv)
 
 		__attribute__ ((unused)) int nbparam = ev.nb_params;
 
-		switch (ev.code) {
+		switch (ev.code)
+		{
 			case _STARPU_FUT_DATA_COPY:
 				handle_data_copy();
 				break;
@@ -111,20 +182,21 @@ int main(int argc, char **argv)
 		}
 	}
 
-	printf("Start : start time %e end time %e length %e\n", start_time, end_time, end_time - start_time);
+	fprintf(fd_out, "Start : start time %e end time %e length %e\n", start_time, end_time, end_time - start_time);
 
 	unsigned src, dst;
 	for (src = 0; src < 16; src++)
 	{
 		for (dst = 0; dst < 16; dst++)
 		{
-			if (transfers[src][dst] != 0) {
-				printf("%d -> %d \t %ld MB\n", src, dst, transfers[src][dst]/(1024*1024));
+			if (transfers[src][dst] != 0)
+			{
+				fprintf(fd_out, "%d -> %d \t %ld MB\n", src, dst, transfers[src][dst]/(1024*1024));
 			}
 		}
 	}
 
-	printf("There was %d tasks and %d work stealing\n", njob, nws);
+	fprintf(fd_out, "There was %d tasks and %d work stealing\n", njob, nws);
 
 	return 0;
 }