starpu_fxt_data_trace.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013 Joris Pablo
  4. * Copyright (C) 2011-2014 Universite de Bordeaux
  5. * Copyright (C) 2014, 2015 CNRS
  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 <config.h>
  20. #include <starpu.h>
  21. #include <string.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 <"PACKAGE_BUGREPORT">.");
  35. fprintf(stderr, "\n");
  36. }
  37. static void 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. exit(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. exit(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. exit(EXIT_SUCCESS);
  57. }
  58. }
  59. }
  60. static void write_gp(int argc, char **argv)
  61. {
  62. FILE *codelet_list = fopen("codelet_list", "r");
  63. if(!codelet_list)
  64. {
  65. perror("Error while opening codelet_list:");
  66. exit(-1);
  67. }
  68. char codelet_name[MAX_LINE_SIZE];
  69. FILE *plt = fopen("data_trace.gp", "w+");
  70. if(!plt)
  71. {
  72. perror("Error while creating data_trace.gp:");
  73. exit(-1);
  74. }
  75. fprintf(plt, "#!/usr/bin/gnuplot -persist\n\n");
  76. fprintf(plt, "set term postscript eps enhanced color\n");
  77. fprintf(plt, "set output \"data_trace.eps\"\n");
  78. fprintf(plt, "set title \"Data trace\"\n");
  79. fprintf(plt, "set logscale x\n");
  80. fprintf(plt, "set logscale y\n");
  81. fprintf(plt, "set xlabel \"data size (B)\"\n");
  82. fprintf(plt, "set ylabel \"tasks size (ms)\"\n");
  83. fprintf(plt, "plot ");
  84. int c_iter;
  85. char *v_iter;
  86. int begin = 1;
  87. while(fgets(codelet_name, MAX_LINE_SIZE, codelet_list) != NULL)
  88. {
  89. if(argc == 0)
  90. {
  91. if(begin)
  92. begin = 0;
  93. else
  94. fprintf(plt, ", ");
  95. }
  96. int size = strlen(codelet_name);
  97. if(size > 0)
  98. codelet_name[size-1] = '\0';
  99. if(argc != 0)
  100. {
  101. for(c_iter = 0, v_iter = argv[c_iter];
  102. c_iter < argc;
  103. c_iter++, v_iter = argv[c_iter])
  104. {
  105. if(!strcmp(v_iter, codelet_name))
  106. {
  107. if(begin)
  108. begin = 0;
  109. else
  110. fprintf(plt, ", ");
  111. fprintf(plt, "\"%s\" using 2:1 with dots lw 1 title \"%s\"", codelet_name, codelet_name);
  112. }
  113. }
  114. }
  115. else
  116. {
  117. fprintf(plt, "\"%s\" using 2:1 with dots lw 1 title \"%s\"", codelet_name, codelet_name);
  118. }
  119. }
  120. fprintf(plt, "\n");
  121. fprintf(stdout, "Gnuplot file <data_trace.gp> has been successfully created.\n");
  122. if(fclose(codelet_list))
  123. {
  124. perror("close failed :");
  125. exit(-1);
  126. }
  127. if(fclose(plt))
  128. {
  129. perror("close failed :");
  130. exit(-1);
  131. }
  132. }
  133. int main(int argc, char **argv)
  134. {
  135. parse_args(argc, argv);
  136. starpu_fxt_write_data_trace(argv[1]);
  137. write_gp(argc - 2, argv + 2);
  138. starpu_perfmodel_free_sampling_directories();
  139. return 0;
  140. }