@@ -31,6 +31,7 @@
#include "util/auxtrace.h"
#include "util/parse-branch-options.h"
#include "util/parse-regs-options.h"
+#include "util/bpf-loader.h"
#include <unistd.h>
#include <sched.h>
@@ -1132,13 +1133,13 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
if (!rec->itr) {
rec->itr = auxtrace_record__init(rec->evlist, &err);
if (err)
- return err;
+ goto out_bpf_clear;
}
err = auxtrace_parse_snapshot_options(rec->itr, &rec->opts,
rec->opts.auxtrace_snapshot_opts);
if (err)
- return err;
+ goto out_bpf_clear;
err = -ENOMEM;
@@ -1201,6 +1202,8 @@ out_symbol_exit:
perf_evlist__delete(rec->evlist);
symbol__exit();
auxtrace_record__free(rec->itr);
+out_bpf_clear:
+ bpf__clear();
return err;
}
@@ -59,6 +59,7 @@
#include "util/thread.h"
#include "util/thread_map.h"
#include "util/counts.h"
+#include "util/bpf-loader.h"
#include <stdlib.h>
#include <sys/prctl.h>
@@ -1224,7 +1225,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
output = fopen(output_name, mode);
if (!output) {
perror("failed to create output file");
- return -1;
+ status = -1;
+ goto out;
}
clock_gettime(CLOCK_REALTIME, &tm);
fprintf(output, "# started on %s\n", ctime(&tm.tv_sec));
@@ -1233,7 +1235,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
output = fdopen(output_fd, mode);
if (!output) {
perror("Failed opening logfd");
- return -errno;
+ status = -errno;
+ goto out;
}
}
@@ -1366,5 +1369,6 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
perf_evlist__free_stats(evsel_list);
out:
perf_evlist__delete(evsel_list);
+ bpf__clear();
return status;
}
@@ -41,6 +41,7 @@
#include "util/sort.h"
#include "util/intlist.h"
#include "util/parse-branch-options.h"
+#include "util/bpf-loader.h"
#include "arch/common.h"
#include "util/debug.h"
@@ -1270,8 +1271,10 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
symbol_conf.priv_size = sizeof(struct annotation);
symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);
- if (symbol__init(NULL) < 0)
- return -1;
+ if (symbol__init(NULL) < 0) {
+ status = -1;
+ goto out_bpf_clear;
+ }
sort__setup_elide(stdout);
@@ -1289,6 +1292,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
out_delete_evlist:
perf_evlist__delete(top.evlist);
-
+out_bpf_clear:
+ bpf__clear();
return status;
}
@@ -31,6 +31,7 @@
#include "util/intlist.h"
#include "util/thread_map.h"
#include "util/stat.h"
+#include "util/bpf-loader.h"
#include "trace-event.h"
#include "util/parse-events.h"
@@ -3109,6 +3110,7 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
if (trace.evlist->nr_entries > 0)
evlist__set_evsel_handler(trace.evlist, trace__event_handler);
+ /* trace__record calls cmd_record, which calls bpf__clear() */
if ((argc >= 1) && (strcmp(argv[0], "record") == 0))
return trace__record(&trace, argc-1, &argv[1]);
@@ -3119,7 +3121,8 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
if (!trace.trace_syscalls && !trace.trace_pgfaults &&
trace.evlist->nr_entries == 0 /* Was --events used? */) {
pr_err("Please specify something to trace.\n");
- return -1;
+ err = -1;
+ goto out;
}
if (output_name != NULL) {
@@ -3178,5 +3181,6 @@ out_close:
if (output_name != NULL)
fclose(trace.output);
out:
+ bpf__clear();
return err;
}
@@ -85,6 +85,7 @@ libperf-$(CONFIG_AUXTRACE) += intel-bts.o
libperf-y += parse-branch-options.o
libperf-y += parse-regs-options.o
+libperf-$(CONFIG_LIBBPF) += bpf-loader.o
libperf-$(CONFIG_LIBELF) += symbol-elf.o
libperf-$(CONFIG_LIBELF) += probe-file.o
libperf-$(CONFIG_LIBELF) += probe-event.o
@@ -19,6 +19,7 @@
#include "thread_map.h"
#include "cpumap.h"
#include "asm/bug.h"
+#include "bpf-loader.h"
#define MAX_NAME_LEN 100
@@ -481,6 +482,60 @@ int parse_events_add_tracepoint(struct list_head *list, int *idx,
return add_tracepoint_event(list, idx, sys, event);
}
+int parse_events_load_bpf(struct parse_events_evlist *data,
+ struct list_head *list,
+ char *bpf_file_name)
+{
+ int err;
+ char errbuf[BUFSIZ];
+ struct perf_evsel *dummy_evsel;
+
+ /*
+ * Currently don't link useful event to list. BPF object files
+ * should be saved to a seprated list and processed together.
+ *
+ * Things could be changed if we solve perf probe reentering
+ * problem. After that probe events file by file is possible.
+ * However, probing cost is still need to be considered.
+ *
+ * We should still link something onto evlist to make it
+ * compatible with other events, or we have to find another
+ * way to collect --filter options and modifiers (currently
+ * modifiers are not allowed lexicically). evsel->tracking
+ * is another thing needs to be considered. Fortunately we have
+ * dummy evsel, which is originally designed for collecting
+ * evsel->tracking.
+ */
+ err = parse_events_add_numeric(data, list, PERF_TYPE_SOFTWARE,
+ PERF_COUNT_SW_DUMMY, NULL);
+ if (err)
+ return err;
+ if (list_empty(list) || !list_is_singular(list)) {
+ data->error->str = strdup(
+ "Internal error: failed to alloc dummy evsel");
+ return -ENOENT;
+ }
+
+ dummy_evsel = list_entry(list->prev, struct perf_evsel, node);
+
+ /* Give it a better name so we can connect this list to the object */
+ zfree(&dummy_evsel->name);
+ dummy_evsel->name = strdup(bpf_file_name);
+
+ err = bpf__prepare_load(bpf_file_name);
+ if (err) {
+ bpf__strerror_prepare_load(bpf_file_name, err,
+ errbuf, sizeof(errbuf));
+ list_del_init(&dummy_evsel->node);
+ perf_evsel__delete(dummy_evsel);
+ data->error->str = strdup(errbuf);
+ data->error->help = strdup("(add -v to see detail)");
+ return err;
+ }
+
+ return 0;
+}
+
static int
parse_breakpoint_type(const char *type, struct perf_event_attr *attr)
{
@@ -119,6 +119,9 @@ int parse_events__modifier_group(struct list_head *list, char *event_mod);
int parse_events_name(struct list_head *list, char *name);
int parse_events_add_tracepoint(struct list_head *list, int *idx,
char *sys, char *event);
+int parse_events_load_bpf(struct parse_events_evlist *data,
+ struct list_head *list,
+ char *bpf_file_name);
int parse_events_add_numeric(struct parse_events_evlist *data,
struct list_head *list,
u32 type, u64 config,
@@ -115,6 +115,7 @@ do { \
group [^,{}/]*[{][^}]*[}][^,{}/]*
event_pmu [^,{}/]+[/][^/]*[/][^,{}/]*
event [^,{}/]+
+bpf_object .*\.(o|bpf)
num_dec [0-9]+
num_hex 0x[a-fA-F0-9]+
@@ -159,6 +160,7 @@ modifier_bp [rwx]{1,3}
}
{event_pmu} |
+{bpf_object} |
{event} {
BEGIN(INITIAL);
REWIND(1);
@@ -264,6 +266,7 @@ r{num_raw_hex} { return raw(yyscanner); }
{num_hex} { return value(yyscanner, 16); }
{modifier_event} { return str(yyscanner, PE_MODIFIER_EVENT); }
+{bpf_object} { return str(yyscanner, PE_BPF_OBJECT); }
{name} { return pmu_str_check(yyscanner); }
"/" { BEGIN(config); return '/'; }
- { return '-'; }
@@ -42,6 +42,7 @@ static inc_group_count(struct list_head *list,
%token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM
%token PE_EVENT_NAME
%token PE_NAME
+%token PE_BPF_OBJECT
%token PE_MODIFIER_EVENT PE_MODIFIER_BP
%token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT
%token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP
@@ -53,6 +54,7 @@ static inc_group_count(struct list_head *list,
%type <num> PE_RAW
%type <num> PE_TERM
%type <str> PE_NAME
+%type <str> PE_BPF_OBJECT
%type <str> PE_NAME_CACHE_TYPE
%type <str> PE_NAME_CACHE_OP_RESULT
%type <str> PE_MODIFIER_EVENT
@@ -69,6 +71,7 @@ static inc_group_count(struct list_head *list,
%type <head> event_legacy_tracepoint
%type <head> event_legacy_numeric
%type <head> event_legacy_raw
+%type <head> event_bpf_file
%type <head> event_def
%type <head> event_mod
%type <head> event_name
@@ -198,7 +201,8 @@ event_def: event_pmu |
event_legacy_mem |
event_legacy_tracepoint sep_dc |
event_legacy_numeric sep_dc |
- event_legacy_raw sep_dc
+ event_legacy_raw sep_dc |
+ event_bpf_file
event_pmu:
PE_NAME '/' event_config '/'
@@ -420,6 +424,18 @@ PE_RAW
$$ = list;
}
+event_bpf_file:
+PE_BPF_OBJECT
+{
+ struct parse_events_evlist *data = _data;
+ struct list_head *list;
+
+ ALLOC_LIST(list);
+ ABORT_ON(parse_events_load_bpf(data, list, $1));
+ $$ = list;
+}
+
+
start_terms: event_config
{
struct parse_events_terms *data = _data;