Skip to content

Commit dcde237

Browse files
committed
Merge tag 'perf-tools-fixes-2020-07-07' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux
Pull perf tooling fixes from Arnaldo Carvalho de Melo: - Intel PT fixes for PEBS-via-PT with registers - Fixes for Intel PT python based GUI - Avoid duplicated sideband events with Intel PT in system wide tracing - Remove needless 'dummy' event from TUI menu, used when synthesizing meta data events for pre-existing processes - Fix corner case segfault when pressing enter in a screen without entries in the TUI for report/top - Fixes for time stamp handling in libtraceevent - Explicitly set utf-8 encoding in perf flamegraph - Update arch/x86/lib/memcpy_64.S copy used in 'perf bench mem memcpy', silencing perf build warning * tag 'perf-tools-fixes-2020-07-07' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux: perf report TUI: Remove needless 'dummy' event from menu perf intel-pt: Fix PEBS sample for XMM registers perf intel-pt: Fix displaying PEBS-via-PT with registers perf intel-pt: Fix recording PEBS-via-PT with registers perf report TUI: Fix segmentation fault in perf_evsel__hists_browse() tools lib traceevent: Add proper KBUFFER_TYPE_TIME_STAMP handling tools lib traceevent: Add API to read time information from kbuffer perf scripts python: exported-sql-viewer.py: Fix time chart call tree perf scripts python: exported-sql-viewer.py: Fix zero id in call tree 'Find' result perf scripts python: exported-sql-viewer.py: Fix zero id in call graph 'Find' result perf scripts python: exported-sql-viewer.py: Fix unexpanded 'Find' result perf record: Fix duplicated sideband events with Intel PT system wide tracing perf scripts python: export-to-postgresql.py: Fix struct.pack() int argument tools arch: Update arch/x86/lib/memcpy_64.S copy used in 'perf bench mem memcpy' perf flamegraph: Explicitly set utf-8 encoding
2 parents 6d12075 + bee9ca1 commit dcde237

File tree

15 files changed

+123
-40
lines changed

15 files changed

+123
-40
lines changed

tools/arch/x86/lib/memcpy_64.S

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <asm/alternative-asm.h>
99
#include <asm/export.h>
1010

