starpu_fxt_stats.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2008-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. //#include "fxt_tool.h"
  17. #include <search.h>
  18. #include <sys/types.h>
  19. #include <sys/stat.h>
  20. #include <fcntl.h>
  21. #include <stdio.h>
  22. #include <stdint.h>
  23. #include <stdlib.h>
  24. #include <common/fxt.h>
  25. #include <common/list.h>
  26. #include <common/config.h>
  27. #include <starpu.h>
  28. static fxt_t fut;
  29. struct fxt_ev_64 ev;
  30. static uint64_t transfers[16][16];
  31. #define PROGNAME "starpu_fxt_stat"
  32. static void usage()
  33. {
  34. fprintf(stderr, "Parse the log generated by FxT\n\n");
  35. fprintf(stderr, "Usage: %s [ options ]\n", PROGNAME);
  36. fprintf(stderr, "\n");
  37. fprintf(stderr, "Options:\n");
  38. fprintf(stderr, " -i <input file> specify the input file.\n");
  39. fprintf(stderr, " -o <output file> specify the output file\n");
  40. fprintf(stderr, " -h, --help display this help and exit\n");
  41. fprintf(stderr, " -v, --version output version information and exit\n\n");
  42. fprintf(stderr, "Report bugs to <%s>.", PACKAGE_BUGREPORT);
  43. fprintf(stderr, "\n");
  44. }
  45. static int parse_args(int argc, char **argv, char **fin, char **fout)
  46. {
  47. int i;
  48. *fin = NULL;
  49. *fout = NULL;
  50. for (i = 1; i < argc; i++)
  51. {
  52. if (strcmp(argv[i], "-o") == 0)
  53. {
  54. *fout = argv[++i];
  55. continue;
  56. }
  57. if (strcmp(argv[i], "-i") == 0)
  58. {
  59. *fin = argv[++i];
  60. continue;
  61. }
  62. if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
  63. {
  64. usage();
  65. return EXIT_SUCCESS;
  66. }
  67. if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0)
  68. {
  69. fputs(PROGNAME " (" PACKAGE_NAME ") " PACKAGE_VERSION "\n", stderr);
  70. return EXIT_SUCCESS;
  71. }
  72. }
  73. if (!*fin)
  74. {
  75. fprintf(stderr, "Incorrect usage, aborting\n");
  76. usage();
  77. return 77;
  78. }
  79. return 0;
  80. }
  81. static void handle_data_copy(void)
  82. {
  83. unsigned src = ev.param[0];
  84. unsigned dst = ev.param[1];
  85. unsigned size = ev.param[2];
  86. transfers[src][dst] += size;
  87. // printf("transfer %d -> %d : %d \n", src, dst, size);
  88. }
  89. /*
  90. * This program should be used to parse the log generated by FxT
  91. */
  92. int main(int argc, char **argv)
  93. {
  94. char *fin, *fout;
  95. int ret;
  96. int fd_in;
  97. FILE *fd_out;
  98. ret = parse_args(argc, argv, &fin, &fout);
  99. if (ret) return ret;
  100. fd_in = open(fin, O_RDONLY);
  101. if (fd_in < 0)
  102. {
  103. perror("open failed :");
  104. exit(-1);
  105. }
  106. fut = fxt_fdopen(fd_in);
  107. if (!fut)
  108. {
  109. perror("fxt_fdopen :");
  110. exit(-1);
  111. }
  112. if (!fout)
  113. {
  114. fd_out = stdout;
  115. }
  116. else
  117. {
  118. fd_out = fopen(fout, "w");
  119. if (fd_out == NULL)
  120. {
  121. perror("open failed :");
  122. exit(-1);
  123. }
  124. }
  125. fxt_blockev_t block;
  126. block = fxt_blockev_enter(fut);
  127. unsigned njob = 0;
  128. unsigned nws = 0;
  129. double start_time = 10e30;
  130. double end_time = -10e30;
  131. while(1)
  132. {
  133. ret = fxt_next_ev(block, FXT_EV_TYPE_64, (struct fxt_ev *)&ev);
  134. if (ret != FXT_EV_OK)
  135. {
  136. fprintf(stderr, "no more block ...\n");
  137. break;
  138. }
  139. end_time = STARPU_MAX(end_time, ev.time);
  140. start_time = STARPU_MIN(start_time, ev.time);
  141. STARPU_ATTRIBUTE_UNUSED int nbparam = ev.nb_params;
  142. switch (ev.code)
  143. {
  144. case _STARPU_FUT_DATA_COPY:
  145. handle_data_copy();
  146. break;
  147. case _STARPU_FUT_JOB_POP:
  148. njob++;
  149. break;
  150. case _STARPU_FUT_WORK_STEALING:
  151. nws++;
  152. break;
  153. default:
  154. break;
  155. }
  156. }
  157. #ifdef HAVE_FXT_BLOCKEV_LEAVE
  158. fxt_blockev_leave(block);
  159. #endif
  160. #ifdef HAVE_FXT_CLOSE
  161. fxt_close(fut);
  162. #else
  163. if (close(fd_in))
  164. {
  165. perror("close failed :");
  166. exit(-1);
  167. }
  168. #endif
  169. fprintf(fd_out, "Start : start time %e end time %e length %e\n", start_time, end_time, end_time - start_time);
  170. unsigned src, dst;
  171. for (src = 0; src < 16; src++)
  172. {
  173. for (dst = 0; dst < 16; dst++)
  174. {
  175. if (transfers[src][dst] != 0)
  176. {
  177. fprintf(fd_out, "%u -> %u \t %lu MB\n", src, dst, (unsigned long)(transfers[src][dst]/(1024*1024)));
  178. }
  179. }
  180. }
  181. fprintf(fd_out, "There was %u tasks and %u work stealing\n", njob, nws);
  182. if (fd_out != stdout)
  183. fclose(fd_out);
  184. return 0;
  185. }