-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf report: Implement browsing of individual samples
Now 'perf report' can show whole time periods with 'perf script', but the user still has to find individual samples of interest manually. It would be expensive and complicated to search for the right samples in the whole perf file. Typically users only need to look at a small number of samples for useful analysis. Also the full scripts tend to show samples of all CPUs and all threads mixed up, which can be very confusing on larger systems. Add a new --samples option to save a small random number of samples per hist entry. Use a reservoir sample technique to select a representatve number of samples. Then allow browsing the samples using 'perf script' as part of the hist entry context menu. This automatically adds the right filters, so only the thread or cpu of the sample is displayed. Then we use less' search functionality to directly jump the to the time stamp of the selected sample. It uses different menus for assembler and source display. Assembler needs xed installed and source needs debuginfo. Currently it only supports as many samples as fit on the screen due to some limitations in the slang ui code. Signed-off-by: Andi Kleen <ak@linux.intel.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Link: http://lkml.kernel.org/r/20190311174605.GA29294@tassilo.jf.intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
- Loading branch information
Andi Kleen
authored and
Arnaldo Carvalho de Melo
committed
Mar 11, 2019
1 parent
6f3da20
commit 4968ac8
Showing
12 changed files
with
226 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* Display a menu with individual samples to browse with perf script */ | ||
#include "util.h" | ||
#include "hist.h" | ||
#include "evsel.h" | ||
#include "hists.h" | ||
#include "sort.h" | ||
#include "config.h" | ||
#include "time-utils.h" | ||
#include <linux/time64.h> | ||
|
||
static u64 context_len = 10 * NSEC_PER_MSEC; | ||
|
||
static int res_sample_config(const char *var, const char *value, void *data __maybe_unused) | ||
{ | ||
if (!strcmp(var, "samples.context")) | ||
return perf_config_u64(&context_len, var, value); | ||
return 0; | ||
} | ||
|
||
void res_sample_init(void) | ||
{ | ||
perf_config(res_sample_config, NULL); | ||
} | ||
|
||
int res_sample_browse(struct res_sample *res_samples, int num_res, | ||
struct perf_evsel *evsel, enum rstype rstype) | ||
{ | ||
char **names; | ||
int i, n; | ||
int choice; | ||
char *cmd; | ||
char pbuf[256], tidbuf[32], cpubuf[32]; | ||
const char *perf = perf_exe(pbuf, sizeof pbuf); | ||
char trange[128], tsample[64]; | ||
struct res_sample *r; | ||
char extra_format[256]; | ||
|
||
/* For now since ui__popup_menu doesn't like lists that don't fit */ | ||
num_res = max(min(SLtt_Screen_Rows - 4, num_res), 0); | ||
|
||
names = calloc(num_res, sizeof(char *)); | ||
if (!names) | ||
return -1; | ||
for (i = 0; i < num_res; i++) { | ||
char tbuf[64]; | ||
|
||
timestamp__scnprintf_nsec(res_samples[i].time, tbuf, sizeof tbuf); | ||
if (asprintf(&names[i], "%s: CPU %d tid %d", tbuf, | ||
res_samples[i].cpu, res_samples[i].tid) < 0) { | ||
while (--i >= 0) | ||
free(names[i]); | ||
free(names); | ||
return -1; | ||
} | ||
} | ||
choice = ui__popup_menu(num_res, names); | ||
for (i = 0; i < num_res; i++) | ||
free(names[i]); | ||
free(names); | ||
|
||
if (choice < 0 || choice >= num_res) | ||
return -1; | ||
r = &res_samples[choice]; | ||
|
||
n = timestamp__scnprintf_nsec(r->time - context_len, trange, sizeof trange); | ||
trange[n++] = ','; | ||
timestamp__scnprintf_nsec(r->time + context_len, trange + n, sizeof trange - n); | ||
|
||
timestamp__scnprintf_nsec(r->time, tsample, sizeof tsample); | ||
|
||
attr_to_script(extra_format, &evsel->attr); | ||
|
||
if (asprintf(&cmd, "%s script %s%s --time %s %s%s %s%s --ns %s %s %s %s %s | less +/%s", | ||
perf, | ||
input_name ? "-i " : "", | ||
input_name ? input_name : "", | ||
trange, | ||
r->cpu >= 0 ? "--cpu " : "", | ||
r->cpu >= 0 ? (sprintf(cpubuf, "%d", r->cpu), cpubuf) : "", | ||
r->tid ? "--tid " : "", | ||
r->tid ? (sprintf(tidbuf, "%d", r->tid), tidbuf) : "", | ||
extra_format, | ||
rstype == A_ASM ? "-F +insn --xed" : | ||
rstype == A_SOURCE ? "-F +srcline,+srccode" : "", | ||
symbol_conf.inline_name ? "--inline" : "", | ||
"--show-lost-events ", | ||
r->tid ? "--show-switch-events --show-task-events " : "", | ||
tsample) < 0) | ||
return -1; | ||
run_script(cmd); | ||
free(cmd); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters