starpu_fxt_data_trace.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #include <stdio.h>
  2. #include <config.h>
  3. #include <starpu.h>
  4. #include <string.h>
  5. #define PROGNAME "starpu_fxt_data_trace"
  6. #define MAX_LINE_SIZE 100
  7. static void usage()
  8. {
  9. fprintf(stderr, "Get statistics about tasks lengths and data size\n\n");
  10. fprintf(stderr, "Usage: %s [ options ] <filename> [<codelet1> <codelet2> .... <codeletn>]\n", PROGNAME);
  11. fprintf(stderr, "\n");
  12. fprintf(stderr, "Options:\n");
  13. fprintf(stderr, " -h, --help display this help and exit\n");
  14. fprintf(stderr, " -v, --version output version information and exit\n\n");
  15. fprintf(stderr, " filename specify the FxT trace input file.\n");
  16. fprintf(stderr, " codeletX specify the codelet name to profile (by default, all codelets are profiled)\n");
  17. fprintf(stderr, "Report bugs to <"PACKAGE_BUGREPORT">.");
  18. fprintf(stderr, "\n");
  19. }
  20. static void parse_args(int argc, char **argv)
  21. {
  22. int i;
  23. if(argc < 2)
  24. {
  25. fprintf(stderr, "Incorrect usage, aborting\n");
  26. usage();
  27. exit(77);
  28. }
  29. for (i = 1; i < argc; i++)
  30. {
  31. if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
  32. {
  33. usage();
  34. exit(EXIT_SUCCESS);
  35. }
  36. if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0)
  37. {
  38. fputs(PROGNAME " (" PACKAGE_NAME ") " PACKAGE_VERSION "\n", stderr);
  39. exit(EXIT_SUCCESS);
  40. }
  41. }
  42. }
  43. static void write_gp(int argc, char **argv)
  44. {
  45. FILE *codelet_list = fopen("codelet_list", "r");
  46. if(!codelet_list)
  47. {
  48. perror("Error while opening codelet_list:");
  49. exit(-1);
  50. }
  51. char codelet_name[MAX_LINE_SIZE];
  52. FILE *plt = fopen("data_trace.gp", "w+");
  53. if(!plt){
  54. perror("Error while creating data_trace.gp:");
  55. exit(-1);
  56. }
  57. fprintf(plt, "#!/usr/bin/gnuplot -persist\n\n");
  58. fprintf(plt, "set term postscript eps enhanced color\n");
  59. fprintf(plt, "set output \"data_trace.eps\"\n");
  60. fprintf(plt, "set title \"Data trace\"\n");
  61. fprintf(plt, "set logscale x\n");
  62. fprintf(plt, "set logscale y\n");
  63. fprintf(plt, "set xlabel \"data size (B)\"\n");
  64. fprintf(plt, "set ylabel \"tasks size (ms)\"\n");
  65. fprintf(plt, "plot ");
  66. int c_iter;
  67. char *v_iter;
  68. int begin = 1;
  69. while(fgets(codelet_name, MAX_LINE_SIZE, codelet_list) != NULL)
  70. {
  71. if(argc == 0)
  72. {
  73. if(begin)
  74. begin = 0;
  75. else
  76. fprintf(plt, ", ");
  77. }
  78. int size = strlen(codelet_name);
  79. if(size > 0)
  80. codelet_name[size-1] = '\0';
  81. if(argc != 0)
  82. {
  83. for(c_iter = 0, v_iter = argv[c_iter];
  84. c_iter < argc;
  85. c_iter++, v_iter = argv[c_iter])
  86. {
  87. if(!strcmp(v_iter, codelet_name))
  88. {
  89. if(begin)
  90. begin = 0;
  91. else
  92. fprintf(plt, ", ");
  93. fprintf(plt, "\"%s\" using 2:1 with dots lw 1 title \"%s\"", codelet_name, codelet_name);
  94. }
  95. }
  96. }
  97. else
  98. {
  99. fprintf(plt, "\"%s\" using 2:1 with dots lw 1 title \"%s\"", codelet_name, codelet_name);
  100. }
  101. }
  102. fprintf(plt, "\n");
  103. fprintf(stdout, "Gnuplot file <data_trace.gp> has been successfully created.\n");
  104. if(fclose(codelet_list))
  105. {
  106. perror("close failed :");
  107. exit(-1);
  108. }
  109. if(fclose(plt))
  110. {
  111. perror("close failed :");
  112. exit(-1);
  113. }
  114. }
  115. int main(int argc, char **argv)
  116. {
  117. parse_args(argc, argv);
  118. starpu_fxt_write_data_trace(argv[1]);
  119. write_gp(argc - 2, argv + 2);
  120. return 0;
  121. }