starpu_fxt_stats.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2008-2011,2013-2014,2016 Université de Bordeaux
  4. * Copyright (C) 2010-2015,2017 CNRS
  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 "fxt_tool.h"
  18. #include <search.h>
  19. #include <sys/types.h>
  20. #include <sys/stat.h>
  21. #include <fcntl.h>
  22. #include <stdio.h>
  23. #include <stdint.h>
  24. #include <stdlib.h>
  25. #include <common/fxt.h>
  26. #include <common/list.h>
  27. #include <common/config.h>
  28. #include <starpu.h>
  29. static fxt_t fut;
  30. struct fxt_ev_64 ev;
  31. static uint64_t transfers[16][16];
  32. #define PROGNAME "starpu_fxt_stat"
  33. static void usage()
  34. {
  35. fprintf(stderr, "Parse the log generated by FxT\n\n");
  36. fprintf(stderr, "Usage: %s [ options ]\n", PROGNAME);
  37. fprintf(stderr, "\n");
  38. fprintf(stderr, "Options:\n");
  39. fprintf(stderr, " -i <input file> specify the input file.\n");
  40. fprintf(stderr, " -o <output file> specify the output file\n");
  41. fprintf(stderr, " -h, --help display this help and exit\n");
  42. fprintf(stderr, " -v, --version output version information and exit\n\n");
  43. fprintf(stderr, "Report bugs to <%s>.", PACKAGE_BUGREPORT);
  44. fprintf(stderr, "\n");
  45. }
  46. static int parse_args(int argc, char **argv, char **fin, char **fout)
  47. {
  48. int i;
  49. *fin = NULL;
  50. *fout = NULL;
  51. for (i = 1; i < argc; i++)
  52. {
  53. if (strcmp(argv[i], "-o") == 0)
  54. {
  55. *fout = argv[++i];
  56. continue;
  57. }
  58. if (strcmp(argv[i], "-i") == 0)
  59. {
  60. *fin = argv[++i];
  61. continue;
  62. }
  63. if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
  64. {
  65. usage();
  66. return EXIT_SUCCESS;
  67. }
  68. if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0)
  69. {
  70. fputs(PROGNAME " (" PACKAGE_NAME ") " PACKAGE_VERSION "\n", stderr);
  71. return EXIT_SUCCESS;
  72. }
  73. }
  74. if (!*fin)
  75. {
  76. fprintf(stderr, "Incorrect usage, aborting\n");
  77. usage();
  78. return 77;
  79. }
  80. return 0;
  81. }
  82. static void handle_data_copy(void)
  83. {
  84. unsigned src = ev.param[0];
  85. unsigned dst = ev.param[1];
  86. unsigned size = ev.param[2];
  87. transfers[src][dst] += size;
  88. // printf("transfer %d -> %d : %d \n", src, dst, size);
  89. }
  90. /*
  91. * This program should be used to parse the log generated by FxT
  92. */
  93. int main(int argc, char **argv)
  94. {
  95. char *fin, *fout;
  96. int ret;
  97. int fd_in;
  98. FILE *fd_out;
  99. ret = parse_args(argc, argv, &fin, &fout);
  100. if (ret) return ret;
  101. fd_in = open(fin, O_RDONLY);
  102. if (fd_in < 0)
  103. {
  104. perror("open failed :");
  105. exit(-1);
  106. }
  107. fut = fxt_fdopen(fd_in);
  108. if (!fut)
  109. {
  110. perror("fxt_fdopen :");
  111. exit(-1);
  112. }
  113. if (!fout)
  114. {
  115. fd_out = stdout;
  116. }
  117. else
  118. {
  119. fd_out = fopen(fout, "w");
  120. if (fd_out == NULL)
  121. {
  122. perror("open failed :");
  123. exit(-1);
  124. }
  125. }
  126. fxt_blockev_t block;
  127. block = fxt_blockev_enter(fut);
  128. unsigned njob = 0;
  129. unsigned nws = 0;
  130. double start_time = 10e30;
  131. double end_time = -10e30;
  132. while(1)
  133. {
  134. ret = fxt_next_ev(block, FXT_EV_TYPE_64, (struct fxt_ev *)&ev);
  135. if (ret != FXT_EV_OK)
  136. {
  137. fprintf(stderr, "no more block ...\n");
  138. break;
  139. }
  140. end_time = STARPU_MAX(end_time, ev.time);
  141. start_time = STARPU_MIN(start_time, ev.time);
  142. STARPU_ATTRIBUTE_UNUSED int nbparam = ev.nb_params;
  143. switch (ev.code)
  144. {
  145. case _STARPU_FUT_DATA_COPY:
  146. handle_data_copy();
  147. break;
  148. case _STARPU_FUT_JOB_POP:
  149. njob++;
  150. break;
  151. case _STARPU_FUT_WORK_STEALING:
  152. nws++;
  153. break;
  154. default:
  155. break;
  156. }
  157. }
  158. fprintf(fd_out, "Start : start time %e end time %e length %e\n", start_time, end_time, end_time - start_time);
  159. unsigned src, dst;
  160. for (src = 0; src < 16; src++)
  161. {
  162. for (dst = 0; dst < 16; dst++)
  163. {
  164. if (transfers[src][dst] != 0)
  165. {
  166. fprintf(fd_out, "%u -> %u \t %lu MB\n", src, dst, (unsigned long)(transfers[src][dst]/(1024*1024)));
  167. }
  168. }
  169. }
  170. fprintf(fd_out, "There was %u tasks and %u work stealing\n", njob, nws);
  171. if (fd_out != stdout)
  172. fclose(fd_out);
  173. return 0;
  174. }