builtin-stat.c 32 KB

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