starpu_fxt_tool.c 28 KB

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