.. | .. |
---|
2 | 2 | #include "builtin.h" |
---|
3 | 3 | #include "perf.h" |
---|
4 | 4 | |
---|
| 5 | +#include "util/dso.h" |
---|
5 | 6 | #include "util/evlist.h" |
---|
6 | 7 | #include "util/evsel.h" |
---|
7 | | -#include "util/util.h" |
---|
8 | 8 | #include "util/config.h" |
---|
| 9 | +#include "util/map.h" |
---|
9 | 10 | #include "util/symbol.h" |
---|
10 | 11 | #include "util/thread.h" |
---|
11 | 12 | #include "util/header.h" |
---|
.. | .. |
---|
13 | 14 | #include "util/tool.h" |
---|
14 | 15 | #include "util/callchain.h" |
---|
15 | 16 | #include "util/time-utils.h" |
---|
| 17 | +#include <linux/err.h> |
---|
16 | 18 | |
---|
| 19 | +#include <subcmd/pager.h> |
---|
17 | 20 | #include <subcmd/parse-options.h> |
---|
18 | 21 | #include "util/trace-event.h" |
---|
19 | 22 | #include "util/data.h" |
---|
20 | 23 | #include "util/cpumap.h" |
---|
21 | 24 | |
---|
22 | 25 | #include "util/debug.h" |
---|
| 26 | +#include "util/string2.h" |
---|
23 | 27 | |
---|
24 | 28 | #include <linux/kernel.h> |
---|
25 | 29 | #include <linux/rbtree.h> |
---|
26 | 30 | #include <linux/string.h> |
---|
| 31 | +#include <linux/zalloc.h> |
---|
27 | 32 | #include <errno.h> |
---|
28 | 33 | #include <inttypes.h> |
---|
29 | 34 | #include <locale.h> |
---|
30 | 35 | #include <regex.h> |
---|
31 | 36 | |
---|
32 | | -#include "sane_ctype.h" |
---|
| 37 | +#include <linux/ctype.h> |
---|
33 | 38 | |
---|
34 | 39 | static int kmem_slab; |
---|
35 | 40 | static int kmem_page; |
---|
.. | .. |
---|
164 | 169 | return 0; |
---|
165 | 170 | } |
---|
166 | 171 | |
---|
167 | | -static int perf_evsel__process_alloc_event(struct perf_evsel *evsel, |
---|
168 | | - struct perf_sample *sample) |
---|
| 172 | +static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sample *sample) |
---|
169 | 173 | { |
---|
170 | | - unsigned long ptr = perf_evsel__intval(evsel, sample, "ptr"), |
---|
171 | | - call_site = perf_evsel__intval(evsel, sample, "call_site"); |
---|
172 | | - int bytes_req = perf_evsel__intval(evsel, sample, "bytes_req"), |
---|
173 | | - bytes_alloc = perf_evsel__intval(evsel, sample, "bytes_alloc"); |
---|
| 174 | + unsigned long ptr = evsel__intval(evsel, sample, "ptr"), |
---|
| 175 | + call_site = evsel__intval(evsel, sample, "call_site"); |
---|
| 176 | + int bytes_req = evsel__intval(evsel, sample, "bytes_req"), |
---|
| 177 | + bytes_alloc = evsel__intval(evsel, sample, "bytes_alloc"); |
---|
174 | 178 | |
---|
175 | 179 | if (insert_alloc_stat(call_site, ptr, bytes_req, bytes_alloc, sample->cpu) || |
---|
176 | 180 | insert_caller_stat(call_site, bytes_req, bytes_alloc)) |
---|
.. | .. |
---|
183 | 187 | return 0; |
---|
184 | 188 | } |
---|
185 | 189 | |
---|
186 | | -static int perf_evsel__process_alloc_node_event(struct perf_evsel *evsel, |
---|
187 | | - struct perf_sample *sample) |
---|
| 190 | +static int evsel__process_alloc_node_event(struct evsel *evsel, struct perf_sample *sample) |
---|
188 | 191 | { |
---|
189 | | - int ret = perf_evsel__process_alloc_event(evsel, sample); |
---|
| 192 | + int ret = evsel__process_alloc_event(evsel, sample); |
---|
190 | 193 | |
---|
191 | 194 | if (!ret) { |
---|
192 | 195 | int node1 = cpu__get_node(sample->cpu), |
---|
193 | | - node2 = perf_evsel__intval(evsel, sample, "node"); |
---|
| 196 | + node2 = evsel__intval(evsel, sample, "node"); |
---|
194 | 197 | |
---|
195 | 198 | if (node1 != node2) |
---|
196 | 199 | nr_cross_allocs++; |
---|
.. | .. |
---|
227 | 230 | return NULL; |
---|
228 | 231 | } |
---|
229 | 232 | |
---|
230 | | -static int perf_evsel__process_free_event(struct perf_evsel *evsel, |
---|
231 | | - struct perf_sample *sample) |
---|
| 233 | +static int evsel__process_free_event(struct evsel *evsel, struct perf_sample *sample) |
---|
232 | 234 | { |
---|
233 | | - unsigned long ptr = perf_evsel__intval(evsel, sample, "ptr"); |
---|
| 235 | + unsigned long ptr = evsel__intval(evsel, sample, "ptr"); |
---|
234 | 236 | struct alloc_stat *s_alloc, *s_caller; |
---|
235 | 237 | |
---|
236 | 238 | s_alloc = search_alloc_stat(ptr, 0, &root_alloc_stat, ptr_cmp); |
---|
.. | .. |
---|
334 | 336 | struct alloc_func *func; |
---|
335 | 337 | struct machine *machine = &kmem_session->machines.host; |
---|
336 | 338 | regex_t alloc_func_regex; |
---|
337 | | - const char pattern[] = "^_?_?(alloc|get_free|get_zeroed)_pages?"; |
---|
| 339 | + static const char pattern[] = "^_?_?(alloc|get_free|get_zeroed)_pages?"; |
---|
338 | 340 | |
---|
339 | 341 | ret = regcomp(&alloc_func_regex, pattern, REG_EXTENDED); |
---|
340 | 342 | if (ret) { |
---|
.. | .. |
---|
379 | 381 | * Find first non-memory allocation function from callchain. |
---|
380 | 382 | * The allocation functions are in the 'alloc_func_list'. |
---|
381 | 383 | */ |
---|
382 | | -static u64 find_callsite(struct perf_evsel *evsel, struct perf_sample *sample) |
---|
| 384 | +static u64 find_callsite(struct evsel *evsel, struct perf_sample *sample) |
---|
383 | 385 | { |
---|
384 | 386 | struct addr_location al; |
---|
385 | 387 | struct machine *machine = &kmem_session->machines.host; |
---|
.. | .. |
---|
407 | 409 | sizeof(key), callcmp); |
---|
408 | 410 | if (!caller) { |
---|
409 | 411 | /* found */ |
---|
410 | | - if (node->map) |
---|
411 | | - addr = map__unmap_ip(node->map, node->ip); |
---|
| 412 | + if (node->ms.map) |
---|
| 413 | + addr = map__unmap_ip(node->ms.map, node->ip); |
---|
412 | 414 | else |
---|
413 | 415 | addr = node->ip; |
---|
414 | 416 | |
---|
.. | .. |
---|
727 | 729 | return NULL; |
---|
728 | 730 | } |
---|
729 | 731 | |
---|
730 | | -static int parse_gfp_flags(struct perf_evsel *evsel, struct perf_sample *sample, |
---|
| 732 | +static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, |
---|
731 | 733 | unsigned int gfp_flags) |
---|
732 | 734 | { |
---|
733 | 735 | struct tep_record record = { |
---|
.. | .. |
---|
748 | 750 | } |
---|
749 | 751 | |
---|
750 | 752 | trace_seq_init(&seq); |
---|
751 | | - tep_event_info(&seq, evsel->tp_format, &record); |
---|
| 753 | + tep_print_event(evsel->tp_format->tep, |
---|
| 754 | + &seq, &record, "%s", TEP_PRINT_INFO); |
---|
752 | 755 | |
---|
753 | 756 | str = strtok_r(seq.buffer, " ", &pos); |
---|
754 | 757 | while (str) { |
---|
.. | .. |
---|
778 | 781 | return 0; |
---|
779 | 782 | } |
---|
780 | 783 | |
---|
781 | | -static int perf_evsel__process_page_alloc_event(struct perf_evsel *evsel, |
---|
782 | | - struct perf_sample *sample) |
---|
| 784 | +static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_sample *sample) |
---|
783 | 785 | { |
---|
784 | 786 | u64 page; |
---|
785 | | - unsigned int order = perf_evsel__intval(evsel, sample, "order"); |
---|
786 | | - unsigned int gfp_flags = perf_evsel__intval(evsel, sample, "gfp_flags"); |
---|
787 | | - unsigned int migrate_type = perf_evsel__intval(evsel, sample, |
---|
| 787 | + unsigned int order = evsel__intval(evsel, sample, "order"); |
---|
| 788 | + unsigned int gfp_flags = evsel__intval(evsel, sample, "gfp_flags"); |
---|
| 789 | + unsigned int migrate_type = evsel__intval(evsel, sample, |
---|
788 | 790 | "migratetype"); |
---|
789 | 791 | u64 bytes = kmem_page_size << order; |
---|
790 | 792 | u64 callsite; |
---|
.. | .. |
---|
796 | 798 | }; |
---|
797 | 799 | |
---|
798 | 800 | if (use_pfn) |
---|
799 | | - page = perf_evsel__intval(evsel, sample, "pfn"); |
---|
| 801 | + page = evsel__intval(evsel, sample, "pfn"); |
---|
800 | 802 | else |
---|
801 | | - page = perf_evsel__intval(evsel, sample, "page"); |
---|
| 803 | + page = evsel__intval(evsel, sample, "page"); |
---|
802 | 804 | |
---|
803 | 805 | nr_page_allocs++; |
---|
804 | 806 | total_page_alloc_bytes += bytes; |
---|
.. | .. |
---|
851 | 853 | return 0; |
---|
852 | 854 | } |
---|
853 | 855 | |
---|
854 | | -static int perf_evsel__process_page_free_event(struct perf_evsel *evsel, |
---|
855 | | - struct perf_sample *sample) |
---|
| 856 | +static int evsel__process_page_free_event(struct evsel *evsel, struct perf_sample *sample) |
---|
856 | 857 | { |
---|
857 | 858 | u64 page; |
---|
858 | | - unsigned int order = perf_evsel__intval(evsel, sample, "order"); |
---|
| 859 | + unsigned int order = evsel__intval(evsel, sample, "order"); |
---|
859 | 860 | u64 bytes = kmem_page_size << order; |
---|
860 | 861 | struct page_stat *pstat; |
---|
861 | 862 | struct page_stat this = { |
---|
.. | .. |
---|
863 | 864 | }; |
---|
864 | 865 | |
---|
865 | 866 | if (use_pfn) |
---|
866 | | - page = perf_evsel__intval(evsel, sample, "pfn"); |
---|
| 867 | + page = evsel__intval(evsel, sample, "pfn"); |
---|
867 | 868 | else |
---|
868 | | - page = perf_evsel__intval(evsel, sample, "page"); |
---|
| 869 | + page = evsel__intval(evsel, sample, "page"); |
---|
869 | 870 | |
---|
870 | 871 | nr_page_frees++; |
---|
871 | 872 | total_page_free_bytes += bytes; |
---|
.. | .. |
---|
929 | 930 | return false; |
---|
930 | 931 | } |
---|
931 | 932 | |
---|
932 | | -typedef int (*tracepoint_handler)(struct perf_evsel *evsel, |
---|
| 933 | +typedef int (*tracepoint_handler)(struct evsel *evsel, |
---|
933 | 934 | struct perf_sample *sample); |
---|
934 | 935 | |
---|
935 | 936 | static int process_sample_event(struct perf_tool *tool __maybe_unused, |
---|
936 | 937 | union perf_event *event, |
---|
937 | 938 | struct perf_sample *sample, |
---|
938 | | - struct perf_evsel *evsel, |
---|
| 939 | + struct evsel *evsel, |
---|
939 | 940 | struct machine *machine) |
---|
940 | 941 | { |
---|
941 | 942 | int err = 0; |
---|
.. | .. |
---|
1362 | 1363 | static int __cmd_kmem(struct perf_session *session) |
---|
1363 | 1364 | { |
---|
1364 | 1365 | int err = -EINVAL; |
---|
1365 | | - struct perf_evsel *evsel; |
---|
1366 | | - const struct perf_evsel_str_handler kmem_tracepoints[] = { |
---|
| 1366 | + struct evsel *evsel; |
---|
| 1367 | + const struct evsel_str_handler kmem_tracepoints[] = { |
---|
1367 | 1368 | /* slab allocator */ |
---|
1368 | | - { "kmem:kmalloc", perf_evsel__process_alloc_event, }, |
---|
1369 | | - { "kmem:kmem_cache_alloc", perf_evsel__process_alloc_event, }, |
---|
1370 | | - { "kmem:kmalloc_node", perf_evsel__process_alloc_node_event, }, |
---|
1371 | | - { "kmem:kmem_cache_alloc_node", perf_evsel__process_alloc_node_event, }, |
---|
1372 | | - { "kmem:kfree", perf_evsel__process_free_event, }, |
---|
1373 | | - { "kmem:kmem_cache_free", perf_evsel__process_free_event, }, |
---|
| 1369 | + { "kmem:kmalloc", evsel__process_alloc_event, }, |
---|
| 1370 | + { "kmem:kmem_cache_alloc", evsel__process_alloc_event, }, |
---|
| 1371 | + { "kmem:kmalloc_node", evsel__process_alloc_node_event, }, |
---|
| 1372 | + { "kmem:kmem_cache_alloc_node", evsel__process_alloc_node_event, }, |
---|
| 1373 | + { "kmem:kfree", evsel__process_free_event, }, |
---|
| 1374 | + { "kmem:kmem_cache_free", evsel__process_free_event, }, |
---|
1374 | 1375 | /* page allocator */ |
---|
1375 | | - { "kmem:mm_page_alloc", perf_evsel__process_page_alloc_event, }, |
---|
1376 | | - { "kmem:mm_page_free", perf_evsel__process_page_free_event, }, |
---|
| 1376 | + { "kmem:mm_page_alloc", evsel__process_page_alloc_event, }, |
---|
| 1377 | + { "kmem:mm_page_free", evsel__process_page_free_event, }, |
---|
1377 | 1378 | }; |
---|
1378 | 1379 | |
---|
1379 | 1380 | if (!perf_session__has_traces(session, "kmem record")) |
---|
.. | .. |
---|
1385 | 1386 | } |
---|
1386 | 1387 | |
---|
1387 | 1388 | evlist__for_each_entry(session->evlist, evsel) { |
---|
1388 | | - if (!strcmp(perf_evsel__name(evsel), "kmem:mm_page_alloc") && |
---|
1389 | | - perf_evsel__field(evsel, "pfn")) { |
---|
| 1389 | + if (!strcmp(evsel__name(evsel), "kmem:mm_page_alloc") && |
---|
| 1390 | + evsel__field(evsel, "pfn")) { |
---|
1390 | 1391 | use_pfn = true; |
---|
1391 | 1392 | break; |
---|
1392 | 1393 | } |
---|
.. | .. |
---|
1925 | 1926 | NULL |
---|
1926 | 1927 | }; |
---|
1927 | 1928 | struct perf_session *session; |
---|
1928 | | - const char errmsg[] = "No %s allocation events found. Have you run 'perf kmem record --%s'?\n"; |
---|
| 1929 | + static const char errmsg[] = "No %s allocation events found. Have you run 'perf kmem record --%s'?\n"; |
---|
1929 | 1930 | int ret = perf_config(kmem_config, NULL); |
---|
1930 | 1931 | |
---|
1931 | 1932 | if (ret) |
---|
1932 | 1933 | return ret; |
---|
1933 | 1934 | |
---|
1934 | 1935 | argc = parse_options_subcommand(argc, argv, kmem_options, |
---|
1935 | | - kmem_subcommands, kmem_usage, 0); |
---|
| 1936 | + kmem_subcommands, kmem_usage, |
---|
| 1937 | + PARSE_OPT_STOP_AT_NON_OPTION); |
---|
1936 | 1938 | |
---|
1937 | 1939 | if (!argc) |
---|
1938 | 1940 | usage_with_options(kmem_usage, kmem_options); |
---|
.. | .. |
---|
1949 | 1951 | return __cmd_record(argc, argv); |
---|
1950 | 1952 | } |
---|
1951 | 1953 | |
---|
1952 | | - data.file.path = input_name; |
---|
| 1954 | + data.path = input_name; |
---|
1953 | 1955 | |
---|
1954 | 1956 | kmem_session = session = perf_session__new(&data, false, &perf_kmem); |
---|
1955 | | - if (session == NULL) |
---|
1956 | | - return -1; |
---|
| 1957 | + if (IS_ERR(session)) |
---|
| 1958 | + return PTR_ERR(session); |
---|
1957 | 1959 | |
---|
1958 | 1960 | ret = -1; |
---|
1959 | 1961 | |
---|
.. | .. |
---|
1966 | 1968 | } |
---|
1967 | 1969 | |
---|
1968 | 1970 | if (kmem_page) { |
---|
1969 | | - struct perf_evsel *evsel; |
---|
| 1971 | + struct evsel *evsel; |
---|
1970 | 1972 | |
---|
1971 | 1973 | evsel = perf_evlist__find_tracepoint_by_name(session->evlist, |
---|
1972 | 1974 | "kmem:mm_page_alloc"); |
---|
.. | .. |
---|
1975 | 1977 | goto out_delete; |
---|
1976 | 1978 | } |
---|
1977 | 1979 | |
---|
1978 | | - kmem_page_size = tep_get_page_size(evsel->tp_format->pevent); |
---|
| 1980 | + kmem_page_size = tep_get_page_size(evsel->tp_format->tep); |
---|
1979 | 1981 | symbol_conf.use_callchain = true; |
---|
1980 | 1982 | } |
---|
1981 | 1983 | |
---|