fxt_tool.c 28 KB

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