builtin-stat.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236
  1. /*
  2. * builtin-stat.c
  3. *
  4. * Builtin stat command: Give a precise performance counters summary
  5. * overview about any workload, CPU or specific PID.
  6. *
  7. * Sample output:
  8. $ perf stat ./hackbench 10
  9. Time: 0.118
  10. Performance counter stats for './hackbench 10':
  11. 1708.761321 task-clock # 11.037 CPUs utilized
  12. 41,190 context-switches # 0.024 M/sec
  13. 6,735 CPU-migrations # 0.004 M/sec
  14. 17,318 page-faults # 0.010 M/sec
  15. 5,205,202,243 cycles # 3.046 GHz
  16. 3,856,436,920 stalled-cycles-frontend # 74.09% frontend cycles idle
  17. 1,600,790,871 stalled-cycles-backend # 30.75% backend cycles idle
  18. 2,603,501,247 instructions # 0.50 insns per cycle
  19. # 1.48 stalled cycles per insn
  20. 484,357,498 branches # 283.455 M/sec
  21. 6,388,934 branch-misses # 1.32% of all branches
  22. 0.154822978 seconds time elapsed
  23. *
  24. * Copyright (C) 2008-2011, Red Hat Inc, Ingo Molnar <mingo@redhat.com>
  25. *
  26. * Improvements and fixes by:
  27. *
  28. * Arjan van de Ven <arjan@linux.intel.com>
  29. * Yanmin Zhang <yanmin.zhang@intel.com>
  30. * Wu Fengguang <fengguang.wu@intel.com>
  31. * Mike Galbraith <efault@gmx.de>
  32. * Paul Mackerras <paulus@samba.org>
  33. * Jaswinder Singh Rajput <jaswinder@kernel.org>
  34. *
  35. * Released under the GPL v2. (and only v2, not any later version)
  36. */
  37. #include "perf.h"
  38. #include "builtin.h"
  39. #include "util/util.h"
  40. #include "util/parse-options.h"
  41. #include "util/parse-events.h"
  42. #include "util/event.h"
  43. #include "util/evlist.h"
  44. #include "util/evsel.h"
  45. #include "util/debug.h"
  46. #include "util/color.h"
  47. #include "util/header.h"
  48. #include "util/cpumap.h"
  49. #include "util/thread.h"
  50. #include "util/thread_map.h"
  51. #include <sys/prctl.h>
  52. #include <math.h>
  53. #include <locale.h>
  54. #define DEFAULT_SEPARATOR " "
  55. static struct perf_event_attr default_attrs[] = {
  56. { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_TASK_CLOCK },
  57. { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_CONTEXT_SWITCHES },
  58. { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_CPU_MIGRATIONS },
  59. { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_PAGE_FAULTS },
  60. { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_CPU_CYCLES },
  61. { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_STALLED_CYCLES_FRONTEND },
  62. { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_STALLED_CYCLES_BACKEND },
  63. { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_INSTRUCTIONS },
  64. { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS },
  65. { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_BRANCH_MISSES },
  66. };
  67. /*
  68. * Detailed stats (-d), covering the L1 and last level data caches:
  69. */
  70. static struct perf_event_attr detailed_attrs[] = {
  71. { .type = PERF_TYPE_HW_CACHE,
  72. .config =
  73. PERF_COUNT_HW_CACHE_L1D << 0 |
  74. (PERF_COUNT_HW_CACHE_OP_READ << 8) |
  75. (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) },
  76. { .type = PERF_TYPE_HW_CACHE,
  77. .config =
  78. PERF_COUNT_HW_CACHE_L1D << 0 |
  79. (PERF_COUNT_HW_CACHE_OP_READ << 8) |
  80. (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) },
  81. { .type = PERF_TYPE_HW_CACHE,
  82. .config =
  83. PERF_COUNT_HW_CACHE_LL << 0 |
  84. (PERF_COUNT_HW_CACHE_OP_READ << 8) |
  85. (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) },
  86. { .type = PERF_TYPE_HW_CACHE,
  87. .config =
  88. PERF_COUNT_HW_CACHE_LL << 0 |
  89. (PERF_COUNT_HW_CACHE_OP_READ << 8) |
  90. (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) },
  91. };
  92. /*
  93. * Very detailed stats (-d -d), covering the instruction cache and the TLB caches:
  94. */
  95. static struct perf_event_attr very_detailed_attrs[] = {
  96. { .type = PERF_TYPE_HW_CACHE,
  97. .config =
  98. PERF_COUNT_HW_CACHE_L1I << 0 |
  99. (PERF_COUNT_HW_CACHE_OP_READ << 8) |
  100. (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) },
  101. { .type = PERF_TYPE_HW_CACHE,
  102. .config =
  103. PERF_COUNT_HW_CACHE_L1I << 0 |
  104. (PERF_COUNT_HW_CACHE_OP_READ << 8) |
  105. (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) },
  106. { .type = PERF_TYPE_HW_CACHE,
  107. .config =
  108. PERF_COUNT_HW_CACHE_DTLB << 0 |
  109. (PERF_COUNT_HW_CACHE_OP_READ << 8) |
  110. (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) },
  111. { .type = PERF_TYPE_HW_CACHE,
  112. .config =
  113. PERF_COUNT_HW_CACHE_DTLB << 0 |
  114. (PERF_COUNT_HW_CACHE_OP_READ << 8) |
  115. (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) },
  116. { .type = PERF_TYPE_HW_CACHE,
  117. .config =
  118. PERF_COUNT_HW_CACHE_ITLB << 0 |
  119. (PERF_COUNT_HW_CACHE_OP_READ << 8) |
  120. (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) },
  121. { .type = PERF_TYPE_HW_CACHE,
  122. .config =
  123. PERF_COUNT_HW_CACHE_ITLB << 0 |
  124. (PERF_COUNT_HW_CACHE_OP_READ << 8) |
  125. (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) },
  126. };
  127. /*
  128. * Very, very detailed stats (-d -d -d), adding prefetch events:
  129. */
  130. static struct perf_event_attr very_very_detailed_attrs[] = {
  131. { .type = PERF_TYPE_HW_CACHE,
  132. .config =
  133. PERF_COUNT_HW_CACHE_L1D << 0 |
  134. (PERF_COUNT_HW_CACHE_OP_PREFETCH << 8) |
  135. (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) },
  136. { .type = PERF_TYPE_HW_CACHE,
  137. .config =
  138. PERF_COUNT_HW_CACHE_L1D << 0 |
  139. (PERF_COUNT_HW_CACHE_OP_PREFETCH << 8) |
  140. (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) },
  141. };
  142. struct perf_evlist *evsel_list;
  143. static bool system_wide = false;
  144. static int run_idx = 0;
  145. static int run_count = 1;
  146. static bool no_inherit = false;
  147. static bool scale = true;
  148. static bool no_aggr = false;
  149. static pid_t target_pid = -1;
  150. static pid_t target_tid = -1;
  151. static pid_t child_pid = -1;
  152. static bool null_run = false;
  153. static int detailed_run = 0;
  154. static bool sync_run = false;
  155. static bool big_num = true;
  156. static int big_num_opt = -1;
  157. static const char *cpu_list;
  158. static const char *csv_sep = NULL;
  159. static bool csv_output = false;
  160. static volatile int done = 0;
  161. struct stats
  162. {
  163. double n, mean, M2;
  164. };
  165. struct perf_stat {
  166. struct stats res_stats[3];
  167. };
  168. static int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel)
  169. {
  170. evsel->priv = zalloc(sizeof(struct perf_stat));
  171. return evsel->priv == NULL ? -ENOMEM : 0;
  172. }
  173. static void perf_evsel__free_stat_priv(struct perf_evsel *evsel)
  174. {
  175. free(evsel->priv);
  176. evsel->priv = NULL;
  177. }
  178. static void update_stats(struct stats *stats, u64 val)
  179. {
  180. double delta;
  181. stats->n++;
  182. delta = val - stats->mean;
  183. stats->mean += delta / stats->n;
  184. stats->M2 += delta*(val - stats->mean);
  185. }
  186. static double avg_stats(struct stats *stats)
  187. {
  188. return stats->mean;
  189. }
  190. /*
  191. * http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
  192. *
  193. * (\Sum n_i^2) - ((\Sum n_i)^2)/n
  194. * s^2 = -------------------------------
  195. * n - 1
  196. *
  197. * http://en.wikipedia.org/wiki/Stddev
  198. *
  199. * The std dev of the mean is related to the std dev by:
  200. *
  201. * s
  202. * s_mean = -------
  203. * sqrt(n)
  204. *
  205. */
  206. static double stddev_stats(struct stats *stats)
  207. {
  208. double variance = stats->M2 / (stats->n - 1);
  209. double variance_mean = variance / stats->n;
  210. return sqrt(variance_mean);
  211. }
  212. struct stats runtime_nsecs_stats[MAX_NR_CPUS];
  213. struct stats runtime_cycles_stats[MAX_NR_CPUS];
  214. struct stats runtime_stalled_cycles_front_stats[MAX_NR_CPUS];
  215. struct stats runtime_stalled_cycles_back_stats[MAX_NR_CPUS];
  216. struct stats runtime_branches_stats[MAX_NR_CPUS];
  217. struct stats runtime_cacherefs_stats[MAX_NR_CPUS];
  218. struct stats runtime_l1_dcache_stats[MAX_NR_CPUS];
  219. struct stats runtime_l1_icache_stats[MAX_NR_CPUS];
  220. struct stats runtime_ll_cache_stats[MAX_NR_CPUS];
  221. struct stats runtime_itlb_cache_stats[MAX_NR_CPUS];
  222. struct stats runtime_dtlb_cache_stats[MAX_NR_CPUS];
  223. struct stats walltime_nsecs_stats;
  224. static int create_perf_stat_counter(struct perf_evsel *evsel)
  225. {
  226. struct perf_event_attr *attr = &evsel->attr;
  227. if (scale)
  228. attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
  229. PERF_FORMAT_TOTAL_TIME_RUNNING;
  230. attr->inherit = !no_inherit;
  231. if (system_wide)
  232. return perf_evsel__open_per_cpu(evsel, evsel_list->cpus, false);
  233. if (target_pid == -1 && target_tid == -1) {
  234. attr->disabled = 1;
  235. attr->enable_on_exec = 1;
  236. }
  237. return perf_evsel__open_per_thread(evsel, evsel_list->threads, false);
  238. }
  239. /*
  240. * Does the counter have nsecs as a unit?
  241. */
  242. static inline int nsec_counter(struct perf_evsel *evsel)
  243. {
  244. if (perf_evsel__match(evsel, SOFTWARE, SW_CPU_CLOCK) ||
  245. perf_evsel__match(evsel, SOFTWARE, SW_TASK_CLOCK))
  246. return 1;
  247. return 0;
  248. }
  249. /*
  250. * Update various tracking values we maintain to print
  251. * more semantic information such as miss/hit ratios,
  252. * instruction rates, etc:
  253. */
  254. static void update_shadow_stats(struct perf_evsel *counter, u64 *count)
  255. {
  256. if (perf_evsel__match(counter, SOFTWARE, SW_TASK_CLOCK))
  257. update_stats(&runtime_nsecs_stats[0], count[0]);
  258. else if (perf_evsel__match(counter, HARDWARE, HW_CPU_CYCLES))
  259. update_stats(&runtime_cycles_stats[0], count[0]);
  260. else if (perf_evsel__match(counter, HARDWARE, HW_STALLED_CYCLES_FRONTEND))
  261. update_stats(&runtime_stalled_cycles_front_stats[0], count[0]);
  262. else if (perf_evsel__match(counter, HARDWARE, HW_STALLED_CYCLES_BACKEND))
  263. update_stats(&runtime_stalled_cycles_back_stats[0], count[0]);
  264. else if (perf_evsel__match(counter, HARDWARE, HW_BRANCH_INSTRUCTIONS))
  265. update_stats(&runtime_branches_stats[0], count[0]);
  266. else if (perf_evsel__match(counter, HARDWARE, HW_CACHE_REFERENCES))
  267. update_stats(&runtime_cacherefs_stats[0], count[0]);
  268. else if (perf_evsel__match(counter, HW_CACHE, HW_CACHE_L1D))
  269. update_stats(&runtime_l1_dcache_stats[0], count[0]);
  270. else if (perf_evsel__match(counter, HW_CACHE, HW_CACHE_L1I))
  271. update_stats(&runtime_l1_icache_stats[0], count[0]);
  272. else if (perf_evsel__match(counter, HW_CACHE, HW_CACHE_LL))
  273. update_stats(&runtime_ll_cache_stats[0], count[0]);
  274. else if (perf_evsel__match(counter, HW_CACHE, HW_CACHE_DTLB))
  275. update_stats(&runtime_dtlb_cache_stats[0], count[0]);
  276. else if (perf_evsel__match(counter, HW_CACHE, HW_CACHE_ITLB))
  277. update_stats(&runtime_itlb_cache_stats[0], count[0]);
  278. }
  279. /*
  280. * Read out the results of a single counter:
  281. * aggregate counts across CPUs in system-wide mode
  282. */
  283. static int read_counter_aggr(struct perf_evsel *counter)
  284. {
  285. struct perf_stat *ps = counter->priv;
  286. u64 *count = counter->counts->aggr.values;
  287. int i;
  288. if (__perf_evsel__read(counter, evsel_list->cpus->nr,
  289. evsel_list->threads->nr, scale) < 0)
  290. return -1;
  291. for (i = 0; i < 3; i++)
  292. update_stats(&ps->res_stats[i], count[i]);
  293. if (verbose) {
  294. fprintf(stderr, "%s: %" PRIu64 " %" PRIu64 " %" PRIu64 "\n",
  295. event_name(counter), count[0], count[1], count[2]);
  296. }
  297. /*
  298. * Save the full runtime - to allow normalization during printout:
  299. */
  300. update_shadow_stats(counter, count);
  301. return 0;
  302. }
  303. /*
  304. * Read out the results of a single counter:
  305. * do not aggregate counts across CPUs in system-wide mode
  306. */
  307. static int read_counter(struct perf_evsel *counter)
  308. {
  309. u64 *count;
  310. int cpu;
  311. for (cpu = 0; cpu < evsel_list->cpus->nr; cpu++) {
  312. if (__perf_evsel__read_on_cpu(counter, cpu, 0, scale) < 0)
  313. return -1;
  314. count = counter->counts->cpu[cpu].values;
  315. update_shadow_stats(counter, count);
  316. }
  317. return 0;
  318. }
  319. static int run_perf_stat(int argc __used, const char **argv)
  320. {
  321. unsigned long long t0, t1;
  322. struct perf_evsel *counter;
  323. int status = 0;
  324. int child_ready_pipe[2], go_pipe[2];
  325. const bool forks = (argc > 0);
  326. char buf;
  327. if (forks && (pipe(child_ready_pipe) < 0 || pipe(go_pipe) < 0)) {
  328. perror("failed to create pipes");
  329. exit(1);
  330. }
  331. if (forks) {
  332. if ((child_pid = fork()) < 0)
  333. perror("failed to fork");
  334. if (!child_pid) {
  335. close(child_ready_pipe[0]);
  336. close(go_pipe[1]);
  337. fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC);
  338. /*
  339. * Do a dummy execvp to get the PLT entry resolved,
  340. * so we avoid the resolver overhead on the real
  341. * execvp call.
  342. */
  343. execvp("", (char **)argv);
  344. /*
  345. * Tell the parent we're ready to go
  346. */
  347. close(child_ready_pipe[1]);
  348. /*
  349. * Wait until the parent tells us to go.
  350. */
  351. if (read(go_pipe[0], &buf, 1) == -1)
  352. perror("unable to read pipe");
  353. execvp(argv[0], (char **)argv);
  354. perror(argv[0]);
  355. exit(-1);
  356. }
  357. if (target_tid == -1 && target_pid == -1 && !system_wide)
  358. evsel_list->threads->map[0] = child_pid;
  359. /*
  360. * Wait for the child to be ready to exec.
  361. */
  362. close(child_ready_pipe[1]);
  363. close(go_pipe[0]);
  364. if (read(child_ready_pipe[0], &buf, 1) == -1)
  365. perror("unable to read pipe");
  366. close(child_ready_pipe[0]);
  367. }
  368. list_for_each_entry(counter, &evsel_list->entries, node) {
  369. if (create_perf_stat_counter(counter) < 0) {
  370. if (errno == EINVAL || errno == ENOSYS || errno == ENOENT) {
  371. if (verbose)
  372. ui__warning("%s event is not supported by the kernel.\n",
  373. event_name(counter));
  374. continue;
  375. }
  376. if (errno == EPERM || errno == EACCES) {
  377. error("You may not have permission to collect %sstats.\n"
  378. "\t Consider tweaking"
  379. " /proc/sys/kernel/perf_event_paranoid or running as root.",
  380. system_wide ? "system-wide " : "");
  381. } else {
  382. error("open_counter returned with %d (%s). "
  383. "/bin/dmesg may provide additional information.\n",
  384. errno, strerror(errno));
  385. }
  386. if (child_pid != -1)
  387. kill(child_pid, SIGTERM);
  388. die("Not all events could be opened.\n");
  389. return -1;
  390. }
  391. }
  392. if (perf_evlist__set_filters(evsel_list)) {
  393. error("failed to set filter with %d (%s)\n", errno,
  394. strerror(errno));
  395. return -1;
  396. }
  397. /*
  398. * Enable counters and exec the command:
  399. */
  400. t0 = rdclock();
  401. if (forks) {
  402. close(go_pipe[1]);
  403. wait(&status);
  404. } else {
  405. while(!done) sleep(1);
  406. }
  407. t1 = rdclock();
  408. update_stats(&walltime_nsecs_stats, t1 - t0);
  409. if (no_aggr) {
  410. list_for_each_entry(counter, &evsel_list->entries, node) {
  411. read_counter(counter);
  412. perf_evsel__close_fd(counter, evsel_list->cpus->nr, 1);
  413. }
  414. } else {
  415. list_for_each_entry(counter, &evsel_list->entries, node) {
  416. read_counter_aggr(counter);
  417. perf_evsel__close_fd(counter, evsel_list->cpus->nr,
  418. evsel_list->threads->nr);
  419. }
  420. }
  421. return WEXITSTATUS(status);
  422. }
  423. static void print_noise_pct(double total, double avg)
  424. {
  425. double pct = 0.0;
  426. if (avg)
  427. pct = 100.0*total/avg;
  428. fprintf(stderr, " ( +-%6.2f%% )", pct);
  429. }
  430. static void print_noise(struct perf_evsel *evsel, double avg)
  431. {
  432. struct perf_stat *ps;
  433. if (run_count == 1)
  434. return;
  435. ps = evsel->priv;
  436. print_noise_pct(stddev_stats(&ps->res_stats[0]), avg);
  437. }
  438. static void nsec_printout(int cpu, struct perf_evsel *evsel, double avg)
  439. {
  440. double msecs = avg / 1e6;
  441. char cpustr[16] = { '\0', };
  442. const char *fmt = csv_output ? "%s%.6f%s%s" : "%s%18.6f%s%-25s";
  443. if (no_aggr)
  444. sprintf(cpustr, "CPU%*d%s",
  445. csv_output ? 0 : -4,
  446. evsel_list->cpus->map[cpu], csv_sep);
  447. fprintf(stderr, fmt, cpustr, msecs, csv_sep, event_name(evsel));
  448. if (evsel->cgrp)
  449. fprintf(stderr, "%s%s", csv_sep, evsel->cgrp->name);
  450. if (csv_output)
  451. return;
  452. if (perf_evsel__match(evsel, SOFTWARE, SW_TASK_CLOCK))
  453. fprintf(stderr, " # %8.3f CPUs utilized ", avg / avg_stats(&walltime_nsecs_stats));
  454. }
  455. static void print_stalled_cycles_frontend(int cpu, struct perf_evsel *evsel __used, double avg)
  456. {
  457. double total, ratio = 0.0;
  458. const char *color;
  459. total = avg_stats(&runtime_cycles_stats[cpu]);
  460. if (total)
  461. ratio = avg / total * 100.0;
  462. color = PERF_COLOR_NORMAL;
  463. if (ratio > 50.0)
  464. color = PERF_COLOR_RED;
  465. else if (ratio > 30.0)
  466. color = PERF_COLOR_MAGENTA;
  467. else if (ratio > 10.0)
  468. color = PERF_COLOR_YELLOW;
  469. fprintf(stderr, " # ");
  470. color_fprintf(stderr, color, "%6.2f%%", ratio);
  471. fprintf(stderr, " frontend cycles idle ");
  472. }
  473. static void print_stalled_cycles_backend(int cpu, struct perf_evsel *evsel __used, double avg)
  474. {
  475. double total, ratio = 0.0;
  476. const char *color;
  477. total = avg_stats(&runtime_cycles_stats[cpu]);
  478. if (total)
  479. ratio = avg / total * 100.0;
  480. color = PERF_COLOR_NORMAL;
  481. if (ratio > 75.0)
  482. color = PERF_COLOR_RED;
  483. else if (ratio > 50.0)
  484. color = PERF_COLOR_MAGENTA;
  485. else if (ratio > 20.0)
  486. color = PERF_COLOR_YELLOW;
  487. fprintf(stderr, " # ");
  488. color_fprintf(stderr, color, "%6.2f%%", ratio);
  489. fprintf(stderr, " backend cycles idle ");
  490. }
  491. static void print_branch_misses(int cpu, struct perf_evsel *evsel __used, double avg)
  492. {
  493. double total, ratio = 0.0;
  494. const char *color;
  495. total = avg_stats(&runtime_branches_stats[cpu]);
  496. if (total)
  497. ratio = avg / total * 100.0;
  498. color = PERF_COLOR_NORMAL;
  499. if (ratio > 20.0)
  500. color = PERF_COLOR_RED;
  501. else if (ratio > 10.0)
  502. color = PERF_COLOR_MAGENTA;
  503. else if (ratio > 5.0)
  504. color = PERF_COLOR_YELLOW;
  505. fprintf(stderr, " # ");
  506. color_fprintf(stderr, color, "%6.2f%%", ratio);
  507. fprintf(stderr, " of all branches ");
  508. }
  509. static void print_l1_dcache_misses(int cpu, struct perf_evsel *evsel __used, double avg)
  510. {
  511. double total, ratio = 0.0;
  512. const char *color;
  513. total = avg_stats(&runtime_l1_dcache_stats[cpu]);
  514. if (total)
  515. ratio = avg / total * 100.0;
  516. color = PERF_COLOR_NORMAL;
  517. if (ratio > 20.0)
  518. color = PERF_COLOR_RED;
  519. else if (ratio > 10.0)
  520. color = PERF_COLOR_MAGENTA;
  521. else if (ratio > 5.0)
  522. color = PERF_COLOR_YELLOW;
  523. fprintf(stderr, " # ");
  524. color_fprintf(stderr, color, "%6.2f%%", ratio);
  525. fprintf(stderr, " of all L1-dcache hits ");
  526. }
  527. static void print_l1_icache_misses(int cpu, struct perf_evsel *evsel __used, double avg)
  528. {
  529. double total, ratio = 0.0;
  530. const char *color;
  531. total = avg_stats(&runtime_l1_icache_stats[cpu]);
  532. if (total)
  533. ratio = avg / total * 100.0;
  534. color = PERF_COLOR_NORMAL;
  535. if (ratio > 20.0)
  536. color = PERF_COLOR_RED;
  537. else if (ratio > 10.0)
  538. color = PERF_COLOR_MAGENTA;
  539. else if (ratio > 5.0)
  540. color = PERF_COLOR_YELLOW;
  541. fprintf(stderr, " # ");
  542. color_fprintf(stderr, color, "%6.2f%%", ratio);
  543. fprintf(stderr, " of all L1-icache hits ");
  544. }
  545. static void print_dtlb_cache_misses(int cpu, struct perf_evsel *evsel __used, double avg)
  546. {
  547. double total, ratio = 0.0;
  548. const char *color;
  549. total = avg_stats(&runtime_dtlb_cache_stats[cpu]);
  550. if (total)
  551. ratio = avg / total * 100.0;
  552. color = PERF_COLOR_NORMAL;
  553. if (ratio > 20.0)
  554. color = PERF_COLOR_RED;
  555. else if (ratio > 10.0)
  556. color = PERF_COLOR_MAGENTA;
  557. else if (ratio > 5.0)
  558. color = PERF_COLOR_YELLOW;
  559. fprintf(stderr, " # ");
  560. color_fprintf(stderr, color, "%6.2f%%", ratio);
  561. fprintf(stderr, " of all dTLB cache hits ");
  562. }
  563. static void print_itlb_cache_misses(int cpu, struct perf_evsel *evsel __used, double avg)
  564. {
  565. double total, ratio = 0.0;
  566. const char *color;
  567. total = avg_stats(&runtime_itlb_cache_stats[cpu]);
  568. if (total)
  569. ratio = avg / total * 100.0;
  570. color = PERF_COLOR_NORMAL;
  571. if (ratio > 20.0)
  572. color = PERF_COLOR_RED;
  573. else if (ratio > 10.0)
  574. color = PERF_COLOR_MAGENTA;
  575. else if (ratio > 5.0)
  576. color = PERF_COLOR_YELLOW;
  577. fprintf(stderr, " # ");
  578. color_fprintf(stderr, color, "%6.2f%%", ratio);
  579. fprintf(stderr, " of all iTLB cache hits ");
  580. }
  581. static void print_ll_cache_misses(int cpu, struct perf_evsel *evsel __used, double avg)
  582. {
  583. double total, ratio = 0.0;
  584. const char *color;
  585. total = avg_stats(&runtime_ll_cache_stats[cpu]);
  586. if (total)
  587. ratio = avg / total * 100.0;
  588. color = PERF_COLOR_NORMAL;
  589. if (ratio > 20.0)
  590. color = PERF_COLOR_RED;
  591. else if (ratio > 10.0)
  592. color = PERF_COLOR_MAGENTA;
  593. else if (ratio > 5.0)
  594. color = PERF_COLOR_YELLOW;
  595. fprintf(stderr, " # ");
  596. color_fprintf(stderr, color, "%6.2f%%", ratio);
  597. fprintf(stderr, " of all LL-cache hits ");
  598. }
  599. static void abs_printout(int cpu, struct perf_evsel *evsel, double avg)
  600. {
  601. double total, ratio = 0.0;
  602. char cpustr[16] = { '\0', };
  603. const char *fmt;
  604. if (csv_output)
  605. fmt = "%s%.0f%s%s";
  606. else if (big_num)
  607. fmt = "%s%'18.0f%s%-25s";
  608. else
  609. fmt = "%s%18.0f%s%-25s";
  610. if (no_aggr)
  611. sprintf(cpustr, "CPU%*d%s",
  612. csv_output ? 0 : -4,
  613. evsel_list->cpus->map[cpu], csv_sep);
  614. else
  615. cpu = 0;
  616. fprintf(stderr, fmt, cpustr, avg, csv_sep, event_name(evsel));
  617. if (evsel->cgrp)
  618. fprintf(stderr, "%s%s", csv_sep, evsel->cgrp->name);
  619. if (csv_output)
  620. return;
  621. if (perf_evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS)) {
  622. total = avg_stats(&runtime_cycles_stats[cpu]);
  623. if (total)
  624. ratio = avg / total;
  625. fprintf(stderr, " # %5.2f insns per cycle ", ratio);
  626. total = avg_stats(&runtime_stalled_cycles_front_stats[cpu]);
  627. total = max(total, avg_stats(&runtime_stalled_cycles_back_stats[cpu]));
  628. if (total && avg) {
  629. ratio = total / avg;
  630. fprintf(stderr, "\n # %5.2f stalled cycles per insn", ratio);
  631. }
  632. } else if (perf_evsel__match(evsel, HARDWARE, HW_BRANCH_MISSES) &&
  633. runtime_branches_stats[cpu].n != 0) {
  634. print_branch_misses(cpu, evsel, avg);
  635. } else if (
  636. evsel->attr.type == PERF_TYPE_HW_CACHE &&
  637. evsel->attr.config == ( PERF_COUNT_HW_CACHE_L1D |
  638. ((PERF_COUNT_HW_CACHE_OP_READ) << 8) |
  639. ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16)) &&
  640. runtime_l1_dcache_stats[cpu].n != 0) {
  641. print_l1_dcache_misses(cpu, evsel, avg);
  642. } else if (
  643. evsel->attr.type == PERF_TYPE_HW_CACHE &&
  644. evsel->attr.config == ( PERF_COUNT_HW_CACHE_L1I |
  645. ((PERF_COUNT_HW_CACHE_OP_READ) << 8) |
  646. ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16)) &&
  647. runtime_l1_icache_stats[cpu].n != 0) {
  648. print_l1_icache_misses(cpu, evsel, avg);
  649. } else if (
  650. evsel->attr.type == PERF_TYPE_HW_CACHE &&
  651. evsel->attr.config == ( PERF_COUNT_HW_CACHE_DTLB |
  652. ((PERF_COUNT_HW_CACHE_OP_READ) << 8) |
  653. ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16)) &&
  654. runtime_dtlb_cache_stats[cpu].n != 0) {
  655. print_dtlb_cache_misses(cpu, evsel, avg);
  656. } else if (
  657. evsel->attr.type == PERF_TYPE_HW_CACHE &&
  658. evsel->attr.config == ( PERF_COUNT_HW_CACHE_ITLB |
  659. ((PERF_COUNT_HW_CACHE_OP_READ) << 8) |
  660. ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16)) &&
  661. runtime_itlb_cache_stats[cpu].n != 0) {
  662. print_itlb_cache_misses(cpu, evsel, avg);
  663. } else if (
  664. evsel->attr.type == PERF_TYPE_HW_CACHE &&
  665. evsel->attr.config == ( PERF_COUNT_HW_CACHE_LL |
  666. ((PERF_COUNT_HW_CACHE_OP_READ) << 8) |
  667. ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16)) &&
  668. runtime_ll_cache_stats[cpu].n != 0) {
  669. print_ll_cache_misses(cpu, evsel, avg);
  670. } else if (perf_evsel__match(evsel, HARDWARE, HW_CACHE_MISSES) &&
  671. runtime_cacherefs_stats[cpu].n != 0) {
  672. total = avg_stats(&runtime_cacherefs_stats[cpu]);
  673. if (total)
  674. ratio = avg * 100 / total;
  675. fprintf(stderr, " # %8.3f %% of all cache refs ", ratio);
  676. } else if (perf_evsel__match(evsel, HARDWARE, HW_STALLED_CYCLES_FRONTEND)) {
  677. print_stalled_cycles_frontend(cpu, evsel, avg);
  678. } else if (perf_evsel__match(evsel, HARDWARE, HW_STALLED_CYCLES_BACKEND)) {
  679. print_stalled_cycles_backend(cpu, evsel, avg);
  680. } else if (perf_evsel__match(evsel, HARDWARE, HW_CPU_CYCLES)) {
  681. total = avg_stats(&runtime_nsecs_stats[cpu]);
  682. if (total)
  683. ratio = 1.0 * avg / total;
  684. fprintf(stderr, " # %8.3f GHz ", ratio);
  685. } else if (runtime_nsecs_stats[cpu].n != 0) {
  686. total = avg_stats(&runtime_nsecs_stats[cpu]);
  687. if (total)
  688. ratio = 1000.0 * avg / total;
  689. fprintf(stderr, " # %8.3f M/sec ", ratio);
  690. } else {
  691. fprintf(stderr, " ");
  692. }
  693. }
  694. /*
  695. * Print out the results of a single counter:
  696. * aggregated counts in system-wide mode
  697. */
  698. static void print_counter_aggr(struct perf_evsel *counter)
  699. {
  700. struct perf_stat *ps = counter->priv;
  701. double avg = avg_stats(&ps->res_stats[0]);
  702. int scaled = counter->counts->scaled;
  703. if (scaled == -1) {
  704. fprintf(stderr, "%*s%s%*s",
  705. csv_output ? 0 : 18,
  706. "<not counted>",
  707. csv_sep,
  708. csv_output ? 0 : -24,
  709. event_name(counter));
  710. if (counter->cgrp)
  711. fprintf(stderr, "%s%s", csv_sep, counter->cgrp->name);
  712. fputc('\n', stderr);
  713. return;
  714. }
  715. if (nsec_counter(counter))
  716. nsec_printout(-1, counter, avg);
  717. else
  718. abs_printout(-1, counter, avg);
  719. if (csv_output) {
  720. fputc('\n', stderr);
  721. return;
  722. }
  723. print_noise(counter, avg);
  724. if (scaled) {
  725. double avg_enabled, avg_running;
  726. avg_enabled = avg_stats(&ps->res_stats[1]);
  727. avg_running = avg_stats(&ps->res_stats[2]);
  728. fprintf(stderr, " [%5.2f%%]", 100 * avg_running / avg_enabled);
  729. }
  730. fprintf(stderr, "\n");
  731. }
  732. /*
  733. * Print out the results of a single counter:
  734. * does not use aggregated count in system-wide
  735. */
  736. static void print_counter(struct perf_evsel *counter)
  737. {
  738. u64 ena, run, val;
  739. int cpu;
  740. for (cpu = 0; cpu < evsel_list->cpus->nr; cpu++) {
  741. val = counter->counts->cpu[cpu].val;
  742. ena = counter->counts->cpu[cpu].ena;
  743. run = counter->counts->cpu[cpu].run;
  744. if (run == 0 || ena == 0) {
  745. fprintf(stderr, "CPU%*d%s%*s%s%*s",
  746. csv_output ? 0 : -4,
  747. evsel_list->cpus->map[cpu], csv_sep,
  748. csv_output ? 0 : 18,
  749. "<not counted>", csv_sep,
  750. csv_output ? 0 : -24,
  751. event_name(counter));
  752. if (counter->cgrp)
  753. fprintf(stderr, "%s%s", csv_sep, counter->cgrp->name);
  754. fputc('\n', stderr);
  755. continue;
  756. }
  757. if (nsec_counter(counter))
  758. nsec_printout(cpu, counter, val);
  759. else
  760. abs_printout(cpu, counter, val);
  761. if (!csv_output) {
  762. print_noise(counter, 1.0);
  763. if (run != ena)
  764. fprintf(stderr, " (%.2f%%)", 100.0 * run / ena);
  765. }
  766. fputc('\n', stderr);
  767. }
  768. }
  769. static void print_stat(int argc, const char **argv)
  770. {
  771. struct perf_evsel *counter;
  772. int i;
  773. fflush(stdout);
  774. if (!csv_output) {
  775. fprintf(stderr, "\n");
  776. fprintf(stderr, " Performance counter stats for ");
  777. if(target_pid == -1 && target_tid == -1) {
  778. fprintf(stderr, "\'%s", argv[0]);
  779. for (i = 1; i < argc; i++)
  780. fprintf(stderr, " %s", argv[i]);
  781. } else if (target_pid != -1)
  782. fprintf(stderr, "process id \'%d", target_pid);
  783. else
  784. fprintf(stderr, "thread id \'%d", target_tid);
  785. fprintf(stderr, "\'");
  786. if (run_count > 1)
  787. fprintf(stderr, " (%d runs)", run_count);
  788. fprintf(stderr, ":\n\n");
  789. }
  790. if (no_aggr) {
  791. list_for_each_entry(counter, &evsel_list->entries, node)
  792. print_counter(counter);
  793. } else {
  794. list_for_each_entry(counter, &evsel_list->entries, node)
  795. print_counter_aggr(counter);
  796. }
  797. if (!csv_output) {
  798. if (!null_run)
  799. fprintf(stderr, "\n");
  800. fprintf(stderr, " %17.9f seconds time elapsed",
  801. avg_stats(&walltime_nsecs_stats)/1e9);
  802. if (run_count > 1) {
  803. fprintf(stderr, " ");
  804. print_noise_pct(stddev_stats(&walltime_nsecs_stats),
  805. avg_stats(&walltime_nsecs_stats));
  806. }
  807. fprintf(stderr, "\n\n");
  808. }
  809. }
  810. static volatile int signr = -1;
  811. static void skip_signal(int signo)
  812. {
  813. if(child_pid == -1)
  814. done = 1;
  815. signr = signo;
  816. }
  817. static void sig_atexit(void)
  818. {
  819. if (child_pid != -1)
  820. kill(child_pid, SIGTERM);
  821. if (signr == -1)
  822. return;
  823. signal(signr, SIG_DFL);
  824. kill(getpid(), signr);
  825. }
  826. static const char * const stat_usage[] = {
  827. "perf stat [<options>] [<command>]",
  828. NULL
  829. };
  830. static int stat__set_big_num(const struct option *opt __used,
  831. const char *s __used, int unset)
  832. {
  833. big_num_opt = unset ? 0 : 1;
  834. return 0;
  835. }
  836. static const struct option options[] = {
  837. OPT_CALLBACK('e', "event", &evsel_list, "event",
  838. "event selector. use 'perf list' to list available events",
  839. parse_events),
  840. OPT_CALLBACK(0, "filter", &evsel_list, "filter",
  841. "event filter", parse_filter),
  842. OPT_BOOLEAN('i', "no-inherit", &no_inherit,
  843. "child tasks do not inherit counters"),
  844. OPT_INTEGER('p', "pid", &target_pid,
  845. "stat events on existing process id"),
  846. OPT_INTEGER('t', "tid", &target_tid,
  847. "stat events on existing thread id"),
  848. OPT_BOOLEAN('a', "all-cpus", &system_wide,
  849. "system-wide collection from all CPUs"),
  850. OPT_BOOLEAN('c', "scale", &scale,
  851. "scale/normalize counters"),
  852. OPT_INCR('v', "verbose", &verbose,
  853. "be more verbose (show counter open errors, etc)"),
  854. OPT_INTEGER('r', "repeat", &run_count,
  855. "repeat command and print average + stddev (max: 100)"),
  856. OPT_BOOLEAN('n', "null", &null_run,
  857. "null run - dont start any counters"),
  858. OPT_INCR('d', "detailed", &detailed_run,
  859. "detailed run - start a lot of events"),
  860. OPT_BOOLEAN('S', "sync", &sync_run,
  861. "call sync() before starting a run"),
  862. OPT_CALLBACK_NOOPT('B', "big-num", NULL, NULL,
  863. "print large numbers with thousands\' separators",
  864. stat__set_big_num),
  865. OPT_STRING('C', "cpu", &cpu_list, "cpu",
  866. "list of cpus to monitor in system-wide"),
  867. OPT_BOOLEAN('A', "no-aggr", &no_aggr,
  868. "disable CPU count aggregation"),
  869. OPT_STRING('x', "field-separator", &csv_sep, "separator",
  870. "print counts with custom separator"),
  871. OPT_CALLBACK('G', "cgroup", &evsel_list, "name",
  872. "monitor event in cgroup name only",
  873. parse_cgroups),
  874. OPT_END()
  875. };
  876. /*
  877. * Add default attributes, if there were no attributes specified or
  878. * if -d/--detailed, -d -d or -d -d -d is used:
  879. */
  880. static int add_default_attributes(void)
  881. {
  882. struct perf_evsel *pos;
  883. size_t attr_nr = 0;
  884. size_t c;
  885. /* Set attrs if no event is selected and !null_run: */
  886. if (null_run)
  887. return 0;
  888. if (!evsel_list->nr_entries) {
  889. for (c = 0; c < ARRAY_SIZE(default_attrs); c++) {
  890. pos = perf_evsel__new(default_attrs + c, c + attr_nr);
  891. if (pos == NULL)
  892. return -1;
  893. perf_evlist__add(evsel_list, pos);
  894. }
  895. attr_nr += c;
  896. }
  897. /* Detailed events get appended to the event list: */
  898. if (detailed_run < 1)
  899. return 0;
  900. /* Append detailed run extra attributes: */
  901. for (c = 0; c < ARRAY_SIZE(detailed_attrs); c++) {
  902. pos = perf_evsel__new(detailed_attrs + c, c + attr_nr);
  903. if (pos == NULL)
  904. return -1;
  905. perf_evlist__add(evsel_list, pos);
  906. }
  907. attr_nr += c;
  908. if (detailed_run < 2)
  909. return 0;
  910. /* Append very detailed run extra attributes: */
  911. for (c = 0; c < ARRAY_SIZE(very_detailed_attrs); c++) {
  912. pos = perf_evsel__new(very_detailed_attrs + c, c + attr_nr);
  913. if (pos == NULL)
  914. return -1;
  915. perf_evlist__add(evsel_list, pos);
  916. }
  917. if (detailed_run < 3)
  918. return 0;
  919. /* Append very, very detailed run extra attributes: */
  920. for (c = 0; c < ARRAY_SIZE(very_very_detailed_attrs); c++) {
  921. pos = perf_evsel__new(very_very_detailed_attrs + c, c + attr_nr);
  922. if (pos == NULL)
  923. return -1;
  924. perf_evlist__add(evsel_list, pos);
  925. }
  926. return 0;
  927. }
  928. int cmd_stat(int argc, const char **argv, const char *prefix __used)
  929. {
  930. struct perf_evsel *pos;
  931. int status = -ENOMEM;
  932. setlocale(LC_ALL, "");
  933. evsel_list = perf_evlist__new(NULL, NULL);
  934. if (evsel_list == NULL)
  935. return -ENOMEM;
  936. argc = parse_options(argc, argv, options, stat_usage,
  937. PARSE_OPT_STOP_AT_NON_OPTION);
  938. if (csv_sep)
  939. csv_output = true;
  940. else
  941. csv_sep = DEFAULT_SEPARATOR;
  942. /*
  943. * let the spreadsheet do the pretty-printing
  944. */
  945. if (csv_output) {
  946. /* User explicitely passed -B? */
  947. if (big_num_opt == 1) {
  948. fprintf(stderr, "-B option not supported with -x\n");
  949. usage_with_options(stat_usage, options);
  950. } else /* Nope, so disable big number formatting */
  951. big_num = false;
  952. } else if (big_num_opt == 0) /* User passed --no-big-num */
  953. big_num = false;
  954. if (!argc && target_pid == -1 && target_tid == -1)
  955. usage_with_options(stat_usage, options);
  956. if (run_count <= 0)
  957. usage_with_options(stat_usage, options);
  958. /* no_aggr, cgroup are for system-wide only */
  959. if ((no_aggr || nr_cgroups) && !system_wide) {
  960. fprintf(stderr, "both cgroup and no-aggregation "
  961. "modes only available in system-wide mode\n");
  962. usage_with_options(stat_usage, options);
  963. }
  964. if (add_default_attributes())
  965. goto out;
  966. if (target_pid != -1)
  967. target_tid = target_pid;
  968. evsel_list->threads = thread_map__new(target_pid, target_tid);
  969. if (evsel_list->threads == NULL) {
  970. pr_err("Problems finding threads of monitor\n");
  971. usage_with_options(stat_usage, options);
  972. }
  973. if (system_wide)
  974. evsel_list->cpus = cpu_map__new(cpu_list);
  975. else
  976. evsel_list->cpus = cpu_map__dummy_new();
  977. if (evsel_list->cpus == NULL) {
  978. perror("failed to parse CPUs map");
  979. usage_with_options(stat_usage, options);
  980. return -1;
  981. }
  982. list_for_each_entry(pos, &evsel_list->entries, node) {
  983. if (perf_evsel__alloc_stat_priv(pos) < 0 ||
  984. perf_evsel__alloc_counts(pos, evsel_list->cpus->nr) < 0 ||
  985. perf_evsel__alloc_fd(pos, evsel_list->cpus->nr, evsel_list->threads->nr) < 0)
  986. goto out_free_fd;
  987. }
  988. /*
  989. * We dont want to block the signals - that would cause
  990. * child tasks to inherit that and Ctrl-C would not work.
  991. * What we want is for Ctrl-C to work in the exec()-ed
  992. * task, but being ignored by perf stat itself:
  993. */
  994. atexit(sig_atexit);
  995. signal(SIGINT, skip_signal);
  996. signal(SIGALRM, skip_signal);
  997. signal(SIGABRT, skip_signal);
  998. status = 0;
  999. for (run_idx = 0; run_idx < run_count; run_idx++) {
  1000. if (run_count != 1 && verbose)
  1001. fprintf(stderr, "[ perf stat: executing run #%d ... ]\n", run_idx + 1);
  1002. if (sync_run)
  1003. sync();
  1004. status = run_perf_stat(argc, argv);
  1005. }
  1006. if (status != -1)
  1007. print_stat(argc, argv);
  1008. out_free_fd:
  1009. list_for_each_entry(pos, &evsel_list->entries, node)
  1010. perf_evsel__free_stat_priv(pos);
  1011. perf_evlist__delete_maps(evsel_list);
  1012. out:
  1013. perf_evlist__delete(evsel_list);
  1014. return status;
  1015. }