fxt_tool.c 24 KB

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