diff options
author | Namhyung Kim <namhyung@kernel.org> | 2012-09-24 04:14:59 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-09-24 10:45:22 -0400 |
commit | a1ae565528757f26d315897929b6fe58c5647915 (patch) | |
tree | 4be0ccc4715ebd97dd454917b6cc76cf656a2ed6 /tools/perf | |
parent | e93699b3c7aeb13eee473b1dc36cbe3a8a0ca397 (diff) |
perf header: Add ->process callbacks to most of features
From now on each feature information is processed and saved in perf
header so that it can be used wherever needed. The BRANCH_STACK feature
is an exception since it needs nothing to be done.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Robert Richter <robert.richter@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1348474503-15070-3-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/util/header.c | 319 |
1 files changed, 308 insertions, 11 deletions
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index ad72b2814ba8..d74b58d4105d 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include "cpumap.h" | 22 | #include "cpumap.h" |
23 | #include "pmu.h" | 23 | #include "pmu.h" |
24 | #include "vdso.h" | 24 | #include "vdso.h" |
25 | #include "strbuf.h" | ||
25 | 26 | ||
26 | static bool no_buildid_cache = false; | 27 | static bool no_buildid_cache = false; |
27 | 28 | ||
@@ -1673,6 +1674,99 @@ static int process_build_id(struct perf_file_section *section, | |||
1673 | return 0; | 1674 | return 0; |
1674 | } | 1675 | } |
1675 | 1676 | ||
1677 | static int process_hostname(struct perf_file_section *section __maybe_unused, | ||
1678 | struct perf_header *ph, int feat __maybe_unused, | ||
1679 | int fd, void *data __maybe_unused) | ||
1680 | { | ||
1681 | ph->env.hostname = do_read_string(fd, ph); | ||
1682 | return ph->env.hostname ? 0 : -ENOMEM; | ||
1683 | } | ||
1684 | |||
1685 | static int process_osrelease(struct perf_file_section *section __maybe_unused, | ||
1686 | struct perf_header *ph, int feat __maybe_unused, | ||
1687 | int fd, void *data __maybe_unused) | ||
1688 | { | ||
1689 | ph->env.os_release = do_read_string(fd, ph); | ||
1690 | return ph->env.os_release ? 0 : -ENOMEM; | ||
1691 | } | ||
1692 | |||
1693 | static int process_version(struct perf_file_section *section __maybe_unused, | ||
1694 | struct perf_header *ph, int feat __maybe_unused, | ||
1695 | int fd, void *data __maybe_unused) | ||
1696 | { | ||
1697 | ph->env.version = do_read_string(fd, ph); | ||
1698 | return ph->env.version ? 0 : -ENOMEM; | ||
1699 | } | ||
1700 | |||
1701 | static int process_arch(struct perf_file_section *section __maybe_unused, | ||
1702 | struct perf_header *ph, int feat __maybe_unused, | ||
1703 | int fd, void *data __maybe_unused) | ||
1704 | { | ||
1705 | ph->env.arch = do_read_string(fd, ph); | ||
1706 | return ph->env.arch ? 0 : -ENOMEM; | ||
1707 | } | ||
1708 | |||
1709 | static int process_nrcpus(struct perf_file_section *section __maybe_unused, | ||
1710 | struct perf_header *ph, int feat __maybe_unused, | ||
1711 | int fd, void *data __maybe_unused) | ||
1712 | { | ||
1713 | size_t ret; | ||
1714 | u32 nr; | ||
1715 | |||
1716 | ret = read(fd, &nr, sizeof(nr)); | ||
1717 | if (ret != sizeof(nr)) | ||
1718 | return -1; | ||
1719 | |||
1720 | if (ph->needs_swap) | ||
1721 | nr = bswap_32(nr); | ||
1722 | |||
1723 | ph->env.nr_cpus_online = nr; | ||
1724 | |||
1725 | ret = read(fd, &nr, sizeof(nr)); | ||
1726 | if (ret != sizeof(nr)) | ||
1727 | return -1; | ||
1728 | |||
1729 | if (ph->needs_swap) | ||
1730 | nr = bswap_32(nr); | ||
1731 | |||
1732 | ph->env.nr_cpus_avail = nr; | ||
1733 | return 0; | ||
1734 | } | ||
1735 | |||
1736 | static int process_cpudesc(struct perf_file_section *section __maybe_unused, | ||
1737 | struct perf_header *ph, int feat __maybe_unused, | ||
1738 | int fd, void *data __maybe_unused) | ||
1739 | { | ||
1740 | ph->env.cpu_desc = do_read_string(fd, ph); | ||
1741 | return ph->env.cpu_desc ? 0 : -ENOMEM; | ||
1742 | } | ||
1743 | |||
1744 | static int process_cpuid(struct perf_file_section *section __maybe_unused, | ||
1745 | struct perf_header *ph, int feat __maybe_unused, | ||
1746 | int fd, void *data __maybe_unused) | ||
1747 | { | ||
1748 | ph->env.cpuid = do_read_string(fd, ph); | ||
1749 | return ph->env.cpuid ? 0 : -ENOMEM; | ||
1750 | } | ||
1751 | |||
1752 | static int process_total_mem(struct perf_file_section *section __maybe_unused, | ||
1753 | struct perf_header *ph, int feat __maybe_unused, | ||
1754 | int fd, void *data __maybe_unused) | ||
1755 | { | ||
1756 | uint64_t mem; | ||
1757 | size_t ret; | ||
1758 | |||
1759 | ret = read(fd, &mem, sizeof(mem)); | ||
1760 | if (ret != sizeof(mem)) | ||
1761 | return -1; | ||
1762 | |||
1763 | if (ph->needs_swap) | ||
1764 | mem = bswap_64(mem); | ||
1765 | |||
1766 | ph->env.total_mem = mem; | ||
1767 | return 0; | ||
1768 | } | ||
1769 | |||
1676 | static char *read_cpuid(struct perf_header *ph, int fd) | 1770 | static char *read_cpuid(struct perf_header *ph, int fd) |
1677 | { | 1771 | { |
1678 | return do_read_string(fd, ph); | 1772 | return do_read_string(fd, ph); |
@@ -1728,6 +1822,208 @@ process_event_desc(struct perf_file_section *section __maybe_unused, | |||
1728 | return 0; | 1822 | return 0; |
1729 | } | 1823 | } |
1730 | 1824 | ||
1825 | static int process_cmdline(struct perf_file_section *section __maybe_unused, | ||
1826 | struct perf_header *ph, int feat __maybe_unused, | ||
1827 | int fd, void *data __maybe_unused) | ||
1828 | { | ||
1829 | size_t ret; | ||
1830 | char *str; | ||
1831 | u32 nr, i; | ||
1832 | struct strbuf sb; | ||
1833 | |||
1834 | ret = read(fd, &nr, sizeof(nr)); | ||
1835 | if (ret != sizeof(nr)) | ||
1836 | return -1; | ||
1837 | |||
1838 | if (ph->needs_swap) | ||
1839 | nr = bswap_32(nr); | ||
1840 | |||
1841 | ph->env.nr_cmdline = nr; | ||
1842 | strbuf_init(&sb, 128); | ||
1843 | |||
1844 | for (i = 0; i < nr; i++) { | ||
1845 | str = do_read_string(fd, ph); | ||
1846 | if (!str) | ||
1847 | goto error; | ||
1848 | |||
1849 | /* include a NULL character at the end */ | ||
1850 | strbuf_add(&sb, str, strlen(str) + 1); | ||
1851 | free(str); | ||
1852 | } | ||
1853 | ph->env.cmdline = strbuf_detach(&sb, NULL); | ||
1854 | return 0; | ||
1855 | |||
1856 | error: | ||
1857 | strbuf_release(&sb); | ||
1858 | return -1; | ||
1859 | } | ||
1860 | |||
1861 | static int process_cpu_topology(struct perf_file_section *section __maybe_unused, | ||
1862 | struct perf_header *ph, int feat __maybe_unused, | ||
1863 | int fd, void *data __maybe_unused) | ||
1864 | { | ||
1865 | size_t ret; | ||
1866 | u32 nr, i; | ||
1867 | char *str; | ||
1868 | struct strbuf sb; | ||
1869 | |||
1870 | ret = read(fd, &nr, sizeof(nr)); | ||
1871 | if (ret != sizeof(nr)) | ||
1872 | return -1; | ||
1873 | |||
1874 | if (ph->needs_swap) | ||
1875 | nr = bswap_32(nr); | ||
1876 | |||
1877 | ph->env.nr_sibling_cores = nr; | ||
1878 | strbuf_init(&sb, 128); | ||
1879 | |||
1880 | for (i = 0; i < nr; i++) { | ||
1881 | str = do_read_string(fd, ph); | ||
1882 | if (!str) | ||
1883 | goto error; | ||
1884 | |||
1885 | /* include a NULL character at the end */ | ||
1886 | strbuf_add(&sb, str, strlen(str) + 1); | ||
1887 | free(str); | ||
1888 | } | ||
1889 | ph->env.sibling_cores = strbuf_detach(&sb, NULL); | ||
1890 | |||
1891 | ret = read(fd, &nr, sizeof(nr)); | ||
1892 | if (ret != sizeof(nr)) | ||
1893 | return -1; | ||
1894 | |||
1895 | if (ph->needs_swap) | ||
1896 | nr = bswap_32(nr); | ||
1897 | |||
1898 | ph->env.nr_sibling_threads = nr; | ||
1899 | |||
1900 | for (i = 0; i < nr; i++) { | ||
1901 | str = do_read_string(fd, ph); | ||
1902 | if (!str) | ||
1903 | goto error; | ||
1904 | |||
1905 | /* include a NULL character at the end */ | ||
1906 | strbuf_add(&sb, str, strlen(str) + 1); | ||
1907 | free(str); | ||
1908 | } | ||
1909 | ph->env.sibling_threads = strbuf_detach(&sb, NULL); | ||
1910 | return 0; | ||
1911 | |||
1912 | error: | ||
1913 | strbuf_release(&sb); | ||
1914 | return -1; | ||
1915 | } | ||
1916 | |||
1917 | static int process_numa_topology(struct perf_file_section *section __maybe_unused, | ||
1918 | struct perf_header *ph, int feat __maybe_unused, | ||
1919 | int fd, void *data __maybe_unused) | ||
1920 | { | ||
1921 | size_t ret; | ||
1922 | u32 nr, node, i; | ||
1923 | char *str; | ||
1924 | uint64_t mem_total, mem_free; | ||
1925 | struct strbuf sb; | ||
1926 | |||
1927 | /* nr nodes */ | ||
1928 | ret = read(fd, &nr, sizeof(nr)); | ||
1929 | if (ret != sizeof(nr)) | ||
1930 | goto error; | ||
1931 | |||
1932 | if (ph->needs_swap) | ||
1933 | nr = bswap_32(nr); | ||
1934 | |||
1935 | ph->env.nr_numa_nodes = nr; | ||
1936 | strbuf_init(&sb, 256); | ||
1937 | |||
1938 | for (i = 0; i < nr; i++) { | ||
1939 | /* node number */ | ||
1940 | ret = read(fd, &node, sizeof(node)); | ||
1941 | if (ret != sizeof(node)) | ||
1942 | goto error; | ||
1943 | |||
1944 | ret = read(fd, &mem_total, sizeof(u64)); | ||
1945 | if (ret != sizeof(u64)) | ||
1946 | goto error; | ||
1947 | |||
1948 | ret = read(fd, &mem_free, sizeof(u64)); | ||
1949 | if (ret != sizeof(u64)) | ||
1950 | goto error; | ||
1951 | |||
1952 | if (ph->needs_swap) { | ||
1953 | node = bswap_32(node); | ||
1954 | mem_total = bswap_64(mem_total); | ||
1955 | mem_free = bswap_64(mem_free); | ||
1956 | } | ||
1957 | |||
1958 | strbuf_addf(&sb, "%u:%"PRIu64":%"PRIu64":", | ||
1959 | node, mem_total, mem_free); | ||
1960 | |||
1961 | str = do_read_string(fd, ph); | ||
1962 | if (!str) | ||
1963 | goto error; | ||
1964 | |||
1965 | /* include a NULL character at the end */ | ||
1966 | strbuf_add(&sb, str, strlen(str) + 1); | ||
1967 | free(str); | ||
1968 | } | ||
1969 | ph->env.numa_nodes = strbuf_detach(&sb, NULL); | ||
1970 | return 0; | ||
1971 | |||
1972 | error: | ||
1973 | strbuf_release(&sb); | ||
1974 | return -1; | ||
1975 | } | ||
1976 | |||
1977 | static int process_pmu_mappings(struct perf_file_section *section __maybe_unused, | ||
1978 | struct perf_header *ph, int feat __maybe_unused, | ||
1979 | int fd, void *data __maybe_unused) | ||
1980 | { | ||
1981 | size_t ret; | ||
1982 | char *name; | ||
1983 | u32 pmu_num; | ||
1984 | u32 type; | ||
1985 | struct strbuf sb; | ||
1986 | |||
1987 | ret = read(fd, &pmu_num, sizeof(pmu_num)); | ||
1988 | if (ret != sizeof(pmu_num)) | ||
1989 | return -1; | ||
1990 | |||
1991 | if (ph->needs_swap) | ||
1992 | pmu_num = bswap_32(pmu_num); | ||
1993 | |||
1994 | if (!pmu_num) { | ||
1995 | pr_debug("pmu mappings not available\n"); | ||
1996 | return 0; | ||
1997 | } | ||
1998 | |||
1999 | ph->env.nr_pmu_mappings = pmu_num; | ||
2000 | strbuf_init(&sb, 128); | ||
2001 | |||
2002 | while (pmu_num) { | ||
2003 | if (read(fd, &type, sizeof(type)) != sizeof(type)) | ||
2004 | goto error; | ||
2005 | if (ph->needs_swap) | ||
2006 | type = bswap_32(type); | ||
2007 | |||
2008 | name = do_read_string(fd, ph); | ||
2009 | if (!name) | ||
2010 | goto error; | ||
2011 | |||
2012 | strbuf_addf(&sb, "%u:%s", type, name); | ||
2013 | /* include a NULL character at the end */ | ||
2014 | strbuf_add(&sb, "", 1); | ||
2015 | |||
2016 | free(name); | ||
2017 | pmu_num--; | ||
2018 | } | ||
2019 | ph->env.pmu_mappings = strbuf_detach(&sb, NULL); | ||
2020 | return 0; | ||
2021 | |||
2022 | error: | ||
2023 | strbuf_release(&sb); | ||
2024 | return -1; | ||
2025 | } | ||
2026 | |||
1731 | struct feature_ops { | 2027 | struct feature_ops { |
1732 | int (*write)(int fd, struct perf_header *h, struct perf_evlist *evlist); | 2028 | int (*write)(int fd, struct perf_header *h, struct perf_evlist *evlist); |
1733 | void (*print)(struct perf_header *h, int fd, FILE *fp); | 2029 | void (*print)(struct perf_header *h, int fd, FILE *fp); |
@@ -1745,10 +2041,11 @@ struct feature_ops { | |||
1745 | .process = process_##func } | 2041 | .process = process_##func } |
1746 | #define FEAT_OPF(n, func) \ | 2042 | #define FEAT_OPF(n, func) \ |
1747 | [n] = { .name = #n, .write = write_##func, .print = print_##func, \ | 2043 | [n] = { .name = #n, .write = write_##func, .print = print_##func, \ |
1748 | .full_only = true } | 2044 | .process = process_##func, .full_only = true } |
1749 | #define FEAT_OPA_R(n, func) \ | 2045 | #define FEAT_OPA_R(n, func) \ |
1750 | [n] = { .name = #n, .write = write_##func, .print = print_##func, \ | 2046 | [n] = { .name = #n, .write = write_##func, .print = print_##func, \ |
1751 | .read = read_##func } | 2047 | .read = read_##func, .process = process_##func, \ |
2048 | .full_only = true } | ||
1752 | 2049 | ||
1753 | /* feature_ops not implemented: */ | 2050 | /* feature_ops not implemented: */ |
1754 | #define print_tracing_data NULL | 2051 | #define print_tracing_data NULL |
@@ -1757,20 +2054,20 @@ struct feature_ops { | |||
1757 | static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = { | 2054 | static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = { |
1758 | FEAT_OPP(HEADER_TRACING_DATA, tracing_data), | 2055 | FEAT_OPP(HEADER_TRACING_DATA, tracing_data), |
1759 | FEAT_OPP(HEADER_BUILD_ID, build_id), | 2056 | FEAT_OPP(HEADER_BUILD_ID, build_id), |
1760 | FEAT_OPA(HEADER_HOSTNAME, hostname), | 2057 | FEAT_OPP(HEADER_HOSTNAME, hostname), |
1761 | FEAT_OPA(HEADER_OSRELEASE, osrelease), | 2058 | FEAT_OPP(HEADER_OSRELEASE, osrelease), |
1762 | FEAT_OPA(HEADER_VERSION, version), | 2059 | FEAT_OPP(HEADER_VERSION, version), |
1763 | FEAT_OPA(HEADER_ARCH, arch), | 2060 | FEAT_OPP(HEADER_ARCH, arch), |
1764 | FEAT_OPA(HEADER_NRCPUS, nrcpus), | 2061 | FEAT_OPP(HEADER_NRCPUS, nrcpus), |
1765 | FEAT_OPA(HEADER_CPUDESC, cpudesc), | 2062 | FEAT_OPP(HEADER_CPUDESC, cpudesc), |
1766 | FEAT_OPA_R(HEADER_CPUID, cpuid), | 2063 | FEAT_OPA_R(HEADER_CPUID, cpuid), |
1767 | FEAT_OPA(HEADER_TOTAL_MEM, total_mem), | 2064 | FEAT_OPP(HEADER_TOTAL_MEM, total_mem), |
1768 | FEAT_OPP(HEADER_EVENT_DESC, event_desc), | 2065 | FEAT_OPP(HEADER_EVENT_DESC, event_desc), |
1769 | FEAT_OPA(HEADER_CMDLINE, cmdline), | 2066 | FEAT_OPP(HEADER_CMDLINE, cmdline), |
1770 | FEAT_OPF(HEADER_CPU_TOPOLOGY, cpu_topology), | 2067 | FEAT_OPF(HEADER_CPU_TOPOLOGY, cpu_topology), |
1771 | FEAT_OPF(HEADER_NUMA_TOPOLOGY, numa_topology), | 2068 | FEAT_OPF(HEADER_NUMA_TOPOLOGY, numa_topology), |
1772 | FEAT_OPA(HEADER_BRANCH_STACK, branch_stack), | 2069 | FEAT_OPA(HEADER_BRANCH_STACK, branch_stack), |
1773 | FEAT_OPA(HEADER_PMU_MAPPINGS, pmu_mappings), | 2070 | FEAT_OPP(HEADER_PMU_MAPPINGS, pmu_mappings), |
1774 | }; | 2071 | }; |
1775 | 2072 | ||
1776 | struct header_print_data { | 2073 | struct header_print_data { |