starpu_fxt_stats.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011, 2012, 2013 Centre National de la Recherche Scientifique
  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 <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(char **argv)
  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, "Reports bugs to <"PACKAGE_BUGREPORT">.");
  43. fprintf(stderr, "\n");
  44. }
  45. static void 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(argv);
  65. exit(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. exit(EXIT_SUCCESS);
  71. }
  72. }
  73. if (!*fin)
  74. {
  75. fprintf(stderr, "Incorrect usage, aborting\n");
  76. usage(argv);
  77. exit(77);
  78. }
  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. parse_args(argc, argv, &fin, &fout);
  98. fd_in = open(fin, O_RDONLY);
  99. if (fd_in < 0)
  100. {
  101. perror("open failed :");
  102. exit(-1);
  103. }
  104. fut = fxt_fdopen(fd_in);
  105. if (!fut)
  106. {
  107. perror("fxt_fdopen :");
  108. exit(-1);
  109. }
  110. if (!fout)
  111. {
  112. fd_out = stdout;
  113. }
  114. else
  115. {
  116. fd_out = fopen(fout, "w");
  117. if (fd_out < 0)
  118. {
  119. perror("open failed :");
  120. exit(-1);
  121. }
  122. }
  123. fxt_blockev_t block;
  124. block = fxt_blockev_enter(fut);
  125. unsigned njob = 0;
  126. unsigned nws = 0;
  127. double start_time = 10e30;
  128. double end_time = -10e30;
  129. while(1)
  130. {
  131. ret = fxt_next_ev(block, FXT_EV_TYPE_64, (struct fxt_ev *)&ev);
  132. if (ret != FXT_EV_OK)
  133. {
  134. fprintf(stderr, "no more block ...\n");
  135. break;
  136. }
  137. end_time = STARPU_MAX(end_time, ev.time);
  138. start_time = STARPU_MIN(start_time, ev.time);
  139. STARPU_ATTRIBUTE_UNUSED int nbparam = ev.nb_params;
  140. switch (ev.code)
  141. {
  142. case _STARPU_FUT_DATA_COPY:
  143. handle_data_copy();
  144. break;
  145. case _STARPU_FUT_JOB_POP:
  146. njob++;
  147. break;
  148. case _STARPU_FUT_WORK_STEALING:
  149. nws++;
  150. break;
  151. default:
  152. break;
  153. }
  154. }
  155. fprintf(fd_out, "Start : start time %e end time %e length %e\n", start_time, end_time, end_time - start_time);
  156. unsigned src, dst;
  157. for (src = 0; src < 16; src++)
  158. {
  159. for (dst = 0; dst < 16; dst++)
  160. {
  161. if (transfers[src][dst] != 0)
  162. {
  163. fprintf(fd_out, "%d -> %d \t %ld MB\n", src, dst, transfers[src][dst]/(1024*1024));
  164. }
  165. }
  166. }
  167. fprintf(fd_out, "There was %d tasks and %d work stealing\n", njob, nws);
  168. return 0;
  169. }