hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/tools/perf/builtin-kmem.c
....@@ -2,10 +2,11 @@
22 #include "builtin.h"
33 #include "perf.h"
44
5
+#include "util/dso.h"
56 #include "util/evlist.h"
67 #include "util/evsel.h"
7
-#include "util/util.h"
88 #include "util/config.h"
9
+#include "util/map.h"
910 #include "util/symbol.h"
1011 #include "util/thread.h"
1112 #include "util/header.h"
....@@ -13,23 +14,27 @@
1314 #include "util/tool.h"
1415 #include "util/callchain.h"
1516 #include "util/time-utils.h"
17
+#include <linux/err.h>
1618
19
+#include <subcmd/pager.h>
1720 #include <subcmd/parse-options.h>
1821 #include "util/trace-event.h"
1922 #include "util/data.h"
2023 #include "util/cpumap.h"
2124
2225 #include "util/debug.h"
26
+#include "util/string2.h"
2327
2428 #include <linux/kernel.h>
2529 #include <linux/rbtree.h>
2630 #include <linux/string.h>
31
+#include <linux/zalloc.h>
2732 #include <errno.h>
2833 #include <inttypes.h>
2934 #include <locale.h>
3035 #include <regex.h>
3136
32
-#include "sane_ctype.h"
37
+#include <linux/ctype.h>
3338
3439 static int kmem_slab;
3540 static int kmem_page;
....@@ -164,13 +169,12 @@
164169 return 0;
165170 }
166171
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)
169173 {
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");
174178
175179 if (insert_alloc_stat(call_site, ptr, bytes_req, bytes_alloc, sample->cpu) ||
176180 insert_caller_stat(call_site, bytes_req, bytes_alloc))
....@@ -183,14 +187,13 @@
183187 return 0;
184188 }
185189
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)
188191 {
189
- int ret = perf_evsel__process_alloc_event(evsel, sample);
192
+ int ret = evsel__process_alloc_event(evsel, sample);
190193
191194 if (!ret) {
192195 int node1 = cpu__get_node(sample->cpu),
193
- node2 = perf_evsel__intval(evsel, sample, "node");
196
+ node2 = evsel__intval(evsel, sample, "node");
194197
195198 if (node1 != node2)
196199 nr_cross_allocs++;
....@@ -227,10 +230,9 @@
227230 return NULL;
228231 }
229232
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)
232234 {
233
- unsigned long ptr = perf_evsel__intval(evsel, sample, "ptr");
235
+ unsigned long ptr = evsel__intval(evsel, sample, "ptr");
234236 struct alloc_stat *s_alloc, *s_caller;
235237
236238 s_alloc = search_alloc_stat(ptr, 0, &root_alloc_stat, ptr_cmp);
....@@ -334,7 +336,7 @@
334336 struct alloc_func *func;
335337 struct machine *machine = &kmem_session->machines.host;
336338 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?";
338340
339341 ret = regcomp(&alloc_func_regex, pattern, REG_EXTENDED);
340342 if (ret) {
....@@ -379,7 +381,7 @@
379381 * Find first non-memory allocation function from callchain.
380382 * The allocation functions are in the 'alloc_func_list'.
381383 */
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)
383385 {
384386 struct addr_location al;
385387 struct machine *machine = &kmem_session->machines.host;
....@@ -407,8 +409,8 @@
407409 sizeof(key), callcmp);
408410 if (!caller) {
409411 /* 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);
412414 else
413415 addr = node->ip;
414416
....@@ -727,7 +729,7 @@
727729 return NULL;
728730 }
729731
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,
731733 unsigned int gfp_flags)
732734 {
733735 struct tep_record record = {
....@@ -748,7 +750,8 @@
748750 }
749751
750752 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);
752755
753756 str = strtok_r(seq.buffer, " ", &pos);
754757 while (str) {
....@@ -778,13 +781,12 @@
778781 return 0;
779782 }
780783
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)
783785 {
784786 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,
788790 "migratetype");
789791 u64 bytes = kmem_page_size << order;
790792 u64 callsite;
....@@ -796,9 +798,9 @@
796798 };
797799
798800 if (use_pfn)
799
- page = perf_evsel__intval(evsel, sample, "pfn");
801
+ page = evsel__intval(evsel, sample, "pfn");
800802 else
801
- page = perf_evsel__intval(evsel, sample, "page");
803
+ page = evsel__intval(evsel, sample, "page");
802804
803805 nr_page_allocs++;
804806 total_page_alloc_bytes += bytes;
....@@ -851,11 +853,10 @@
851853 return 0;
852854 }
853855
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)
856857 {
857858 u64 page;
858
- unsigned int order = perf_evsel__intval(evsel, sample, "order");
859
+ unsigned int order = evsel__intval(evsel, sample, "order");
859860 u64 bytes = kmem_page_size << order;
860861 struct page_stat *pstat;
861862 struct page_stat this = {
....@@ -863,9 +864,9 @@
863864 };
864865
865866 if (use_pfn)
866
- page = perf_evsel__intval(evsel, sample, "pfn");
867
+ page = evsel__intval(evsel, sample, "pfn");
867868 else
868
- page = perf_evsel__intval(evsel, sample, "page");
869
+ page = evsel__intval(evsel, sample, "page");
869870
870871 nr_page_frees++;
871872 total_page_free_bytes += bytes;
....@@ -929,13 +930,13 @@
929930 return false;
930931 }
931932
932
-typedef int (*tracepoint_handler)(struct perf_evsel *evsel,
933
+typedef int (*tracepoint_handler)(struct evsel *evsel,
933934 struct perf_sample *sample);
934935
935936 static int process_sample_event(struct perf_tool *tool __maybe_unused,
936937 union perf_event *event,
937938 struct perf_sample *sample,
938
- struct perf_evsel *evsel,
939
+ struct evsel *evsel,
939940 struct machine *machine)
940941 {
941942 int err = 0;
....@@ -1362,18 +1363,18 @@
13621363 static int __cmd_kmem(struct perf_session *session)
13631364 {
13641365 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[] = {
13671368 /* 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, },
13741375 /* 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, },
13771378 };
13781379
13791380 if (!perf_session__has_traces(session, "kmem record"))
....@@ -1385,8 +1386,8 @@
13851386 }
13861387
13871388 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")) {
13901391 use_pfn = true;
13911392 break;
13921393 }
....@@ -1925,14 +1926,15 @@
19251926 NULL
19261927 };
19271928 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";
19291930 int ret = perf_config(kmem_config, NULL);
19301931
19311932 if (ret)
19321933 return ret;
19331934
19341935 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);
19361938
19371939 if (!argc)
19381940 usage_with_options(kmem_usage, kmem_options);
....@@ -1949,11 +1951,11 @@
19491951 return __cmd_record(argc, argv);
19501952 }
19511953
1952
- data.file.path = input_name;
1954
+ data.path = input_name;
19531955
19541956 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);
19571959
19581960 ret = -1;
19591961
....@@ -1966,7 +1968,7 @@
19661968 }
19671969
19681970 if (kmem_page) {
1969
- struct perf_evsel *evsel;
1971
+ struct evsel *evsel;
19701972
19711973 evsel = perf_evlist__find_tracepoint_by_name(session->evlist,
19721974 "kmem:mm_page_alloc");
....@@ -1975,7 +1977,7 @@
19751977 goto out_delete;
19761978 }
19771979
1978
- kmem_page_size = tep_get_page_size(evsel->tp_format->pevent);
1980
+ kmem_page_size = tep_get_page_size(evsel->tp_format->tep);
19791981 symbol_conf.use_callchain = true;
19801982 }
19811983