starpu_fxt_data_trace.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013 Joris Pablo
  4. * Copyright (C) 2014,2015,2017 CNRS
  5. * Copyright (C) 2011-2014,2016,2019 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <stdio.h>
  19. #include <starpu.h>
  20. #include <string.h>
  21. #include <sys/stat.h>
  22. #include <common/config.h>
  23. #define PROGNAME "starpu_fxt_data_trace"
  24. #define MAX_LINE_SIZE 100
  25. static void usage()
  26. {
  27. fprintf(stderr, "Get statistics about tasks lengths and data size\n\n");
  28. fprintf(stderr, "Usage: %s [ options ] <filename> [<codelet1> <codelet2> .... <codeletn>]\n", PROGNAME);
  29. fprintf(stderr, "\n");
  30. fprintf(stderr, "Options:\n");
  31. fprintf(stderr, " -h, --help display this help and exit\n");
  32. fprintf(stderr, " -v, --version output version information and exit\n\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)
  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. return EXIT_SUCCESS;
  53. }
  54. if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0)
  55. {
  56. fputs(PROGNAME " (" PACKAGE_NAME ") " PACKAGE_VERSION "\n", stderr);
  57. return EXIT_SUCCESS;
  58. }
  59. }
  60. return 0;
  61. }
  62. static void write_gp(int argc, char **argv)
  63. {
  64. FILE *codelet_list = fopen("codelet_list", "r");
  65. if(!codelet_list)
  66. {
  67. perror("Error while opening codelet_list:");
  68. exit(-1);
  69. }
  70. char codelet_name[MAX_LINE_SIZE];
  71. const char *file_name = "data_trace.gp";
  72. FILE *plt = fopen(file_name, "w+");
  73. if(!plt)
  74. {
  75. perror("Error while creating data_trace.gp:");
  76. exit(-1);
  77. }
  78. fprintf(plt, "#!/usr/bin/gnuplot -persist\n\n");
  79. fprintf(plt, "set term postscript eps enhanced color\n");
  80. fprintf(plt, "set output \"data_trace.eps\"\n");
  81. fprintf(plt, "set title \"Data trace\"\n");
  82. fprintf(plt, "set logscale x\n");
  83. fprintf(plt, "set logscale y\n");
  84. fprintf(plt, "set xlabel \"data size (B)\"\n");
  85. fprintf(plt, "set ylabel \"tasks size (ms)\"\n");
  86. fprintf(plt, "plot ");
  87. int c_iter;
  88. char *v_iter;
  89. int begin = 1;
  90. while(fgets(codelet_name, MAX_LINE_SIZE, codelet_list) != NULL)
  91. {
  92. if(argc == 0)
  93. {
  94. if(begin)
  95. begin = 0;
  96. else
  97. fprintf(plt, ", ");
  98. }
  99. int size = strlen(codelet_name);
  100. if(size > 0)
  101. codelet_name[size-1] = '\0';
  102. if(argc != 0)
  103. {
  104. for(c_iter = 0, v_iter = argv[c_iter];
  105. c_iter < argc;
  106. c_iter++, v_iter = argv[c_iter])
  107. {
  108. if(!strcmp(v_iter, codelet_name))
  109. {
  110. if(begin)
  111. begin = 0;
  112. else
  113. fprintf(plt, ", ");
  114. fprintf(plt, "\"%s\" using 2:1 with dots lw 1 title \"%s\"", codelet_name, codelet_name);
  115. }
  116. }
  117. }
  118. else
  119. {
  120. fprintf(plt, "\"%s\" using 2:1 with dots lw 1 title \"%s\"", codelet_name, codelet_name);
  121. }
  122. }
  123. fprintf(plt, "\n");
  124. if(fclose(codelet_list))
  125. {
  126. perror("close failed :");
  127. exit(-1);
  128. }
  129. if(fclose(plt))
  130. {
  131. perror("close failed :");
  132. exit(-1);
  133. }
  134. struct stat sb;
  135. int ret = stat(file_name, &sb);
  136. if (ret)
  137. {
  138. perror("stat");
  139. STARPU_ABORT();
  140. }
  141. /* Make the gnuplot scrit executable for the owner */
  142. ret = chmod(file_name, sb.st_mode|S_IXUSR);
  143. if (ret)
  144. {
  145. perror("chmod");
  146. STARPU_ABORT();
  147. }
  148. fprintf(stdout, "Gnuplot file <data_trace.gp> has been successfully created.\n");
  149. }
  150. int main(int argc, char **argv)
  151. {
  152. int ret = parse_args(argc, argv);
  153. if (ret) return ret;
  154. starpu_fxt_write_data_trace(argv[1]);
  155. write_gp(argc - 2, argv + 2);
  156. starpu_perfmodel_free_sampling_directories();
  157. return 0;
  158. }