Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp211093imu; Thu, 20 Dec 2018 20:29:24 -0800 (PST) X-Google-Smtp-Source: AFSGD/VimF7uS7zbiCd+q6wbTTI+4XDPczhC+dlHsTrADwaYvgOTuZ/g9Faq+VTNve5VpcfW9aJP X-Received: by 2002:a62:3811:: with SMTP id f17mr1008265pfa.206.1545366564428; Thu, 20 Dec 2018 20:29:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545366564; cv=none; d=google.com; s=arc-20160816; b=PJmZC2jfIyD7BrhJCtKT5Y0UphAzEat08ZhNtqDsuM+alEUTq752XLh4CtFVKx+KLY r2WR+93mtBZGZ3Uur6/smaYNphcOiYs+RH/qKZD5rsGd01a8CrGYSvSIfjApzUN9c3UC eGfothfecPeMiSURMibjoTXmYZuI+PgjPZucya120IJY9rNaF/pubKT0EpUN1Tu1HFYg Bf/+eBF/OALlgek6u2KwIbuobG9vRTeetb3RYwh3Kn7hia9k3EZ39Rs0LKEBoWDDA1BO dEvb4UjQCIbRuhVHGkgHFQAETdRYw/lv7i5bIG71RKryJLJEK93LAJpSg5S7ffTSpPml 4gtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:smtp-origin-cluster:cc:to :smtp-origin-hostname:from:smtp-origin-hostprefix:dkim-signature; bh=WGMviR76W7ZSLtIvtBj5jPmGeoOdJ0D0/oexGvtmvDs=; b=AM3nW/apuG3ytRqSpa1EgqhefHLlHungzZ/PziFz+zY39VKlM2IBJMomZ7cU1XE+pL JeUZnRsM1nBO83eoxcl5OFpJBvkEnBdS4PZX9h/Q+9cUFk34T4jLRJB/tumreol7QchP NqKVjYQx7uYaU+DUyy9cEOMA6ZGxuKl4f7Q1SqqoulI86mjU3Am+ysEloROFt/npZEza xGR4VI2w/qNDWC0p5kKRp3DEA4r/hUVkOTOveDj24lbNhOgQcHYVt0G4MwIFfqgyzb4T cXF/u0/Jvv4UdQXIUrz2y9QqrUlp3nTuz/9xeAmTQjEcWOzRtpTpaGT8NgbhdbdHtQi0 BT+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=aMRUov09; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j10si1870740plg.123.2018.12.20.20.29.08; Thu, 20 Dec 2018 20:29:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=aMRUov09; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389226AbeLTSar (ORCPT + 99 others); Thu, 20 Dec 2018 13:30:47 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:51392 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387406AbeLTS3L (ORCPT ); Thu, 20 Dec 2018 13:29:11 -0500 Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id wBKISHYk026923 for ; Thu, 20 Dec 2018 10:29:10 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=WGMviR76W7ZSLtIvtBj5jPmGeoOdJ0D0/oexGvtmvDs=; b=aMRUov09Pxg8v6flMa3NWowD8KUL/NjMVN+cjOVetJhUrvTlzsGK5XBE6wnWUM8Y0/Rw GWNYKL6oMRupj0I+Nukmr0zvs58n74pgFqb6VSU9DxFeFhmPWtbLd/ElNezczzqKoZtc umycjvoGwWcSm8rNF3C9NBEPWE28Xe3XLZY= Received: from maileast.thefacebook.com ([199.201.65.23]) by mx0a-00082601.pphosted.com with ESMTP id 2pgf6grahu-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 20 Dec 2018 10:29:10 -0800 Received: from mx-out.facebook.com (2620:10d:c0a1:3::13) by mail.thefacebook.com (2620:10d:c021:18::174) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA) id 15.1.1531.3; Thu, 20 Dec 2018 10:29:08 -0800 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id ACB4062E1444; Thu, 20 Dec 2018 10:29:07 -0800 (PST) Smtp-Origin-Hostprefix: devbig From: Song Liu Smtp-Origin-Hostname: devbig006.ftw2.facebook.com To: , CC: Song Liu , , , , , Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH v5 perf, bpf-next 6/7] perf util: handle PERF_RECORD_BPF_EVENT Date: Thu, 20 Dec 2018 10:29:03 -0800 Message-ID: <20181220182904.4193196-7-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181220182904.4193196-1-songliubraving@fb.com> References: <20181220182904.4193196-1-songliubraving@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-12-20_09:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds basic handling of PERF_RECORD_BPF_EVENT. Tracking of PERF_RECORD_BPF_EVENT is OFF by default. Option --bpf-event is added to turn it on. Signed-off-by: Song Liu --- tools/perf/builtin-record.c | 1 + tools/perf/perf.h | 1 + tools/perf/util/Build | 2 ++ tools/perf/util/bpf-event.c | 15 +++++++++++++++ tools/perf/util/bpf-event.h | 11 +++++++++++ tools/perf/util/event.c | 20 ++++++++++++++++++++ tools/perf/util/event.h | 16 ++++++++++++++++ tools/perf/util/evsel.c | 10 ++++++++++ tools/perf/util/evsel.h | 1 + tools/perf/util/machine.c | 3 +++ tools/perf/util/session.c | 4 ++++ tools/perf/util/tool.h | 3 ++- 12 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 tools/perf/util/bpf-event.c create mode 100644 tools/perf/util/bpf-event.h diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 488779bc4c8d..8983ab2e60dd 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -1604,6 +1604,7 @@ static struct option __record_options[] = { OPT_BOOLEAN(0, "tail-synthesize", &record.opts.tail_synthesize, "synthesize non-sample events at the end of output"), OPT_BOOLEAN(0, "overwrite", &record.opts.overwrite, "use overwrite mode"), + OPT_BOOLEAN(0, "bpf-event", &record.opts.bpf_event, "record bpf events"), OPT_BOOLEAN(0, "strict-freq", &record.opts.strict_freq, "Fail if the specified frequency can't be used"), OPT_CALLBACK('F', "freq", &record.opts, "freq or 'max'", diff --git a/tools/perf/perf.h b/tools/perf/perf.h index 0ed4a34c74c4..a45a85ab38d4 100644 --- a/tools/perf/perf.h +++ b/tools/perf/perf.h @@ -66,6 +66,7 @@ struct record_opts { bool ignore_missing_thread; bool strict_freq; bool sample_id; + bool bpf_event; unsigned int freq; unsigned int mmap_pages; unsigned int auxtrace_mmap_pages; diff --git a/tools/perf/util/Build b/tools/perf/util/Build index b7bf201fe8a8..99455f30c264 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -151,6 +151,8 @@ endif libperf-y += perf-hooks.o +libperf-$(CONFIG_LIBBPF) += bpf-event.o + libperf-$(CONFIG_CXX) += c++/ CFLAGS_config.o += -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c new file mode 100644 index 000000000000..f24f75506f51 --- /dev/null +++ b/tools/perf/util/bpf-event.c @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include "bpf-event.h" +#include "debug.h" +#include "symbol.h" + +int machine__process_bpf_event(struct machine *machine __maybe_unused, + union perf_event *event, + struct perf_sample *sample __maybe_unused) +{ + if (dump_trace) + perf_event__fprintf_bpf_event(event, stderr); + return 0; +} diff --git a/tools/perf/util/bpf-event.h b/tools/perf/util/bpf-event.h new file mode 100644 index 000000000000..d5ca355dd298 --- /dev/null +++ b/tools/perf/util/bpf-event.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __PERF_BPF_EVENT_H +#define __PERF_BPF_EVENT_H + +#include "machine.h" + +int machine__process_bpf_event(struct machine *machine, + union perf_event *event, + struct perf_sample *sample); + +#endif diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index 4b47194eaa4b..0e2eb3a3eab4 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -25,6 +25,7 @@ #include "asm/bug.h" #include "stat.h" #include "session.h" +#include "bpf-event.h" static const char *perf_event__names[] = { [0] = "TOTAL", @@ -45,6 +46,7 @@ static const char *perf_event__names[] = { [PERF_RECORD_SWITCH_CPU_WIDE] = "SWITCH_CPU_WIDE", [PERF_RECORD_NAMESPACES] = "NAMESPACES", [PERF_RECORD_KSYMBOL] = "KSYMBOL", + [PERF_RECORD_BPF_EVENT] = "BPF_EVENT", [PERF_RECORD_HEADER_ATTR] = "ATTR", [PERF_RECORD_HEADER_EVENT_TYPE] = "EVENT_TYPE", [PERF_RECORD_HEADER_TRACING_DATA] = "TRACING_DATA", @@ -1345,6 +1347,14 @@ int perf_event__process_ksymbol(struct perf_tool *tool __maybe_unused, return machine__process_ksymbol(machine, event, sample); } +int perf_event__process_bpf_event(struct perf_tool *tool __maybe_unused, + union perf_event *event, + struct perf_sample *sample __maybe_unused, + struct machine *machine) +{ + return machine__process_bpf_event(machine, event, sample); +} + size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp) { return fprintf(fp, " %d/%d: [%#" PRIx64 "(%#" PRIx64 ") @ %#" PRIx64 "]: %c %s\n", @@ -1484,6 +1494,13 @@ size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp) event->ksymbol_event.name); } +size_t perf_event__fprintf_bpf_event(union perf_event *event, FILE *fp) +{ + return fprintf(fp, " bpf event with type %u, flags %u, id %u\n", + event->bpf_event.type, event->bpf_event.flags, + event->bpf_event.id); +} + size_t perf_event__fprintf(union perf_event *event, FILE *fp) { size_t ret = fprintf(fp, "PERF_RECORD_%s", @@ -1522,6 +1539,9 @@ size_t perf_event__fprintf(union perf_event *event, FILE *fp) case PERF_RECORD_KSYMBOL: ret += perf_event__fprintf_ksymbol(event, fp); break; + case PERF_RECORD_BPF_EVENT: + ret += perf_event__fprintf_bpf_event(event, fp); + break; default: ret += fprintf(fp, "\n"); } diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h index 100b59f1fdec..eef795e89bef 100644 --- a/tools/perf/util/event.h +++ b/tools/perf/util/event.h @@ -96,6 +96,16 @@ struct ksymbol_event { char name[KSYM_NAME_LEN]; }; +struct bpf_event { + struct perf_event_header header; + u16 type; + u16 flags; + u32 id; + + /* for bpf_prog types */ + u8 tag[BPF_TAG_SIZE]; // prog tag +}; + #define PERF_SAMPLE_MASK \ (PERF_SAMPLE_IP | PERF_SAMPLE_TID | \ PERF_SAMPLE_TIME | PERF_SAMPLE_ADDR | \ @@ -664,6 +674,7 @@ union perf_event { struct time_conv_event time_conv; struct feature_event feat; struct ksymbol_event ksymbol_event; + struct bpf_event bpf_event; }; void perf_event__print_totals(void); @@ -767,6 +778,10 @@ int perf_event__process_ksymbol(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, struct machine *machine); +int perf_event__process_bpf_event(struct perf_tool *tool, + union perf_event *event, + struct perf_sample *sample, + struct machine *machine); int perf_tool__process_synth_event(struct perf_tool *tool, union perf_event *event, struct machine *machine, @@ -832,6 +847,7 @@ size_t perf_event__fprintf_thread_map(union perf_event *event, FILE *fp); size_t perf_event__fprintf_cpu_map(union perf_event *event, FILE *fp); size_t perf_event__fprintf_namespaces(union perf_event *event, FILE *fp); size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp); +size_t perf_event__fprintf_bpf_event(union perf_event *event, FILE *fp); size_t perf_event__fprintf(union perf_event *event, FILE *fp); int kallsyms__get_function_start(const char *kallsyms_filename, diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index de34ce875648..1e8b7d2897e3 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1036,6 +1036,8 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts, attr->mmap2 = track && !perf_missing_features.mmap2; attr->comm = track; attr->ksymbol = track && !perf_missing_features.ksymbol; + attr->bpf_event = track && opts->bpf_event && + !perf_missing_features.bpf_event; if (opts->record_namespaces) attr->namespaces = track; @@ -1654,6 +1656,7 @@ int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr, PRINT_ATTRf(write_backward, p_unsigned); PRINT_ATTRf(namespaces, p_unsigned); PRINT_ATTRf(ksymbol, p_unsigned); + PRINT_ATTRf(bpf_event, p_unsigned); PRINT_ATTRn("{ wakeup_events, wakeup_watermark }", wakeup_events, p_unsigned); PRINT_ATTRf(bp_type, p_unsigned); @@ -1815,6 +1818,8 @@ int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, evsel->attr.read_format &= ~(PERF_FORMAT_GROUP|PERF_FORMAT_ID); if (perf_missing_features.ksymbol) evsel->attr.ksymbol = 0; + if (perf_missing_features.bpf_event) + evsel->attr.bpf_event = 0; retry_sample_id: if (perf_missing_features.sample_id_all) evsel->attr.sample_id_all = 0; @@ -1964,6 +1969,11 @@ int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, perf_missing_features.ksymbol = true; pr_debug2("switching off ksymbol\n"); goto fallback_missing_features; + } else if (!perf_missing_features.bpf_event && + evsel->attr.bpf_event) { + perf_missing_features.bpf_event = true; + pr_debug2("switching off bpf_event\n"); + goto fallback_missing_features; } else if (!perf_missing_features.sample_id_all) { perf_missing_features.sample_id_all = true; pr_debug2("switching off sample_id_all\n"); diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index c647c1963f7a..490d7972e87a 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -169,6 +169,7 @@ struct perf_missing_features { bool write_backward; bool group_read; bool ksymbol; + bool bpf_event; }; extern struct perf_missing_features perf_missing_features; diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 5b50442d77c9..61854e2ded95 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -21,6 +21,7 @@ #include "unwind.h" #include "linux/hash.h" #include "asm/bug.h" +#include "bpf-event.h" #include "sane_ctype.h" #include @@ -1869,6 +1870,8 @@ int machine__process_event(struct machine *machine, union perf_event *event, ret = machine__process_switch_event(machine, event); break; case PERF_RECORD_KSYMBOL: ret = machine__process_ksymbol(machine, event, sample); break; + case PERF_RECORD_BPF_EVENT: + ret = machine__process_bpf_event(machine, event, sample); break; default: ret = -1; break; diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 2c1976a66164..640c78871cb5 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -373,6 +373,8 @@ void perf_tool__fill_defaults(struct perf_tool *tool) tool->context_switch = perf_event__process_switch; if (tool->ksymbol == NULL) tool->ksymbol = perf_event__process_ksymbol; + if (tool->bpf_event == NULL) + tool->bpf_event = perf_event__process_bpf_event; if (tool->read == NULL) tool->read = process_event_sample_stub; if (tool->throttle == NULL) @@ -1304,6 +1306,8 @@ static int machines__deliver_event(struct machines *machines, return tool->context_switch(tool, event, sample, machine); case PERF_RECORD_KSYMBOL: return tool->ksymbol(tool, event, sample, machine); + case PERF_RECORD_BPF_EVENT: + return tool->bpf_event(tool, event, sample, machine); default: ++evlist->stats.nr_unknown_events; return -1; diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h index 9c81ca2f3cf7..250391672f9f 100644 --- a/tools/perf/util/tool.h +++ b/tools/perf/util/tool.h @@ -54,7 +54,8 @@ struct perf_tool { context_switch, throttle, unthrottle, - ksymbol; + ksymbol, + bpf_event; event_attr_op attr; event_attr_op event_update; -- 2.17.1