1 // SPDX-License-Identifier: GPL-2.0
2 /* Display a menu with individual samples to browse with perf script */
8 #include "time-utils.h"
10 #include "../../util/util.h" // perf_exe()
11 #include "../../perf.h"
14 #include <linux/time64.h>
15 #include <linux/zalloc.h>
17 static u64 context_len
= 10 * NSEC_PER_MSEC
;
19 static int res_sample_config(const char *var
, const char *value
, void *data __maybe_unused
)
21 if (!strcmp(var
, "samples.context"))
22 return perf_config_u64(&context_len
, var
, value
);
26 void res_sample_init(void)
28 perf_config(res_sample_config
, NULL
);
31 int res_sample_browse(struct res_sample
*res_samples
, int num_res
,
32 struct evsel
*evsel
, enum rstype rstype
)
38 char pbuf
[256], tidbuf
[32], cpubuf
[32];
39 const char *perf
= perf_exe(pbuf
, sizeof pbuf
);
40 char trange
[128], tsample
[64];
42 char extra_format
[256];
44 names
= calloc(num_res
, sizeof(char *));
47 for (i
= 0; i
< num_res
; i
++) {
50 timestamp__scnprintf_nsec(res_samples
[i
].time
, tbuf
, sizeof tbuf
);
51 if (asprintf(&names
[i
], "%s: CPU %d tid %d", tbuf
,
52 res_samples
[i
].cpu
, res_samples
[i
].tid
) < 0) {
59 choice
= ui__popup_menu(num_res
, names
, NULL
);
60 for (i
= 0; i
< num_res
; i
++)
64 if (choice
< 0 || choice
>= num_res
)
66 r
= &res_samples
[choice
];
68 n
= timestamp__scnprintf_nsec(r
->time
- context_len
, trange
, sizeof trange
);
70 timestamp__scnprintf_nsec(r
->time
+ context_len
, trange
+ n
, sizeof trange
- n
);
72 timestamp__scnprintf_nsec(r
->time
, tsample
, sizeof tsample
);
74 attr_to_script(extra_format
, &evsel
->core
.attr
);
76 if (asprintf(&cmd
, "%s script %s%s --time %s %s%s %s%s --ns %s %s %s %s %s | less +/%s",
78 input_name
? "-i " : "",
79 input_name
? input_name
: "",
81 r
->cpu
>= 0 ? "--cpu " : "",
82 r
->cpu
>= 0 ? (sprintf(cpubuf
, "%d", r
->cpu
), cpubuf
) : "",
83 r
->tid
? "--tid " : "",
84 r
->tid
? (sprintf(tidbuf
, "%d", r
->tid
), tidbuf
) : "",
86 rstype
== A_ASM
? "-F +insn --xed" :
87 rstype
== A_SOURCE
? "-F +srcline,+srccode" : "",
88 symbol_conf
.inline_name
? "--inline" : "",
89 "--show-lost-events ",
90 r
->tid
? "--show-switch-events --show-task-events " : "",