builtin-stat.c 32 KB

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