builtin-stat.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  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. fprintf(stderr, " ( +-%6.2f%% )", pct);
  433. }
  434. static void print_noise(struct perf_evsel *evsel, double avg)
  435. {
  436. struct perf_stat *ps;
  437. if (run_count == 1)
  438. return;
  439. ps = evsel->priv;
  440. print_noise_pct(stddev_stats(&ps->res_stats[0]), avg);
  441. }
  442. static void nsec_printout(int cpu, struct perf_evsel *evsel, double avg)
  443. {
  444. double msecs = avg / 1e6;
  445. char cpustr[16] = { '\0', };
  446. const char *fmt = csv_output ? "%s%.6f%s%s" : "%s%18.6f%s%-25s";
  447. if (no_aggr)
  448. sprintf(cpustr, "CPU%*d%s",
  449. csv_output ? 0 : -4,
  450. evsel_list->cpus->map[cpu], csv_sep);
  451. fprintf(stderr, fmt, cpustr, msecs, csv_sep, event_name(evsel));
  452. if (evsel->cgrp)
  453. fprintf(stderr, "%s%s", csv_sep, evsel->cgrp->name);
  454. if (csv_output)
  455. return;
  456. if (perf_evsel__match(evsel, SOFTWARE, SW_TASK_CLOCK))
  457. fprintf(stderr, " # %8.3f CPUs utilized ", avg / avg_stats(&walltime_nsecs_stats));
  458. }
  459. static void print_stalled_cycles_frontend(int cpu, struct perf_evsel *evsel __used, double avg)
  460. {
  461. double total, ratio = 0.0;
  462. const char *color;
  463. total = avg_stats(&runtime_cycles_stats[cpu]);
  464. if (total)
  465. ratio = avg / total * 100.0;
  466. color = PERF_COLOR_NORMAL;
  467. if (ratio > 50.0)
  468. color = PERF_COLOR_RED;
  469. else if (ratio > 30.0)
  470. color = PERF_COLOR_MAGENTA;
  471. else if (ratio > 10.0)
  472. color = PERF_COLOR_YELLOW;
  473. fprintf(stderr, " # ");
  474. color_fprintf(stderr, color, "%6.2f%%", ratio);
  475. fprintf(stderr, " frontend cycles idle ");
  476. }
  477. static void print_stalled_cycles_backend(int cpu, struct perf_evsel *evsel __used, double avg)
  478. {
  479. double total, ratio = 0.0;
  480. const char *color;
  481. total = avg_stats(&runtime_cycles_stats[cpu]);
  482. if (total)
  483. ratio = avg / total * 100.0;
  484. color = PERF_COLOR_NORMAL;
  485. if (ratio > 75.0)
  486. color = PERF_COLOR_RED;
  487. else if (ratio > 50.0)
  488. color = PERF_COLOR_MAGENTA;
  489. else if (ratio > 20.0)
  490. color = PERF_COLOR_YELLOW;
  491. fprintf(stderr, " # ");
  492. color_fprintf(stderr, color, "%6.2f%%", ratio);
  493. fprintf(stderr, " backend cycles idle ");
  494. }
  495. static void print_branch_misses(int cpu, struct perf_evsel *evsel __used, double avg)
  496. {
  497. double total, ratio = 0.0;
  498. const char *color;
  499. total = avg_stats(&runtime_branches_stats[cpu]);
  500. if (total)
  501. ratio = avg / total * 100.0;
  502. color = PERF_COLOR_NORMAL;
  503. if (ratio > 20.0)
  504. color = PERF_COLOR_RED;
  505. else if (ratio > 10.0)
  506. color = PERF_COLOR_MAGENTA;
  507. else if (ratio > 5.0)
  508. color = PERF_COLOR_YELLOW;
  509. fprintf(stderr, " # ");
  510. color_fprintf(stderr, color, "%6.2f%%", ratio);
  511. fprintf(stderr, " of all branches ");
  512. }
  513. static void print_l1_dcache_misses(int cpu, struct perf_evsel *evsel __used, double avg)
  514. {
  515. double total, ratio = 0.0;
  516. const char *color;
  517. total = avg_stats(&runtime_l1_dcache_stats[cpu]);
  518. if (total)
  519. ratio = avg / total * 100.0;
  520. color = PERF_COLOR_NORMAL;
  521. if (ratio > 20.0)
  522. color = PERF_COLOR_RED;
  523. else if (ratio > 10.0)
  524. color = PERF_COLOR_MAGENTA;
  525. else if (ratio > 5.0)
  526. color = PERF_COLOR_YELLOW;
  527. fprintf(stderr, " # ");
  528. color_fprintf(stderr, color, "%6.2f%%", ratio);
  529. fprintf(stderr, " of all L1-dcache hits ");
  530. }
  531. static void print_l1_icache_misses(int cpu, struct perf_evsel *evsel __used, double avg)
  532. {
  533. double total, ratio = 0.0;
  534. const char *color;
  535. total = avg_stats(&runtime_l1_icache_stats[cpu]);
  536. if (total)
  537. ratio = avg / total * 100.0;
  538. color = PERF_COLOR_NORMAL;
  539. if (ratio > 20.0)
  540. color = PERF_COLOR_RED;
  541. else if (ratio > 10.0)
  542. color = PERF_COLOR_MAGENTA;
  543. else if (ratio > 5.0)
  544. color = PERF_COLOR_YELLOW;
  545. fprintf(stderr, " # ");
  546. color_fprintf(stderr, color, "%6.2f%%", ratio);
  547. fprintf(stderr, " of all L1-icache hits ");
  548. }
  549. static void print_dtlb_cache_misses(int cpu, struct perf_evsel *evsel __used, double avg)
  550. {
  551. double total, ratio = 0.0;
  552. const char *color;
  553. total = avg_stats(&runtime_dtlb_cache_stats[cpu]);
  554. if (total)
  555. ratio = avg / total * 100.0;
  556. color = PERF_COLOR_NORMAL;
  557. if (ratio > 20.0)
  558. color = PERF_COLOR_RED;
  559. else if (ratio > 10.0)
  560. color = PERF_COLOR_MAGENTA;
  561. else if (ratio > 5.0)
  562. color = PERF_COLOR_YELLOW;
  563. fprintf(stderr, " # ");
  564. color_fprintf(stderr, color, "%6.2f%%", ratio);
  565. fprintf(stderr, " of all dTLB cache hits ");
  566. }
  567. static void print_itlb_cache_misses(int cpu, struct perf_evsel *evsel __used, double avg)
  568. {
  569. double total, ratio = 0.0;
  570. const char *color;
  571. total = avg_stats(&runtime_itlb_cache_stats[cpu]);
  572. if (total)
  573. ratio = avg / total * 100.0;
  574. color = PERF_COLOR_NORMAL;
  575. if (ratio > 20.0)
  576. color = PERF_COLOR_RED;
  577. else if (ratio > 10.0)
  578. color = PERF_COLOR_MAGENTA;
  579. else if (ratio > 5.0)
  580. color = PERF_COLOR_YELLOW;
  581. fprintf(stderr, " # ");
  582. color_fprintf(stderr, color, "%6.2f%%", ratio);
  583. fprintf(stderr, " of all iTLB cache hits ");
  584. }
  585. static void print_ll_cache_misses(int cpu, struct perf_evsel *evsel __used, double avg)
  586. {
  587. double total, ratio = 0.0;
  588. const char *color;
  589. total = avg_stats(&runtime_ll_cache_stats[cpu]);
  590. if (total)
  591. ratio = avg / total * 100.0;
  592. color = PERF_COLOR_NORMAL;
  593. if (ratio > 20.0)
  594. color = PERF_COLOR_RED;
  595. else if (ratio > 10.0)
  596. color = PERF_COLOR_MAGENTA;
  597. else if (ratio > 5.0)
  598. color = PERF_COLOR_YELLOW;
  599. fprintf(stderr, " # ");
  600. color_fprintf(stderr, color, "%6.2f%%", ratio);
  601. fprintf(stderr, " of all LL-cache hits ");
  602. }
  603. static void abs_printout(int cpu, struct perf_evsel *evsel, double avg)
  604. {
  605. double total, ratio = 0.0;
  606. char cpustr[16] = { '\0', };
  607. const char *fmt;
  608. if (csv_output)
  609. fmt = "%s%.0f%s%s";
  610. else if (big_num)
  611. fmt = "%s%'18.0f%s%-25s";
  612. else
  613. fmt = "%s%18.0f%s%-25s";
  614. if (no_aggr)
  615. sprintf(cpustr, "CPU%*d%s",
  616. csv_output ? 0 : -4,
  617. evsel_list->cpus->map[cpu], csv_sep);
  618. else
  619. cpu = 0;
  620. fprintf(stderr, fmt, cpustr, avg, csv_sep, event_name(evsel));
  621. if (evsel->cgrp)
  622. fprintf(stderr, "%s%s", csv_sep, evsel->cgrp->name);
  623. if (csv_output)
  624. return;
  625. if (perf_evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS)) {
  626. total = avg_stats(&runtime_cycles_stats[cpu]);
  627. if (total)
  628. ratio = avg / total;
  629. fprintf(stderr, " # %5.2f insns per cycle ", ratio);
  630. total = avg_stats(&runtime_stalled_cycles_front_stats[cpu]);
  631. total = max(total, avg_stats(&runtime_stalled_cycles_back_stats[cpu]));
  632. if (total && avg) {
  633. ratio = total / avg;
  634. fprintf(stderr, "\n # %5.2f stalled cycles per insn", ratio);
  635. }
  636. } else if (perf_evsel__match(evsel, HARDWARE, HW_BRANCH_MISSES) &&
  637. runtime_branches_stats[cpu].n != 0) {
  638. print_branch_misses(cpu, evsel, avg);
  639. } else if (
  640. evsel->attr.type == PERF_TYPE_HW_CACHE &&
  641. evsel->attr.config == ( PERF_COUNT_HW_CACHE_L1D |
  642. ((PERF_COUNT_HW_CACHE_OP_READ) << 8) |
  643. ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16)) &&
  644. runtime_l1_dcache_stats[cpu].n != 0) {
  645. print_l1_dcache_misses(cpu, evsel, avg);
  646. } else if (
  647. evsel->attr.type == PERF_TYPE_HW_CACHE &&
  648. evsel->attr.config == ( PERF_COUNT_HW_CACHE_L1I |
  649. ((PERF_COUNT_HW_CACHE_OP_READ) << 8) |
  650. ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16)) &&
  651. runtime_l1_icache_stats[cpu].n != 0) {
  652. print_l1_icache_misses(cpu, evsel, avg);
  653. } else if (
  654. evsel->attr.type == PERF_TYPE_HW_CACHE &&
  655. evsel->attr.config == ( PERF_COUNT_HW_CACHE_DTLB |
  656. ((PERF_COUNT_HW_CACHE_OP_READ) << 8) |
  657. ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16)) &&
  658. runtime_dtlb_cache_stats[cpu].n != 0) {
  659. print_dtlb_cache_misses(cpu, evsel, avg);
  660. } else if (
  661. evsel->attr.type == PERF_TYPE_HW_CACHE &&
  662. evsel->attr.config == ( PERF_COUNT_HW_CACHE_ITLB |
  663. ((PERF_COUNT_HW_CACHE_OP_READ) << 8) |
  664. ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16)) &&
  665. runtime_itlb_cache_stats[cpu].n != 0) {
  666. print_itlb_cache_misses(cpu, evsel, avg);
  667. } else if (
  668. evsel->attr.type == PERF_TYPE_HW_CACHE &&
  669. evsel->attr.config == ( PERF_COUNT_HW_CACHE_LL |
  670. ((PERF_COUNT_HW_CACHE_OP_READ) << 8) |
  671. ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16)) &&
  672. runtime_ll_cache_stats[cpu].n != 0) {
  673. print_ll_cache_misses(cpu, evsel, avg);
  674. } else if (perf_evsel__match(evsel, HARDWARE, HW_CACHE_MISSES) &&
  675. runtime_cacherefs_stats[cpu].n != 0) {
  676. total = avg_stats(&runtime_cacherefs_stats[cpu]);
  677. if (total)
  678. ratio = avg * 100 / total;
  679. fprintf(stderr, " # %8.3f %% of all cache refs ", ratio);
  680. } else if (perf_evsel__match(evsel, HARDWARE, HW_STALLED_CYCLES_FRONTEND)) {
  681. print_stalled_cycles_frontend(cpu, evsel, avg);
  682. } else if (perf_evsel__match(evsel, HARDWARE, HW_STALLED_CYCLES_BACKEND)) {
  683. print_stalled_cycles_backend(cpu, evsel, avg);
  684. } else if (perf_evsel__match(evsel, HARDWARE, HW_CPU_CYCLES)) {
  685. total = avg_stats(&runtime_nsecs_stats[cpu]);
  686. if (total)
  687. ratio = 1.0 * avg / total;
  688. fprintf(stderr, " # %8.3f GHz ", ratio);
  689. } else if (runtime_nsecs_stats[cpu].n != 0) {
  690. total = avg_stats(&runtime_nsecs_stats[cpu]);
  691. if (total)
  692. ratio = 1000.0 * avg / total;
  693. fprintf(stderr, " # %8.3f M/sec ", ratio);
  694. } else {
  695. fprintf(stderr, " ");
  696. }
  697. }
  698. /*
  699. * Print out the results of a single counter:
  700. * aggregated counts in system-wide mode
  701. */
  702. static void print_counter_aggr(struct perf_evsel *counter)
  703. {
  704. struct perf_stat *ps = counter->priv;
  705. double avg = avg_stats(&ps->res_stats[0]);
  706. int scaled = counter->counts->scaled;
  707. if (scaled == -1) {
  708. fprintf(stderr, "%*s%s%*s",
  709. csv_output ? 0 : 18,
  710. counter->supported ? CNTR_NOT_COUNTED : CNTR_NOT_SUPPORTED,
  711. csv_sep,
  712. csv_output ? 0 : -24,
  713. event_name(counter));
  714. if (counter->cgrp)
  715. fprintf(stderr, "%s%s", csv_sep, counter->cgrp->name);
  716. fputc('\n', stderr);
  717. return;
  718. }
  719. if (nsec_counter(counter))
  720. nsec_printout(-1, counter, avg);
  721. else
  722. abs_printout(-1, counter, avg);
  723. if (csv_output) {
  724. fputc('\n', stderr);
  725. return;
  726. }
  727. print_noise(counter, avg);
  728. if (scaled) {
  729. double avg_enabled, avg_running;
  730. avg_enabled = avg_stats(&ps->res_stats[1]);
  731. avg_running = avg_stats(&ps->res_stats[2]);
  732. fprintf(stderr, " [%5.2f%%]", 100 * avg_running / avg_enabled);
  733. }
  734. fprintf(stderr, "\n");
  735. }
  736. /*
  737. * Print out the results of a single counter:
  738. * does not use aggregated count in system-wide
  739. */
  740. static void print_counter(struct perf_evsel *counter)
  741. {
  742. u64 ena, run, val;
  743. int cpu;
  744. for (cpu = 0; cpu < evsel_list->cpus->nr; cpu++) {
  745. val = counter->counts->cpu[cpu].val;
  746. ena = counter->counts->cpu[cpu].ena;
  747. run = counter->counts->cpu[cpu].run;
  748. if (run == 0 || ena == 0) {
  749. fprintf(stderr, "CPU%*d%s%*s%s%*s",
  750. csv_output ? 0 : -4,
  751. evsel_list->cpus->map[cpu], csv_sep,
  752. csv_output ? 0 : 18,
  753. counter->supported ? CNTR_NOT_COUNTED : CNTR_NOT_SUPPORTED,
  754. csv_sep,
  755. csv_output ? 0 : -24,
  756. event_name(counter));
  757. if (counter->cgrp)
  758. fprintf(stderr, "%s%s", csv_sep, counter->cgrp->name);
  759. fputc('\n', stderr);
  760. continue;
  761. }
  762. if (nsec_counter(counter))
  763. nsec_printout(cpu, counter, val);
  764. else
  765. abs_printout(cpu, counter, val);
  766. if (!csv_output) {
  767. print_noise(counter, 1.0);
  768. if (run != ena)
  769. fprintf(stderr, " (%.2f%%)", 100.0 * run / ena);
  770. }
  771. fputc('\n', stderr);
  772. }
  773. }
  774. static void print_stat(int argc, const char **argv)
  775. {
  776. struct perf_evsel *counter;
  777. int i;
  778. fflush(stdout);
  779. if (!csv_output) {
  780. fprintf(stderr, "\n");
  781. fprintf(stderr, " Performance counter stats for ");
  782. if(target_pid == -1 && target_tid == -1) {
  783. fprintf(stderr, "\'%s", argv[0]);
  784. for (i = 1; i < argc; i++)
  785. fprintf(stderr, " %s", argv[i]);
  786. } else if (target_pid != -1)
  787. fprintf(stderr, "process id \'%d", target_pid);
  788. else
  789. fprintf(stderr, "thread id \'%d", target_tid);
  790. fprintf(stderr, "\'");
  791. if (run_count > 1)
  792. fprintf(stderr, " (%d runs)", run_count);
  793. fprintf(stderr, ":\n\n");
  794. }
  795. if (no_aggr) {
  796. list_for_each_entry(counter, &evsel_list->entries, node)
  797. print_counter(counter);
  798. } else {
  799. list_for_each_entry(counter, &evsel_list->entries, node)
  800. print_counter_aggr(counter);
  801. }
  802. if (!csv_output) {
  803. if (!null_run)
  804. fprintf(stderr, "\n");
  805. fprintf(stderr, " %17.9f seconds time elapsed",
  806. avg_stats(&walltime_nsecs_stats)/1e9);
  807. if (run_count > 1) {
  808. fprintf(stderr, " ");
  809. print_noise_pct(stddev_stats(&walltime_nsecs_stats),
  810. avg_stats(&walltime_nsecs_stats));
  811. }
  812. fprintf(stderr, "\n\n");
  813. }
  814. }
  815. static volatile int signr = -1;
  816. static void skip_signal(int signo)
  817. {
  818. if(child_pid == -1)
  819. done = 1;
  820. signr = signo;
  821. }
  822. static void sig_atexit(void)
  823. {
  824. if (child_pid != -1)
  825. kill(child_pid, SIGTERM);
  826. if (signr == -1)
  827. return;
  828. signal(signr, SIG_DFL);
  829. kill(getpid(), signr);
  830. }
  831. static const char * const stat_usage[] = {
  832. "perf stat [<options>] [<command>]",
  833. NULL
  834. };
  835. static int stat__set_big_num(const struct option *opt __used,
  836. const char *s __used, int unset)
  837. {
  838. big_num_opt = unset ? 0 : 1;
  839. return 0;
  840. }
  841. static const struct option options[] = {
  842. OPT_CALLBACK('e', "event", &evsel_list, "event",
  843. "event selector. use 'perf list' to list available events",
  844. parse_events),
  845. OPT_CALLBACK(0, "filter", &evsel_list, "filter",
  846. "event filter", parse_filter),
  847. OPT_BOOLEAN('i', "no-inherit", &no_inherit,
  848. "child tasks do not inherit counters"),
  849. OPT_INTEGER('p', "pid", &target_pid,
  850. "stat events on existing process id"),
  851. OPT_INTEGER('t', "tid", &target_tid,
  852. "stat events on existing thread id"),
  853. OPT_BOOLEAN('a', "all-cpus", &system_wide,
  854. "system-wide collection from all CPUs"),
  855. OPT_BOOLEAN('c', "scale", &scale,
  856. "scale/normalize counters"),
  857. OPT_INCR('v', "verbose", &verbose,
  858. "be more verbose (show counter open errors, etc)"),
  859. OPT_INTEGER('r', "repeat", &run_count,
  860. "repeat command and print average + stddev (max: 100)"),
  861. OPT_BOOLEAN('n', "null", &null_run,
  862. "null run - dont start any counters"),
  863. OPT_INCR('d', "detailed", &detailed_run,
  864. "detailed run - start a lot of events"),
  865. OPT_BOOLEAN('S', "sync", &sync_run,
  866. "call sync() before starting a run"),
  867. OPT_CALLBACK_NOOPT('B', "big-num", NULL, NULL,
  868. "print large numbers with thousands\' separators",
  869. stat__set_big_num),
  870. OPT_STRING('C', "cpu", &cpu_list, "cpu",
  871. "list of cpus to monitor in system-wide"),
  872. OPT_BOOLEAN('A', "no-aggr", &no_aggr,
  873. "disable CPU count aggregation"),
  874. OPT_STRING('x', "field-separator", &csv_sep, "separator",
  875. "print counts with custom separator"),
  876. OPT_CALLBACK('G', "cgroup", &evsel_list, "name",
  877. "monitor event in cgroup name only",
  878. parse_cgroups),
  879. OPT_END()
  880. };
  881. /*
  882. * Add default attributes, if there were no attributes specified or
  883. * if -d/--detailed, -d -d or -d -d -d is used:
  884. */
  885. static int add_default_attributes(void)
  886. {
  887. struct perf_evsel *pos;
  888. size_t attr_nr = 0;
  889. size_t c;
  890. /* Set attrs if no event is selected and !null_run: */
  891. if (null_run)
  892. return 0;
  893. if (!evsel_list->nr_entries) {
  894. for (c = 0; c < ARRAY_SIZE(default_attrs); c++) {
  895. pos = perf_evsel__new(default_attrs + c, c + attr_nr);
  896. if (pos == NULL)
  897. return -1;
  898. perf_evlist__add(evsel_list, pos);
  899. }
  900. attr_nr += c;
  901. }
  902. /* Detailed events get appended to the event list: */
  903. if (detailed_run < 1)
  904. return 0;
  905. /* Append detailed run extra attributes: */
  906. for (c = 0; c < ARRAY_SIZE(detailed_attrs); c++) {
  907. pos = perf_evsel__new(detailed_attrs + c, c + attr_nr);
  908. if (pos == NULL)
  909. return -1;
  910. perf_evlist__add(evsel_list, pos);
  911. }
  912. attr_nr += c;
  913. if (detailed_run < 2)
  914. return 0;
  915. /* Append very detailed run extra attributes: */
  916. for (c = 0; c < ARRAY_SIZE(very_detailed_attrs); c++) {
  917. pos = perf_evsel__new(very_detailed_attrs + c, c + attr_nr);
  918. if (pos == NULL)
  919. return -1;
  920. perf_evlist__add(evsel_list, pos);
  921. }
  922. if (detailed_run < 3)
  923. return 0;
  924. /* Append very, very detailed run extra attributes: */
  925. for (c = 0; c < ARRAY_SIZE(very_very_detailed_attrs); c++) {
  926. pos = perf_evsel__new(very_very_detailed_attrs + c, c + attr_nr);
  927. if (pos == NULL)
  928. return -1;
  929. perf_evlist__add(evsel_list, pos);
  930. }
  931. return 0;
  932. }
  933. int cmd_stat(int argc, const char **argv, const char *prefix __used)
  934. {
  935. struct perf_evsel *pos;
  936. int status = -ENOMEM;
  937. setlocale(LC_ALL, "");
  938. evsel_list = perf_evlist__new(NULL, NULL);
  939. if (evsel_list == NULL)
  940. return -ENOMEM;
  941. argc = parse_options(argc, argv, options, stat_usage,
  942. PARSE_OPT_STOP_AT_NON_OPTION);
  943. if (csv_sep)
  944. csv_output = true;
  945. else
  946. csv_sep = DEFAULT_SEPARATOR;
  947. /*
  948. * let the spreadsheet do the pretty-printing
  949. */
  950. if (csv_output) {
  951. /* User explicitely passed -B? */
  952. if (big_num_opt == 1) {
  953. fprintf(stderr, "-B option not supported with -x\n");
  954. usage_with_options(stat_usage, options);
  955. } else /* Nope, so disable big number formatting */
  956. big_num = false;
  957. } else if (big_num_opt == 0) /* User passed --no-big-num */
  958. big_num = false;
  959. if (!argc && target_pid == -1 && target_tid == -1)
  960. usage_with_options(stat_usage, options);
  961. if (run_count <= 0)
  962. usage_with_options(stat_usage, options);
  963. /* no_aggr, cgroup are for system-wide only */
  964. if ((no_aggr || nr_cgroups) && !system_wide) {
  965. fprintf(stderr, "both cgroup and no-aggregation "
  966. "modes only available in system-wide mode\n");
  967. usage_with_options(stat_usage, options);
  968. }
  969. if (add_default_attributes())
  970. goto out;
  971. if (target_pid != -1)
  972. target_tid = target_pid;
  973. evsel_list->threads = thread_map__new(target_pid, target_tid);
  974. if (evsel_list->threads == NULL) {
  975. pr_err("Problems finding threads of monitor\n");
  976. usage_with_options(stat_usage, options);
  977. }
  978. if (system_wide)
  979. evsel_list->cpus = cpu_map__new(cpu_list);
  980. else
  981. evsel_list->cpus = cpu_map__dummy_new();
  982. if (evsel_list->cpus == NULL) {
  983. perror("failed to parse CPUs map");
  984. usage_with_options(stat_usage, options);
  985. return -1;
  986. }
  987. list_for_each_entry(pos, &evsel_list->entries, node) {
  988. if (perf_evsel__alloc_stat_priv(pos) < 0 ||
  989. perf_evsel__alloc_counts(pos, evsel_list->cpus->nr) < 0 ||
  990. perf_evsel__alloc_fd(pos, evsel_list->cpus->nr, evsel_list->threads->nr) < 0)
  991. goto out_free_fd;
  992. }
  993. /*
  994. * We dont want to block the signals - that would cause
  995. * child tasks to inherit that and Ctrl-C would not work.
  996. * What we want is for Ctrl-C to work in the exec()-ed
  997. * task, but being ignored by perf stat itself:
  998. */
  999. atexit(sig_atexit);
  1000. signal(SIGINT, skip_signal);
  1001. signal(SIGALRM, skip_signal);
  1002. signal(SIGABRT, skip_signal);
  1003. status = 0;
  1004. for (run_idx = 0; run_idx < run_count; run_idx++) {
  1005. if (run_count != 1 && verbose)
  1006. fprintf(stderr, "[ perf stat: executing run #%d ... ]\n", run_idx + 1);
  1007. if (sync_run)
  1008. sync();
  1009. status = run_perf_stat(argc, argv);
  1010. }
  1011. if (status != -1)
  1012. print_stat(argc, argv);
  1013. out_free_fd:
  1014. list_for_each_entry(pos, &evsel_list->entries, node)
  1015. perf_evsel__free_stat_priv(pos);
  1016. perf_evlist__delete_maps(evsel_list);
  1017. out:
  1018. perf_evlist__delete(evsel_list);
  1019. return status;
  1020. }