11+
.pushsection .noinstr.text, "ax"
12+
1113
/*
1214
* We build a jump to memcpy_orig by default which gets NOPped out on
1315
* the majority of x86 CPUs which set REP_GOOD. In addition, CPUs which
@@ -184,6 +186,8 @@ SYM_FUNC_START(memcpy_orig)
184186
retq
185187
SYM_FUNC_END(memcpy_orig)
186188

189+
.popsection
190+
187191
#ifndef CONFIG_UML
188192

189193
MCSAFE_TEST_CTL

tools/lib/traceevent/kbuffer-parse.c

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ translate_data(struct kbuffer *kbuf, void *data, void **rptr,
361361
break;
362362

363363
case KBUFFER_TYPE_TIME_EXTEND:
364+
case KBUFFER_TYPE_TIME_STAMP:
364365
extend = read_4(kbuf, data);
365366
data += 4;
366367
extend <<= TS_SHIFT;
@@ -369,10 +370,6 @@ translate_data(struct kbuffer *kbuf, void *data, void **rptr,
369370
*length = 0;
370371
break;
371372

372-
case KBUFFER_TYPE_TIME_STAMP:
373-
data += 12;
374-
*length = 0;
375-
break;
376373
case 0:
377374
*length = read_4(kbuf, data) - 4;
378375
*length = (*length + 3) & ~3;
@@ -397,7 +394,11 @@ static unsigned int update_pointers(struct kbuffer *kbuf)
397394

398395
type_len = translate_data(kbuf, ptr, &ptr, &delta, &length);
399396

400-
kbuf->timestamp += delta;
397+
if (type_len == KBUFFER_TYPE_TIME_STAMP)
398+
kbuf->timestamp = delta;
399+
else
400+
kbuf->timestamp += delta;
401+
401402
kbuf->index = calc_index(kbuf, ptr);
402403
kbuf->next = kbuf->index + length;
403404

@@ -454,7 +455,9 @@ static int __next_event(struct kbuffer *kbuf)
454455
if (kbuf->next >= kbuf->size)
455456
return -1;
456457
type = update_pointers(kbuf);
457-
} while (type == KBUFFER_TYPE_TIME_EXTEND || type == KBUFFER_TYPE_PADDING);
458+
} while (type == KBUFFER_TYPE_TIME_EXTEND ||
459+
type == KBUFFER_TYPE_TIME_STAMP ||
460+
type == KBUFFER_TYPE_PADDING);
458461

459462
return 0;
460463
}
@@ -546,6 +549,34 @@ int kbuffer_load_subbuffer(struct kbuffer *kbuf, void *subbuffer)
546549
return 0;
547550
}
548551

552+
/**
553+
* kbuffer_subbuf_timestamp - read the timestamp from a sub buffer
554+
* @kbuf: The kbuffer to load
555+
* @subbuf: The subbuffer to read from.
556+
*
557+
* Return the timestamp from a subbuffer.
558+
*/
559+
unsigned long long kbuffer_subbuf_timestamp(struct kbuffer *kbuf, void *subbuf)
560+
{
561+
return kbuf->read_8(subbuf);
562+
}
563+
564+
/**
565+
* kbuffer_ptr_delta - read the delta field from a record
566+
* @kbuf: The kbuffer to load
567+
* @ptr: The record in the buffe.
568+
*
569+
* Return the timestamp delta from a record
570+
*/
571+
unsigned int kbuffer_ptr_delta(struct kbuffer *kbuf, void *ptr)
572+
{
573+
unsigned int type_len_ts;
574+
575+
type_len_ts = read_4(kbuf, ptr);
576+
return ts4host(kbuf, type_len_ts);
577+
}
578+
579+
549580
/**
550581
* kbuffer_read_event - read the next event in the kbuffer subbuffer
551582
* @kbuf: The kbuffer to read from

tools/lib/traceevent/kbuffer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ int kbuffer_load_subbuffer(struct kbuffer *kbuf, void *subbuffer);
4949
void *kbuffer_read_event(struct kbuffer *kbuf, unsigned long long *ts);
5050
void *kbuffer_next_event(struct kbuffer *kbuf, unsigned long long *ts);
5151
unsigned long long kbuffer_timestamp(struct kbuffer *kbuf);
52+
unsigned long long kbuffer_subbuf_timestamp(struct kbuffer *kbuf, void *subbuf);
53+
unsigned int kbuffer_ptr_delta(struct kbuffer *kbuf, void *ptr);
5254

5355
void *kbuffer_translate_data(int swap, void *data, unsigned int *size);
5456

tools/perf/arch/x86/util/intel-pt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
641641
}
642642
evsel->core.attr.freq = 0;
643643
evsel->core.attr.sample_period = 1;
644+
evsel->no_aux_samples = true;
644645
intel_pt_evsel = evsel;
645646
opts->full_auxtrace = true;
646647
}

tools/perf/builtin-record.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -852,20 +852,20 @@ static int record__open(struct record *rec)
852852
* event synthesis.
853853
*/
854854
if (opts->initial_delay || target__has_cpu(&opts->target)) {
855-
if (perf_evlist__add_dummy(evlist))
856-
return -ENOMEM;
855+
pos = perf_evlist__get_tracking_event(evlist);
856+
if (!evsel__is_dummy_event(pos)) {
857+
/* Set up dummy event. */
858+
if (perf_evlist__add_dummy(evlist))
859+
return -ENOMEM;
860+
pos = evlist__last(evlist);
861+
perf_evlist__set_tracking_event(evlist, pos);
862+
}
857863

858-
/* Disable tracking of mmaps on lead event. */
859-
pos = evlist__first(evlist);
860-
pos->tracking = 0;
861-
/* Set up dummy event. */
862-
pos = evlist__last(evlist);
863-
pos->tracking = 1;
864864
/*
865865
* Enable the dummy event when the process is forked for
866866
* initial_delay, immediately for system wide.
867867
*/
868-
if (opts->initial_delay)
868+
if (opts->initial_delay && !pos->immediate)
869869
pos->core.attr.enable_on_exec = 1;
870870
else
871871
pos->immediate = 1;

tools/perf/builtin-script.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ static int perf_evsel__check_attr(struct evsel *evsel, struct perf_session *sess
462462
return -EINVAL;
463463

464464
if (PRINT_FIELD(IREGS) &&
465-
evsel__check_stype(evsel, PERF_SAMPLE_REGS_INTR, "IREGS", PERF_OUTPUT_IREGS))
465+
evsel__do_check_stype(evsel, PERF_SAMPLE_REGS_INTR, "IREGS", PERF_OUTPUT_IREGS, allow_user_set))
466466
return -EINVAL;
467467

468468
if (PRINT_FIELD(UREGS) &&

tools/perf/scripts/python/export-to-postgresql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ def cbr(id, raw_buf):
10551055
cbr = data[0]
10561056
MHz = (data[4] + 500) / 1000
10571057
percent = ((cbr * 1000 / data[2]) + 5) / 10
1058-
value = struct.pack("!hiqiiiiii", 4, 8, id, 4, cbr, 4, MHz, 4, percent)
1058+
value = struct.pack("!hiqiiiiii", 4, 8, id, 4, cbr, 4, int(MHz), 4, int(percent))
10591059
cbr_file.write(value)
10601060

10611061
def mwait(id, raw_buf):

tools/perf/scripts/python/exported-sql-viewer.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,8 @@ def DoFindSelect(self, query, match):
768768
" FROM calls"
769769
" INNER JOIN call_paths ON calls.call_path_id = call_paths.id"
770770
" INNER JOIN symbols ON call_paths.symbol_id = symbols.id"
771-
" WHERE symbols.name" + match +
771+
" WHERE calls.id <> 0"
772+
" AND symbols.name" + match +
772773
" GROUP BY comm_id, thread_id, call_path_id"
773774
" ORDER BY comm_id, thread_id, call_path_id")
774775

@@ -963,7 +964,8 @@ def DoFindSelect(self, query, match):
963964
" FROM calls"
964965
" INNER JOIN call_paths ON calls.call_path_id = call_paths.id"
965966
" INNER JOIN symbols ON call_paths.symbol_id = symbols.id"
966-
" WHERE symbols.name" + match +
967+
" WHERE calls.id <> 0"
968+
" AND symbols.name" + match +
967969
" ORDER BY comm_id, thread_id, call_time, calls.id")
968970

