aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/util/callchain.c103
-rw-r--r--tools/perf/util/python.c13
-rw-r--r--tools/perf/util/util.c104
-rw-r--r--tools/perf/util/util.h4
4 files changed, 116 insertions, 108 deletions
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index 0096d45a06b3..81fc29ac798f 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -24,6 +24,21 @@
24#include "machine.h" 24#include "machine.h"
25#include "callchain.h" 25#include "callchain.h"
26 26
27#define CALLCHAIN_PARAM_DEFAULT \
28 .mode = CHAIN_GRAPH_ABS, \
29 .min_percent = 0.5, \
30 .order = ORDER_CALLEE, \
31 .key = CCKEY_FUNCTION, \
32 .value = CCVAL_PERCENT, \
33
34struct callchain_param callchain_param = {
35 CALLCHAIN_PARAM_DEFAULT
36};
37
38struct callchain_param callchain_param_default = {
39 CALLCHAIN_PARAM_DEFAULT
40};
41
27__thread struct callchain_cursor callchain_cursor; 42__thread struct callchain_cursor callchain_cursor;
28 43
29int parse_callchain_record_opt(const char *arg, struct callchain_param *param) 44int parse_callchain_record_opt(const char *arg, struct callchain_param *param)
@@ -113,6 +128,32 @@ static int parse_callchain_value(const char *value)
113 return -1; 128 return -1;
114} 129}
115 130
131static int get_stack_size(const char *str, unsigned long *_size)
132{
133 char *endptr;
134 unsigned long size;
135 unsigned long max_size = round_down(USHRT_MAX, sizeof(u64));
136
137 size = strtoul(str, &endptr, 0);
138
139 do {
140 if (*endptr)
141 break;
142
143 size = round_up(size, sizeof(u64));
144 if (!size || size > max_size)
145 break;
146
147 *_size = size;
148 return 0;
149
150 } while (0);
151
152 pr_err("callchain: Incorrect stack dump size (max %ld): %s\n",
153 max_size, str);
154 return -1;
155}
156
116static int 157static int
117__parse_callchain_report_opt(const char *arg, bool allow_record_opt) 158__parse_callchain_report_opt(const char *arg, bool allow_record_opt)
118{ 159{
@@ -196,6 +237,68 @@ int parse_callchain_top_opt(const char *arg)
196 return __parse_callchain_report_opt(arg, true); 237 return __parse_callchain_report_opt(arg, true);
197} 238}
198 239
240int parse_callchain_record(const char *arg, struct callchain_param *param)
241{
242 char *tok, *name, *saveptr = NULL;
243 char *buf;
244 int ret = -1;
245
246 /* We need buffer that we know we can write to. */
247 buf = malloc(strlen(arg) + 1);
248 if (!buf)
249 return -ENOMEM;
250
251 strcpy(buf, arg);
252
253 tok = strtok_r((char *)buf, ",", &saveptr);
254 name = tok ? : (char *)buf;
255
256 do {
257 /* Framepointer style */
258 if (!strncmp(name, "fp", sizeof("fp"))) {
259 if (!strtok_r(NULL, ",", &saveptr)) {
260 param->record_mode = CALLCHAIN_FP;
261 ret = 0;
262 } else
263 pr_err("callchain: No more arguments "
264 "needed for --call-graph fp\n");
265 break;
266
267 /* Dwarf style */
268 } else if (!strncmp(name, "dwarf", sizeof("dwarf"))) {
269 const unsigned long default_stack_dump_size = 8192;
270
271 ret = 0;
272 param->record_mode = CALLCHAIN_DWARF;
273 param->dump_size = default_stack_dump_size;
274
275 tok = strtok_r(NULL, ",", &saveptr);
276 if (tok) {
277 unsigned long size = 0;
278
279 ret = get_stack_size(tok, &size);
280 param->dump_size = size;
281 }
282 } else if (!strncmp(name, "lbr", sizeof("lbr"))) {
283 if (!strtok_r(NULL, ",", &saveptr)) {
284 param->record_mode = CALLCHAIN_LBR;
285 ret = 0;
286 } else
287 pr_err("callchain: No more arguments "
288 "needed for --call-graph lbr\n");
289 break;
290 } else {
291 pr_err("callchain: Unknown --call-graph option "
292 "value: %s\n", arg);
293 break;
294 }
295
296 } while (0);
297
298 free(buf);
299 return ret;
300}
301
199int perf_callchain_config(const char *var, const char *value) 302int perf_callchain_config(const char *var, const char *value)
200{ 303{
201 char *endptr; 304 char *endptr;
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 0533711af44d..c129e99114ae 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -4,6 +4,7 @@
4#include <poll.h> 4#include <poll.h>
5#include <linux/err.h> 5#include <linux/err.h>
6#include "evlist.h" 6#include "evlist.h"
7#include "callchain.h"
7#include "evsel.h" 8#include "evsel.h"
8#include "event.h" 9#include "event.h"
9#include "cpumap.h" 10#include "cpumap.h"
@@ -11,6 +12,18 @@
11#include "thread_map.h" 12#include "thread_map.h"
12 13
13/* 14/*
15 * Provide these two so that we don't have to link against callchain.c and
16 * start dragging hist.c, etc.
17 */
18struct callchain_param callchain_param;
19
20int parse_callchain_record(const char *arg __maybe_unused,
21 struct callchain_param *param __maybe_unused)
22{
23 return 0;
24}
25
26/*
14 * Support debug printing even though util/debug.c is not linked. That means 27 * Support debug printing even though util/debug.c is not linked. That means
15 * implementing 'verbose' and 'eprintf'. 28 * implementing 'verbose' and 'eprintf'.
16 */ 29 */
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index ae8036f06329..131d21a659fb 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -17,24 +17,8 @@
17#include <linux/log2.h> 17#include <linux/log2.h>
18#include <linux/time64.h> 18#include <linux/time64.h>
19#include <unistd.h> 19#include <unistd.h>
20#include "callchain.h"
21#include "strlist.h" 20#include "strlist.h"
22 21
23#define CALLCHAIN_PARAM_DEFAULT \
24 .mode = CHAIN_GRAPH_ABS, \
25 .min_percent = 0.5, \
26 .order = ORDER_CALLEE, \
27 .key = CCKEY_FUNCTION, \
28 .value = CCVAL_PERCENT, \
29
30struct callchain_param callchain_param = {
31 CALLCHAIN_PARAM_DEFAULT
32};
33
34struct callchain_param callchain_param_default = {
35 CALLCHAIN_PARAM_DEFAULT
36};
37
38/* 22/*
39 * XXX We need to find a better place for these things... 23 * XXX We need to find a better place for these things...
40 */ 24 */
@@ -377,94 +361,6 @@ unsigned long parse_tag_value(const char *str, struct parse_tag *tags)
377 return (unsigned long) -1; 361 return (unsigned long) -1;
378} 362}
379 363
380int get_stack_size(const char *str, unsigned long *_size)
381{
382 char *endptr;
383 unsigned long size;
384 unsigned long max_size = round_down(USHRT_MAX, sizeof(u64));
385
386 size = strtoul(str, &endptr, 0);
387
388 do {
389 if (*endptr)
390 break;
391
392 size = round_up(size, sizeof(u64));
393 if (!size || size > max_size)
394 break;
395
396 *_size = size;
397 return 0;
398
399 } while (0);
400
401 pr_err("callchain: Incorrect stack dump size (max %ld): %s\n",
402 max_size, str);
403 return -1;
404}
405
406int parse_callchain_record(const char *arg, struct callchain_param *param)
407{
408 char *tok, *name, *saveptr = NULL;
409 char *buf;
410 int ret = -1;
411
412 /* We need buffer that we know we can write to. */
413 buf = malloc(strlen(arg) + 1);
414 if (!buf)
415 return -ENOMEM;
416
417 strcpy(buf, arg);
418
419 tok = strtok_r((char *)buf, ",", &saveptr);
420 name = tok ? : (char *)buf;
421
422 do {
423 /* Framepointer style */
424 if (!strncmp(name, "fp", sizeof("fp"))) {
425 if (!strtok_r(NULL, ",", &saveptr)) {
426 param->record_mode = CALLCHAIN_FP;
427 ret = 0;
428 } else
429 pr_err("callchain: No more arguments "
430 "needed for --call-graph fp\n");
431 break;
432
433 /* Dwarf style */
434 } else if (!strncmp(name, "dwarf", sizeof("dwarf"))) {
435 const unsigned long default_stack_dump_size = 8192;
436
437 ret = 0;
438 param->record_mode = CALLCHAIN_DWARF;
439 param->dump_size = default_stack_dump_size;
440
441 tok = strtok_r(NULL, ",", &saveptr);
442 if (tok) {
443 unsigned long size = 0;
444
445 ret = get_stack_size(tok, &size);
446 param->dump_size = size;
447 }
448 } else if (!strncmp(name, "lbr", sizeof("lbr"))) {
449 if (!strtok_r(NULL, ",", &saveptr)) {
450 param->record_mode = CALLCHAIN_LBR;
451 ret = 0;
452 } else
453 pr_err("callchain: No more arguments "
454 "needed for --call-graph lbr\n");
455 break;
456 } else {
457 pr_err("callchain: Unknown --call-graph option "
458 "value: %s\n", arg);
459 break;
460 }
461
462 } while (0);
463
464 free(buf);
465 return ret;
466}
467
468int perf_event_paranoid(void) 364int perf_event_paranoid(void)
469{ 365{
470 int value; 366 int value;
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 5dea8a96cf84..fcad17ce5c19 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -17,7 +17,6 @@
17#include <stdlib.h> 17#include <stdlib.h>
18#include <stdarg.h> 18#include <stdarg.h>
19#include <string.h> 19#include <string.h>
20#include <limits.h>
21#include <sys/param.h> 20#include <sys/param.h>
22#include <sys/types.h> 21#include <sys/types.h>
23#include <assert.h> 22#include <assert.h>
@@ -25,7 +24,6 @@
25#include <poll.h> 24#include <poll.h>
26#include <sys/socket.h> 25#include <sys/socket.h>
27#include <sys/ioctl.h> 26#include <sys/ioctl.h>
28#include <linux/kernel.h>
29#include <linux/types.h> 27#include <linux/types.h>
30 28
31extern char buildid_dir[]; 29extern char buildid_dir[];
@@ -99,8 +97,6 @@ void mem_bswap_32(void *src, int byte_size);
99 97
100bool find_process(const char *name); 98bool find_process(const char *name);
101 99
102int get_stack_size(const char *str, unsigned long *_size);
103
104int fetch_kernel_version(unsigned int *puint, 100int fetch_kernel_version(unsigned int *puint,
105 char *str, size_t str_sz); 101 char *str, size_t str_sz);
106#define KVER_VERSION(x) (((x) >> 16) & 0xff) 102#define KVER_VERSION(x) (((x) >> 16) & 0xff)