fxt-tool.c 20 KB

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