fxt_tool.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  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_done(void)
  388. {
  389. uint64_t tag_id;
  390. tag_id = ev.param[0];
  391. unsigned long has_name = ev.param[2];
  392. char *name = has_name?(char *)&ev.param[3]:"unknown";
  393. int worker;
  394. worker = find_worker_id(ev.param[1]);
  395. char *colour;
  396. char buffer[32];
  397. if (per_task_colour) {
  398. snprintf(buffer, 32, "%.4f,%.4f,%.4f",
  399. get_colour_symbol_red(name)/1024.0,
  400. get_colour_symbol_green(name)/1024.0,
  401. get_colour_symbol_blue(name)/1024.0);
  402. colour = &buffer[0];
  403. }
  404. else {
  405. colour= (worker < 0)?"0.0,0.0,0.0":get_worker_color(worker);
  406. }
  407. dot_set_tag_done(tag_id, colour);
  408. }
  409. static void handle_mpi_barrier(void)
  410. {
  411. rank = ev.param[0];
  412. /* Add an event in the trace */
  413. fprintf(out_paje_file, "9 %f event %sp %d\n", get_event_time_stamp(), prefix, rank);
  414. }
  415. static void handle_mpi_isend(void)
  416. {
  417. int dest = ev.param[0];
  418. int mpi_tag = ev.param[1];
  419. size_t size = ev.param[2];
  420. float date = get_event_time_stamp();
  421. add_mpi_send_transfer(rank, dest, mpi_tag, size, date);
  422. }
  423. static void handle_mpi_irecv_end(void)
  424. {
  425. int src = ev.param[0];
  426. int mpi_tag = ev.param[1];
  427. float date = get_event_time_stamp();
  428. add_mpi_recv_transfer(src, rank, mpi_tag, date);
  429. }
  430. static void parse_args(int argc, char **argv)
  431. {
  432. /* We want to support arguments such as "fxt_tool -i trace_*" */
  433. unsigned reading_input_filenames = 0;
  434. int i;
  435. for (i = 1; i < argc; i++) {
  436. if (strcmp(argv[i], "-c") == 0) {
  437. per_task_colour = 1;
  438. reading_input_filenames = 0;
  439. continue;
  440. }
  441. if (strcmp(argv[i], "-o") == 0) {
  442. out_paje_path = argv[++i];
  443. reading_input_filenames = 0;
  444. continue;
  445. }
  446. if (strcmp(argv[i], "-i") == 0) {
  447. filenames[ninputfiles++] = argv[++i];
  448. reading_input_filenames = 1;
  449. continue;
  450. }
  451. if (strcmp(argv[i], "-no-counter") == 0) {
  452. no_counter = 1;
  453. reading_input_filenames = 0;
  454. continue;
  455. }
  456. if (strcmp(argv[i], "-no-bus") == 0) {
  457. no_bus = 1;
  458. reading_input_filenames = 0;
  459. continue;
  460. }
  461. if (strcmp(argv[i], "-d") == 0) {
  462. generate_distrib = 1;
  463. reading_input_filenames = 0;
  464. continue;
  465. }
  466. if (strcmp(argv[i], "-h") == 0) {
  467. fprintf(stderr, "Usage : %s [-c] [-no-counter] [-no-bus] [-i input_filename] [-o output_filename]\n", argv[0]);
  468. fprintf(stderr, "\t-c: use a different colour for every type of task.\n");
  469. exit(-1);
  470. }
  471. /* That's pretty dirty: if the reading_input_filenames flag is
  472. * set, and that the argument does not match an option, we
  473. * assume this may be another filename */
  474. if (reading_input_filenames)
  475. {
  476. filenames[ninputfiles++] = argv[i];
  477. continue;
  478. }
  479. }
  480. }
  481. void parse_new_file(char *filename_in, char *file_prefix, uint64_t file_offset)
  482. {
  483. prefix = file_prefix;
  484. offset = file_offset;
  485. /* Open the trace file */
  486. int fd_in;
  487. fd_in = open(filename_in, O_RDONLY);
  488. if (fd_in < 0) {
  489. perror("open failed :");
  490. exit(-1);
  491. }
  492. static fxt_t fut;
  493. fut = fxt_fdopen(fd_in);
  494. if (!fut) {
  495. perror("fxt_fdopen :");
  496. exit(-1);
  497. }
  498. fxt_blockev_t block;
  499. block = fxt_blockev_enter(fut);
  500. /* create a htable to identify each worker(tid) */
  501. hcreate(MAXWORKERS);
  502. symbol_list = symbol_name_list_new();
  503. communication_list = communication_list_new();
  504. /* TODO starttime ...*/
  505. /* create the "program" container */
  506. fprintf(out_paje_file, "7 0.0 %sp P MPIroot program%s \n", prefix, prefix);
  507. /* create a variable with the number of tasks */
  508. if (!no_counter)
  509. {
  510. fprintf(out_paje_file, "7 %f %ssched Sc %sp scheduler \n", 0.0, prefix, prefix);
  511. fprintf(out_paje_file, "13 0.0 ntask %ssched 0.0\n", prefix);
  512. }
  513. unsigned first_event = 1;
  514. while(1) {
  515. int ret = fxt_next_ev(block, FXT_EV_TYPE_64, (struct fxt_ev *)&ev);
  516. if (ret != FXT_EV_OK) {
  517. fprintf(stderr, "no more block ...\n");
  518. break;
  519. }
  520. __attribute__ ((unused)) int nbparam = ev.nb_params;
  521. if (first_event)
  522. {
  523. first_event = 0;
  524. start_time = ev.time;
  525. }
  526. switch (ev.code) {
  527. case STARPU_FUT_WORKER_INIT_START:
  528. handle_worker_init_start();
  529. break;
  530. case STARPU_FUT_WORKER_INIT_END:
  531. handle_worker_init_end();
  532. break;
  533. case STARPU_FUT_NEW_MEM_NODE:
  534. handle_new_mem_node();
  535. break;
  536. /* detect when the workers were idling or not */
  537. case STARPU_FUT_START_CODELET_BODY:
  538. handle_start_codelet_body();
  539. break;
  540. case STARPU_FUT_END_CODELET_BODY:
  541. handle_end_codelet_body();
  542. break;
  543. case STARPU_FUT_START_CALLBACK:
  544. handle_start_callback();
  545. break;
  546. case STARPU_FUT_END_CALLBACK:
  547. handle_end_callback();
  548. break;
  549. /* monitor stack size */
  550. case STARPU_FUT_JOB_PUSH:
  551. if (!no_counter)
  552. handle_job_push();
  553. break;
  554. case STARPU_FUT_JOB_POP:
  555. if (!no_counter)
  556. handle_job_pop();
  557. break;
  558. /* check the memory transfer overhead */
  559. case STARPU_FUT_START_FETCH_INPUT:
  560. handle_worker_status("Fi");
  561. break;
  562. case STARPU_FUT_START_PUSH_OUTPUT:
  563. handle_worker_status("Po");
  564. break;
  565. case STARPU_FUT_START_PROGRESS:
  566. handle_worker_status("P");
  567. break;
  568. case STARPU_FUT_END_FETCH_INPUT:
  569. case STARPU_FUT_END_PROGRESS:
  570. case STARPU_FUT_END_PUSH_OUTPUT:
  571. handle_worker_status("B");
  572. break;
  573. case STARPU_FUT_CODELET_TAG:
  574. /* XXX */
  575. break;
  576. case STARPU_FUT_CODELET_TAG_DEPS:
  577. handle_codelet_tag_deps();
  578. break;
  579. case STARPU_FUT_TASK_DONE:
  580. handle_task_done();
  581. break;
  582. case STARPU_FUT_DATA_COPY:
  583. if (!no_bus)
  584. handle_data_copy();
  585. break;
  586. case STARPU_FUT_START_DRIVER_COPY:
  587. if (!no_bus)
  588. handle_start_driver_copy();
  589. break;
  590. case STARPU_FUT_END_DRIVER_COPY:
  591. if (!no_bus)
  592. handle_end_driver_copy();
  593. break;
  594. case STARPU_FUT_WORK_STEALING:
  595. /* XXX */
  596. break;
  597. case STARPU_FUT_WORKER_DEINIT_START:
  598. handle_worker_deinit_start();
  599. break;
  600. case STARPU_FUT_WORKER_DEINIT_END:
  601. handle_worker_deinit_end();
  602. break;
  603. case STARPU_FUT_START_ALLOC:
  604. if (!no_bus)
  605. handle_memnode_event("A");
  606. break;
  607. case STARPU_FUT_START_ALLOC_REUSE:
  608. if (!no_bus)
  609. handle_memnode_event("Ar");
  610. break;
  611. case STARPU_FUT_START_MEMRECLAIM:
  612. handle_memnode_event("R");
  613. break;
  614. case STARPU_FUT_END_ALLOC:
  615. case STARPU_FUT_END_ALLOC_REUSE:
  616. case STARPU_FUT_END_MEMRECLAIM:
  617. if (!no_bus)
  618. handle_memnode_event("No");
  619. break;
  620. case STARPU_FUT_USER_EVENT:
  621. handle_user_event();
  622. break;
  623. case FUT_MPI_BARRIER:
  624. handle_mpi_barrier();
  625. break;
  626. case FUT_MPI_ISEND:
  627. handle_mpi_isend();
  628. break;
  629. case FUT_MPI_IRECV_END:
  630. handle_mpi_irecv_end();
  631. break;
  632. default:
  633. fprintf(stderr, "unknown event.. %x at time %llx WITH OFFSET %llx\n",
  634. (unsigned)ev.code, (long long unsigned)ev.time, (long long unsigned)(ev.time-offset));
  635. break;
  636. }
  637. }
  638. hdestroy();
  639. /* Close the trace file */
  640. if (close(fd_in))
  641. {
  642. perror("close failed :");
  643. exit(-1);
  644. }
  645. }
  646. /*
  647. * This program should be used to parse the log generated by FxT
  648. */
  649. int main(int argc, char **argv)
  650. {
  651. int fd_out;
  652. parse_args(argc, argv);
  653. init_dag_dot();
  654. if (generate_distrib)
  655. distrib_time = fopen(distrib_time_path, "w+");
  656. paje_output_file_init();
  657. if (ninputfiles == 1)
  658. {
  659. /* we usually only have a single trace */
  660. uint64_t file_start_time = find_start_time(filenames[0]);
  661. parse_new_file(filenames[0], "", file_start_time);
  662. }
  663. else {
  664. unsigned inputfile;
  665. uint64_t offsets[64];
  666. uint64_t found_offsets[64];
  667. uint64_t start_times[64];
  668. uint64_t max = 0;
  669. /*
  670. * Find the trace offsets:
  671. * - If there is no sync point
  672. * psi_k(x) = x - start_k
  673. * - If there is a sync point sync_k
  674. * psi_k(x) = x - sync_k + M
  675. * where M = max { sync_i - start_i | there exists sync_i}
  676. * More generally:
  677. * - psi_k(x) = x - offset_k
  678. */
  679. int unique_keys[64];
  680. int rank_k[64];
  681. uint64_t start_k[64];
  682. uint64_t sync_k[64];
  683. unsigned sync_k_exists[64];
  684. uint64_t M = 0;
  685. unsigned found_one_sync_point = 0;
  686. int key;
  687. unsigned display_mpi = 0;
  688. /* Compute all start_k */
  689. for (inputfile = 0; inputfile < ninputfiles; inputfile++)
  690. {
  691. uint64_t file_start = find_start_time(filenames[inputfile]);
  692. start_k[inputfile] = file_start;
  693. }
  694. /* Compute all sync_k if they exist */
  695. for (inputfile = 0; inputfile < ninputfiles; inputfile++)
  696. {
  697. int ret = find_sync_point(filenames[inputfile],
  698. &sync_k[inputfile],
  699. &unique_keys[inputfile],
  700. &rank_k[inputfile]);
  701. if (ret == -1)
  702. {
  703. /* There was no sync point, we assume there is no offset */
  704. sync_k_exists[inputfile] = 0;
  705. }
  706. else {
  707. if (!found_one_sync_point)
  708. {
  709. key = unique_keys[inputfile];
  710. display_mpi = 1;
  711. found_one_sync_point = 1;
  712. }
  713. else {
  714. if (key != unique_keys[inputfile])
  715. {
  716. fprintf(stderr, "Warning: traces are coming from different run so we will not try to display MPI communications.\n");
  717. display_mpi = 0;
  718. }
  719. }
  720. STARPU_ASSERT(sync_k[inputfile] >= start_k[inputfile]);
  721. sync_k_exists[inputfile] = 1;
  722. uint64_t diff = sync_k[inputfile] - start_k[inputfile];
  723. if (diff > M)
  724. M = diff;
  725. }
  726. }
  727. /* Compute the offset */
  728. for (inputfile = 0; inputfile < ninputfiles; inputfile++)
  729. {
  730. offsets[inputfile] = sync_k_exists[inputfile]?
  731. (sync_k[inputfile]-M):start_k[inputfile];
  732. }
  733. /* generate the Paje trace for the different files */
  734. for (inputfile = 0; inputfile < ninputfiles; inputfile++)
  735. {
  736. int filerank = rank_k[inputfile];
  737. fprintf(stderr, "Handle file %s (rank %d)\n", filenames[inputfile], filerank);
  738. char file_prefix[32];
  739. snprintf(file_prefix, 32, "mpi_%d_", filerank);
  740. parse_new_file(filenames[inputfile], file_prefix, offsets[inputfile]);
  741. }
  742. /* display the MPI transfers if possible */
  743. if (display_mpi)
  744. for (inputfile = 0; inputfile < ninputfiles; inputfile++)
  745. {
  746. int filerank = rank_k[inputfile];
  747. display_all_transfers_from_trace(out_paje_file, filerank);
  748. }
  749. }
  750. display_bandwidth_evolution();
  751. /* close the different files */
  752. fclose(out_paje_file);
  753. if (generate_distrib)
  754. fclose(distrib_time);
  755. terminate_dat_dot();
  756. return 0;
  757. }