starpu_fxt_stats.c 4.2 KB

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