starpu_fxt_data_trace.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013 Joris Pablo
  4. * Copyright (C) 2014-2015,2017 CNRS
  5. * Copyright (C) 2011-2014,2016 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <stdio.h>
  19. #include <starpu.h>
  20. #include <string.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. FILE *plt = fopen("data_trace.gp", "w+");
  71. if(!plt)
  72. {
  73. perror("Error while creating data_trace.gp:");
  74. exit(-1);
  75. }
  76. fprintf(plt, "#!/usr/bin/gnuplot -persist\n\n");
  77. fprintf(plt, "set term postscript eps enhanced color\n");
  78. fprintf(plt, "set output \"data_trace.eps\"\n");
  79. fprintf(plt, "set title \"Data trace\"\n");
  80. fprintf(plt, "set logscale x\n");
  81. fprintf(plt, "set logscale y\n");
  82. fprintf(plt, "set xlabel \"data size (B)\"\n");
  83. fprintf(plt, "set ylabel \"tasks size (ms)\"\n");
  84. fprintf(plt, "plot ");
  85. int c_iter;
  86. char *v_iter;
  87. int begin = 1;
  88. while(fgets(codelet_name, MAX_LINE_SIZE, codelet_list) != NULL)
  89. {
  90. if(argc == 0)
  91. {
  92. if(begin)
  93. begin = 0;
  94. else
  95. fprintf(plt, ", ");
  96. }
  97. int size = strlen(codelet_name);
  98. if(size > 0)
  99. codelet_name[size-1] = '\0';
  100. if(argc != 0)
  101. {
  102. for(c_iter = 0, v_iter = argv[c_iter];
  103. c_iter < argc;
  104. c_iter++, v_iter = argv[c_iter])
  105. {
  106. if(!strcmp(v_iter, codelet_name))
  107. {
  108. if(begin)
  109. begin = 0;
  110. else
  111. fprintf(plt, ", ");
  112. fprintf(plt, "\"%s\" using 2:1 with dots lw 1 title \"%s\"", codelet_name, codelet_name);
  113. }
  114. }
  115. }
  116. else
  117. {
  118. fprintf(plt, "\"%s\" using 2:1 with dots lw 1 title \"%s\"", codelet_name, codelet_name);
  119. }
  120. }
  121. fprintf(plt, "\n");
  122. fprintf(stdout, "Gnuplot file <data_trace.gp> has been successfully created.\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. }
  134. int main(int argc, char **argv)
  135. {
  136. int ret = parse_args(argc, argv);
  137. if (ret) return ret;
  138. starpu_fxt_write_data_trace(argv[1]);
  139. write_gp(argc - 2, argv + 2);
  140. starpu_perfmodel_free_sampling_directories();
  141. return 0;
  142. }