fxt_tool.c 27 KB

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