mirror of
https://github.com/armbian/linux-cix.git
synced 2026-01-06 12:30:45 -08:00
perf parse-events: Break out tracepoint and printing
Move print_*_events functions out of parse-events.c into a new print-events.c. Move tracepoint code into tracepoint.c or trace-event-info.c (sole user). This reduces the dependencies of parse-events.c and makes it more amenable to being a library in the future. Remove some unnecessary definitions from parse-events.h. Fix a checkpatch.pl warning on using unsigned rather than unsigned int. Fix some line length warnings too. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: https://lore.kernel.org/r/20220729204217.250166-3-irogers@google.com [ Add include linux/stddef.h before perf_events.h for systems where __always_inline isn't pulled in before used, such as older Alpine Linux ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
committed by
Arnaldo Carvalho de Melo
parent
32f457abb8
commit
9b7c7728f4
@@ -10,7 +10,7 @@
|
||||
*/
|
||||
#include "builtin.h"
|
||||
|
||||
#include "util/parse-events.h"
|
||||
#include "util/print-events.h"
|
||||
#include "util/pmu.h"
|
||||
#include "util/pmu-hybrid.h"
|
||||
#include "util/debug.h"
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <subcmd/pager.h>
|
||||
#include <subcmd/parse-options.h>
|
||||
#include "util/trace-event.h"
|
||||
#include "util/tracepoint.h"
|
||||
|
||||
#include "util/debug.h"
|
||||
#include "util/session.h"
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "util/data.h"
|
||||
#include "util/debug.h"
|
||||
#include "util/string2.h"
|
||||
#include "util/tracepoint.h"
|
||||
#include <linux/err.h>
|
||||
|
||||
#ifdef LACKS_OPEN_MEMSTREAM_PROTOTYPE
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
#include "trace-event.h"
|
||||
#include "util/parse-events.h"
|
||||
#include "util/bpf-loader.h"
|
||||
#include "util/tracepoint.h"
|
||||
#include "callchain.h"
|
||||
#include "print_binary.h"
|
||||
#include "string2.h"
|
||||
|
||||
@@ -26,6 +26,8 @@ perf-y += mmap.o
|
||||
perf-y += memswap.o
|
||||
perf-y += parse-events.o
|
||||
perf-y += parse-events-hybrid.o
|
||||
perf-y += print-events.o
|
||||
perf-y += tracepoint.o
|
||||
perf-y += perf_regs.o
|
||||
perf-y += path.o
|
||||
perf-y += print_binary.o
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -11,7 +11,6 @@
|
||||
#include <linux/perf_event.h>
|
||||
#include <string.h>
|
||||
|
||||
struct list_head;
|
||||
struct evsel;
|
||||
struct evlist;
|
||||
struct parse_events_error;
|
||||
@@ -19,14 +18,6 @@ struct parse_events_error;
|
||||
struct option;
|
||||
struct perf_pmu;
|
||||
|
||||
struct tracepoint_path {
|
||||
char *system;
|
||||
char *name;
|
||||
struct tracepoint_path *next;
|
||||
};
|
||||
|
||||
struct tracepoint_path *tracepoint_id_to_path(u64 config);
|
||||
struct tracepoint_path *tracepoint_name_to_path(const char *name);
|
||||
bool have_tracepoints(struct list_head *evlist);
|
||||
|
||||
const char *event_type(int type);
|
||||
@@ -46,8 +37,6 @@ int parse_events_terms(struct list_head *terms, const char *str);
|
||||
int parse_filter(const struct option *opt, const char *str, int unset);
|
||||
int exclude_perf(const struct option *opt, const char *arg, int unset);
|
||||
|
||||
#define EVENTS_HELP_MAX (128*1024)
|
||||
|
||||
enum perf_pmu_event_symbol_type {
|
||||
PMU_EVENT_SYMBOL_ERR, /* not a PMU EVENT */
|
||||
PMU_EVENT_SYMBOL, /* normal style PMU event */
|
||||
@@ -56,11 +45,6 @@ enum perf_pmu_event_symbol_type {
|
||||
PMU_EVENT_SYMBOL_SUFFIX2, /* suffix of pre-suf2 style event */
|
||||
};
|
||||
|
||||
struct perf_pmu_event_symbol {
|
||||
char *symbol;
|
||||
enum perf_pmu_event_symbol_type type;
|
||||
};
|
||||
|
||||
enum {
|
||||
PARSE_EVENTS__TERM_TYPE_NUM,
|
||||
PARSE_EVENTS__TERM_TYPE_STR,
|
||||
@@ -219,28 +203,13 @@ void parse_events_update_lists(struct list_head *list_event,
|
||||
void parse_events_evlist_error(struct parse_events_state *parse_state,
|
||||
int idx, const char *str);
|
||||
|
||||
void print_events(const char *event_glob, bool name_only, bool quiet,
|
||||
bool long_desc, bool details_flag, bool deprecated,
|
||||
const char *pmu_name);
|
||||
|
||||
struct event_symbol {
|
||||
const char *symbol;
|
||||
const char *alias;
|
||||
};
|
||||
extern struct event_symbol event_symbols_hw[];
|
||||
extern struct event_symbol event_symbols_sw[];
|
||||
void print_symbol_events(const char *event_glob, unsigned type,
|
||||
struct event_symbol *syms, unsigned max,
|
||||
bool name_only);
|
||||
void print_tool_events(const char *event_glob, bool name_only);
|
||||
void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
|
||||
bool name_only);
|
||||
int print_hwcache_events(const char *event_glob, bool name_only);
|
||||
void print_sdt_events(const char *subsys_glob, const char *event_glob,
|
||||
bool name_only);
|
||||
int is_valid_tracepoint(const char *event_string);
|
||||
|
||||
int valid_event_mount(const char *eventfs);
|
||||
char *parse_events_formats_error_string(char *additional_terms);
|
||||
|
||||
void parse_events_error__init(struct parse_events_error *err);
|
||||
|
||||
572
tools/perf/util/print-events.c
Normal file
572
tools/perf/util/print-events.c
Normal file
File diff suppressed because it is too large
Load Diff
22
tools/perf/util/print-events.h
Normal file
22
tools/perf/util/print-events.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef __PERF_PRINT_EVENTS_H
|
||||
#define __PERF_PRINT_EVENTS_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
struct event_symbol;
|
||||
|
||||
void print_events(const char *event_glob, bool name_only, bool quiet_flag,
|
||||
bool long_desc, bool details_flag, bool deprecated,
|
||||
const char *pmu_name);
|
||||
int print_hwcache_events(const char *event_glob, bool name_only);
|
||||
void print_sdt_events(const char *subsys_glob, const char *event_glob,
|
||||
bool name_only);
|
||||
void print_symbol_events(const char *event_glob, unsigned int type,
|
||||
struct event_symbol *syms, unsigned int max,
|
||||
bool name_only);
|
||||
void print_tool_events(const char *event_glob, bool name_only);
|
||||
void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
|
||||
bool name_only);
|
||||
|
||||
#endif /* __PERF_PRINT_EVENTS_H */
|
||||
@@ -19,16 +19,24 @@
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/zalloc.h>
|
||||
#include <internal/lib.h> // page_size
|
||||
#include <sys/param.h>
|
||||
|
||||
#include "trace-event.h"
|
||||
#include "tracepoint.h"
|
||||
#include <api/fs/tracing_path.h>
|
||||
#include "evsel.h"
|
||||
#include "debug.h"
|
||||
|
||||
#define VERSION "0.6"
|
||||
#define MAX_EVENT_LENGTH 512
|
||||
|
||||
static int output_fd;
|
||||
|
||||
struct tracepoint_path {
|
||||
char *system;
|
||||
char *name;
|
||||
struct tracepoint_path *next;
|
||||
};
|
||||
|
||||
int bigendian(void)
|
||||
{
|
||||
@@ -400,6 +408,94 @@ put_tracepoints_path(struct tracepoint_path *tps)
|
||||
}
|
||||
}
|
||||
|
||||
static struct tracepoint_path *tracepoint_id_to_path(u64 config)
|
||||
{
|
||||
struct tracepoint_path *path = NULL;
|
||||
DIR *sys_dir, *evt_dir;
|
||||
struct dirent *sys_dirent, *evt_dirent;
|
||||
char id_buf[24];
|
||||
int fd;
|
||||
u64 id;
|
||||
char evt_path[MAXPATHLEN];
|
||||
char *dir_path;
|
||||
|
||||
sys_dir = tracing_events__opendir();
|
||||
if (!sys_dir)
|
||||
return NULL;
|
||||
|
||||
for_each_subsystem(sys_dir, sys_dirent) {
|
||||
dir_path = get_events_file(sys_dirent->d_name);
|
||||
if (!dir_path)
|
||||
continue;
|
||||
evt_dir = opendir(dir_path);
|
||||
if (!evt_dir)
|
||||
goto next;
|
||||
|
||||
for_each_event(dir_path, evt_dir, evt_dirent) {
|
||||
|
||||
scnprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path,
|
||||
evt_dirent->d_name);
|
||||
fd = open(evt_path, O_RDONLY);
|
||||
if (fd < 0)
|
||||
continue;
|
||||
if (read(fd, id_buf, sizeof(id_buf)) < 0) {
|
||||
close(fd);
|
||||
continue;
|
||||
}
|
||||
close(fd);
|
||||
id = atoll(id_buf);
|
||||
if (id == config) {
|
||||
put_events_file(dir_path);
|
||||
closedir(evt_dir);
|
||||
closedir(sys_dir);
|
||||
path = zalloc(sizeof(*path));
|
||||
if (!path)
|
||||
return NULL;
|
||||
if (asprintf(&path->system, "%.*s",
|
||||
MAX_EVENT_LENGTH, sys_dirent->d_name) < 0) {
|
||||
free(path);
|
||||
return NULL;
|
||||
}
|
||||
if (asprintf(&path->name, "%.*s",
|
||||
MAX_EVENT_LENGTH, evt_dirent->d_name) < 0) {
|
||||
zfree(&path->system);
|
||||
free(path);
|
||||
return NULL;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
}
|
||||
closedir(evt_dir);
|
||||
next:
|
||||
put_events_file(dir_path);
|
||||
}
|
||||
|
||||
closedir(sys_dir);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct tracepoint_path *tracepoint_name_to_path(const char *name)
|
||||
{
|
||||
struct tracepoint_path *path = zalloc(sizeof(*path));
|
||||
char *str = strchr(name, ':');
|
||||
|
||||
if (path == NULL || str == NULL) {
|
||||
free(path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
path->system = strndup(name, str - name);
|
||||
path->name = strdup(str+1);
|
||||
|
||||
if (path->system == NULL || path->name == NULL) {
|
||||
zfree(&path->system);
|
||||
zfree(&path->name);
|
||||
zfree(&path);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
static struct tracepoint_path *
|
||||
get_tracepoints_path(struct list_head *pattrs)
|
||||
{
|
||||
|
||||
63
tools/perf/util/tracepoint.c
Normal file
63
tools/perf/util/tracepoint.c
Normal file
@@ -0,0 +1,63 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include "tracepoint.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/param.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <api/fs/tracing_path.h>
|
||||
|
||||
int tp_event_has_id(const char *dir_path, struct dirent *evt_dir)
|
||||
{
|
||||
char evt_path[MAXPATHLEN];
|
||||
int fd;
|
||||
|
||||
snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path, evt_dir->d_name);
|
||||
fd = open(evt_path, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return -EINVAL;
|
||||
close(fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check whether event is in <debugfs_mount_point>/tracing/events
|
||||
*/
|
||||
int is_valid_tracepoint(const char *event_string)
|
||||
{
|
||||
DIR *sys_dir, *evt_dir;
|
||||
struct dirent *sys_dirent, *evt_dirent;
|
||||
char evt_path[MAXPATHLEN];
|
||||
char *dir_path;
|
||||
|
||||
sys_dir = tracing_events__opendir();
|
||||
if (!sys_dir)
|
||||
return 0;
|
||||
|
||||
for_each_subsystem(sys_dir, sys_dirent) {
|
||||
dir_path = get_events_file(sys_dirent->d_name);
|
||||
if (!dir_path)
|
||||
continue;
|
||||
evt_dir = opendir(dir_path);
|
||||
if (!evt_dir)
|
||||
goto next;
|
||||
|
||||
for_each_event(dir_path, evt_dir, evt_dirent) {
|
||||
snprintf(evt_path, MAXPATHLEN, "%s:%s",
|
||||
sys_dirent->d_name, evt_dirent->d_name);
|
||||
if (!strcmp(evt_path, event_string)) {
|
||||
closedir(evt_dir);
|
||||
closedir(sys_dir);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
closedir(evt_dir);
|
||||
next:
|
||||
put_events_file(dir_path);
|
||||
}
|
||||
closedir(sys_dir);
|
||||
return 0;
|
||||
}
|
||||
25
tools/perf/util/tracepoint.h
Normal file
25
tools/perf/util/tracepoint.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef __PERF_TRACEPOINT_H
|
||||
#define __PERF_TRACEPOINT_H
|
||||
|
||||
#include <dirent.h>
|
||||
#include <string.h>
|
||||
|
||||
int tp_event_has_id(const char *dir_path, struct dirent *evt_dir);
|
||||
|
||||
#define for_each_event(dir_path, evt_dir, evt_dirent) \
|
||||
while ((evt_dirent = readdir(evt_dir)) != NULL) \
|
||||
if (evt_dirent->d_type == DT_DIR && \
|
||||
(strcmp(evt_dirent->d_name, ".")) && \
|
||||
(strcmp(evt_dirent->d_name, "..")) && \
|
||||
(!tp_event_has_id(dir_path, evt_dirent)))
|
||||
|
||||
#define for_each_subsystem(sys_dir, sys_dirent) \
|
||||
while ((sys_dirent = readdir(sys_dir)) != NULL) \
|
||||
if (sys_dirent->d_type == DT_DIR && \
|
||||
(strcmp(sys_dirent->d_name, ".")) && \
|
||||
(strcmp(sys_dirent->d_name, "..")))
|
||||
|
||||
int is_valid_tracepoint(const char *event_string);
|
||||
|
||||
#endif /* __PERF_TRACEPOINT_H */
|
||||
Reference in New Issue
Block a user