histo-svg.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
  4. *
  5. * This program 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. * This program 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 "histo-svg.h"
  17. static uint64_t absolute_start_time;
  18. static uint64_t start_time;
  19. static uint64_t absolute_end_time;
  20. static uint64_t end_time;
  21. static char *out_path;
  22. static FILE *out_file;
  23. static void add_region(worker_mode color, uint64_t start, uint64_t end, unsigned worker)
  24. {
  25. float starty, endy, startx, endx;
  26. starty = SVG_BORDERY + (SVG_THICKNESS + SVG_GAP)*worker;
  27. endy = starty + SVG_THICKNESS;
  28. double ratio_start, ratio_end;
  29. ratio_start = (double)(start - start_time) / (double)(end_time - start_time);
  30. ratio_end = (double)(end - start_time) / (double)(end_time - start_time);
  31. startx = (float)(SVG_BORDERX + ratio_start*(SVG_WIDTH - 2*SVG_BORDERX));
  32. endx = (float)(SVG_BORDERX + ratio_end*(SVG_WIDTH - 2*SVG_BORDERX));
  33. // printf("startx %d endx %d ratio %f %f starty %d endy %d\n", startx, endx, ratio_start, ratio_end, starty, endy);
  34. char *color_str;
  35. switch (color) {
  36. case WORKING:
  37. color_str = "green";
  38. break;
  39. case IDLE:
  40. default:
  41. color_str = "red";
  42. break;
  43. }
  44. fprintf(out_file, "<rect x=\"%fcm\" y=\"%fcm\" width=\"%fcm\" height=\"%fcm\" stroke-width=\"10\%%\" stroke=\"black\" fill=\"%s\"/>\n", startx, starty, endx - startx, endy -starty, color_str);
  45. }
  46. static void display_worker(event_list_t events, unsigned worker, char *worker_name)
  47. {
  48. uint64_t prev = start_time;
  49. worker_mode prev_state = IDLE;
  50. // SWFText namestr = newSWFText();
  51. // SWFText_setFont(namestr, font);
  52. // SWFText_setColor(namestr, 0, 0, 0, 0xff);
  53. // SWFText_setHeight(namestr, 10);
  54. // SWFText_moveTo(namestr, SVG_BORDERX/2 - strlen(worker_name),
  55. // SVG_BORDERY + (SVG_THICKNESS + SVG_GAP)*worker + SVG_THICKNESS/2);
  56. // SWFText_addString(namestr, worker_name, NULL);
  57. //
  58. // SWFMovie_add(movie, (SWFBlock)namestr);
  59. fprintf(out_file, "<text x=\"%fcm\" y=\"%fcm\" font-size=\"%fcm\" fill=\"blue\" text-anchor=\"center\" > <tspan font-weight=\"bold\">%s</tspan></text>\n", 0.5f*SVG_BORDERX, SVG_BORDERY + (SVG_THICKNESS + SVG_GAP)*worker + 0.5f*SVG_THICKNESS, SVG_THICKNESS/4.0f, worker_name);
  60. event_itor_t i;
  61. for (i = event_list_begin(events);
  62. i != event_list_end(events);
  63. i = event_list_next(i))
  64. {
  65. add_region(prev_state, prev, i->time, worker);
  66. prev = i->time;
  67. prev_state = i->mode;
  68. }
  69. }
  70. //char str_start[20];
  71. //char str_end[20];
  72. //
  73. //static void display_start_end_buttons(void)
  74. //{
  75. // unsigned x_start, x_end, y;
  76. // unsigned size = 15;
  77. //
  78. // sprintf(str_start, "start\n%lu", start_time-absolute_start_time);
  79. // sprintf(str_end, "end\n%lu", end_time -absolute_start_time);
  80. //
  81. // x_start = SVG_BORDERX;
  82. // x_end = SVG_WIDTH - SVG_BORDERX;
  83. // y = SVG_BORDERY/2;
  84. //
  85. // SWFText text_start = newSWFText();
  86. // SWFText_setFont(text_start, font);
  87. // SWFText_setColor(text_start, 0, 0, 0, 0xff);
  88. // SWFText_setHeight(text_start, size);
  89. // SWFText_moveTo(text_start, x_start, y);
  90. // SWFText_addString(text_start, str_start, NULL);
  91. //
  92. // SWFText text_end = newSWFText();
  93. // SWFText_setFont(text_end, font);
  94. // SWFText_setColor(text_end, 0, 0, 0, 0xff);
  95. // SWFText_setHeight(text_end, size);
  96. // SWFText_moveTo(text_end, x_end, y);
  97. // SWFText_addString(text_end, str_end, NULL);
  98. //
  99. // SWFMovie_add(movie, (SWFBlock)text_start);
  100. // SWFMovie_add(movie, (SWFBlock)text_end);
  101. //
  102. //}
  103. static void display_workq_evolution(workq_list_t taskq, unsigned nworkers, unsigned maxq_size)
  104. {
  105. float endy, starty;
  106. starty = SVG_BORDERY + (SVG_THICKNESS + SVG_GAP)*nworkers;
  107. endy = starty + SVG_THICKNESS;
  108. fprintf(out_file, "<line x1=\"%fcm\" y1=\"%fcm\" x2=\"%fcm\" y2=\"%fcm\" stroke=\"black\" stroke-width=\"100\%%\" />\n", SVG_BORDERX, endy, SVG_WIDTH - SVG_BORDERX, endy);
  109. fprintf(out_file, "<line x1=\"%fcm\" y1=\"%fcm\" x2=\"%fcm\" y2=\"%fcm\" stroke=\"black\" stroke-width=\"100\%%\" />\n", SVG_BORDERX, starty, SVG_BORDERX, endy);
  110. float prevx, prevy;
  111. prevx = SVG_BORDERX;
  112. prevy = endy;
  113. workq_itor_t i;
  114. for (i = workq_list_begin(taskq);
  115. i != workq_list_end(taskq);
  116. i = workq_list_next(i))
  117. {
  118. float event_pos;
  119. double event_ratio;
  120. float y;
  121. event_ratio = ( i->time - start_time )/ (double)(end_time - start_time);
  122. event_pos = (SVG_BORDERX + event_ratio*(SVG_WIDTH - 2*SVG_BORDERX));
  123. double qratio;
  124. qratio = ((double)(i->current_size))/((double)maxq_size);
  125. y = ((double)endy - qratio *((double)SVG_THICKNESS));
  126. fprintf(out_file, "<line x1=\"%fcm\" y1=\"%fcm\" x2=\"%fcm\" y2=\"%fcm\" stroke=\"black\" stroke-width=\"30\%%\" />\n", prevx, prevy, event_pos, y);
  127. prevx = event_pos;
  128. prevy = y;
  129. }
  130. // SWFShape_drawLine(shape, (int)SVG_BORDERX - (int)prevx, (int)endy - (int)prevy);
  131. //
  132. // SWFMovie_add(movie, (SWFBlock)shape);
  133. fprintf(out_file, "<line x1=\"%fcm\" y1=\"%fcm\" x2=\"%fcm\" y2=\"%fcm\" stroke=\"black\" stroke-width=\"100\%%\" />\n", prevx, prevy, SVG_BORDERX, endy);
  134. }
  135. void svg_output_file_init(void)
  136. {
  137. /* create a new file */
  138. out_file = fopen(out_path, "w+");
  139. /* create some header for a valid svg file */
  140. fprintf(out_file, "<?xml version=\"1.0\" standalone=\"no\"?>\n");
  141. fprintf(out_file, "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
  142. fprintf(out_file, "<svg width=\"%fcm\" height=\"%fcm\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n", SVG_WIDTH, SVG_HEIGHT);
  143. /* a little description is not too much */
  144. fprintf(out_file, "<desc>Gantt diagram ...</desc>\n");
  145. }
  146. void svg_output_file_terminate(void)
  147. {
  148. fprintf(out_file, "</svg>\n");
  149. /* close the file */
  150. fclose(out_file);
  151. }
  152. void svg_engine_generate_output(event_list_t *events, workq_list_t taskq, char **worker_name,
  153. unsigned nworkers, unsigned maxq_size,
  154. uint64_t _start_time, uint64_t _end_time, char *path)
  155. {
  156. out_path = path;
  157. unsigned worker;
  158. start_time = _start_time;
  159. absolute_start_time = _start_time;
  160. end_time = _end_time;
  161. absolute_end_time = _end_time;
  162. svg_output_file_init();
  163. for (worker = 0; worker < nworkers; worker++)
  164. {
  165. display_worker(events[worker], worker, worker_name[worker]);
  166. }
  167. display_workq_evolution(taskq, nworkers, maxq_size);
  168. svg_output_file_terminate();
  169. }