builtin-stat.c (6c1912898ed21bef2d7f8b52902b8bc3c0e5c2b5) builtin-stat.c (07eafd4e053a41d72611848b8758df0752b53ee4)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * builtin-stat.c
4 *
5 * Builtin stat command: Give a precise performance counters summary
6 * overview about any workload, CPU or specific PID.
7 *
8 * Sample output:

--- 1736 unchanged lines hidden (view full) ---

1745 (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) },
1746
1747 { .type = PERF_TYPE_HW_CACHE,
1748 .config =
1749 PERF_COUNT_HW_CACHE_L1D << 0 |
1750 (PERF_COUNT_HW_CACHE_OP_PREFETCH << 8) |
1751 (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) },
1752};
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * builtin-stat.c
4 *
5 * Builtin stat command: Give a precise performance counters summary
6 * overview about any workload, CPU or specific PID.
7 *
8 * Sample output:

--- 1736 unchanged lines hidden (view full) ---

1745 (PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16) },
1746
1747 { .type = PERF_TYPE_HW_CACHE,
1748 .config =
1749 PERF_COUNT_HW_CACHE_L1D << 0 |
1750 (PERF_COUNT_HW_CACHE_OP_PREFETCH << 8) |
1751 (PERF_COUNT_HW_CACHE_RESULT_MISS << 16) },
1752};
1753 struct parse_events_error errinfo;
1754
1755 /* Set attrs if no event is selected and !null_run: */
1756 if (stat_config.null_run)
1757 return 0;
1758
1753 /* Set attrs if no event is selected and !null_run: */
1754 if (stat_config.null_run)
1755 return 0;
1756
1759 bzero(&errinfo, sizeof(errinfo));
1760 if (transaction_run) {
1757 if (transaction_run) {
1758 struct parse_events_error errinfo;
1761 /* Handle -T as -M transaction. Once platform specific metrics
1762 * support has been added to the json files, all architectures
1763 * will use this approach. To determine transaction support
1764 * on an architecture test for such a metric name.
1765 */
1766 if (metricgroup__has_metric("transaction")) {
1767 struct option opt = { .value = &evsel_list };
1768
1769 return metricgroup__parse_groups(&opt, "transaction",
1770 stat_config.metric_no_group,
1771 stat_config.metric_no_merge,
1772 &stat_config.metric_events);
1773 }
1774
1759 /* Handle -T as -M transaction. Once platform specific metrics
1760 * support has been added to the json files, all architectures
1761 * will use this approach. To determine transaction support
1762 * on an architecture test for such a metric name.
1763 */
1764 if (metricgroup__has_metric("transaction")) {
1765 struct option opt = { .value = &evsel_list };
1766
1767 return metricgroup__parse_groups(&opt, "transaction",
1768 stat_config.metric_no_group,
1769 stat_config.metric_no_merge,
1770 &stat_config.metric_events);
1771 }
1772
1773 parse_events_error__init(&errinfo);
1775 if (pmu_have_event("cpu", "cycles-ct") &&
1776 pmu_have_event("cpu", "el-start"))
1777 err = parse_events(evsel_list, transaction_attrs,
1778 &errinfo);
1779 else
1780 err = parse_events(evsel_list,
1781 transaction_limited_attrs,
1782 &errinfo);
1783 if (err) {
1784 fprintf(stderr, "Cannot set up transaction events\n");
1785 parse_events_error__print(&errinfo, transaction_attrs);
1774 if (pmu_have_event("cpu", "cycles-ct") &&
1775 pmu_have_event("cpu", "el-start"))
1776 err = parse_events(evsel_list, transaction_attrs,
1777 &errinfo);
1778 else
1779 err = parse_events(evsel_list,
1780 transaction_limited_attrs,
1781 &errinfo);
1782 if (err) {
1783 fprintf(stderr, "Cannot set up transaction events\n");
1784 parse_events_error__print(&errinfo, transaction_attrs);
1786 return -1;
1787 }
1785 }
1788 return 0;
1786 parse_events_error__exit(&errinfo);
1787 return err ? -1 : 0;
1789 }
1790
1791 if (smi_cost) {
1788 }
1789
1790 if (smi_cost) {
1791 struct parse_events_error errinfo;
1792 int smi;
1793
1794 if (sysfs__read_int(FREEZE_ON_SMI_PATH, &smi) < 0) {
1795 fprintf(stderr, "freeze_on_smi is not supported.\n");
1796 return -1;
1797 }
1798
1799 if (!smi) {
1800 if (sysfs__write_int(FREEZE_ON_SMI_PATH, 1) < 0) {
1801 fprintf(stderr, "Failed to set freeze_on_smi.\n");
1802 return -1;
1803 }
1804 smi_reset = true;
1805 }
1806
1792 int smi;
1793
1794 if (sysfs__read_int(FREEZE_ON_SMI_PATH, &smi) < 0) {
1795 fprintf(stderr, "freeze_on_smi is not supported.\n");
1796 return -1;
1797 }
1798
1799 if (!smi) {
1800 if (sysfs__write_int(FREEZE_ON_SMI_PATH, 1) < 0) {
1801 fprintf(stderr, "Failed to set freeze_on_smi.\n");
1802 return -1;
1803 }
1804 smi_reset = true;
1805 }
1806
1807 if (pmu_have_event("msr", "aperf") &&
1808 pmu_have_event("msr", "smi")) {
1809 if (!force_metric_only)
1810 stat_config.metric_only = true;
1811 err = parse_events(evsel_list, smi_cost_attrs, &errinfo);
1812 } else {
1807 if (!pmu_have_event("msr", "aperf") ||
1808 !pmu_have_event("msr", "smi")) {
1813 fprintf(stderr, "To measure SMI cost, it needs "
1814 "msr/aperf/, msr/smi/ and cpu/cycles/ support\n");
1809 fprintf(stderr, "To measure SMI cost, it needs "
1810 "msr/aperf/, msr/smi/ and cpu/cycles/ support\n");
1815 parse_events_error__print(&errinfo, smi_cost_attrs);
1816 return -1;
1817 }
1811 return -1;
1812 }
1813 if (!force_metric_only)
1814 stat_config.metric_only = true;
1815
1816 parse_events_error__init(&errinfo);
1817 err = parse_events(evsel_list, smi_cost_attrs, &errinfo);
1818 if (err) {
1819 parse_events_error__print(&errinfo, smi_cost_attrs);
1820 fprintf(stderr, "Cannot set up SMI cost events\n");
1818 if (err) {
1819 parse_events_error__print(&errinfo, smi_cost_attrs);
1820 fprintf(stderr, "Cannot set up SMI cost events\n");
1821 return -1;
1822 }
1821 }
1823 return 0;
1822 parse_events_error__exit(&errinfo);
1823 return err ? -1 : 0;
1824 }
1825
1826 if (topdown_run) {
1827 const char **metric_attrs = topdown_metric_attrs;
1828 unsigned int max_level = 1;
1829 char *str = NULL;
1830 bool warn = false;
1831

--- 38 unchanged lines hidden (view full) ---

1870 }
1871
1872 if (topdown_filter_events(topdown_attrs, &str,
1873 arch_topdown_check_group(&warn)) < 0) {
1874 pr_err("Out of memory\n");
1875 return -1;
1876 }
1877 if (topdown_attrs[0] && str) {
1824 }
1825
1826 if (topdown_run) {
1827 const char **metric_attrs = topdown_metric_attrs;
1828 unsigned int max_level = 1;
1829 char *str = NULL;
1830 bool warn = false;
1831

--- 38 unchanged lines hidden (view full) ---

1870 }
1871
1872 if (topdown_filter_events(topdown_attrs, &str,
1873 arch_topdown_check_group(&warn)) < 0) {
1874 pr_err("Out of memory\n");
1875 return -1;
1876 }
1877 if (topdown_attrs[0] && str) {
1878 struct parse_events_error errinfo;
1878 if (warn)
1879 arch_topdown_group_warn();
1880setup_metrics:
1879 if (warn)
1880 arch_topdown_group_warn();
1881setup_metrics:
1882 parse_events_error__init(&errinfo);
1881 err = parse_events(evsel_list, str, &errinfo);
1882 if (err) {
1883 fprintf(stderr,
1884 "Cannot set up top down events %s: %d\n",
1885 str, err);
1886 parse_events_error__print(&errinfo, str);
1883 err = parse_events(evsel_list, str, &errinfo);
1884 if (err) {
1885 fprintf(stderr,
1886 "Cannot set up top down events %s: %d\n",
1887 str, err);
1888 parse_events_error__print(&errinfo, str);
1889 parse_events_error__exit(&errinfo);
1887 free(str);
1888 return -1;
1889 }
1890 free(str);
1891 return -1;
1892 }
1893 parse_events_error__exit(&errinfo);
1890 } else {
1891 fprintf(stderr, "System does not support topdown\n");
1892 return -1;
1893 }
1894 free(str);
1895 }
1896
1897 if (!evsel_list->core.nr_entries) {
1898 if (perf_pmu__has_hybrid()) {
1894 } else {
1895 fprintf(stderr, "System does not support topdown\n");
1896 return -1;
1897 }
1898 free(str);
1899 }
1900
1901 if (!evsel_list->core.nr_entries) {
1902 if (perf_pmu__has_hybrid()) {
1903 struct parse_events_error errinfo;
1899 const char *hybrid_str = "cycles,instructions,branches,branch-misses";
1900
1901 if (target__has_cpu(&target))
1902 default_sw_attrs[0].config = PERF_COUNT_SW_CPU_CLOCK;
1903
1904 if (evlist__add_default_attrs(evsel_list,
1905 default_sw_attrs) < 0) {
1906 return -1;
1907 }
1908
1904 const char *hybrid_str = "cycles,instructions,branches,branch-misses";
1905
1906 if (target__has_cpu(&target))
1907 default_sw_attrs[0].config = PERF_COUNT_SW_CPU_CLOCK;
1908
1909 if (evlist__add_default_attrs(evsel_list,
1910 default_sw_attrs) < 0) {
1911 return -1;
1912 }
1913
1914 parse_events_error__init(&errinfo);
1909 err = parse_events(evsel_list, hybrid_str, &errinfo);
1910 if (err) {
1911 fprintf(stderr,
1912 "Cannot set up hybrid events %s: %d\n",
1913 hybrid_str, err);
1914 parse_events_error__print(&errinfo, hybrid_str);
1915 err = parse_events(evsel_list, hybrid_str, &errinfo);
1916 if (err) {
1917 fprintf(stderr,
1918 "Cannot set up hybrid events %s: %d\n",
1919 hybrid_str, err);
1920 parse_events_error__print(&errinfo, hybrid_str);
1915 return -1;
1916 }
1921 }
1917 return err;
1922 parse_events_error__exit(&errinfo);
1923 return err ? -1 : 0;
1918 }
1919
1920 if (target__has_cpu(&target))
1921 default_attrs0[0].config = PERF_COUNT_SW_CPU_CLOCK;
1922
1923 if (evlist__add_default_attrs(evsel_list, default_attrs0) < 0)
1924 return -1;
1925 if (pmu_have_event("cpu", "stalled-cycles-frontend")) {

--- 686 unchanged lines hidden ---
1924 }
1925
1926 if (target__has_cpu(&target))
1927 default_attrs0[0].config = PERF_COUNT_SW_CPU_CLOCK;
1928
1929 if (evlist__add_default_attrs(evsel_list, default_attrs0) < 0)
1930 return -1;
1931 if (pmu_have_event("cpu", "stalled-cycles-frontend")) {

--- 686 unchanged lines hidden ---