starpu_fxt_tool.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 Centre National de la Recherche Scientifique
  4. *
  5. * StarPU 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. * StarPU 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 "fxt_tool.h"
  17. #include <inttypes.h>
  18. /*
  19. * Default user options
  20. */
  21. static unsigned per_task_colour = 0;
  22. static unsigned generate_distrib = 0;
  23. static unsigned no_counter = 0;
  24. static unsigned no_bus = 0;
  25. /* TODO don't make that global ? */
  26. struct fxt_ev_64 ev;
  27. /* In case we are going to gather multiple traces (eg in the case of MPI
  28. * processes), we may need to prefix the name of the containers. */
  29. char *prefix = "";
  30. uint64_t offset = 0;
  31. int rank = -1;
  32. static uint64_t start_time = 0;
  33. static uint64_t end_time = 0;
  34. static int nworkers = 0;
  35. //static char *filename = NULL;
  36. /* XXX remove the 64 ... */
  37. unsigned ninputfiles = 0;
  38. static char *filenames[64];
  39. static uint64_t last_codelet_hash[STARPU_NMAXWORKERS];
  40. static double last_codelet_start[STARPU_NMAXWORKERS];
  41. static char last_codelet_symbol[128][STARPU_NMAXWORKERS];
  42. /* If more than a period of time has elapsed, we flush the profiling info,
  43. * otherwise they are accumulated everytime there is a new relevant event. */
  44. #define ACTIVITY_PERIOD 75.0
  45. static double last_activity_flush_timestamp[STARPU_NMAXWORKERS];
  46. static double accumulated_sleep_time[STARPU_NMAXWORKERS];
  47. static double accumulated_exec_time[STARPU_NMAXWORKERS];
  48. LIST_TYPE(symbol_name,
  49. char *name;
  50. );
  51. static symbol_name_list_t symbol_list;
  52. LIST_TYPE(communication,
  53. unsigned comid;
  54. float comm_start;
  55. float bandwidth;
  56. unsigned node;
  57. );
  58. static communication_list_t communication_list;
  59. /*
  60. * Paje trace file tools
  61. */
  62. static char *out_paje_path = "paje.trace";
  63. static FILE *out_paje_file;
  64. static char *distrib_time_path = "distrib.data";
  65. static FILE *distrib_time;
  66. static char *activity_path = "activity.data";
  67. static FILE *activity_file;
  68. static void paje_output_file_init(void)
  69. {
  70. /* create a new file */
  71. out_paje_file = fopen(out_paje_path, "w+");
  72. if (!out_paje_file)
  73. {
  74. perror("fopen");
  75. STARPU_ABORT();
  76. }
  77. write_paje_header(out_paje_file);
  78. fprintf(out_paje_file, " \n \
  79. 1 MPIP 0 \"MPI Program\" \n \
  80. 1 P MPIP \"Program\" \n \
  81. 1 Mn P \"Memory Node\" \n \
  82. 1 T Mn \"Worker\" \n \
  83. 1 Sc P \"Scheduler State\" \n \
  84. 2 event T \"event type\" \n \
  85. 3 S T \"Thread State\" \n \
  86. 3 MS Mn \"Memory Node State\" \n \
  87. 4 ntask Sc \"Number of tasks\" \n \
  88. 4 bw Mn \"Bandwidth\" \n \
  89. 6 I S Initializing \"0.0 .7 1.0\" \n \
  90. 6 D S Deinitializing \"0.0 .1 .7\" \n \
  91. 6 Fi S FetchingInput \"1.0 .1 1.0\" \n \
  92. 6 Po S PushingOutput \"0.1 1.0 1.0\" \n \
  93. 6 E S Executing \".0 .6 .4\" \n \
  94. 6 C S Callback \".0 .3 .8\" \n \
  95. 6 B S Blocked \".9 .1 .0\" \n \
  96. 6 Sl S Sleeping \".9 .1 .0\" \n \
  97. 6 P S Progressing \".4 .1 .6\" \n \
  98. 6 A MS Allocating \".4 .1 .0\" \n \
  99. 6 Ar MS AllocatingReuse \".1 .1 .8\" \n \
  100. 6 R MS Reclaiming \".0 .1 .4\" \n \
  101. 6 Co MS DriverCopy \".3 .5 .1\" \n \
  102. 6 No MS Nothing \".0 .0 .0\" \n \
  103. 5 MPIL MPIP P P MPIL\n \
  104. 5 L P Mn Mn L\n");
  105. fprintf(out_paje_file, "7 0.0 MPIroot MPIP 0 root\n");
  106. }
  107. /*
  108. * Generic tools
  109. */
  110. static float get_event_time_stamp(void)
  111. {
  112. return (float)((ev.time-offset)/1000000.0);
  113. }
  114. static int register_worker_id(unsigned long tid)
  115. {
  116. int workerid = nworkers++;
  117. /* create a new key in the htable */
  118. char *tidstr = malloc(16*sizeof(char));
  119. sprintf(tidstr, "%ld", tid);
  120. ENTRY item;
  121. item.key = tidstr;
  122. item.data = (void *)(uintptr_t)workerid;
  123. ENTRY *res;
  124. res = hsearch(item, FIND);
  125. /* only register a thread once */
  126. STARPU_ASSERT(res == NULL);
  127. res = hsearch(item, ENTER);
  128. STARPU_ASSERT(res);
  129. return workerid;
  130. }
  131. static int find_worker_id(unsigned long tid)
  132. {
  133. char tidstr[16];
  134. sprintf(tidstr, "%ld", tid);
  135. ENTRY item;
  136. item.key = tidstr;
  137. item.data = NULL;
  138. ENTRY *res;
  139. res = hsearch(item, FIND);
  140. if (!res)
  141. return -1;
  142. int id = (uintptr_t)(res->data);
  143. return id;
  144. }
  145. static void update_accumulated_time(int worker, double sleep_time, double exec_time, double current_timestamp, int forceflush)
  146. {
  147. accumulated_sleep_time[worker] += sleep_time;
  148. accumulated_exec_time[worker] += exec_time;
  149. /* If sufficient time has elapsed since the last flush, we have a new
  150. * point in our graph */
  151. double elapsed = current_timestamp - last_activity_flush_timestamp[worker];
  152. if (forceflush || (elapsed > ACTIVITY_PERIOD))
  153. {
  154. fprintf(activity_file, "%d\t%lf\t%lf\t%lf\t%lf\n", worker, current_timestamp, elapsed, accumulated_exec_time[worker], accumulated_sleep_time[worker]);
  155. /* reset the accumulated times */
  156. last_activity_flush_timestamp[worker] = current_timestamp;
  157. accumulated_sleep_time[worker] = 0.0;
  158. accumulated_exec_time[worker] = 0.0;
  159. }
  160. }
  161. /*
  162. * Initialization
  163. */
  164. static void handle_new_mem_node(void)
  165. {
  166. fprintf(out_paje_file, "7 %f %"PRIu64" Mn %sp %sMEMNODE%"PRIu64"\n", get_event_time_stamp(), ev.param[0], prefix, prefix, ev.param[0]);
  167. if (!no_bus)
  168. fprintf(out_paje_file, "13 %f bw %sMEMNODE%"PRIu64" 0.0\n", 0.0f, prefix, ev.param[0]);
  169. }
  170. static void handle_worker_init_start(void)
  171. {
  172. /*
  173. arg0 : type of worker (cuda, cpu ..)
  174. arg1 : memory node
  175. arg2 : thread id
  176. */
  177. fprintf(out_paje_file, "7 %f %s%"PRIu64" T %sMEMNODE%"PRIu64" %s%"PRIu64"\n",
  178. get_event_time_stamp(), prefix, ev.param[3], prefix, ev.param[2], prefix, ev.param[3]);
  179. int devid = ev.param[1];
  180. int workerid = register_worker_id(ev.param[3]);
  181. char *kindstr = "";
  182. switch (ev.param[0]) {
  183. case STARPU_FUT_APPS_KEY:
  184. set_next_other_worker_color(workerid);
  185. kindstr = "apps";
  186. break;
  187. case STARPU_FUT_CPU_KEY:
  188. set_next_cpu_worker_color(workerid);
  189. kindstr = "cpu";
  190. break;
  191. case STARPU_FUT_CUDA_KEY:
  192. set_next_cuda_worker_color(workerid);
  193. kindstr = "cuda";
  194. break;
  195. case STARPU_FUT_OPENCL_KEY:
  196. set_next_opencl_worker_color(workerid);
  197. kindstr = "opencl";
  198. break;
  199. default:
  200. STARPU_ABORT();
  201. }
  202. /* start initialization */
  203. fprintf(out_paje_file, "10 %f S %s%"PRIu64" I\n",
  204. get_event_time_stamp(), prefix, ev.param[3]);
  205. fprintf(activity_file, "name\t%d\t%s %d\n", workerid, kindstr, devid);
  206. }
  207. static void handle_worker_init_end(void)
  208. {
  209. fprintf(out_paje_file, "10 %f S %s%"PRIu64" B\n",
  210. get_event_time_stamp(), prefix, ev.param[0]);
  211. /* Initilize the accumulated time counters */
  212. int worker = find_worker_id(ev.param[0]);
  213. last_activity_flush_timestamp[worker] = get_event_time_stamp();
  214. accumulated_sleep_time[worker] = 0.0;
  215. accumulated_exec_time[worker] = 0.0;
  216. }
  217. static void handle_worker_deinit_start(void)
  218. {
  219. fprintf(out_paje_file, "10 %f S %s%"PRIu64" D\n",
  220. get_event_time_stamp(), prefix, ev.param[0]);
  221. }
  222. static void handle_worker_deinit_end(void)
  223. {
  224. fprintf(out_paje_file, "8 %f %s%"PRIu64" T\n",
  225. get_event_time_stamp(), prefix, ev.param[1]);
  226. }
  227. static void create_paje_state_if_not_found(char *name)
  228. {
  229. symbol_name_itor_t itor;
  230. for (itor = symbol_name_list_begin(symbol_list);
  231. itor != symbol_name_list_end(symbol_list);
  232. itor = symbol_name_list_next(itor))
  233. {
  234. if (!strcmp(name, itor->name))
  235. {
  236. /* we found an entry */
  237. return;
  238. }
  239. }
  240. /* it's the first time ... */
  241. symbol_name_t entry = symbol_name_new();
  242. entry->name = malloc(strlen(name));
  243. strcpy(entry->name, name);
  244. symbol_name_list_push_front(symbol_list, entry);
  245. /* choose some colour ... that's disguting yes */
  246. unsigned hash_symbol_red = get_colour_symbol_red(name);
  247. unsigned hash_symbol_green = get_colour_symbol_green(name);
  248. unsigned hash_symbol_blue = get_colour_symbol_blue(name);
  249. fprintf(stderr, "name %s hash red %d green %d blue %d \n", name, hash_symbol_red, hash_symbol_green, hash_symbol_blue);
  250. uint32_t hash_sum = hash_symbol_red + hash_symbol_green + hash_symbol_blue;
  251. float red = (1.0f * hash_symbol_red) / hash_sum;
  252. float green = (1.0f * hash_symbol_green) / hash_sum;
  253. float blue = (1.0f * hash_symbol_blue) / hash_sum;
  254. /* create the Paje state */
  255. fprintf(out_paje_file, "6 %s S %s \"%f %f %f\" \n", name, name, red, green, blue);
  256. }
  257. static void handle_start_codelet_body(void)
  258. {
  259. int worker;
  260. worker = find_worker_id(ev.param[1]);
  261. if (worker < 0) return;
  262. unsigned long has_name = ev.param[2];
  263. char *name = has_name?(char *)&ev.param[3]:"unknown";
  264. snprintf(last_codelet_symbol[worker], 128, "%s", name);
  265. /* TODO */
  266. last_codelet_hash[worker] = 0;
  267. float start_codelet_time = get_event_time_stamp();
  268. last_codelet_start[worker] = start_codelet_time;
  269. if (per_task_colour)
  270. {
  271. create_paje_state_if_not_found(name);
  272. fprintf(out_paje_file, "10 %f S %s%"PRIu64" %s\n", start_codelet_time, prefix, ev.param[1], name);
  273. }
  274. else {
  275. fprintf(out_paje_file, "10 %f S %s%"PRIu64" E\n", start_codelet_time, prefix, ev.param[1]);
  276. }
  277. end_time = STARPU_MAX(end_time, ev.time);
  278. }
  279. static void handle_end_codelet_body(void)
  280. {
  281. int worker;
  282. worker = find_worker_id(ev.param[1]);
  283. if (worker < 0) return;
  284. float end_codelet_time = get_event_time_stamp();
  285. fprintf(out_paje_file, "10 %f S %s%"PRIu64" B\n", end_codelet_time, prefix, ev.param[1]);
  286. float codelet_length = (end_codelet_time - last_codelet_start[worker]);
  287. update_accumulated_time(worker, 0.0, codelet_length, end_codelet_time, 0);
  288. if (generate_distrib)
  289. fprintf(distrib_time, "%s\t%s%d\t%"PRIx64"\t%f\n", last_codelet_symbol[worker],
  290. prefix, worker, last_codelet_hash[worker], codelet_length);
  291. end_time = STARPU_MAX(end_time, ev.time);
  292. }
  293. static void handle_user_event(void)
  294. {
  295. int worker;
  296. unsigned long code = ev.param[0];
  297. worker = find_worker_id(ev.param[1]);
  298. if (worker < 0)
  299. {
  300. fprintf(out_paje_file, "9 %f event %sp %ld\n", get_event_time_stamp(), prefix, code);
  301. }
  302. else {
  303. fprintf(out_paje_file, "9 %f event %s%"PRIu64" %ld\n", get_event_time_stamp(), prefix, ev.param[1], code);
  304. }
  305. }
  306. static void handle_start_callback(void)
  307. {
  308. int worker;
  309. worker = find_worker_id(ev.param[1]);
  310. if (worker < 0) return;
  311. fprintf(out_paje_file, "10 %f S %s%"PRIu64" C\n", get_event_time_stamp(), prefix, ev.param[1] );
  312. }
  313. static void handle_end_callback(void)
  314. {
  315. int worker;
  316. worker = find_worker_id(ev.param[1]);
  317. if (worker < 0) return;
  318. fprintf(out_paje_file, "10 %f S %s%"PRIu64" B\n", get_event_time_stamp(), prefix, ev.param[1] );
  319. }
  320. static void handle_worker_status(const char *newstatus)
  321. {
  322. int worker;
  323. worker = find_worker_id(ev.param[1]);
  324. if (worker < 0) return;
  325. fprintf(out_paje_file, "10 %f S %s%"PRIu64" %s\n",
  326. get_event_time_stamp(), prefix, ev.param[1], newstatus);
  327. end_time = STARPU_MAX(end_time, ev.time);
  328. }
  329. static double last_sleep_start[STARPU_NMAXWORKERS];
  330. static void handle_start_sleep(void)
  331. {
  332. int worker;
  333. worker = find_worker_id(ev.param[0]);
  334. if (worker < 0) return;
  335. float start_sleep_time = get_event_time_stamp();
  336. last_sleep_start[worker] = start_sleep_time;
  337. fprintf(out_paje_file, "10 %f S %s%"PRIu64" Sl\n",
  338. get_event_time_stamp(), prefix, ev.param[0]);
  339. end_time = STARPU_MAX(end_time, ev.time);
  340. }
  341. static void handle_end_sleep(void)
  342. {
  343. int worker;
  344. worker = find_worker_id(ev.param[0]);
  345. if (worker < 0) return;
  346. float end_sleep_timestamp = get_event_time_stamp();
  347. fprintf(out_paje_file, "10 %f S %s%"PRIu64" B\n",
  348. end_sleep_timestamp, prefix, ev.param[0]);
  349. double sleep_length = end_sleep_timestamp - last_sleep_start[worker];
  350. update_accumulated_time(worker, sleep_length, 0.0, end_sleep_timestamp, 0);
  351. end_time = STARPU_MAX(end_time, ev.time);
  352. }
  353. static void handle_data_copy(void)
  354. {
  355. }
  356. static void handle_start_driver_copy(void)
  357. {
  358. unsigned src = ev.param[0];
  359. unsigned dst = ev.param[1];
  360. unsigned size = ev.param[2];
  361. unsigned comid = ev.param[3];
  362. if (!no_bus)
  363. {
  364. fprintf(out_paje_file, "10 %f MS %sMEMNODE%d Co\n", get_event_time_stamp(), prefix, dst);
  365. fprintf(out_paje_file, "18 %f L %sp %d %sMEMNODE%d com_%d\n", get_event_time_stamp(), prefix, size, prefix, src, comid);
  366. /* create a structure to store the start of the communication, this will be matched later */
  367. communication_t com = communication_new();
  368. com->comid = comid;
  369. com->comm_start = get_event_time_stamp();
  370. /* that's a hack: either src or dst is non null */
  371. com->node = (src + dst);
  372. communication_list_push_back(communication_list, com);
  373. }
  374. }
  375. static void handle_end_driver_copy(void)
  376. {
  377. unsigned dst = ev.param[1];
  378. unsigned size = ev.param[2];
  379. unsigned comid = ev.param[3];
  380. if (!no_bus)
  381. {
  382. fprintf(out_paje_file, "10 %f MS %sMEMNODE%d No\n", get_event_time_stamp(), prefix, dst);
  383. fprintf(out_paje_file, "19 %f L %sp %d %sMEMNODE%d com_%d\n", get_event_time_stamp(), prefix, size, prefix, dst, comid);
  384. /* look for a data transfer to match */
  385. communication_itor_t itor;
  386. for (itor = communication_list_begin(communication_list);
  387. itor != communication_list_end(communication_list);
  388. itor = communication_list_next(itor))
  389. {
  390. if (itor->comid == comid)
  391. {
  392. float comm_end = get_event_time_stamp();
  393. float bandwidth = (float)((0.001*size)/(comm_end - itor->comm_start));
  394. itor->bandwidth = bandwidth;
  395. communication_t com = communication_new();
  396. com->comid = comid;
  397. com->comm_start = get_event_time_stamp();
  398. com->bandwidth = -bandwidth;
  399. com->node = itor->node;
  400. communication_list_push_back(communication_list, com);
  401. break;
  402. }
  403. }
  404. }
  405. }
  406. static void display_bandwidth_evolution(void)
  407. {
  408. float current_bandwidth = 0.0;
  409. float current_bandwidth_per_node[32] = {0.0};
  410. communication_itor_t itor;
  411. for (itor = communication_list_begin(communication_list);
  412. itor != communication_list_end(communication_list);
  413. itor = communication_list_next(itor))
  414. {
  415. current_bandwidth += itor->bandwidth;
  416. fprintf(out_paje_file, "13 %f bw %sMEMNODE0 %f\n",
  417. itor->comm_start, prefix, current_bandwidth);
  418. current_bandwidth_per_node[itor->node] += itor->bandwidth;
  419. fprintf(out_paje_file, "13 %f bw %sMEMNODE%d %f\n",
  420. itor->comm_start, prefix, itor->node, current_bandwidth_per_node[itor->node]);
  421. }
  422. }
  423. static void handle_memnode_event(const char *eventstr)
  424. {
  425. unsigned memnode = ev.param[0];
  426. fprintf(out_paje_file, "10 %f MS %sMEMNODE%d %s\n",
  427. get_event_time_stamp(), prefix, memnode, eventstr);
  428. }
  429. /*
  430. * Number of task submitted to the scheduler
  431. */
  432. static int curq_size = 0;
  433. static void handle_job_push(void)
  434. {
  435. float current_timestamp = get_event_time_stamp();
  436. curq_size++;
  437. if (!no_counter)
  438. fprintf(out_paje_file, "13 %f ntask %ssched %f\n", current_timestamp, prefix, (float)curq_size);
  439. fprintf(activity_file, "cnt_ready\t%lf\t%ld\n", current_timestamp, curq_size);
  440. }
  441. static void handle_job_pop(void)
  442. {
  443. float current_timestamp = get_event_time_stamp();
  444. curq_size--;
  445. if (!no_counter)
  446. fprintf(out_paje_file, "13 %f ntask %ssched %f\n", current_timestamp, prefix, (float)curq_size);
  447. fprintf(activity_file, "cnt_ready\t%lf\t%ld\n", current_timestamp, curq_size);
  448. }
  449. void handle_update_task_cnt(void)
  450. {
  451. float current_timestamp = get_event_time_stamp();
  452. unsigned long nsubmitted = ev.param[0];
  453. fprintf(activity_file, "cnt_submitted\t%lf\t%ld\n", current_timestamp, nsubmitted);
  454. }
  455. static void handle_codelet_tag_deps(void)
  456. {
  457. uint64_t child;
  458. uint64_t father;
  459. child = ev.param[0];
  460. father = ev.param[1];
  461. add_deps(child, father);
  462. }
  463. static void handle_task_deps(void)
  464. {
  465. unsigned long dep_prev = ev.param[0];
  466. unsigned long dep_succ = ev.param[1];
  467. /* There is a dependency between both job id : dep_prev -> dep_succ */
  468. add_task_deps(dep_prev, dep_succ);
  469. }
  470. static void handle_task_done(void)
  471. {
  472. unsigned long job_id;
  473. job_id = ev.param[0];
  474. unsigned long has_name = ev.param[3];
  475. char *name = has_name?(char *)&ev.param[4]:"unknown";
  476. int worker;
  477. worker = find_worker_id(ev.param[1]);
  478. const char *colour;
  479. char buffer[32];
  480. if (per_task_colour) {
  481. snprintf(buffer, 32, "#%x%x%x",
  482. get_colour_symbol_red(name)/4,
  483. get_colour_symbol_green(name)/4,
  484. get_colour_symbol_blue(name)/4);
  485. colour = &buffer[0];
  486. }
  487. else {
  488. colour= (worker < 0)?"#aaaaaa":get_worker_color(worker);
  489. }
  490. unsigned exclude_from_dag = ev.param[2];
  491. if (!exclude_from_dag)
  492. dot_set_task_done(job_id, name, colour);
  493. }
  494. static void handle_tag_done(void)
  495. {
  496. uint64_t tag_id;
  497. tag_id = ev.param[0];
  498. unsigned long has_name = ev.param[2];
  499. char *name = has_name?(char *)&ev.param[3]:"unknown";
  500. int worker;
  501. worker = find_worker_id(ev.param[1]);
  502. const char *colour;
  503. char buffer[32];
  504. if (per_task_colour) {
  505. snprintf(buffer, 32, "%.4f,%.4f,%.4f",
  506. get_colour_symbol_red(name)/1024.0,
  507. get_colour_symbol_green(name)/1024.0,
  508. get_colour_symbol_blue(name)/1024.0);
  509. colour = &buffer[0];
  510. }
  511. else {
  512. colour= (worker < 0)?"0.0,0.0,0.0":get_worker_color(worker);
  513. }
  514. dot_set_tag_done(tag_id, colour);
  515. }
  516. static void handle_mpi_barrier(void)
  517. {
  518. rank = ev.param[0];
  519. /* Add an event in the trace */
  520. fprintf(out_paje_file, "9 %f event %sp %d\n", get_event_time_stamp(), prefix, rank);
  521. }
  522. static void handle_mpi_isend(void)
  523. {
  524. int dest = ev.param[0];
  525. int mpi_tag = ev.param[1];
  526. size_t size = ev.param[2];
  527. float date = get_event_time_stamp();
  528. add_mpi_send_transfer(rank, dest, mpi_tag, size, date);
  529. }
  530. static void handle_mpi_irecv_end(void)
  531. {
  532. int src = ev.param[0];
  533. int mpi_tag = ev.param[1];
  534. float date = get_event_time_stamp();
  535. add_mpi_recv_transfer(src, rank, mpi_tag, date);
  536. }
  537. static void handle_set_profiling(void)
  538. {
  539. int status = ev.param[0];
  540. fprintf(activity_file, "set_profiling\t%lf\t%d\n", get_event_time_stamp(), status);
  541. }
  542. static void handle_task_wait_for_all(void)
  543. {
  544. dot_add_sync_point();
  545. }
  546. static void parse_args(int argc, char **argv)
  547. {
  548. /* We want to support arguments such as "fxt_tool -i trace_*" */
  549. unsigned reading_input_filenames = 0;
  550. int i;
  551. for (i = 1; i < argc; i++) {
  552. if (strcmp(argv[i], "-c") == 0) {
  553. per_task_colour = 1;
  554. reading_input_filenames = 0;
  555. continue;
  556. }
  557. if (strcmp(argv[i], "-o") == 0) {
  558. out_paje_path = argv[++i];
  559. reading_input_filenames = 0;
  560. continue;
  561. }
  562. if (strcmp(argv[i], "-i") == 0) {
  563. filenames[ninputfiles++] = argv[++i];
  564. reading_input_filenames = 1;
  565. continue;
  566. }
  567. if (strcmp(argv[i], "-no-counter") == 0) {
  568. no_counter = 1;
  569. reading_input_filenames = 0;
  570. continue;
  571. }
  572. if (strcmp(argv[i], "-no-bus") == 0) {
  573. no_bus = 1;
  574. reading_input_filenames = 0;
  575. continue;
  576. }
  577. if (strcmp(argv[i], "-d") == 0) {
  578. generate_distrib = 1;
  579. reading_input_filenames = 0;
  580. continue;
  581. }
  582. if (strcmp(argv[i], "-h") == 0) {
  583. fprintf(stderr, "Usage : %s [-c] [-no-counter] [-no-bus] [-i input_filename] [-o output_filename]\n", argv[0]);
  584. fprintf(stderr, "\t-c: use a different colour for every type of task.\n");
  585. exit(-1);
  586. }
  587. /* That's pretty dirty: if the reading_input_filenames flag is
  588. * set, and that the argument does not match an option, we
  589. * assume this may be another filename */
  590. if (reading_input_filenames)
  591. {
  592. filenames[ninputfiles++] = argv[i];
  593. continue;
  594. }
  595. }
  596. }
  597. void parse_new_file(char *filename_in, char *file_prefix, uint64_t file_offset)
  598. {
  599. prefix = file_prefix;
  600. offset = file_offset;
  601. /* Open the trace file */
  602. int fd_in;
  603. fd_in = open(filename_in, O_RDONLY);
  604. if (fd_in < 0) {
  605. perror("open failed :");
  606. exit(-1);
  607. }
  608. static fxt_t fut;
  609. fut = fxt_fdopen(fd_in);
  610. if (!fut) {
  611. perror("fxt_fdopen :");
  612. exit(-1);
  613. }
  614. fxt_blockev_t block;
  615. block = fxt_blockev_enter(fut);
  616. /* create a htable to identify each worker(tid) */
  617. hcreate(STARPU_NMAXWORKERS);
  618. symbol_list = symbol_name_list_new();
  619. communication_list = communication_list_new();
  620. /* TODO starttime ...*/
  621. /* create the "program" container */
  622. fprintf(out_paje_file, "7 0.0 %sp P MPIroot program%s \n", prefix, prefix);
  623. /* create a variable with the number of tasks */
  624. if (!no_counter)
  625. {
  626. fprintf(out_paje_file, "7 %f %ssched Sc %sp scheduler \n", 0.0, prefix, prefix);
  627. fprintf(out_paje_file, "13 0.0 ntask %ssched 0.0\n", prefix);
  628. }
  629. unsigned first_event = 1;
  630. while(1) {
  631. int ret = fxt_next_ev(block, FXT_EV_TYPE_64, (struct fxt_ev *)&ev);
  632. if (ret != FXT_EV_OK) {
  633. fprintf(stderr, "no more block ...\n");
  634. break;
  635. }
  636. __attribute__ ((unused)) int nbparam = ev.nb_params;
  637. if (first_event)
  638. {
  639. first_event = 0;
  640. start_time = ev.time;
  641. }
  642. switch (ev.code) {
  643. case STARPU_FUT_WORKER_INIT_START:
  644. handle_worker_init_start();
  645. break;
  646. case STARPU_FUT_WORKER_INIT_END:
  647. handle_worker_init_end();
  648. break;
  649. case STARPU_FUT_NEW_MEM_NODE:
  650. handle_new_mem_node();
  651. break;
  652. /* detect when the workers were idling or not */
  653. case STARPU_FUT_START_CODELET_BODY:
  654. handle_start_codelet_body();
  655. break;
  656. case STARPU_FUT_END_CODELET_BODY:
  657. handle_end_codelet_body();
  658. break;
  659. case STARPU_FUT_START_CALLBACK:
  660. handle_start_callback();
  661. break;
  662. case STARPU_FUT_END_CALLBACK:
  663. handle_end_callback();
  664. break;
  665. case STARPU_FUT_UPDATE_TASK_CNT:
  666. handle_update_task_cnt();
  667. break;
  668. /* monitor stack size */
  669. case STARPU_FUT_JOB_PUSH:
  670. handle_job_push();
  671. break;
  672. case STARPU_FUT_JOB_POP:
  673. handle_job_pop();
  674. break;
  675. /* check the memory transfer overhead */
  676. case STARPU_FUT_START_FETCH_INPUT:
  677. handle_worker_status("Fi");
  678. break;
  679. case STARPU_FUT_START_PUSH_OUTPUT:
  680. handle_worker_status("Po");
  681. break;
  682. case STARPU_FUT_START_PROGRESS:
  683. handle_worker_status("P");
  684. break;
  685. case STARPU_FUT_END_FETCH_INPUT:
  686. case STARPU_FUT_END_PROGRESS:
  687. case STARPU_FUT_END_PUSH_OUTPUT:
  688. handle_worker_status("B");
  689. break;
  690. case STARPU_FUT_WORKER_SLEEP_START:
  691. handle_start_sleep();
  692. break;
  693. case STARPU_FUT_WORKER_SLEEP_END:
  694. handle_end_sleep();
  695. break;
  696. case STARPU_FUT_TAG:
  697. /* XXX */
  698. break;
  699. case STARPU_FUT_TAG_DEPS:
  700. handle_codelet_tag_deps();
  701. break;
  702. case STARPU_FUT_TASK_DEPS:
  703. handle_task_deps();
  704. break;
  705. case STARPU_FUT_TASK_DONE:
  706. handle_task_done();
  707. break;
  708. case STARPU_FUT_TAG_DONE:
  709. handle_tag_done();
  710. break;
  711. case STARPU_FUT_DATA_COPY:
  712. if (!no_bus)
  713. handle_data_copy();
  714. break;
  715. case STARPU_FUT_START_DRIVER_COPY:
  716. if (!no_bus)
  717. handle_start_driver_copy();
  718. break;
  719. case STARPU_FUT_END_DRIVER_COPY:
  720. if (!no_bus)
  721. handle_end_driver_copy();
  722. break;
  723. case STARPU_FUT_WORK_STEALING:
  724. /* XXX */
  725. break;
  726. case STARPU_FUT_WORKER_DEINIT_START:
  727. handle_worker_deinit_start();
  728. break;
  729. case STARPU_FUT_WORKER_DEINIT_END:
  730. handle_worker_deinit_end();
  731. break;
  732. case STARPU_FUT_START_ALLOC:
  733. if (!no_bus)
  734. handle_memnode_event("A");
  735. break;
  736. case STARPU_FUT_START_ALLOC_REUSE:
  737. if (!no_bus)
  738. handle_memnode_event("Ar");
  739. break;
  740. case STARPU_FUT_START_MEMRECLAIM:
  741. handle_memnode_event("R");
  742. break;
  743. case STARPU_FUT_END_ALLOC:
  744. case STARPU_FUT_END_ALLOC_REUSE:
  745. case STARPU_FUT_END_MEMRECLAIM:
  746. if (!no_bus)
  747. handle_memnode_event("No");
  748. break;
  749. case STARPU_FUT_USER_EVENT:
  750. handle_user_event();
  751. break;
  752. case FUT_MPI_BARRIER:
  753. handle_mpi_barrier();
  754. break;
  755. case FUT_MPI_ISEND:
  756. handle_mpi_isend();
  757. break;
  758. case FUT_MPI_IRECV_END:
  759. handle_mpi_irecv_end();
  760. break;
  761. case STARPU_FUT_SET_PROFILING:
  762. handle_set_profiling();
  763. break;
  764. case STARPU_FUT_TASK_WAIT_FOR_ALL:
  765. handle_task_wait_for_all();
  766. break;
  767. default:
  768. fprintf(stderr, "unknown event.. %x at time %llx WITH OFFSET %llx\n",
  769. (unsigned)ev.code, (long long unsigned)ev.time, (long long unsigned)(ev.time-offset));
  770. break;
  771. }
  772. }
  773. hdestroy();
  774. /* Close the trace file */
  775. if (close(fd_in))
  776. {
  777. perror("close failed :");
  778. exit(-1);
  779. }
  780. }
  781. /*
  782. * This program should be used to parse the log generated by FxT
  783. */
  784. int main(int argc, char **argv)
  785. {
  786. int fd_out;
  787. parse_args(argc, argv);
  788. init_dag_dot();
  789. if (generate_distrib)
  790. distrib_time = fopen(distrib_time_path, "w+");
  791. activity_file = fopen(activity_path, "w+");
  792. paje_output_file_init();
  793. if (ninputfiles == 1)
  794. {
  795. /* we usually only have a single trace */
  796. uint64_t file_start_time = find_start_time(filenames[0]);
  797. parse_new_file(filenames[0], "", file_start_time);
  798. }
  799. else {
  800. unsigned inputfile;
  801. uint64_t offsets[64];
  802. uint64_t found_offsets[64];
  803. uint64_t start_times[64];
  804. uint64_t max = 0;
  805. /*
  806. * Find the trace offsets:
  807. * - If there is no sync point
  808. * psi_k(x) = x - start_k
  809. * - If there is a sync point sync_k
  810. * psi_k(x) = x - sync_k + M
  811. * where M = max { sync_i - start_i | there exists sync_i}
  812. * More generally:
  813. * - psi_k(x) = x - offset_k
  814. */
  815. int unique_keys[64];
  816. int rank_k[64];
  817. uint64_t start_k[64];
  818. uint64_t sync_k[64];
  819. unsigned sync_k_exists[64];
  820. uint64_t M = 0;
  821. unsigned found_one_sync_point = 0;
  822. int key;
  823. unsigned display_mpi = 0;
  824. /* Compute all start_k */
  825. for (inputfile = 0; inputfile < ninputfiles; inputfile++)
  826. {
  827. uint64_t file_start = find_start_time(filenames[inputfile]);
  828. start_k[inputfile] = file_start;
  829. }
  830. /* Compute all sync_k if they exist */
  831. for (inputfile = 0; inputfile < ninputfiles; inputfile++)
  832. {
  833. int ret = find_sync_point(filenames[inputfile],
  834. &sync_k[inputfile],
  835. &unique_keys[inputfile],
  836. &rank_k[inputfile]);
  837. if (ret == -1)
  838. {
  839. /* There was no sync point, we assume there is no offset */
  840. sync_k_exists[inputfile] = 0;
  841. }
  842. else {
  843. if (!found_one_sync_point)
  844. {
  845. key = unique_keys[inputfile];
  846. display_mpi = 1;
  847. found_one_sync_point = 1;
  848. }
  849. else {
  850. if (key != unique_keys[inputfile])
  851. {
  852. fprintf(stderr, "Warning: traces are coming from different run so we will not try to display MPI communications.\n");
  853. display_mpi = 0;
  854. }
  855. }
  856. STARPU_ASSERT(sync_k[inputfile] >= start_k[inputfile]);
  857. sync_k_exists[inputfile] = 1;
  858. uint64_t diff = sync_k[inputfile] - start_k[inputfile];
  859. if (diff > M)
  860. M = diff;
  861. }
  862. }
  863. /* Compute the offset */
  864. for (inputfile = 0; inputfile < ninputfiles; inputfile++)
  865. {
  866. offsets[inputfile] = sync_k_exists[inputfile]?
  867. (sync_k[inputfile]-M):start_k[inputfile];
  868. }
  869. /* generate the Paje trace for the different files */
  870. for (inputfile = 0; inputfile < ninputfiles; inputfile++)
  871. {
  872. int filerank = rank_k[inputfile];
  873. fprintf(stderr, "Handle file %s (rank %d)\n", filenames[inputfile], filerank);
  874. char file_prefix[32];
  875. snprintf(file_prefix, 32, "mpi_%d_", filerank);
  876. parse_new_file(filenames[inputfile], file_prefix, offsets[inputfile]);
  877. }
  878. /* display the MPI transfers if possible */
  879. if (display_mpi)
  880. for (inputfile = 0; inputfile < ninputfiles; inputfile++)
  881. {
  882. int filerank = rank_k[inputfile];
  883. display_all_transfers_from_trace(out_paje_file, filerank);
  884. }
  885. }
  886. display_bandwidth_evolution();
  887. /* close the different files */
  888. fclose(out_paje_file);
  889. fclose(activity_file);
  890. if (generate_distrib)
  891. fclose(distrib_time);
  892. terminate_dat_dot();
  893. return 0;
  894. }