starpu_perfmodel_plot.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2020 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. options->fxt_options.out_paje_path = NULL;
  91. options->fxt_options.activity_path = NULL;
  92. options->fxt_options.distrib_time_path = NULL;
  93. options->fxt_options.dag_path = NULL;
  94. options->fxt_options.dumped_codelets = &options->dumped_codelets;
  95. #endif
  96. /* We want to support arguments such as "-i trace_*" */
  97. unsigned reading_input_filenames = 0;
  98. int i;
  99. for (i = 1; i < argc; i++)
  100. {
  101. if (strcmp(argv[i], "-s") == 0)
  102. {
  103. options->symbol = argv[++i];
  104. correct_usage = 1;
  105. continue;
  106. }
  107. if (strcmp(argv[i], "-se") == 0)
  108. {
  109. options->symbol = argv[++i];
  110. options->energy_symbol = argv[++i];
  111. correct_usage = 1;
  112. continue;
  113. }
  114. if (strcmp(argv[i], "-o") == 0)
  115. {
  116. free(*directory);
  117. *directory = strdup(argv[++i]);
  118. #ifdef STARPU_USE_FXT
  119. options->fxt_options.dir = strdup(*directory);
  120. #endif
  121. continue;
  122. }
  123. if (strcmp(argv[i], "-i") == 0)
  124. {
  125. reading_input_filenames = 1;
  126. #ifdef STARPU_USE_FXT
  127. options->fxt_options.filenames[options->fxt_options.ninputfiles++] = argv[++i];
  128. options->with_fxt_file = 1;
  129. #else
  130. fprintf(stderr, "Warning: FxT support was not enabled in StarPU: FxT traces will thus be ignored!\n");
  131. #endif
  132. continue;
  133. }
  134. if (strcmp(argv[i], "-l") == 0)
  135. {
  136. options->list = 1;
  137. correct_usage = 1;
  138. continue;
  139. }
  140. if (strcmp(argv[i], "-lc") == 0)
  141. {
  142. options->list_combs = 1;
  143. continue;
  144. }
  145. if (strcmp(argv[i], "-f") == 0)
  146. {
  147. options->gflops = 1;
  148. continue;
  149. }
  150. if (strcmp(argv[i], "-e") == 0)
  151. {
  152. options->energy = 1;
  153. continue;
  154. }
  155. if (strcmp(argv[i], "-c") == 0)
  156. {
  157. options->comb_is_set = 1;
  158. options->comb = atoi(argv[++i]);
  159. continue;
  160. }
  161. if (strcmp(argv[i], "-d") == 0)
  162. {
  163. options->directory = 1;
  164. correct_usage = 1;
  165. continue;
  166. }
  167. if (strcmp(argv[i], "-h") == 0 ||
  168. strcmp(argv[i], "--help") == 0)
  169. {
  170. usage();
  171. exit(EXIT_SUCCESS);
  172. }
  173. if (strcmp(argv[i], "-v") == 0 ||
  174. strcmp(argv[i], "--version") == 0)
  175. {
  176. fputs(PROGNAME " (" PACKAGE_NAME ") " PACKAGE_VERSION "\n", stderr);
  177. exit(EXIT_SUCCESS);
  178. }
  179. /* If the reading_input_filenames flag is set, and that the
  180. * argument does not match an option, we assume this may be
  181. * another filename */
  182. if (reading_input_filenames)
  183. {
  184. #ifdef STARPU_USE_FXT
  185. options->fxt_options.filenames[options->fxt_options.ninputfiles++] = argv[i];
  186. #endif
  187. continue;
  188. }
  189. }
  190. if (correct_usage == 0)
  191. {
  192. fprintf(stderr, "Incorrect usage, aborting\n");
  193. usage();
  194. exit(-1);
  195. }
  196. }
  197. static char *replace_char(char *str, char old, char new)
  198. {
  199. char *p = strdup(str);
  200. char *ptr = p;
  201. while (*ptr)
  202. {
  203. if (*ptr == old) *ptr = new;
  204. ptr ++;
  205. }
  206. return p;
  207. }
  208. static void print_comma(FILE *gnuplot_file, int *first)
  209. {
  210. if (*first)
  211. {
  212. *first = 0;
  213. }
  214. else
  215. {
  216. fprintf(gnuplot_file, ",\\\n\t");
  217. }
  218. }
  219. 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)
  220. {
  221. char arch_name[256];
  222. const char *factor;
  223. if (options->energy)
  224. factor = "";
  225. else
  226. factor = "0.001 * ";
  227. starpu_perfmodel_get_arch_name(arch, arch_name, 256, impl);
  228. #ifdef STARPU_USE_FXT
  229. if (options->with_fxt_file && impl == 0)
  230. {
  231. if (options->gflops)
  232. {
  233. _STARPU_DISP("gflops unit selected, ignoring fxt trace\n");
  234. }
  235. else
  236. {
  237. char *arch_name2 = replace_char(arch_name, '_', '-');
  238. print_comma(gnuplot_file, first);
  239. fprintf(gnuplot_file, "\"< grep '^%s' %s\" using 3:4 title \"Profiling %s\"", arch_name, options->data_file_name, arch_name2);
  240. free(arch_name2);
  241. }
  242. }
  243. #endif
  244. /* Only display the regression model if we could actually build a model */
  245. if (!options->gflops && arch_model->regression.valid && !arch_model->regression.nl_valid)
  246. {
  247. print_comma(gnuplot_file, first);
  248. fprintf(stderr, "\tLinear: y = alpha size ^ beta\n");
  249. fprintf(stderr, "\t\talpha = %e\n", arch_model->regression.alpha * 0.001);
  250. fprintf(stderr, "\t\tbeta = %e\n", arch_model->regression.beta);
  251. fprintf(gnuplot_file, "%s%g * x ** %g title \"Linear Regression %s\"", factor,
  252. arch_model->regression.alpha, arch_model->regression.beta, arch_name);
  253. }
  254. if (!options->gflops && arch_model->regression.nl_valid)
  255. {
  256. print_comma(gnuplot_file, first);
  257. fprintf(stderr, "\tNon-Linear: y = a size ^b + c\n");
  258. fprintf(stderr, "\t\ta = %e\n", arch_model->regression.a * 0.001);
  259. fprintf(stderr, "\t\tb = %e\n", arch_model->regression.b);
  260. fprintf(stderr, "\t\tc = %e\n", arch_model->regression.c * 0.001);
  261. fprintf(gnuplot_file, "%s%g * x ** %g + %s%g title \"Non-Linear Regression %s\"", factor,
  262. arch_model->regression.a, arch_model->regression.b, factor, arch_model->regression.c, arch_name);
  263. }
  264. }
  265. 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)
  266. {
  267. FILE *datafile;
  268. struct starpu_perfmodel_history_list *ptr;
  269. char arch_name[32];
  270. int col;
  271. unsigned long minimum = 0;
  272. datafile = fopen(options->avg_file_name, "w");
  273. col = 2;
  274. int i;
  275. for(i = 0; i < model->state->ncombs; i++)
  276. {
  277. int comb = model->state->combs[i];
  278. if (options->comb_is_set == 0 || options->comb == comb)
  279. {
  280. struct starpu_perfmodel_arch *arch;
  281. int impl;
  282. arch = starpu_perfmodel_arch_comb_fetch(comb);
  283. for(impl = 0; impl < model->state->nimpls[comb]; impl++)
  284. {
  285. struct starpu_perfmodel_per_arch *arch_model = &model->state->per_arch[comb][impl];
  286. starpu_perfmodel_get_arch_name(arch, arch_name, 32, impl);
  287. if (arch_model->list)
  288. {
  289. char *arch_name2 = replace_char(arch_name, '_', '-');
  290. print_comma(gnuplot_file, first);
  291. fprintf(gnuplot_file, "\"%s\" using 1:%d:%d with errorlines title \"Average %s\"", options->avg_file_name, col, col+1, arch_name2);
  292. col += 2;
  293. free(arch_name2);
  294. }
  295. }
  296. }
  297. }
  298. /* Dump entries in size order */
  299. while (1)
  300. {
  301. unsigned long last = minimum;
  302. minimum = ULONG_MAX;
  303. /* Get the next minimum */
  304. for(i = 0; i < model->state->ncombs; i++)
  305. {
  306. int comb = model->state->combs[i];
  307. if (options->comb_is_set == 0 || options->comb == comb)
  308. {
  309. int impl;
  310. for(impl = 0; impl < model->state->nimpls[comb]; impl++)
  311. {
  312. struct starpu_perfmodel_per_arch *arch_model = &model->state->per_arch[comb][impl];
  313. for (ptr = arch_model->list; ptr; ptr = ptr->next)
  314. {
  315. unsigned long size = ptr->entry->size;
  316. if (size > last && size < minimum)
  317. minimum = size;
  318. }
  319. }
  320. }
  321. }
  322. if (minimum == ULONG_MAX)
  323. break;
  324. fprintf(stderr, "%lu ", minimum);
  325. fprintf(datafile, "%-15lu ", minimum);
  326. /* Find that minimum */
  327. for(i = 0; i < model->state->ncombs; i++)
  328. {
  329. int comb = model->state->combs[i];
  330. if (options->comb_is_set == 0 || options->comb == comb)
  331. {
  332. int impl;
  333. for(impl = 0; impl < model->state->nimpls[comb]; impl++)
  334. {
  335. int found = 0;
  336. struct starpu_perfmodel_per_arch *arch_model = &model->state->per_arch[comb][impl];
  337. for (ptr = arch_model->list; ptr; ptr = ptr->next)
  338. {
  339. struct starpu_perfmodel_history_entry *entry = ptr->entry;
  340. if (entry->size == minimum)
  341. {
  342. if (options->energy_symbol)
  343. {
  344. /* Look for the same in the energy model */
  345. if (impl >= energy_model->state->nimpls[comb])
  346. /* Doesn't have measurements for this impl */
  347. break;
  348. struct starpu_perfmodel_per_arch *arch_model2 = &energy_model->state->per_arch[comb][impl];
  349. struct starpu_perfmodel_history_list *ptr2;
  350. for (ptr2 = arch_model2->list; ptr2; ptr2 = ptr2->next)
  351. {
  352. struct starpu_perfmodel_history_entry *entry2 = ptr2->entry;
  353. if (entry2->size == minimum)
  354. {
  355. /* Found the same size, can print */
  356. double rel_delta = sqrt(
  357. (entry2->deviation * entry2->deviation) / (entry2->mean * entry2->mean)
  358. + (entry->deviation * entry->deviation) / (entry->mean * entry->mean));
  359. if (options->gflops)
  360. fprintf(datafile, "\t%-15le\t%-15le", entry->flops / (entry->mean * 1000) / entry2->mean,
  361. entry->flops / (entry->mean * 1000) / entry2->mean * rel_delta);
  362. else
  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. }
  442. #endif
  443. static void display_selected_models(FILE *gnuplot_file, struct starpu_perfmodel *model, struct starpu_perfmodel *energy_model, struct _perfmodel_plot_options *options)
  444. {
  445. char *symbol = replace_char(options->symbol, '_', '-');
  446. fprintf(gnuplot_file, "#!/usr/bin/gnuplot -persist\n");
  447. fprintf(gnuplot_file, "\n");
  448. fprintf(gnuplot_file, "set term postscript eps enhanced color\n");
  449. fprintf(gnuplot_file, "set output \"starpu_%s%s.eps\"\n", options->energy_symbol?"power_":"", options->symbol);
  450. fprintf(gnuplot_file, "set title \"Model for codelet %s\"\n", symbol);
  451. fprintf(gnuplot_file, "set xlabel \"Total data size\"\n");
  452. if (options->gflops)
  453. if (options->energy_symbol)
  454. fprintf(gnuplot_file, "set ylabel \"GFlop/W\"\n");
  455. else if (options->energy)
  456. fprintf(gnuplot_file, "set ylabel \"GFlop/J\"\n");
  457. else
  458. fprintf(gnuplot_file, "set ylabel \"GFlop/s\"\n");
  459. else
  460. if (options->energy_symbol)
  461. fprintf(gnuplot_file, "set ylabel \"Power (W)\"\n");
  462. else if (options->energy)
  463. fprintf(gnuplot_file, "set ylabel \"Energy (J)\"\n");
  464. else
  465. fprintf(gnuplot_file, "set ylabel \"Time (ms)\"\n");
  466. fprintf(gnuplot_file, "\n");
  467. fprintf(gnuplot_file, "set key top left\n");
  468. fprintf(gnuplot_file, "set logscale x\n");
  469. fprintf(gnuplot_file, "set logscale y\n");
  470. fprintf(gnuplot_file, "\n");
  471. /* If no input data is given to gnuplot, we at least need to specify an
  472. * arbitrary range. */
  473. if (options->with_fxt_file == 0 || options->gflops)
  474. fprintf(gnuplot_file, "set xrange [1:10**9]\n\n");
  475. int first = 1;
  476. fprintf(gnuplot_file, "plot\t");
  477. /* display all or selected combinations */
  478. if (!options->energy_symbol)
  479. display_all_perf_models(gnuplot_file, model, &first, options);
  480. display_history_based_perf_models(gnuplot_file, model, energy_model, &first, options);
  481. free(symbol);
  482. }
  483. int main(int argc, char **argv)
  484. {
  485. int ret = 0;
  486. struct starpu_perfmodel model = { .type = STARPU_PERFMODEL_INVALID };
  487. struct starpu_perfmodel energy_model = { .type = STARPU_PERFMODEL_INVALID };
  488. char gnuplot_file_name[256];
  489. struct _perfmodel_plot_options options;
  490. char *directory = strdup("./");
  491. #if defined(_WIN32) && !defined(__CYGWIN__)
  492. WSADATA wsadata;
  493. WSAStartup(MAKEWORD(1,0), &wsadata);
  494. #endif
  495. parse_args(argc, argv, &options, &directory);
  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. snprintf(gnuplot_file_name, sizeof(gnuplot_file_name), "%s/starpu_power_%s.gp", directory, options.symbol);
  543. else
  544. snprintf(gnuplot_file_name, sizeof(gnuplot_file_name), "%s/starpu_%s.gp", directory, options.symbol);
  545. snprintf(options.avg_file_name, sizeof(options.avg_file_name), "%s/starpu_%s_avg.data", directory, options.symbol);
  546. FILE *gnuplot_file = fopen(gnuplot_file_name, "w+");
  547. STARPU_ASSERT_MSG(gnuplot_file, "Cannot create file <%s>\n", gnuplot_file_name);
  548. display_selected_models(gnuplot_file, &model, &energy_model, &options);
  549. fprintf(gnuplot_file,"\n");
  550. fclose(gnuplot_file);
  551. /* Retrieve the current mode of the gnuplot executable */
  552. struct stat sb;
  553. ret = stat(gnuplot_file_name, &sb);
  554. if (ret)
  555. {
  556. perror("stat");
  557. STARPU_ABORT();
  558. }
  559. /* Make the gnuplot scrit executable for the owner */
  560. ret = chmod(gnuplot_file_name, sb.st_mode|S_IXUSR);
  561. if (ret)
  562. {
  563. perror("chmod");
  564. STARPU_ABORT();
  565. }
  566. _STARPU_DISP("Gnuplot file <%s> generated\n", gnuplot_file_name);
  567. }
  568. }
  569. starpu_perfmodel_free_sampling();
  570. free(directory);
  571. return ret;
  572. }