fxt-tool.c 22 KB

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