969971
def FindPath(self, query):
@@ -1050,6 +1052,7 @@ def DisplayFound(self, ids):
10501052
child = self.model.index(row, 0, parent)
10511053
if child.internalPointer().dbid == dbid:
10521054
found = True
1055+
self.view.setExpanded(parent, True)
10531056
self.view.setCurrentIndex(child)
10541057
parent = child
10551058
break
@@ -1127,6 +1130,7 @@ def DisplayThreadAtTime(self, comm_id, thread_id, time):
11271130
child = self.model.index(row, 0, parent)
11281131
if child.internalPointer().dbid == dbid:
11291132
found = True
1133+
self.view.setExpanded(parent, True)
11301134
self.view.setCurrentIndex(child)
11311135
parent = child
11321136
break
@@ -1139,6 +1143,7 @@ def DisplayThreadAtTime(self, comm_id, thread_id, time):
11391143
return
11401144
last_child = None
11411145
for row in xrange(n):
1146+
self.view.setExpanded(parent, True)
11421147
child = self.model.index(row, 0, parent)
11431148
child_call_time = child.internalPointer().call_time
11441149
if child_call_time < time:
@@ -1151,9 +1156,11 @@ def DisplayThreadAtTime(self, comm_id, thread_id, time):
11511156
if not last_child:
11521157
if not found:
11531158
child = self.model.index(0, 0, parent)
1159+
self.view.setExpanded(parent, True)
11541160
self.view.setCurrentIndex(child)
11551161
return
11561162
found = True
1163+
self.view.setExpanded(parent, True)
11571164
self.view.setCurrentIndex(last_child)
11581165
parent = last_child
11591166

tools/perf/scripts/python/flamegraph.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from __future__ import print_function
1818
import sys
1919
import os
20+
import io
2021
import argparse
2122
import json
2223

@@ -81,7 +82,7 @@ def trace_end(self):
8182

