histo-flash.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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-flash.h"
  17. static SWFMovie movie;
  18. static uint64_t absolute_start_time;
  19. static uint64_t start_time;
  20. static uint64_t absolute_end_time;
  21. static uint64_t end_time;
  22. static SWFFont font;
  23. void flash_engine_init(void)
  24. {
  25. Ming_init();
  26. Ming_setScale(1.0);
  27. movie = newSWFMovie();
  28. SWFMovie_setBackground(movie, 0xff, 0xff, 0xff);
  29. SWFMovie_setDimension(movie, WIDTH, HEIGHT);
  30. const char *fontpath = "Sans.fdb";
  31. FILE *f = fopen(fontpath,"r");
  32. STARPU_ASSERT(f);
  33. font = loadSWFFontFromFile(f);
  34. if (font == NULL) {
  35. perror("could not open font :");
  36. exit(-1);
  37. }
  38. }
  39. #define PEN_WIDTH 0
  40. static void add_region(worker_mode color, uint64_t start, uint64_t end, unsigned worker)
  41. {
  42. unsigned starty, endy, startx, endx;
  43. starty = BORDERY + (THICKNESS + GAP)*worker;
  44. endy = starty + THICKNESS;
  45. double ratio_start, ratio_end;
  46. ratio_start = (double)(start - start_time) / (double)(end_time - start_time);
  47. ratio_end = (double)(end - start_time) / (double)(end_time - start_time);
  48. startx = (unsigned)(BORDERX + ratio_start*(WIDTH - 2*BORDERX));
  49. endx = (unsigned)(BORDERX + ratio_end*(WIDTH - 2*BORDERX));
  50. // printf("startx %d endx %d ratio %f %f starty %d endy %d\n", startx, endx, ratio_start, ratio_end, starty, endy);
  51. int region_color[3];
  52. switch (color) {
  53. case WORKING:
  54. region_color[0] = 0;
  55. region_color[1] = 255;
  56. region_color[2] = 0;
  57. break;
  58. case IDLE:
  59. default:
  60. region_color[0] = 255;
  61. region_color[1] = 0;
  62. region_color[2] = 0;
  63. break;
  64. }
  65. SWFShape shape = newSWFShape();
  66. // SWFShape_setLine(shape, PEN_WIDTH, region_color[0], region_color[1], region_color[2], 255);
  67. SWFShape_setLine(shape, PEN_WIDTH, 0, 0, 0, 255);
  68. SWFFillStyle style= SWFShape_addSolidFillStyle(shape, region_color[0], region_color[1], region_color[2], 255);
  69. SWFShape_setRightFillStyle(shape, style);
  70. SWFShape_movePenTo(shape, startx, starty);
  71. SWFShape_drawLine(shape, endx-startx, 0);
  72. SWFShape_drawLine(shape, 0, endy-starty);
  73. SWFShape_drawLine(shape, (int)startx-(int)endx, 0);
  74. SWFShape_drawLine(shape, 0, -((int)endy-(int)starty));
  75. SWFMovie_add(movie, (SWFBlock)shape);
  76. }
  77. static void display_worker(event_list_t events, unsigned worker, char *worker_name)
  78. {
  79. uint64_t prev = start_time;
  80. worker_mode prev_state = IDLE;
  81. SWFText namestr = newSWFText();
  82. SWFText_setFont(namestr, font);
  83. SWFText_setColor(namestr, 0, 0, 0, 0xff);
  84. SWFText_setHeight(namestr, 10);
  85. SWFText_moveTo(namestr, BORDERX/2 - strlen(worker_name),
  86. BORDERY + (THICKNESS + GAP)*worker + THICKNESS/2);
  87. SWFText_addString(namestr, worker_name, NULL);
  88. SWFMovie_add(movie, (SWFBlock)namestr);
  89. event_itor_t i;
  90. for (i = event_list_begin(events);
  91. i != event_list_end(events);
  92. i = event_list_next(i))
  93. {
  94. add_region(prev_state, prev, i->time, worker);
  95. prev = i->time;
  96. prev_state = i->mode;
  97. }
  98. }
  99. static char str_start[20];
  100. static char str_end[20];
  101. static void display_start_end_buttons(void)
  102. {
  103. unsigned x_start, x_end, y;
  104. unsigned size = 15;
  105. sprintf(str_start, "start\n%lu", start_time-absolute_start_time);
  106. sprintf(str_end, "end\n%lu", end_time -absolute_start_time);
  107. x_start = BORDERX;
  108. x_end = WIDTH - BORDERX;
  109. y = BORDERY/2;
  110. SWFText text_start = newSWFText();
  111. SWFText_setFont(text_start, font);
  112. SWFText_setColor(text_start, 0, 0, 0, 0xff);
  113. SWFText_setHeight(text_start, size);
  114. SWFText_moveTo(text_start, x_start, y);
  115. SWFText_addString(text_start, str_start, NULL);
  116. SWFText text_end = newSWFText();
  117. SWFText_setFont(text_end, font);
  118. SWFText_setColor(text_end, 0, 0, 0, 0xff);
  119. SWFText_setHeight(text_end, size);
  120. SWFText_moveTo(text_end, x_end, y);
  121. SWFText_addString(text_end, str_end, NULL);
  122. SWFMovie_add(movie, (SWFBlock)text_start);
  123. SWFMovie_add(movie, (SWFBlock)text_end);
  124. }
  125. static void display_workq_evolution(workq_list_t taskq, unsigned nworkers, unsigned maxq_size)
  126. {
  127. unsigned endy, starty;
  128. starty = BORDERY + (THICKNESS + GAP)*nworkers;
  129. endy = starty + THICKNESS;
  130. SWFShape shape = newSWFShape();
  131. SWFShape_setLine(shape, PEN_WIDTH, 0, 0, 0, 255);
  132. // SWFFillStyle style= SWFShape_addSolidFillStyle(shape, 0, 0, 0, 255);
  133. SWFShape_movePenTo(shape, BORDERX, endy);
  134. SWFShape_drawLine(shape, WIDTH - 2 *BORDERX, 0);
  135. SWFShape_movePenTo(shape, BORDERX, starty);
  136. SWFShape_drawLine(shape, 0, THICKNESS);
  137. SWFMovie_add(movie, (SWFBlock)shape);
  138. shape = newSWFShape();
  139. SWFShape_setLine(shape, 0, 0, 0, 0, 255);
  140. SWFShape_movePenTo(shape, BORDERX, endy);
  141. int prevx, prevy;
  142. prevx = BORDERX;
  143. prevy = endy;
  144. workq_itor_t i;
  145. for (i = workq_list_begin(taskq);
  146. i != workq_list_end(taskq);
  147. i = workq_list_next(i))
  148. {
  149. unsigned event_pos;
  150. double event_ratio;
  151. unsigned y;
  152. event_ratio = ( i->time - start_time )/ (double)(end_time - start_time);
  153. event_pos = (unsigned)(BORDERX + event_ratio*(WIDTH - 2*BORDERX));
  154. double qratio;
  155. qratio = ((double)(i->current_size))/((double)maxq_size);
  156. y = (unsigned)((double)endy - qratio *((double)THICKNESS));
  157. SWFShape_drawLine(shape, (int)event_pos - (int)prevx, (int)y - (int)prevy);
  158. prevx = event_pos;
  159. prevy = y;
  160. }
  161. SWFShape_drawLine(shape, (int)BORDERX - (int)prevx, (int)endy - (int)prevy);
  162. SWFMovie_add(movie, (SWFBlock)shape);
  163. }
  164. void flash_engine_generate_output(event_list_t *events, workq_list_t taskq, char **worker_name,
  165. unsigned nworkers, unsigned maxq_size,
  166. uint64_t _start_time, uint64_t _end_time, char *path)
  167. {
  168. unsigned worker;
  169. start_time = _start_time;
  170. absolute_start_time = _start_time;
  171. end_time = _end_time;
  172. absolute_end_time = _end_time;
  173. display_start_end_buttons();
  174. for (worker = 0; worker < nworkers; worker++)
  175. {
  176. display_worker(events[worker], worker, worker_name[worker]);
  177. }
  178. display_workq_evolution(taskq, nworkers, maxq_size);
  179. printf("save output ... \n");
  180. SWFMovie_save(movie, path);
  181. }