starpu_fxt_data_trace.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. * Copyright (C) 2013 Joris Pablo
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <stdio.h>
  18. #include <starpu.h>
  19. #include <string.h>
  20. #include <sys/stat.h>
  21. #include <common/config.h>
  22. #define PROGNAME "starpu_fxt_data_trace"
  23. #define MAX_LINE_SIZE 100
  24. static void usage()
  25. {
  26. fprintf(stderr, "Get statistics about tasks lengths and data size\n\n");
  27. fprintf(stderr, "Usage: %s [ options ] <filename> [<codelet1> <codelet2> .... <codeletn>]\n", PROGNAME);
  28. fprintf(stderr, "\n");
  29. fprintf(stderr, "Options:\n");
  30. fprintf(stderr, " -h, --help display this help and exit\n");
  31. fprintf(stderr, " -v, --version output version information and exit\n\n");
  32. fprintf(stderr, " -d directory where to save output files (by default current directory)\n");
  33. fprintf(stderr, " filename specify the FxT trace input file.\n");
  34. fprintf(stderr, " codeletX specify the codelet name to profile (by default, all codelets are profiled)\n");
  35. fprintf(stderr, "Report bugs to <%s>.", PACKAGE_BUGREPORT);
  36. fprintf(stderr, "\n");
  37. }
  38. static int parse_args(int argc, char **argv, int *pos, char **directory)
  39. {
  40. int i;
  41. if(argc < 2)
  42. {
  43. fprintf(stderr, "Incorrect usage, aborting\n");
  44. usage();
  45. return 77;
  46. }
  47. for (i = 1; i < argc; i++)
  48. {
  49. if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
  50. {
  51. usage();
  52. exit(EXIT_FAILURE);
  53. }
  54. if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0)
  55. {
  56. fputs(PROGNAME " (" PACKAGE_NAME ") " PACKAGE_VERSION "\n", stderr);
  57. exit(EXIT_FAILURE);
  58. }
  59. if (strcmp(argv[i], "-d") == 0)
  60. {
  61. free(*directory);
  62. *directory = strdup(argv[++i]);
  63. *pos += 2;
  64. continue;
  65. }
  66. }
  67. return 0;
  68. }
  69. static void write_gp(char *dir, int argc, char **argv)
  70. {
  71. char codelet_filename[256];
  72. snprintf(codelet_filename, sizeof(codelet_filename), "%s/codelet_list", dir);
  73. FILE *codelet_list = fopen(codelet_filename, "r");
  74. if(!codelet_list)
  75. {
  76. STARPU_ABORT_MSG("Failed to open '%s' (err %s)", codelet_filename, strerror(errno));
  77. exit(-1);
  78. }
  79. char codelet_name[MAX_LINE_SIZE];
  80. char file_name[256];
  81. snprintf(file_name, sizeof(file_name), "%s/data_trace.gp", dir);
  82. FILE *plt = fopen(file_name, "w+");
  83. if(!plt)
  84. {
  85. STARPU_ABORT_MSG("Failed to open '%s' (err %s)", file_name, strerror(errno));
  86. exit(-1);
  87. }
  88. fprintf(plt, "#!/usr/bin/gnuplot -persist\n\n");
  89. fprintf(plt, "set term postscript eps enhanced color\n");
  90. fprintf(plt, "set output \"%s/data_trace.eps\"\n", dir);
  91. fprintf(plt, "set title \"Data trace\"\n");
  92. fprintf(plt, "set logscale x\n");
  93. fprintf(plt, "set logscale y\n");
  94. fprintf(plt, "set xlabel \"data size (B)\"\n");
  95. fprintf(plt, "set ylabel \"tasks size (ms)\"\n");
  96. fprintf(plt, "plot ");
  97. int c_iter;
  98. char *v_iter;
  99. int begin = 1;
  100. while(fgets(codelet_name, MAX_LINE_SIZE, codelet_list) != NULL)
  101. {
  102. if(argc == 0)
  103. {
  104. if(begin)
  105. begin = 0;
  106. else
  107. fprintf(plt, ", ");
  108. }
  109. int size = strlen(codelet_name);
  110. if(size > 0)
  111. codelet_name[size-1] = '\0';
  112. if(argc != 0)
  113. {
  114. for(c_iter = 0, v_iter = argv[c_iter];
  115. c_iter < argc;
  116. c_iter++, v_iter = argv[c_iter])
  117. {
  118. if(!strcmp(v_iter, codelet_name))
  119. {
  120. if(begin)
  121. begin = 0;
  122. else
  123. fprintf(plt, ", ");
  124. fprintf(plt, "\"%s\" using 2:1 with dots lw 1 title \"%s\"", codelet_name, codelet_name);
  125. }
  126. }
  127. }
  128. else
  129. {
  130. fprintf(plt, "\"%s/%s\" using 2:1 with dots lw 1 title \"%s\"", dir, codelet_name, codelet_name);
  131. }
  132. }
  133. fprintf(plt, "\n");
  134. if(fclose(codelet_list))
  135. {
  136. perror("close failed :");
  137. exit(-1);
  138. }
  139. if(fclose(plt))
  140. {
  141. perror("close failed :");
  142. exit(-1);
  143. }
  144. struct stat sb;
  145. int ret = stat(file_name, &sb);
  146. if (ret)
  147. {
  148. perror("stat");
  149. STARPU_ABORT();
  150. }
  151. /* Make the gnuplot scrit executable for the owner */
  152. ret = chmod(file_name, sb.st_mode|S_IXUSR
  153. #ifdef S_IXGRP
  154. |S_IXGRP
  155. #endif
  156. #ifdef S_IXOTH
  157. |S_IXOTH
  158. #endif
  159. );
  160. if (ret)
  161. {
  162. perror("chmod");
  163. STARPU_ABORT();
  164. }
  165. fprintf(stdout, "Gnuplot file <%s/data_trace.gp> has been successfully created.\n", dir);
  166. }
  167. int main(int argc, char **argv)
  168. {
  169. char *directory = strdup(".");
  170. int pos=0;
  171. int ret = parse_args(argc, argv, &pos, &directory);
  172. if (ret)
  173. {
  174. free(directory);
  175. return ret;
  176. }
  177. starpu_fxt_write_data_trace_in_dir(argv[1+pos], directory);
  178. write_gp(directory, argc - (2 + pos), argv + 2 + pos);
  179. starpu_perfmodel_free_sampling();
  180. free(directory);
  181. return 0;
  182. }