8283
if self.args.format == "html":
8384
try:
84-
with open(self.args.template) as f:
85+
with io.open(self.args.template, encoding="utf-8") as f:
8586
output_str = f.read().replace("/** @flamegraph_json **/",
8687
json_str)
8788
except IOError as e:
@@ -93,11 +94,12 @@ def trace_end(self):
9394
output_fn = self.args.output or "stacks.json"
9495

9596
if output_fn == "-":
96-
sys.stdout.write(output_str)
97+
with io.open(sys.stdout.fileno(), "w", encoding="utf-8", closefd=False) as out:
98+
out.write(output_str)
9799
else:
98100
print("dumping data to {}".format(output_fn))
99101
try:
100-
with open(output_fn, "w") as out:
102+
with io.open(output_fn, "w", encoding="utf-8") as out:
101103
out.write(output_str)
102104
except IOError as e:
103105
print("Error writing output file: {}".format(e), file=sys.stderr)

tools/perf/ui/browsers/hists.c

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2288,6 +2288,11 @@ static struct thread *hist_browser__selected_thread(struct hist_browser *browser
22882288
return browser->he_selection->thread;
22892289
}
22902290

2291+
static struct res_sample *hist_browser__selected_res_sample(struct hist_browser *browser)
2292+
{
2293+
return browser->he_selection ? browser->he_selection->res_samples : NULL;
2294+
}
2295+
22912296
/* Check whether the browser is for 'top' or 'report' */
22922297
static inline bool is_report_browser(void *timer)
22932298
{
@@ -3357,16 +3362,16 @@ static int perf_evsel__hists_browse(struct evsel *evsel, int nr_events,
33573362
&options[nr_options], NULL, NULL, evsel);
33583363
nr_options += add_res_sample_opt(browser, &actions[nr_options],
33593364
&options[nr_options],
3360-
hist_browser__selected_entry(browser)->res_samples,
3361-
evsel, A_NORMAL);
3365+
hist_browser__selected_res_sample(browser),
3366+
evsel, A_NORMAL);
33623367
nr_options += add_res_sample_opt(browser, &actions[nr_options],
33633368
&options[nr_options],
3364-
hist_browser__selected_entry(browser)->res_samples,
3365-
evsel, A_ASM);
3369+
hist_browser__selected_res_sample(browser),
3370+
evsel, A_ASM);
33663371
nr_options += add_res_sample_opt(browser, &actions[nr_options],
33673372
&options[nr_options],
3368-
hist_browser__selected_entry(browser)->res_samples,
3369-
evsel, A_SOURCE);
3373+
hist_browser__selected_res_sample(browser),
3374+
evsel, A_SOURCE);
33703375
nr_options += add_switch_opt(browser, &actions[nr_options],
33713376
&options[nr_options]);
33723377
skip_scripting:
@@ -3598,6 +3603,23 @@ static int __perf_evlist__tui_browse_hists(struct evlist *evlist,
35983603
hbt, warn_lost_event);
35993604
}
36003605

3606+
static bool perf_evlist__single_entry(struct evlist *evlist)
3607+
{
3608+
int nr_entries = evlist->core.nr_entries;
3609+
3610+
if (nr_entries == 1)
3611+
return true;
3612+
3613+
if (nr_entries == 2) {
3614+
struct evsel *last = evlist__last(evlist);
3615+
3616+
if (evsel__is_dummy_event(last))
3617+
return true;
3618+
}
3619+
3620+
return false;
3621+
}
3622+
36013623
int perf_evlist__tui_browse_hists(struct evlist *evlist, const char *help,
36023624
struct hist_browser_timer *hbt,
36033625
float min_pcnt,
@@ -3608,7 +3630,7 @@ int perf_evlist__tui_browse_hists(struct evlist *evlist, const char *help,
36083630
int nr_entries = evlist->core.nr_entries;
36093631

36103632
single_entry:
3611-
if (nr_entries == 1) {
3633+
if (perf_evlist__single_entry(evlist)) {
36123634
struct evsel *first = evlist__first(evlist);
36133635

36143636
return perf_evsel__hists_browse(first, nr_entries, help,

0 commit comments

Comments
 (0)