anim.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2015 Université de Bordeaux
  4. * Copyright (C) 2015 Anthony Simonet
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <stdint.h>
  18. #include <stdlib.h>
  19. #include <common/uthash.h>
  20. #include <starpu.h>
  21. #include "starpu_fxt.h"
  22. static struct component {
  23. UT_hash_handle hh;
  24. char *name;
  25. int workerid;
  26. uint64_t ptr;
  27. unsigned nchildren;
  28. struct component **children;
  29. struct component *parent;
  30. unsigned ntasks;
  31. unsigned npriotasks;
  32. } *components;
  33. static unsigned global_state = 1;
  34. static unsigned nsubmitted;
  35. static unsigned curq_size;
  36. static unsigned nflowing;
  37. #define COMPONENT_ADD(head, field, add) HASH_ADD(hh, head, field, sizeof(uint64_t), add);
  38. #define COMPONENT_FIND(head, find, out) HASH_FIND(hh, head, &find, sizeof(uint64_t), out);
  39. static struct component *fxt_component_root(void)
  40. {
  41. struct component *comp, *tmp;
  42. HASH_ITER(hh, components, comp, tmp)
  43. {
  44. while (comp->parent)
  45. comp = comp->parent;
  46. return comp;
  47. }
  48. return NULL;
  49. }
  50. void _starpu_fxt_component_new(uint64_t component, char *name)
  51. {
  52. struct component *comp = malloc(sizeof(*comp));
  53. if (!strncmp(name, "worker ", 7))
  54. {
  55. comp->name = strdup("worker");
  56. comp->workerid = atoi(name+7);
  57. }
  58. else
  59. {
  60. comp->name = strdup(name);
  61. comp->workerid = -1;
  62. }
  63. comp->ptr = component;
  64. comp->nchildren = 0;
  65. comp->children = NULL;
  66. comp->parent = NULL;
  67. comp->ntasks = 0;
  68. comp->npriotasks = 0;
  69. COMPONENT_ADD(components, ptr, comp);
  70. }
  71. static void fxt_component_dump(FILE *file, struct component *comp, unsigned depth)
  72. {
  73. unsigned i;
  74. fprintf(file,"%*s%s (%d %"PRIx64", %d tasks %d prio tasks)\n", 2*depth, "", comp->name, depth, comp->ptr, comp->ntasks, comp->npriotasks);
  75. for (i = 0; i < comp->nchildren; i++)
  76. if (comp->children[i]->parent == comp)
  77. fxt_component_dump(file, comp->children[i], depth+1);
  78. }
  79. void _starpu_fxt_component_dump(FILE *file)
  80. {
  81. fxt_component_dump(file, fxt_component_root(), 0);
  82. }
  83. static void fxt_worker_print(FILE *file, struct starpu_fxt_options *options, int workerid, unsigned comp_workerid, unsigned depth)
  84. {
  85. fprintf(file, "\t\t\t%*s<table><tr><td class='worker_box%s'><center>%s\n", 2*depth, "",
  86. (int) comp_workerid == workerid ? "_sched":"",
  87. options->worker_names[comp_workerid]);
  88. if (_starpu_last_codelet_symbol[comp_workerid][0])
  89. fprintf(file, "\t\t\t%*s<table><tr><td class='run_task'>%s</td></tr></table>\n", 2*(depth+1), "", _starpu_last_codelet_symbol[comp_workerid]);
  90. else
  91. fprintf(file, "\t\t\t%*s<table><tr><td class='fake_task'></td></tr></table>\n", 2*(depth+1), "");
  92. fprintf(file, "\t\t\t%*s</center></td></tr>\n", 2*depth, "");
  93. fprintf(file, "\t\t\t%*s</table>", 2*depth, "");
  94. }
  95. static void fxt_component_print(FILE *file, struct starpu_fxt_options *options, int workerid, struct component *from, struct component *to, struct component *comp, unsigned depth)
  96. {
  97. unsigned i, n;
  98. unsigned ntasks = comp->ntasks + comp->npriotasks;
  99. if (from == comp)
  100. /* Additionally show now-empty slot */
  101. ntasks++;
  102. for (i = 0, n = 0; i < comp->nchildren; i++)
  103. if (comp->children[i]->parent == comp)
  104. n++;
  105. fprintf(file, "\t\t\t%*s<table><tr><td class='box' colspan=%d><center>%s\n", 2*depth, "", n, comp->name);
  106. if (!strcmp(comp->name,"prio") || !strcmp(comp->name,"fifo") || !strcmp(comp->name,"heft") || !strcmp(comp->name,"work_stealing"))
  107. {
  108. /* Show task queue */
  109. #define N 3
  110. n = ntasks;
  111. if (n > N)
  112. n = N;
  113. for (i = 0; i < N-n; i++)
  114. fprintf(file, "\t\t\t%*s<table><tr><td class='fake_task'></td></tr></table>\n", 2*depth, "");
  115. if (ntasks)
  116. {
  117. if (ntasks > N)
  118. fprintf(file, "\t\t\t%*s<table><tr><td class='%s'>%d</td></tr></table>\n", 2*depth, "",
  119. from == comp
  120. ? (comp->npriotasks >= N ? "last_task_full_prio" : "last_task_full")
  121. : (comp->npriotasks >= N ? "task_prio" : "task"),
  122. comp->ntasks + comp->npriotasks);
  123. else
  124. fprintf(file, "\t\t\t%*s<table><tr><td class='%s'></td></tr></table>\n", 2*depth, "",
  125. from == comp
  126. ? "last_task_empty"
  127. : (comp->ntasks ? "task" : "task_prio"));
  128. for (i = 1; i < n; i++)
  129. fprintf(file, "\t\t\t%*s<table><tr><td class='%s'></td></tr></table>\n", 2*depth, "",
  130. n - i > comp->npriotasks ? "task" : "task_prio");
  131. }
  132. }
  133. else
  134. {
  135. if (ntasks == 0)
  136. fprintf(file, "\t\t\t%*s<table><tr><td class='fake_task'></td></tr></table>\n", 2*depth, "");
  137. else if (ntasks == 1)
  138. fprintf(file, "\t\t\t%*s<table><tr><td class='%s'></td></tr></table>\n", 2*depth, "",
  139. from == comp
  140. ? "last_task_empty"
  141. : (comp->npriotasks ? "task_prio" : "task"));
  142. else
  143. fprintf(file, "\t\t\t%*s<table><tr><td class='%s'>%d</td></tr></table>\n", 2*depth, "",
  144. from == comp
  145. ? (comp->npriotasks ? "last_task_full_prio" : "last_task_full")
  146. : (comp->npriotasks ? "task_prio" : "task"), comp->ntasks + comp->npriotasks);
  147. }
  148. fprintf(file, "\t\t\t%*s</center></td></tr>\n", 2*depth, "");
  149. if (comp->nchildren > 0)
  150. {
  151. fprintf(file, "\t\t\t%*s<tr>\n", 2*depth, "");
  152. for (i = 0; i < comp->nchildren; i++)
  153. if (comp->children[i]->parent == comp)
  154. {
  155. fprintf(file, "\t\t\t%*s<td>\n", 2*depth, "");
  156. fxt_component_print(file, options, workerid, from, to, comp->children[i], depth+1);
  157. fprintf(file, "\t\t\t%*s</td>\n", 2*depth, "");
  158. }
  159. fprintf(file, "\t\t\t%*s</tr>\n", 2*depth, "");
  160. }
  161. if (!strcmp(comp->name, "worker"))
  162. {
  163. fprintf(file, "\t\t\t%*s<tr>\n", 2*depth, "");
  164. fprintf(file, "\t\t\t%*s<td>\n", 2*depth, "");
  165. fxt_worker_print(file, options, workerid, comp->workerid, depth+1);
  166. fprintf(file, "\t\t\t%*s</td>\n", 2*depth, "");
  167. fprintf(file, "\t\t\t%*s</tr>\n", 2*depth, "");
  168. }
  169. fprintf(file, "\t\t\t%*s</table>", 2*depth, "");
  170. }
  171. void _starpu_fxt_component_print(FILE *file, struct starpu_fxt_options *options, int workerid, struct component *from, struct component *to)
  172. {
  173. fprintf(file, "<center>\n");
  174. fxt_component_print(file, options, workerid, from, to, fxt_component_root(), 0);
  175. fprintf(file, "</center>\n");
  176. }
  177. void _starpu_fxt_component_print_header(FILE *file)
  178. {
  179. /* CSS and Javascript code from Anthony Simonet */
  180. fprintf(file, "<!DOCTYPE html>\n");
  181. fprintf(file, "<html lang='fr'>\n");
  182. fprintf(file, "\t<head>\n");
  183. fprintf(file, "\t\t<meta charset='utf-8'>\n");
  184. fprintf(file, "\t\t<link rel='stylesheet' href='http://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css'>\n");
  185. fprintf(file, "\t\t<script src='http://code.jquery.com/jquery-1.10.2.js'></script>\n");
  186. fprintf(file, "\t\t<script src='http://code.jquery.com/ui/1.11.2/jquery-ui.js'></script>\n");
  187. //fprintf(file, "\t\t<link rel='stylesheet' href='/resources/demos/style.css'>\n");
  188. //fprintf(file, "\t\t<link rel='stylesheet' type='text/css' href='../styles.css'>\n");
  189. fprintf(file, "\t\t<style>\n");
  190. fprintf(file, "\t\t\ttable {\n");
  191. fprintf(file, "\t\t\t\tmargin: 0;\n");
  192. fprintf(file, "\t\t\t\tpadding: 0;\n");
  193. fprintf(file, "\t\t\t}\n");
  194. fprintf(file, "\t\t\ttd {\n");
  195. fprintf(file, "\t\t\t\tmargin: 0;\n");
  196. fprintf(file, "\t\t\t\tpadding: 0;\n");
  197. fprintf(file, "\t\t\t\tvertical-align: top;\n");
  198. fprintf(file, "\t\t\t\ttext-align: center;\n");
  199. fprintf(file, "\t\t\t}\n");
  200. fprintf(file, "\t\t\ttd.box {\n");
  201. fprintf(file, "\t\t\t\tborder: solid 1px;\n");
  202. fprintf(file, "\t\t\t}\n");
  203. fprintf(file, "\t\t\ttd.worker_box {\n");
  204. fprintf(file, "\t\t\t\tborder: solid 1px;\n");
  205. /* Fixed width to make output more homogeneous */
  206. fprintf(file, "\t\t\t\twidth: 75px;\n");
  207. fprintf(file, "\t\t\t}\n");
  208. fprintf(file, "\t\t\ttd.worker_box_sched {\n");
  209. fprintf(file, "\t\t\t\tborder: solid 1px;\n");
  210. /* Fixed width to make output more homogeneous */
  211. fprintf(file, "\t\t\t\twidth: 75px;\n");
  212. fprintf(file, "\t\t\t\tbackground-color: lightgreen;\n");
  213. fprintf(file, "\t\t\t}\n");
  214. /* Task */
  215. fprintf(file, "\t\t\ttd.task {\n");
  216. fprintf(file, "\t\t\t\tborder: solid 1px;\n");
  217. fprintf(file, "\t\t\t\twidth: 23px;\n");
  218. fprintf(file, "\t\t\t\theight: 23px;\n");
  219. fprintf(file, "\t\t\t\tbackground-color: #87CEEB;\n");
  220. fprintf(file, "\t\t\t}\n");
  221. /* Task being run (with codelet name) */
  222. fprintf(file, "\t\t\ttd.run_task {\n");
  223. fprintf(file, "\t\t\t\tborder: solid 1px;\n");
  224. fprintf(file, "\t\t\t\twidth: 69px;\n");
  225. fprintf(file, "\t\t\t\tmax-width: 69px;\n");
  226. fprintf(file, "\t\t\t\toverflow: hidden;\n");
  227. fprintf(file, "\t\t\t\tfont-size: 50%%;\n");
  228. fprintf(file, "\t\t\t\theight: 23px;\n");
  229. fprintf(file, "\t\t\t\tbackground-color: #87CEEB;\n");
  230. fprintf(file, "\t\t\t}\n");
  231. /* Prioritized Task */
  232. fprintf(file, "\t\t\ttd.task_prio {\n");
  233. fprintf(file, "\t\t\t\tborder: solid 1px;\n");
  234. fprintf(file, "\t\t\t\twidth: 23px;\n");
  235. fprintf(file, "\t\t\t\theight: 23px;\n");
  236. fprintf(file, "\t\t\t\tbackground-color: red;\n");
  237. fprintf(file, "\t\t\t}\n");
  238. /* Slot of previous task */
  239. fprintf(file, "\t\t\ttd.last_task_empty {\n");
  240. fprintf(file, "\t\t\t\tborder: dashed 1px;\n");
  241. fprintf(file, "\t\t\t\twidth: 23px;\n");
  242. fprintf(file, "\t\t\t\theight: 23px;\n");
  243. fprintf(file, "\t\t\t\tbackground-color: white;\n");
  244. fprintf(file, "\t\t\t}\n");
  245. /* Slot of previous task (but still other tasks) */
  246. fprintf(file, "\t\t\ttd.last_task_full {\n");
  247. fprintf(file, "\t\t\t\tborder: dashed 1px;\n");
  248. fprintf(file, "\t\t\t\twidth: 23px;\n");
  249. fprintf(file, "\t\t\t\theight: 23px;\n");
  250. fprintf(file, "\t\t\t\tbackground-color: #87CEEB;\n");
  251. fprintf(file, "\t\t\t}\n");
  252. /* Slot of previous task (but still other prioritized) */
  253. fprintf(file, "\t\t\ttd.last_task_full_prio {\n");
  254. fprintf(file, "\t\t\t\tborder: dashed 1px;\n");
  255. fprintf(file, "\t\t\t\twidth: 23px;\n");
  256. fprintf(file, "\t\t\t\theight: 23px;\n");
  257. fprintf(file, "\t\t\t\tbackground-color: red;\n");
  258. fprintf(file, "\t\t\t}\n");
  259. /* Empty task slot */
  260. fprintf(file, "\t\t\ttd.fake_task {\n");
  261. fprintf(file, "\t\t\t\twidth: 25px;\n");
  262. fprintf(file, "\t\t\t\theight: 25px;\n");
  263. fprintf(file, "\t\t\t}\n");
  264. fprintf(file, "\t\t</style>\n");
  265. fprintf(file, "\t\t<script>\n");
  266. fprintf(file, "\t\t\tfunction getInput(){\n");
  267. fprintf(file, "\t\t\t\tvar input = document.getElementById('input').value;\n");
  268. fprintf(file, "\t\t\t\tif (input <= 0 || input > $('#slider').slider('option', 'max')){\n");
  269. fprintf(file, "\t\t\t\t\talert('Invalid state value');\n");
  270. fprintf(file, "\t\t\t\t}\n");
  271. fprintf(file, "\t\t\t\tdocument.getElementById('et' + document.getElementById('etape').value).style.display = 'none';\n");
  272. fprintf(file, "\t\t\t\tdocument.getElementById('et' + input).style.display = 'block';\n");
  273. fprintf(file, "\t\t\t\t$('#etape').val(input);\n");
  274. fprintf(file, "\t\t\t\t$('#slider').slider('value', input);\n");
  275. fprintf(file, "\t\t\t}\n");
  276. fprintf(file, "\t\t</script>\n");
  277. fprintf(file, "\t\t<script>\n");
  278. fprintf(file, "\t\t\tvar myVar = null;\n");
  279. fprintf(file, "\t\t\tfunction changeState(number){\n");
  280. fprintf(file, "\t\t\t\tvar state = document.getElementById('etape').value;\n");
  281. fprintf(file, "\t\t\t\tvar state2 = parseInt(state) + parseInt(number);\n");
  282. fprintf(file, "\t\t\t\tvar min = $('#slider').slider('option', 'min');\n");
  283. fprintf(file, "\t\t\t\tvar max = $('#slider').slider('option', 'max');\n");
  284. fprintf(file, "\t\t\t\t\tdocument.getElementById('et' + document.getElementById('etape').value).style.display = 'none';\n");
  285. fprintf(file, "\t\t\t\tif (state2 >= min && state2 <= max){\n");
  286. fprintf(file, "\t\t\t\t\tdocument.getElementById('et' + state2).style.display = 'block';\n");
  287. fprintf(file, "\t\t\t\t\t$('#etape').val(state2);\n");
  288. fprintf(file, "\t\t\t\t\t$('#slider').slider('value', state2);\n");
  289. fprintf(file, "\t\t\t\t}\n");
  290. fprintf(file, "\t\t\t\telse if (state2 < min){\n");
  291. fprintf(file, "\t\t\t\t\tdocument.getElementById('et' + min).style.display = 'block';\n");
  292. fprintf(file, "\t\t\t\t\t$('#etape').val(min);\n");
  293. fprintf(file, "\t\t\t\t\t$('#slider').slider('value', min);\n");
  294. fprintf(file, "\t\t\t\t}\n");
  295. fprintf(file, "\t\t\t\telse if (state2 > max){\n");
  296. fprintf(file, "\t\t\t\t\tdocument.getElementById('et' + max).style.display = 'block';\n");
  297. fprintf(file, "\t\t\t\t\t$('#etape').val(max);\n");
  298. fprintf(file, "\t\t\t\t\t$('#slider').slider('value', max);\n");
  299. fprintf(file, "\t\t\t\t}\n");
  300. fprintf(file, "\t\t\t}\n");
  301. fprintf(file, "\t\t</script>\n");
  302. fprintf(file, "\t</head>\n");
  303. fprintf(file, "\t<body>\n");
  304. }
  305. static void fxt_component_print_step(FILE *file, struct starpu_fxt_options *options, double timestamp, int workerid, unsigned push, struct component *from, struct component *to)
  306. {
  307. fprintf(file, "\t\t<div id='et%d' style='display:%s;'><center><!-- Étape %d -->\n",
  308. global_state, global_state > 1 ? "none":"block", global_state);
  309. fprintf(file, "\t\t<p>Time %f, %d submitted %d ready, %s</p>\n", timestamp, nsubmitted, curq_size-nflowing, push?"push":"pull");
  310. //fprintf(file, "\t\t\t<tt><pre>\n");
  311. //_starpu_fxt_component_dump(file);
  312. //fprintf(file, "\t\t\t</pre></tt>\n");
  313. _starpu_fxt_component_print(file, options, workerid, from, to);
  314. fprintf(file,"\t\t</center></div>");
  315. global_state++;
  316. }
  317. void _starpu_fxt_component_connect(uint64_t parent, uint64_t child)
  318. {
  319. struct component *parent_p, *child_p;
  320. unsigned n;
  321. COMPONENT_FIND(components, parent, parent_p);
  322. COMPONENT_FIND(components, child, child_p);
  323. STARPU_ASSERT(parent_p);
  324. STARPU_ASSERT(child_p);
  325. n = ++parent_p->nchildren;
  326. parent_p->children = realloc(parent_p->children, n * sizeof(*parent_p->children));
  327. parent_p->children[n-1] = child_p;
  328. if (!child_p->parent)
  329. child_p->parent = parent_p;
  330. }
  331. void _starpu_fxt_component_update_ntasks(unsigned _nsubmitted, unsigned _curq_size)
  332. {
  333. nsubmitted = _nsubmitted;
  334. curq_size = _curq_size;
  335. }
  336. void _starpu_fxt_component_push(FILE *output, struct starpu_fxt_options *options, double timestamp, int workerid, uint64_t from, uint64_t to, uint64_t task STARPU_ATTRIBUTE_UNUSED, unsigned prio)
  337. {
  338. struct component *from_p = NULL, *to_p = NULL;
  339. if (to == from)
  340. return;
  341. if (from)
  342. {
  343. COMPONENT_FIND(components, from, from_p);
  344. STARPU_ASSERT(from_p);
  345. }
  346. if (to)
  347. {
  348. COMPONENT_FIND(components, to, to_p);
  349. STARPU_ASSERT(to_p);
  350. }
  351. if (from_p)
  352. {
  353. if (prio)
  354. from_p->npriotasks--;
  355. else
  356. from_p->ntasks--;
  357. }
  358. else
  359. nflowing++;
  360. if (prio)
  361. to_p->npriotasks++;
  362. else
  363. to_p->ntasks++;
  364. // fprintf(stderr,"push from %s to %s\n", from_p?from_p->name:"none", to_p?to_p->name:"none");
  365. fxt_component_print_step(output, options, timestamp, workerid, 1, from_p, to_p);
  366. }
  367. void _starpu_fxt_component_pull(FILE *output, struct starpu_fxt_options *options, double timestamp, int workerid, uint64_t from, uint64_t to, uint64_t task STARPU_ATTRIBUTE_UNUSED, unsigned prio)
  368. {
  369. struct component *from_p = NULL, *to_p = NULL;
  370. if (to == from)
  371. return;
  372. if (from)
  373. {
  374. COMPONENT_FIND(components, from, from_p);
  375. STARPU_ASSERT(from_p);
  376. }
  377. if (to)
  378. {
  379. COMPONENT_FIND(components, to, to_p);
  380. STARPU_ASSERT(to_p);
  381. }
  382. if (prio)
  383. from_p->npriotasks--;
  384. else
  385. from_p->ntasks--;
  386. if (to_p)
  387. {
  388. if (prio)
  389. to_p->npriotasks++;
  390. else
  391. to_p->ntasks++;
  392. }
  393. else
  394. nflowing--;
  395. // fprintf(stderr,"pull from %s to %s\n", from_p?from_p->name:"none", to_p?to_p->name:"none");
  396. fxt_component_print_step(output, options, timestamp, workerid, 0, from_p, to_p);
  397. }
  398. void _starpu_fxt_component_finish(FILE *file)
  399. {
  400. /* Javascript code from Anthony Simonet */
  401. fprintf(file, "\t\t<script>\n");
  402. fprintf(file, "\t\t\t$(function(){\n");
  403. fprintf(file, "\t\t\t\tsliderDiv = $('#slider') <!-- Alias -->\n");
  404. fprintf(file, "\t\t\t\tsliderDiv.slider({\n");
  405. fprintf(file, "\t\t\t\t\tvalue: 1,\n");
  406. fprintf(file, "\t\t\t\t\tmin: 1,\n");
  407. fprintf(file, "\t\t\t\t\tmax: %d,\n", global_state-1);
  408. fprintf(file, "\t\t\t\t\tstep: 1,\n");
  409. fprintf(file, "\t\t\t\t\tanimate: 'fast',\n");
  410. fprintf(file, "\t\t\t\t\tslide: function(event, ui){\n");
  411. fprintf(file, "\t\t\t\t\t\tvar l_value = sliderDiv.slider('option', 'value');\n");
  412. fprintf(file, "\t\t\t\t\t\t$('#etape').val(ui.value);\n");
  413. fprintf(file, "\t\t\t\t\t\tdocument.getElementById('et' + l_value).style.display = 'none';\n");
  414. fprintf(file, "\t\t\t\t\t\tdocument.getElementById('et' + ui.value).style.display = 'block';\n");
  415. fprintf(file, "\t\t\t\t\t}\n");
  416. fprintf(file, "\t\t\t\t});\n");
  417. fprintf(file, "\t\t\t\t$('#etape').val(sliderDiv.slider('value')); <!-- Initialisation au lancement de la page -->\n");
  418. fprintf(file, "\t\t\t\t$('#max').val(sliderDiv.slider('option', 'max'));\n");
  419. fprintf(file, "\t\t\t});\n");
  420. fprintf(file, "\t\t</script>\n");
  421. fprintf(file, "\t\t<div id ='slider'></div>\n");
  422. fprintf(file, "\t\t<center>\n");
  423. fprintf(file, "\t\t\t<p>\n");
  424. fprintf(file, "\t\t\t\t<input type='button' value='-100' onclick=\"changeState(-100);\"/>\n");
  425. fprintf(file, "\t\t\t\t<input type='button' value='<<' onmousedown=\"myVar = setInterval('changeState(-1)', 50)\" onmouseup=\"clearInterval(myVar)\" onmouseout=\"clearInterval(myVar)\"/>\n");
  426. fprintf(file, "\t\t\t\t<input type='button' value='<' onclick=\"changeState(-1);\"/>\n");
  427. fprintf(file, "\t\t\t\t<label for='etape'>State</label>\n");
  428. fprintf(file, "\t\t\t\t<input type='text' id='etape' size='3mm' readonly style='border:0;'>\n");
  429. fprintf(file, "\t\t\t\t<label for='max'>in</label>\n");
  430. fprintf(file, "\t\t\t\t<input type='text' id='max' size='3mm' readonly style='border:0;'>\n");
  431. fprintf(file, "\t\t\t\t<input type='button' value='>' onclick=\"changeState(1);\" />\n");
  432. fprintf(file, "\t\t\t\t<input type='button' value='>>' onmousedown=\"myVar = setInterval('changeState(1)', 50)\" onmouseup=\"clearInterval(myVar)\" onmouseout=\"clearInterval(myVar)\"/>\n");
  433. fprintf(file, "\t\t\t\t<input type='button' value='+100' onclick=\"changeState(100);\"/>\n");
  434. fprintf(file, "\t\t\t</p>\n");
  435. fprintf(file, "\t\t\t\t<span id='range'>Auto speed (state/s): 4</span>\n");
  436. fprintf(file, "\t\t\t\t<input type='range' id='autoRange' min='1' max='50' value='4' step='1' onchange=\"showValue(this.value); clearInterval(myVar);\" />\n");
  437. fprintf(file, "\t\t\t\t<script>\n");
  438. fprintf(file, "\t\t\t\t\tdocument.getElementById('autoRange').value = 4;\n");
  439. fprintf(file, "\t\t\t\t\tfunction showValue(newValue)\n");
  440. fprintf(file, "\t\t\t\t\t{\n");
  441. fprintf(file, "\t\t\t\t\t\tdocument.getElementById('range').innerHTML='Auto speed (state/s): '+ newValue;\n");
  442. fprintf(file, "\t\t\t\t\t}\n");
  443. fprintf(file, "\t\t\t\t</script>\n");
  444. fprintf(file, "\t\t\t\t<input type='button' value='Auto' onclick=\"if(myVar){ clearInterval(myVar); myVar = null;}changeState(1); myVar = setInterval('changeState(1)', 1000/document.getElementById('autoRange').value);\"/>\n");
  445. fprintf(file, "\t\t\t\t<input type='button' value='Stop' onclick=\"clearInterval(myVar);\"/>\n");
  446. fprintf(file, "\t\t\t<p>\n");
  447. fprintf(file, "\t\t\t</p>\n");
  448. fprintf(file, "\t\t\t<FORM>\n");
  449. fprintf(file, "\t\t\t\t<span>Go to state</span>\n");
  450. fprintf(file, "\t\t\t\t<input type='text' name='setinput' id='input' value='' onKeyPress=\"if(event.keyCode == 13){ getInput(); javascript:this.value=''}\" onFocus=\"javascript:this.value=''\"/>\n");
  451. fprintf(file, "\t\t\t\t<input type='text' name='message' id='' value='' style='display:none'>\n"); /* Dummy input preventing the page from being refreshed when enter is pressed. */
  452. fprintf(file, "\t\t\t\t<input type='button' value='Go' onclick=\"getInput(); javascript:input.value=''\"/>\n");
  453. fprintf(file, "\t\t\t</FORM>\n");
  454. fprintf(file, "\t\t\t<br />\n");
  455. fprintf(file, "\t\t</center>\n");
  456. fprintf(file, "\t</body>\n");
  457. fprintf(file, "</html>\n");
  458. }