starpu_fxt_data_trace.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2020 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, " filename specify the FxT trace input file.\n");
  33. fprintf(stderr, " codeletX specify the codelet name to profile (by default, all codelets are profiled)\n");
  34. fprintf(stderr, "Report bugs to <%s>.", PACKAGE_BUGREPORT);
  35. fprintf(stderr, "\n");
  36. }
  37. static int parse_args(int argc, char **argv)
  38. {
  39. int i;
  40. if(argc < 2)
  41. {
  42. fprintf(stderr, "Incorrect usage, aborting\n");
  43. usage();
  44. return 77;
  45. }
  46. for (i = 1; i < argc; i++)
  47. {
  48. if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
  49. {
  50. usage();
  51. return EXIT_SUCCESS;
  52. }
  53. if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0)
  54. {
  55. fputs(PROGNAME " (" PACKAGE_NAME ") " PACKAGE_VERSION "\n", stderr);
  56. return EXIT_SUCCESS;
  57. }
  58. }
  59. return 0;
  60. }
  61. static void write_gp(int argc, char **argv)
  62. {
  63. FILE *codelet_list = fopen("codelet_list", "r");
  64. if(!codelet_list)
  65. {
  66. perror("Error while opening codelet_list:");
  67. exit(-1);
  68. }
  69. char codelet_name[MAX_LINE_SIZE];
  70. const char *file_name = "data_trace.gp";
  71. FILE *plt = fopen(file_name, "w+");
  72. if(!plt)
  73. {
  74. perror("Error while creating data_trace.gp:");
  75. exit(-1);
  76. }
  77. fprintf(plt, "#!/usr/bin/gnuplot -persist\n\n");
  78. fprintf(plt, "set term postscript eps enhanced color\n");
  79. fprintf(plt, "set output \"data_trace.eps\"\n");
  80. fprintf(plt, "set title \"Data trace\"\n");
  81. fprintf(plt, "set logscale x\n");
  82. fprintf(plt, "set logscale y\n");
  83. fprintf(plt, "set xlabel \"data size (B)\"\n");
  84. fprintf(plt, "set ylabel \"tasks size (ms)\"\n");
  85. fprintf(plt, "plot ");
  86. int c_iter;
  87. char *v_iter;
  88. int begin = 1;
  89. while(fgets(codelet_name, MAX_LINE_SIZE, codelet_list) != NULL)
  90. {
  91. if(argc == 0)
  92. {
  93. if(begin)
  94. begin = 0;
  95. else
  96. fprintf(plt, ", ");
  97. }
  98. int size = strlen(codelet_name);
  99. if(size > 0)
  100. codelet_name[size-1] = '\0';
  101. if(argc != 0)
  102. {
  103. for(c_iter = 0, v_iter = argv[c_iter];
  104. c_iter < argc;
  105. c_iter++, v_iter = argv[c_iter])
  106. {
  107. if(!strcmp(v_iter, codelet_name))
  108. {
  109. if(begin)
  110. begin = 0;
  111. else
  112. fprintf(plt, ", ");
  113. fprintf(plt, "\"%s\" using 2:1 with dots lw 1 title \"%s\"", codelet_name, codelet_name);
  114. }
  115. }
  116. }
  117. else
  118. {
  119. fprintf(plt, "\"%s\" using 2:1 with dots lw 1 title \"%s\"", codelet_name, codelet_name);
  120. }
  121. }
  122. fprintf(plt, "\n");
  123. if(fclose(codelet_list))
  124. {
  125. perror("close failed :");
  126. exit(-1);
  127. }
  128. if(fclose(plt))
  129. {
  130. perror("close failed :");
  131. exit(-1);
  132. }
  133. struct stat sb;
  134. int ret = stat(file_name, &sb);
  135. if (ret)
  136. {
  137. perror("stat");
  138. STARPU_ABORT();
  139. }
  140. /* Make the gnuplot scrit executable for the owner */
  141. ret = chmod(file_name, sb.st_mode|S_IXUSR);
  142. if (ret)
  143. {
  144. perror("chmod");
  145. STARPU_ABORT();
  146. }
  147. fprintf(stdout, "Gnuplot file <data_trace.gp> has been successfully created.\n");
  148. }
  149. int main(int argc, char **argv)
  150. {
  151. int ret = parse_args(argc, argv);
  152. if (ret) return ret;
  153. starpu_fxt_write_data_trace(argv[1]);
  154. write_gp(argc - 2, argv + 2);
  155. starpu_perfmodel_free_sampling();
  156. return 0;
  157. }