mirror of
https://github.com/torvalds/linux.git
synced 2026-09-22 20:54:03 +02:00
perf python: Use evsel in sample in pyrf_event
Avoid a duplicated evsel by using the one in sample. Add evsel__get/put to the evsel in perf_sample. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alice Rogers <alice.mei.rogers@gmail.com> Cc: Dapeng Mi <dapeng1.mi@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@linaro.org> Cc: Leo Yan <leo.yan@linux.dev> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Richter <tmricht@linux.ibm.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
This commit is contained in:
parent
ab24487aaa
commit
674ca42f13
|
|
@ -726,8 +726,11 @@ static int perf_event__repipe_common_mmap(const struct perf_tool *tool,
|
|||
}
|
||||
|
||||
if (dso && !dso__hit(dso)) {
|
||||
if (!sample->evsel)
|
||||
if (!sample->evsel) {
|
||||
sample->evsel = evlist__event2evsel(inject->session->evlist, event);
|
||||
if (sample->evsel)
|
||||
evsel__get(sample->evsel);
|
||||
}
|
||||
|
||||
if (sample->evsel) {
|
||||
dso__set_hit(dso);
|
||||
|
|
|
|||
|
|
@ -3678,8 +3678,11 @@ static void trace__handle_event(struct trace *trace, union perf_event *event, st
|
|||
return;
|
||||
}
|
||||
|
||||
if (sample->evsel == NULL)
|
||||
if (sample->evsel == NULL) {
|
||||
sample->evsel = evlist__id2evsel(trace->evlist, sample->id);
|
||||
if (sample->evsel)
|
||||
evsel__get(sample->evsel);
|
||||
}
|
||||
|
||||
if (sample->evsel == NULL) {
|
||||
fprintf(trace->output, "Unknown tp ID %" PRIu64 ", skipping...\n", sample->id);
|
||||
|
|
|
|||
|
|
@ -3418,7 +3418,7 @@ int __evsel__parse_sample(struct evsel *evsel, union perf_event *event,
|
|||
union u64_swap u;
|
||||
|
||||
perf_sample__init(data, /*all=*/true);
|
||||
data->evsel = evsel;
|
||||
data->evsel = evsel__get(evsel);
|
||||
data->cpu = data->pid = data->tid = -1;
|
||||
data->stream_id = data->id = data->time = -1ULL;
|
||||
data->period = evsel->core.attr.sample_period;
|
||||
|
|
|
|||
|
|
@ -1830,9 +1830,9 @@ static int intel_pt_synth_branch_sample(struct intel_pt_queue *ptq)
|
|||
ptq->last_br_cyc_cnt = ptq->ipc_cyc_cnt;
|
||||
}
|
||||
|
||||
perf_sample__exit(&sample);
|
||||
ret = intel_pt_deliver_synth_event(pt, event, &sample,
|
||||
pt->branches_sample_type);
|
||||
perf_sample__exit(&sample);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -1967,6 +1967,7 @@ static int intel_pt_synth_ptwrite_sample(struct intel_pt_queue *ptq)
|
|||
union perf_event *event = ptq->event_buf;
|
||||
struct perf_sample sample = { .ip = 0, };
|
||||
struct perf_synth_intel_ptwrite raw;
|
||||
int ret;
|
||||
|
||||
if (intel_pt_skip_event(pt))
|
||||
return 0;
|
||||
|
|
@ -1983,8 +1984,9 @@ static int intel_pt_synth_ptwrite_sample(struct intel_pt_queue *ptq)
|
|||
sample.raw_size = perf_synth__raw_size(raw);
|
||||
sample.raw_data = perf_synth__raw_data(&raw);
|
||||
|
||||
return intel_pt_deliver_synth_event(pt, event, &sample,
|
||||
pt->ptwrites_sample_type);
|
||||
ret = intel_pt_deliver_synth_event(pt, event, &sample, pt->ptwrites_sample_type);
|
||||
perf_sample__exit(&sample);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int intel_pt_synth_cbr_sample(struct intel_pt_queue *ptq)
|
||||
|
|
|
|||
|
|
@ -63,7 +63,6 @@ PyMODINIT_FUNC PyInit_perf(void);
|
|||
|
||||
struct pyrf_event {
|
||||
PyObject_HEAD
|
||||
struct evsel *evsel;
|
||||
struct perf_sample sample;
|
||||
union perf_event event;
|
||||
};
|
||||
|
|
@ -294,7 +293,6 @@ static PyMemberDef pyrf_sample_event__members[] = {
|
|||
|
||||
static void pyrf_sample_event__delete(struct pyrf_event *pevent)
|
||||
{
|
||||
evsel__put(pevent->evsel);
|
||||
perf_sample__exit(&pevent->sample);
|
||||
Py_TYPE(pevent)->tp_free((PyObject *)pevent);
|
||||
}
|
||||
|
|
@ -316,7 +314,7 @@ static PyObject *pyrf_sample_event__repr(const struct pyrf_event *pevent)
|
|||
#ifdef HAVE_LIBTRACEEVENT
|
||||
static bool is_tracepoint(const struct pyrf_event *pevent)
|
||||
{
|
||||
return pevent->evsel->core.attr.type == PERF_TYPE_TRACEPOINT;
|
||||
return pevent->sample.evsel->core.attr.type == PERF_TYPE_TRACEPOINT;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
|
|
@ -363,7 +361,7 @@ tracepoint_field(const struct pyrf_event *pe, struct tep_format_field *field)
|
|||
static PyObject*
|
||||
get_tracepoint_field(struct pyrf_event *pevent, PyObject *attr_name)
|
||||
{
|
||||
struct evsel *evsel = pevent->evsel;
|
||||
struct evsel *evsel = pevent->sample.evsel;
|
||||
struct tep_event *tp_format = evsel__tp_format(evsel);
|
||||
struct tep_format_field *field;
|
||||
|
||||
|
|
@ -529,7 +527,7 @@ static PyObject *pyrf_event__new(const union perf_event *event)
|
|||
pevent = PyObject_New(struct pyrf_event, ptype);
|
||||
if (pevent != NULL) {
|
||||
memcpy(&pevent->event, event, event->header.size);
|
||||
pevent->evsel = NULL;
|
||||
perf_sample__init(&pevent->sample, /*all=*/false);
|
||||
}
|
||||
return (PyObject *)pevent;
|
||||
}
|
||||
|
|
@ -1907,8 +1905,6 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
|
|||
return Py_None;
|
||||
}
|
||||
|
||||
pevent->evsel = evsel__get(evsel);
|
||||
|
||||
perf_mmap__consume(&md->core);
|
||||
|
||||
err = evsel__parse_sample(evsel, &pevent->event, &pevent->sample);
|
||||
|
|
|
|||
|
|
@ -343,6 +343,7 @@ void evlist__s390_sample_raw(struct evlist *evlist, union perf_event *event,
|
|||
sample->evsel = evlist__event2evsel(evlist, event);
|
||||
if (!sample->evsel)
|
||||
return;
|
||||
evsel__get(sample->evsel);
|
||||
}
|
||||
|
||||
/* Check for raw data in sample */
|
||||
|
|
|
|||
|
|
@ -1,18 +1,23 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#include "sample.h"
|
||||
#include "debug.h"
|
||||
#include "thread.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <elf.h>
|
||||
#include <linux/zalloc.h>
|
||||
|
||||
#include "../../arch/x86/include/asm/insn.h"
|
||||
#include "debug.h"
|
||||
#include "evsel.h"
|
||||
#include "thread.h"
|
||||
|
||||
#ifndef EM_CSKY
|
||||
#define EM_CSKY 252
|
||||
#endif
|
||||
#ifndef EM_LOONGARCH
|
||||
#define EM_LOONGARCH 258
|
||||
#endif
|
||||
#include <linux/zalloc.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "../../arch/x86/include/asm/insn.h"
|
||||
|
||||
void perf_sample__init(struct perf_sample *sample, bool all)
|
||||
{
|
||||
|
|
@ -29,6 +34,8 @@ void perf_sample__init(struct perf_sample *sample, bool all)
|
|||
|
||||
void perf_sample__exit(struct perf_sample *sample)
|
||||
{
|
||||
evsel__put(sample->evsel);
|
||||
sample->evsel = NULL;
|
||||
zfree(&sample->user_regs);
|
||||
zfree(&sample->intr_regs);
|
||||
if (sample->merged_callchain) {
|
||||
|
|
|
|||
|
|
@ -1855,6 +1855,7 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist,
|
|||
|
||||
list_for_each_entry_safe(de, tmp, evlist__deferred_samples(evlist), list) {
|
||||
struct perf_sample orig_sample;
|
||||
struct evsel *new_evsel;
|
||||
|
||||
perf_sample__init(&orig_sample, /*all=*/false);
|
||||
ret = evlist__parse_sample(evlist, de->event, &orig_sample);
|
||||
|
|
@ -1875,7 +1876,11 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist,
|
|||
else
|
||||
orig_sample.deferred_callchain = false;
|
||||
|
||||
orig_sample.evsel = evlist__id2evsel(evlist, orig_sample.id);
|
||||
new_evsel = evlist__id2evsel(evlist, orig_sample.id);
|
||||
if (new_evsel != orig_sample.evsel) {
|
||||
evsel__put(orig_sample.evsel);
|
||||
orig_sample.evsel = evsel__get(new_evsel);
|
||||
}
|
||||
ret = evlist__deliver_sample(evlist, tool, de->event,
|
||||
&orig_sample, machine);
|
||||
|
||||
|
|
@ -1904,6 +1909,7 @@ static int session__flush_deferred_samples(struct perf_session *session,
|
|||
|
||||
list_for_each_entry_safe(de, tmp, evlist__deferred_samples(evlist), list) {
|
||||
struct perf_sample sample;
|
||||
struct evsel *new_evsel;
|
||||
|
||||
perf_sample__init(&sample, /*all=*/false);
|
||||
ret = evlist__parse_sample(evlist, de->event, &sample);
|
||||
|
|
@ -1914,7 +1920,11 @@ static int session__flush_deferred_samples(struct perf_session *session,
|
|||
}
|
||||
sample.file_offset = de->file_offset;
|
||||
|
||||
sample.evsel = evlist__id2evsel(evlist, sample.id);
|
||||
new_evsel = evlist__id2evsel(evlist, sample.id);
|
||||
if (new_evsel != sample.evsel) {
|
||||
evsel__put(sample.evsel);
|
||||
sample.evsel = evsel__get(new_evsel);
|
||||
}
|
||||
ret = evlist__deliver_sample(evlist, tool, de->event,
|
||||
&sample, machine);
|
||||
|
||||
|
|
@ -1960,8 +1970,11 @@ static int machines__deliver_event(struct machines *machines,
|
|||
|
||||
dump_event(evlist, event, file_offset, sample, file_path);
|
||||
|
||||
if (!sample->evsel)
|
||||
if (!sample->evsel) {
|
||||
sample->evsel = evlist__id2evsel(evlist, sample->id);
|
||||
if (sample->evsel)
|
||||
sample->evsel = evsel__get(sample->evsel);
|
||||
}
|
||||
else
|
||||
assert(sample->evsel == evlist__id2evsel(evlist, sample->id));
|
||||
machine = machines__find_for_cpumode(machines, event, sample);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user