starpu_perfmodel_plot.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. * Copyright (C) 2011 Télécom-SudParis
  5. * Copyright (C) 2013 Thibaut Lambert
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <common/config.h>
  19. #include <assert.h>
  20. #include <unistd.h>
  21. #include <stdio.h>
  22. #include <sys/stat.h>
  23. #include <limits.h>
  24. #ifdef STARPU_USE_FXT
  25. #include <common/fxt.h>
  26. #endif
  27. #include <common/utils.h>
  28. #include <starpu.h>
  29. #include <core/perfmodel/perfmodel.h> // we need to browse the list associated to history-based models
  30. #if defined(_WIN32) && !defined(__CYGWIN__)
  31. #include <windows.h>
  32. #endif
  33. #define PROGNAME "starpu_perfmodel_plot"
  34. struct _perfmodel_plot_options
  35. {
  36. /* display all available models */
  37. int list;
  38. /* display directory */
  39. int directory;
  40. /* what kernel ? */
  41. char *symbol;
  42. /* what energy model ? */
  43. char *energy_symbol;
  44. /* which combination */
  45. int comb_is_set;
  46. int comb;
  47. /* display all available combinations of a specific model */
  48. int list_combs;
  49. int gflops;
  50. int energy;
  51. /* Unless a FxT file is specified, we just display the model */
  52. int with_fxt_file;
  53. char avg_file_name[256];
  54. #ifdef STARPU_USE_FXT
  55. struct starpu_fxt_codelet_event *dumped_codelets;
  56. struct starpu_fxt_options fxt_options;
  57. char data_file_name[256];
  58. #endif
  59. };
  60. static void usage()
  61. {
  62. fprintf(stderr, "Draw a graph corresponding to the execution time of a given perfmodel\n");
  63. fprintf(stderr, "Usage: %s [ options ]\n", PROGNAME);
  64. fprintf(stderr, "\n");
  65. fprintf(stderr, "One must specify a symbol with the -s option or use -l or -d\n");
  66. fprintf(stderr, "Options:\n");
  67. fprintf(stderr, " -d display the directory storing performance models\n");
  68. fprintf(stderr, " -l display all available models\n");
  69. fprintf(stderr, " -s <symbol> specify the symbol\n");
  70. fprintf(stderr, " -e display perfmodel as energy instead of time\n");
  71. fprintf(stderr, " -se <time_symbol> <energy_symbol> \n");
  72. fprintf(stderr, " specify both a time symbol and an energy symbol\n");
  73. fprintf(stderr, " -f draw GFlops instead of time\n");
  74. fprintf(stderr, " -i <Fxt files> input FxT files generated by StarPU\n");
  75. fprintf(stderr, " -lc display all combinations of a given model\n");
  76. fprintf(stderr, " -c <combination> specify the combination (use the option -lc to list all combinations of a given model)\n");
  77. fprintf(stderr, " -o <directory> specify directory in which to create output files (current directory by default)\n");
  78. fprintf(stderr, " -h, --help display this help and exit\n");
  79. fprintf(stderr, " -v, --version output version information and exit\n\n");
  80. fprintf(stderr, "Report bugs to <%s>.", PACKAGE_BUGREPORT);
  81. fprintf(stderr, "\n");
  82. }
  83. static void parse_args(int argc, char **argv, struct _perfmodel_plot_options *options, char **directory)
  84. {
  85. int correct_usage = 0;
  86. memset(options, 0, sizeof(struct _perfmodel_plot_options));
  87. #ifdef STARPU_USE_FXT
  88. /* Default options */
  89. starpu_fxt_options_init(&options->fxt_options);
  90. free(options->fxt_options.out_paje_path);
  91. options->fxt_options.out_paje_path = NULL;
  92. free(options->fxt_options.activity_path);
  93. options->fxt_options.activity_path = NULL;
  94. free(options->fxt_options.distrib_time_path);
  95. options->fxt_options.distrib_time_path = NULL;
  96. free(options->fxt_options.dag_path);
  97. options->fxt_options.dag_path = NULL;
  98. options->fxt_options.dumped_codelets = &options->dumped_codelets;
  99. #endif
  100. /* We want to support arguments such as "-i trace_*" */
  101. unsigned reading_input_filenames = 0;
  102. int i;
  103. for (i = 1; i < argc; i++)
  104. {
  105. if (strcmp(argv[i], "-s") == 0)
  106. {
  107. options->symbol = argv[++i];
  108. correct_usage = 1;
  109. continue;
  110. }
  111. if (strcmp(argv[i], "-se") == 0)
  112. {
  113. options->symbol = argv[++i];
  114. options->energy_symbol = argv[++i];
  115. correct_usage = 1;
  116. continue;
  117. }
  118. if (strcmp(argv[i], "-o") == 0)
  119. {
  120. free(*directory);
  121. *directory = strdup(argv[++i]);
  122. #ifdef STARPU_USE_FXT
  123. options->fxt_options.dir = strdup(*directory);
  124. #endif
  125. continue;
  126. }
  127. if (strcmp(argv[i], "-i") == 0)
  128. {
  129. reading_input_filenames = 1;
  130. #ifdef STARPU_USE_FXT
  131. options->fxt_options.filenames[options->fxt_options.ninputfiles++] = argv[++i];
  132. options->with_fxt_file = 1;
  133. #else
  134. fprintf(stderr, "Warning: FxT support was not enabled in StarPU: FxT traces will thus be ignored!\n");
  135. #endif
  136. continue;
  137. }
  138. if (strcmp(argv[i], "-l") == 0)
  139. {
  140. options->list = 1;
  141. correct_usage = 1;
  142. continue;
  143. }
  144. if (strcmp(argv[i], "-lc") == 0)
  145. {
  146. options->list_combs = 1;
  147. continue;
  148. }
  149. if (strcmp(argv[i], "-f") == 0)
  150. {
  151. options->gflops = 1;
  152. continue;
  153. }
  154. if (strcmp(argv[i], "-e") == 0)
  155. {
  156. options->energy = 1;
  157. continue;
  158. }
  159. if (strcmp(argv[i], "-c") == 0)
  160. {
  161. options->comb_is_set = 1;
  162. options->comb = atoi(argv[++i]);
  163. continue;
  164. }
  165. if (strcmp(argv[i], "-d") == 0)
  166. {
  167. options->directory = 1;
  168. correct_usage = 1;
  169. continue;
  170. }
  171. if (strcmp(argv[i], "-h") == 0 ||
  172. strcmp(argv[i], "--help") == 0)
  173. {
  174. usage();
  175. exit(EXIT_SUCCESS);
  176. }
  177. if (strcmp(argv[i], "-v") == 0 ||
  178. strcmp(argv[i], "--version") == 0)
  179. {
  180. fputs(PROGNAME " (" PACKAGE_NAME ") " PACKAGE_VERSION "\n", stderr);
  181. exit(EXIT_SUCCESS);
  182. }
  183. /* If the reading_input_filenames flag is set, and that the
  184. * argument does not match an option, we assume this may be
  185. * another filename */
  186. if (reading_input_filenames)
  187. {
  188. #ifdef STARPU_USE_FXT
  189. options->fxt_options.filenames[options->fxt_options.ninputfiles++] = argv[i];
  190. #endif
  191. continue;
  192. }
  193. }
  194. if (correct_usage == 0)
  195. {
  196. fprintf(stderr, "Incorrect usage, aborting\n");
  197. usage();
  198. exit(-1);
  199. }
  200. }
  201. static char *replace_char(char *str, char old, char new)
  202. {
  203. char *p = strdup(str);
  204. char *ptr = p;
  205. while (*ptr)
  206. {
  207. if (*ptr == old) *ptr = new;
  208. ptr ++;
  209. }
  210. return p;
  211. }
  212. static void print_comma(FILE *gnuplot_file, int *first)
  213. {
  214. if (*first)
  215. {
  216. *first = 0;
  217. }
  218. else
  219. {
  220. fprintf(gnuplot_file, ",\\\n\t");
  221. }
  222. }
  223. static void display_perf_model(FILE *gnuplot_file, struct starpu_perfmodel_arch* arch, struct starpu_perfmodel_per_arch *arch_model, int impl, int *first, struct _perfmodel_plot_options *options)
  224. {
  225. char arch_name[256];
  226. const char *factor;
  227. if (options->energy)
  228. factor = "";
  229. else
  230. factor = "0.001 * ";
  231. starpu_perfmodel_get_arch_name(arch, arch_name, 256, impl);
  232. #ifdef STARPU_USE_FXT
  233. if (options->with_fxt_file && impl == 0)
  234. {
  235. if (options->gflops)
  236. {
  237. _STARPU_DISP("gflops unit selected, ignoring fxt trace\n");
  238. }
  239. else
  240. {
  241. char *arch_name2 = replace_char(arch_name, '_', '-');
  242. print_comma(gnuplot_file, first);
  243. fprintf(gnuplot_file, "\"< grep '^%s' %s\" using 3:4 title \"Profiling %s\"", arch_name, options->data_file_name, arch_name2);
  244. free(arch_name2);
  245. }
  246. }
  247. #endif
  248. /* Only display the regression model if we could actually build a model */
  249. if (!options->gflops && arch_model->regression.valid && !arch_model->regression.nl_valid)
  250. {
  251. print_comma(gnuplot_file, first);
  252. fprintf(stderr, "\tLinear: y = alpha size ^ beta\n");
  253. fprintf(stderr, "\t\talpha = %e\n", arch_model->regression.alpha * 0.001);
  254. fprintf(stderr, "\t\tbeta = %e\n", arch_model->regression.beta);
  255. fprintf(gnuplot_file, "%s%g * x ** %g title \"Linear Regression %s\"", factor,
  256. arch_model->regression.alpha, arch_model->regression.beta, arch_name);
  257. }
  258. if (!options->gflops && arch_model->regression.nl_valid)
  259. {
  260. print_comma(gnuplot_file, first);
  261. fprintf(stderr, "\tNon-Linear: y = a size ^b + c\n");
  262. fprintf(stderr, "\t\ta = %e\n", arch_model->regression.a * 0.001);
  263. fprintf(stderr, "\t\tb = %e\n", arch_model->regression.b);
  264. fprintf(stderr, "\t\tc = %e\n", arch_model->regression.c * 0.001);
  265. fprintf(gnuplot_file, "%s%g * x ** %g + %s%g title \"Non-Linear Regression %s\"", factor,
  266. arch_model->regression.a, arch_model->regression.b, factor, arch_model->regression.c, arch_name);
  267. }
  268. }
  269. static void display_history_based_perf_models(FILE *gnuplot_file, struct starpu_perfmodel *model, struct starpu_perfmodel *energy_model, int *first, struct _perfmodel_plot_options *options)
  270. {
  271. FILE *datafile;
  272. struct starpu_perfmodel_history_list *ptr;
  273. char arch_name[32];
  274. int col;
  275. unsigned long minimum = 0;
  276. datafile = fopen(options->avg_file_name, "w");
  277. col = 2;
  278. int i;
  279. for(i = 0; i < model->state->ncombs; i++)
  280. {
  281. int comb = model->state->combs[i];
  282. if (options->comb_is_set == 0 || options->comb == comb)
  283. {
  284. struct starpu_perfmodel_arch *arch;
  285. int impl;
  286. arch = starpu_perfmodel_arch_comb_fetch(comb);
  287. for(impl = 0; impl < model->state->nimpls[comb]; impl++)
  288. {
  289. struct starpu_perfmodel_per_arch *arch_model = &model->state->per_arch[comb][impl];
  290. starpu_perfmodel_get_arch_name(arch, arch_name, 32, impl);
  291. if (arch_model->list)
  292. {
  293. char *arch_name2 = replace_char(arch_name, '_', '-');
  294. print_comma(gnuplot_file, first);
  295. fprintf(gnuplot_file, "\"%s\" using 1:%d:%d with errorlines title \"Average %s\"", options->avg_file_name, col, col+1, arch_name2);
  296. col += 2;
  297. free(arch_name2);
  298. }
  299. }
  300. }
  301. }
  302. /* Dump entries in size order */
  303. while (1)
  304. {
  305. unsigned long last = minimum;
  306. minimum = ULONG_MAX;
  307. /* Get the next minimum */
  308. for(i = 0; i < model->state->ncombs; i++)
  309. {
  310. int comb = model->state->combs[i];
  311. if (options->comb_is_set == 0 || options->comb == comb)
  312. {
  313. int impl;
  314. for(impl = 0; impl < model->state->nimpls[comb]; impl++)
  315. {
  316. struct starpu_perfmodel_per_arch *arch_model = &model->state->per_arch[comb][impl];
  317. for (ptr = arch_model->list; ptr; ptr = ptr->next)
  318. {
  319. unsigned long size = ptr->entry->size;
  320. if (size > last && size < minimum)
  321. minimum = size;
  322. }
  323. }
  324. }
  325. }
  326. if (minimum == ULONG_MAX)
  327. break;
  328. fprintf(stderr, "%lu ", minimum);
  329. fprintf(datafile, "%-15lu ", minimum);
  330. /* Find that minimum */
  331. for(i = 0; i < model->state->ncombs; i++)
  332. {
  333. int comb = model->state->combs[i];
  334. if (options->comb_is_set == 0 || options->comb == comb)
  335. {
  336. int impl;
  337. for(impl = 0; impl < model->state->nimpls[comb]; impl++)
  338. {
  339. int found = 0;
  340. struct starpu_perfmodel_per_arch *arch_model = &model->state->per_arch[comb][impl];
  341. for (ptr = arch_model->list; ptr; ptr = ptr->next)
  342. {
  343. struct starpu_perfmodel_history_entry *entry = ptr->entry;
  344. if (entry->size == minimum)
  345. {
  346. if (options->energy_symbol)
  347. {
  348. /* Look for the same in the energy model */
  349. if (impl >= energy_model->state->nimpls[comb])
  350. /* Doesn't have measurements for this impl */
  351. break;
  352. struct starpu_perfmodel_per_arch *arch_model2 = &energy_model->state->per_arch[comb][impl];
  353. struct starpu_perfmodel_history_list *ptr2;
  354. for (ptr2 = arch_model2->list; ptr2; ptr2 = ptr2->next)
  355. {
  356. struct starpu_perfmodel_history_entry *entry2 = ptr2->entry;
  357. if (entry2->size == minimum)
  358. {
  359. /* Found the same size, can print */
  360. double rel_delta = sqrt(
  361. (entry2->deviation * entry2->deviation) / (entry2->mean * entry2->mean)
  362. + (entry->deviation * entry->deviation) / (entry->mean * entry->mean));
  363. fprintf(datafile, "\t%-15le\t%-15le", entry2->mean / (entry->mean / 1000000),
  364. entry2->mean / (entry->mean / 1000000) * rel_delta);
  365. found = 1;
  366. break;
  367. }
  368. }
  369. }
  370. else
  371. {
  372. if (options->gflops)
  373. if (options->energy)
  374. fprintf(datafile, "\t%-15le\t%-15le", entry->flops / entry->mean / 1000000000,
  375. entry->flops * entry->deviation / (entry->mean * entry->mean) / 1000000000
  376. );
  377. else
  378. fprintf(datafile, "\t%-15le\t%-15le", entry->flops / (entry->mean * 1000),
  379. entry->flops * entry->deviation / (entry->mean * entry->mean * 1000)
  380. );
  381. else
  382. if (options->energy)
  383. fprintf(datafile, "\t%-15le\t%-15le", entry->mean, entry->deviation);
  384. else
  385. fprintf(datafile, "\t%-15le\t%-15le", 0.001*entry->mean, 0.001*entry->deviation);
  386. found = 1;
  387. }
  388. break;
  389. }
  390. }
  391. if (!found && arch_model->list)
  392. /* No value for this arch. */
  393. fprintf(datafile, "\t\"\"\t\"\"");
  394. }
  395. }
  396. }
  397. fprintf(datafile, "\n");
  398. }
  399. fprintf(stderr, "\n");
  400. fclose(datafile);
  401. }
  402. static void display_all_perf_models(FILE *gnuplot_file, struct starpu_perfmodel *model, int *first, struct _perfmodel_plot_options *options)
  403. {
  404. int i;
  405. for(i = 0; i < model->state->ncombs; i++)
  406. {
  407. int comb = model->state->combs[i];
  408. if (options->comb_is_set == 0 || options->comb == comb)
  409. {
  410. struct starpu_perfmodel_arch *arch;
  411. int impl;
  412. arch = starpu_perfmodel_arch_comb_fetch(comb);
  413. for(impl = 0; impl < model->state->nimpls[comb]; impl++)
  414. {
  415. struct starpu_perfmodel_per_arch *archmodel = &model->state->per_arch[comb][impl];
  416. display_perf_model(gnuplot_file, arch, archmodel, impl, first, options);
  417. }
  418. }
  419. }
  420. }
  421. #ifdef STARPU_USE_FXT
  422. static void dump_data_file(FILE *data_file, struct _perfmodel_plot_options *options)
  423. {
  424. int i;
  425. for (i = 0; i < options->fxt_options.dumped_codelets_count; i++)
  426. {
  427. /* Dump only if the codelet symbol matches user's request (with or without the machine name) */
  428. char *tmp = strdup(options->symbol);
  429. char *dot = strchr(tmp, '.');
  430. if (dot) tmp[strlen(tmp)-strlen(dot)] = '\0';
  431. if ((strncmp(options->dumped_codelets[i].symbol, options->symbol, (FXT_MAX_PARAMS - 4)*sizeof(unsigned long)-1) == 0)
  432. || (strncmp(options->dumped_codelets[i].symbol, tmp, (FXT_MAX_PARAMS - 4)*sizeof(unsigned long)-1) == 0))
  433. {
  434. char *archname = options->dumped_codelets[i].perfmodel_archname;
  435. size_t size = options->dumped_codelets[i].size;
  436. float time = options->dumped_codelets[i].time;
  437. fprintf(data_file, "%s %f %f\n", archname, (float)size, time);
  438. }
  439. free(tmp);
  440. }
  441. free(options->dumped_codelets);
  442. }
  443. #endif
  444. static void display_selected_models(FILE *gnuplot_file, struct starpu_perfmodel *model, struct starpu_perfmodel *energy_model, struct _perfmodel_plot_options *options)
  445. {
  446. char *symbol = replace_char(options->symbol, '_', '-');
  447. fprintf(gnuplot_file, "#!/usr/bin/gnuplot -persist\n");
  448. fprintf(gnuplot_file, "\n");
  449. fprintf(gnuplot_file, "set term postscript eps enhanced color\n");
  450. fprintf(gnuplot_file, "set output \"starpu_%s%s.eps\"\n", options->energy_symbol?"power_":options->gflops?"gflops_":"", options->symbol);
  451. fprintf(gnuplot_file, "set title \"Model for codelet %s\"\n", symbol);
  452. fprintf(gnuplot_file, "set xlabel \"Total data size\"\n");
  453. if (options->energy_symbol)
  454. fprintf(gnuplot_file, "set ylabel \"Power (W)\"\n");
  455. else if (options->gflops)
  456. if (options->energy)
  457. fprintf(gnuplot_file, "set ylabel \"GFlop/s/W\"\n");
  458. else
  459. fprintf(gnuplot_file, "set ylabel \"GFlop/s\"\n");
  460. else
  461. if (options->energy)
  462. fprintf(gnuplot_file, "set ylabel \"Energy (J)\"\n");
  463. else
  464. fprintf(gnuplot_file, "set ylabel \"Time (ms)\"\n");
  465. fprintf(gnuplot_file, "\n");
  466. fprintf(gnuplot_file, "set key top left\n");
  467. fprintf(gnuplot_file, "set logscale x\n");
  468. fprintf(gnuplot_file, "set logscale y\n");
  469. fprintf(gnuplot_file, "\n");
  470. /* If no input data is given to gnuplot, we at least need to specify an
  471. * arbitrary range. */
  472. if (options->with_fxt_file == 0 || options->gflops)
  473. fprintf(gnuplot_file, "set xrange [1 < * < 10**5 : 10**6 < * < 10**9]\n\n");
  474. int first = 1;
  475. fprintf(gnuplot_file, "plot\t");
  476. /* display all or selected combinations */
  477. if (!options->energy_symbol)
  478. display_all_perf_models(gnuplot_file, model, &first, options);
  479. display_history_based_perf_models(gnuplot_file, model, energy_model, &first, options);
  480. free(symbol);
  481. }
  482. int main(int argc, char **argv)
  483. {
  484. int ret = 0;
  485. struct starpu_perfmodel model = { .type = STARPU_PERFMODEL_INVALID };
  486. struct starpu_perfmodel energy_model = { .type = STARPU_PERFMODEL_INVALID };
  487. char gnuplot_file_name[256];
  488. struct _perfmodel_plot_options options;
  489. char *directory = strdup("./");
  490. #if defined(_WIN32) && !defined(__CYGWIN__)
  491. WSADATA wsadata;
  492. WSAStartup(MAKEWORD(1,0), &wsadata);
  493. #endif
  494. parse_args(argc, argv, &options, &directory);
  495. starpu_drivers_preinit();
  496. starpu_perfmodel_initialize();
  497. if (options.directory)
  498. {
  499. starpu_perfmodel_directory(stdout);
  500. }
  501. else if (options.list)
  502. {
  503. ret = starpu_perfmodel_list(stdout);
  504. if (ret)
  505. {
  506. _STARPU_DISP("The performance model directory is invalid\n");
  507. }
  508. }
  509. else
  510. {
  511. /* Load the performance model associated to the symbol */
  512. ret = starpu_perfmodel_load_symbol(options.symbol, &model);
  513. if (options.energy_symbol)
  514. ret = starpu_perfmodel_load_symbol(options.energy_symbol, &energy_model);
  515. if (ret)
  516. {
  517. _STARPU_DISP("The performance model for the symbol <%s> could not be loaded\n", options.symbol);
  518. }
  519. else if (options.list_combs)
  520. {
  521. ret = starpu_perfmodel_list_combs(stdout, &model);
  522. if (ret)
  523. {
  524. fprintf(stderr, "Error when listing combinations for model <%s>\n", options.symbol);
  525. }
  526. }
  527. else
  528. {
  529. /* If some FxT input was specified, we put the points on the graph */
  530. #ifdef STARPU_USE_FXT
  531. if (options.with_fxt_file)
  532. {
  533. starpu_fxt_generate_trace(&options.fxt_options);
  534. snprintf(options.data_file_name, sizeof(options.data_file_name), "%s/starpu_%s.data", directory, options.symbol);
  535. FILE *data_file = fopen(options.data_file_name, "w+");
  536. STARPU_ASSERT(data_file);
  537. dump_data_file(data_file, &options);
  538. fclose(data_file);
  539. }
  540. #endif
  541. if (options.energy_symbol)
  542. {
  543. snprintf(gnuplot_file_name, sizeof(gnuplot_file_name), "%s/starpu_power_%s.gp", directory, options.symbol);
  544. snprintf(options.avg_file_name, sizeof(options.avg_file_name), "%s/starpu_power_%s_avg.data", directory, options.symbol);
  545. }
  546. else
  547. {
  548. snprintf(gnuplot_file_name, sizeof(gnuplot_file_name), "%s/starpu_%s.gp", directory, options.symbol);
  549. snprintf(options.avg_file_name, sizeof(options.avg_file_name), "%s/starpu_%s_avg.data", directory, options.symbol);
  550. }
  551. FILE *gnuplot_file = fopen(gnuplot_file_name, "w+");
  552. STARPU_ASSERT_MSG(gnuplot_file, "Cannot create file <%s>\n", gnuplot_file_name);
  553. display_selected_models(gnuplot_file, &model, &energy_model, &options);
  554. fprintf(gnuplot_file,"\n");
  555. fclose(gnuplot_file);
  556. /* Retrieve the current mode of the gnuplot executable */
  557. struct stat sb;
  558. ret = stat(gnuplot_file_name, &sb);
  559. if (ret)
  560. {
  561. perror("stat");
  562. STARPU_ABORT();
  563. }
  564. /* Make the gnuplot scrit executable */
  565. ret = chmod(gnuplot_file_name, sb.st_mode|S_IXUSR
  566. #ifdef S_IXGRP
  567. |S_IXGRP
  568. #endif
  569. #ifdef S_IXOTH
  570. |S_IXOTH
  571. #endif
  572. );
  573. if (ret)
  574. {
  575. perror("chmod");
  576. STARPU_ABORT();
  577. }
  578. _STARPU_DISP("Gnuplot file <%s> generated\n", gnuplot_file_name);
  579. }
  580. starpu_perfmodel_unload_model(&model);
  581. if (options.energy_symbol)
  582. starpu_perfmodel_unload_model(&energy_model);
  583. }
  584. starpu_perfmodel_free_sampling();
  585. free(directory);
  586. #ifdef STARPU_USE_FXT
  587. free(options.fxt_options.dir);
  588. starpu_fxt_options_shutdown(&options.fxt_options);
  589. #endif
  590. return ret;
  591. }