libperf: Move to tools/lib/perf
Move libperf from its current location under tools/perf to a separate directory under tools/lib/. Also change various paths (mainly includes) to reflect the libperf move to a separate directory and add a new directory under MANIFEST. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Michael Petlan <mpetlan@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lore.kernel.org/lkml/20191206210612.8676-2-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
committed by
Arnaldo Carvalho de Melo
parent
6ae9c10b7c
commit
3ce311afb5
19
tools/lib/perf/include/internal/cpumap.h
Normal file
19
tools/lib/perf/include/internal/cpumap.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef __LIBPERF_INTERNAL_CPUMAP_H
|
||||
#define __LIBPERF_INTERNAL_CPUMAP_H
|
||||
|
||||
#include <linux/refcount.h>
|
||||
|
||||
struct perf_cpu_map {
|
||||
refcount_t refcnt;
|
||||
int nr;
|
||||
int map[];
|
||||
};
|
||||
|
||||
#ifndef MAX_NR_CPUS
|
||||
#define MAX_NR_CPUS 2048
|
||||
#endif
|
||||
|
||||
int perf_cpu_map__idx(struct perf_cpu_map *cpus, int cpu);
|
||||
|
||||
#endif /* __LIBPERF_INTERNAL_CPUMAP_H */
|
||||
127
tools/lib/perf/include/internal/evlist.h
Normal file
127
tools/lib/perf/include/internal/evlist.h
Normal file
@@ -0,0 +1,127 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef __LIBPERF_INTERNAL_EVLIST_H
|
||||
#define __LIBPERF_INTERNAL_EVLIST_H
|
||||
|
||||
#include <linux/list.h>
|
||||
#include <api/fd/array.h>
|
||||
#include <internal/evsel.h>
|
||||
|
||||
#define PERF_EVLIST__HLIST_BITS 8
|
||||
#define PERF_EVLIST__HLIST_SIZE (1 << PERF_EVLIST__HLIST_BITS)
|
||||
|
||||
struct perf_cpu_map;
|
||||
struct perf_thread_map;
|
||||
struct perf_mmap_param;
|
||||
|
||||
struct perf_evlist {
|
||||
struct list_head entries;
|
||||
int nr_entries;
|
||||
bool has_user_cpus;
|
||||
struct perf_cpu_map *cpus;
|
||||
struct perf_cpu_map *all_cpus;
|
||||
struct perf_thread_map *threads;
|
||||
int nr_mmaps;
|
||||
size_t mmap_len;
|
||||
struct fdarray pollfd;
|
||||
struct hlist_head heads[PERF_EVLIST__HLIST_SIZE];
|
||||
struct perf_mmap *mmap;
|
||||
struct perf_mmap *mmap_ovw;
|
||||
struct perf_mmap *mmap_first;
|
||||
struct perf_mmap *mmap_ovw_first;
|
||||
};
|
||||
|
||||
typedef void
|
||||
(*perf_evlist_mmap__cb_idx_t)(struct perf_evlist*, struct perf_mmap_param*, int, bool);
|
||||
typedef struct perf_mmap*
|
||||
(*perf_evlist_mmap__cb_get_t)(struct perf_evlist*, bool, int);
|
||||
typedef int
|
||||
(*perf_evlist_mmap__cb_mmap_t)(struct perf_mmap*, struct perf_mmap_param*, int, int);
|
||||
|
||||
struct perf_evlist_mmap_ops {
|
||||
perf_evlist_mmap__cb_idx_t idx;
|
||||
perf_evlist_mmap__cb_get_t get;
|
||||
perf_evlist_mmap__cb_mmap_t mmap;
|
||||
};
|
||||
|
||||
int perf_evlist__alloc_pollfd(struct perf_evlist *evlist);
|
||||
int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd,
|
||||
void *ptr, short revent);
|
||||
|
||||
int perf_evlist__mmap_ops(struct perf_evlist *evlist,
|
||||
struct perf_evlist_mmap_ops *ops,
|
||||
struct perf_mmap_param *mp);
|
||||
|
||||
void perf_evlist__init(struct perf_evlist *evlist);
|
||||
void perf_evlist__exit(struct perf_evlist *evlist);
|
||||
|
||||
/**
|
||||
* __perf_evlist__for_each_entry - iterate thru all the evsels
|
||||
* @list: list_head instance to iterate
|
||||
* @evsel: struct perf_evsel iterator
|
||||
*/
|
||||
#define __perf_evlist__for_each_entry(list, evsel) \
|
||||
list_for_each_entry(evsel, list, node)
|
||||
|
||||
/**
|
||||
* evlist__for_each_entry - iterate thru all the evsels
|
||||
* @evlist: perf_evlist instance to iterate
|
||||
* @evsel: struct perf_evsel iterator
|
||||
*/
|
||||
#define perf_evlist__for_each_entry(evlist, evsel) \
|
||||
__perf_evlist__for_each_entry(&(evlist)->entries, evsel)
|
||||
|
||||
/**
|
||||
* __perf_evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
|
||||
* @list: list_head instance to iterate
|
||||
* @evsel: struct evsel iterator
|
||||
*/
|
||||
#define __perf_evlist__for_each_entry_reverse(list, evsel) \
|
||||
list_for_each_entry_reverse(evsel, list, node)
|
||||
|
||||
/**
|
||||
* perf_evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
|
||||
* @evlist: evlist instance to iterate
|
||||
* @evsel: struct evsel iterator
|
||||
*/
|
||||
#define perf_evlist__for_each_entry_reverse(evlist, evsel) \
|
||||
__perf_evlist__for_each_entry_reverse(&(evlist)->entries, evsel)
|
||||
|
||||
/**
|
||||
* __perf_evlist__for_each_entry_safe - safely iterate thru all the evsels
|
||||
* @list: list_head instance to iterate
|
||||
* @tmp: struct evsel temp iterator
|
||||
* @evsel: struct evsel iterator
|
||||
*/
|
||||
#define __perf_evlist__for_each_entry_safe(list, tmp, evsel) \
|
||||
list_for_each_entry_safe(evsel, tmp, list, node)
|
||||
|
||||
/**
|
||||
* perf_evlist__for_each_entry_safe - safely iterate thru all the evsels
|
||||
* @evlist: evlist instance to iterate
|
||||
* @evsel: struct evsel iterator
|
||||
* @tmp: struct evsel temp iterator
|
||||
*/
|
||||
#define perf_evlist__for_each_entry_safe(evlist, tmp, evsel) \
|
||||
__perf_evlist__for_each_entry_safe(&(evlist)->entries, tmp, evsel)
|
||||
|
||||
static inline struct perf_evsel *perf_evlist__first(struct perf_evlist *evlist)
|
||||
{
|
||||
return list_entry(evlist->entries.next, struct perf_evsel, node);
|
||||
}
|
||||
|
||||
static inline struct perf_evsel *perf_evlist__last(struct perf_evlist *evlist)
|
||||
{
|
||||
return list_entry(evlist->entries.prev, struct perf_evsel, node);
|
||||
}
|
||||
|
||||
u64 perf_evlist__read_format(struct perf_evlist *evlist);
|
||||
|
||||
void perf_evlist__id_add(struct perf_evlist *evlist,
|
||||
struct perf_evsel *evsel,
|
||||
int cpu, int thread, u64 id);
|
||||
|
||||
int perf_evlist__id_add_fd(struct perf_evlist *evlist,
|
||||
struct perf_evsel *evsel,
|
||||
int cpu, int thread, int fd);
|
||||
|
||||
#endif /* __LIBPERF_INTERNAL_EVLIST_H */
|
||||
63
tools/lib/perf/include/internal/evsel.h
Normal file
63
tools/lib/perf/include/internal/evsel.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef __LIBPERF_INTERNAL_EVSEL_H
|
||||
#define __LIBPERF_INTERNAL_EVSEL_H
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <linux/perf_event.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
struct perf_cpu_map;
|
||||
struct perf_thread_map;
|
||||
struct xyarray;
|
||||
|
||||
/*
|
||||
* Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are
|
||||
* more than one entry in the evlist.
|
||||
*/
|
||||
struct perf_sample_id {
|
||||
struct hlist_node node;
|
||||
u64 id;
|
||||
struct perf_evsel *evsel;
|
||||
/*
|
||||
* 'idx' will be used for AUX area sampling. A sample will have AUX area
|
||||
* data that will be queued for decoding, where there are separate
|
||||
* queues for each CPU (per-cpu tracing) or task (per-thread tracing).
|
||||
* The sample ID can be used to lookup 'idx' which is effectively the
|
||||
* queue number.
|
||||
*/
|
||||
int idx;
|
||||
int cpu;
|
||||
pid_t tid;
|
||||
|
||||
/* Holds total ID period value for PERF_SAMPLE_READ processing. */
|
||||
u64 period;
|
||||
};
|
||||
|
||||
struct perf_evsel {
|
||||
struct list_head node;
|
||||
struct perf_event_attr attr;
|
||||
struct perf_cpu_map *cpus;
|
||||
struct perf_cpu_map *own_cpus;
|
||||
struct perf_thread_map *threads;
|
||||
struct xyarray *fd;
|
||||
struct xyarray *sample_id;
|
||||
u64 *id;
|
||||
u32 ids;
|
||||
|
||||
/* parse modifier helper */
|
||||
int nr_members;
|
||||
bool system_wide;
|
||||
};
|
||||
|
||||
void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr);
|
||||
int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
|
||||
void perf_evsel__close_fd(struct perf_evsel *evsel);
|
||||
void perf_evsel__free_fd(struct perf_evsel *evsel);
|
||||
int perf_evsel__read_size(struct perf_evsel *evsel);
|
||||
int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter);
|
||||
|
||||
int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
|
||||
void perf_evsel__free_id(struct perf_evsel *evsel);
|
||||
|
||||
#endif /* __LIBPERF_INTERNAL_EVSEL_H */
|
||||
12
tools/lib/perf/include/internal/lib.h
Normal file
12
tools/lib/perf/include/internal/lib.h
Normal file
@@ -0,0 +1,12 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef __LIBPERF_INTERNAL_LIB_H
|
||||
#define __LIBPERF_INTERNAL_LIB_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
extern unsigned int page_size;
|
||||
|
||||
ssize_t readn(int fd, void *buf, size_t n);
|
||||
ssize_t writen(int fd, const void *buf, size_t n);
|
||||
|
||||
#endif /* __LIBPERF_INTERNAL_CPUMAP_H */
|
||||
55
tools/lib/perf/include/internal/mmap.h
Normal file
55
tools/lib/perf/include/internal/mmap.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef __LIBPERF_INTERNAL_MMAP_H
|
||||
#define __LIBPERF_INTERNAL_MMAP_H
|
||||
|
||||
#include <linux/compiler.h>
|
||||
#include <linux/refcount.h>
|
||||
#include <linux/types.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/* perf sample has 16 bits size limit */
|
||||
#define PERF_SAMPLE_MAX_SIZE (1 << 16)
|
||||
|
||||
struct perf_mmap;
|
||||
|
||||
typedef void (*libperf_unmap_cb_t)(struct perf_mmap *map);
|
||||
|
||||
/**
|
||||
* struct perf_mmap - perf's ring buffer mmap details
|
||||
*
|
||||
* @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
|
||||
*/
|
||||
struct perf_mmap {
|
||||
void *base;
|
||||
int mask;
|
||||
int fd;
|
||||
int cpu;
|
||||
refcount_t refcnt;
|
||||
u64 prev;
|
||||
u64 start;
|
||||
u64 end;
|
||||
bool overwrite;
|
||||
u64 flush;
|
||||
libperf_unmap_cb_t unmap_cb;
|
||||
char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
|
||||
struct perf_mmap *next;
|
||||
};
|
||||
|
||||
struct perf_mmap_param {
|
||||
int prot;
|
||||
int mask;
|
||||
};
|
||||
|
||||
size_t perf_mmap__mmap_len(struct perf_mmap *map);
|
||||
|
||||
void perf_mmap__init(struct perf_mmap *map, struct perf_mmap *prev,
|
||||
bool overwrite, libperf_unmap_cb_t unmap_cb);
|
||||
int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
|
||||
int fd, int cpu);
|
||||
void perf_mmap__munmap(struct perf_mmap *map);
|
||||
void perf_mmap__get(struct perf_mmap *map);
|
||||
void perf_mmap__put(struct perf_mmap *map);
|
||||
|
||||
u64 perf_mmap__read_head(struct perf_mmap *map);
|
||||
|
||||
#endif /* __LIBPERF_INTERNAL_MMAP_H */
|
||||
33
tools/lib/perf/include/internal/tests.h
Normal file
33
tools/lib/perf/include/internal/tests.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef __LIBPERF_INTERNAL_TESTS_H
|
||||
#define __LIBPERF_INTERNAL_TESTS_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int tests_failed;
|
||||
|
||||
#define __T_START \
|
||||
do { \
|
||||
fprintf(stdout, "- running %s...", __FILE__); \
|
||||
fflush(NULL); \
|
||||
tests_failed = 0; \
|
||||
} while (0)
|
||||
|
||||
#define __T_END \
|
||||
do { \
|
||||
if (tests_failed) \
|
||||
fprintf(stdout, " FAILED (%d)\n", tests_failed); \
|
||||
else \
|
||||
fprintf(stdout, "OK\n"); \
|
||||
} while (0)
|
||||
|
||||
#define __T(text, cond) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
fprintf(stderr, "FAILED %s:%d %s\n", __FILE__, __LINE__, text); \
|
||||
tests_failed++; \
|
||||
return -1; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#endif /* __LIBPERF_INTERNAL_TESTS_H */
|
||||
23
tools/lib/perf/include/internal/threadmap.h
Normal file
23
tools/lib/perf/include/internal/threadmap.h
Normal file
@@ -0,0 +1,23 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef __LIBPERF_INTERNAL_THREADMAP_H
|
||||
#define __LIBPERF_INTERNAL_THREADMAP_H
|
||||
|
||||
#include <linux/refcount.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
struct thread_map_data {
|
||||
pid_t pid;
|
||||
char *comm;
|
||||
};
|
||||
|
||||
struct perf_thread_map {
|
||||
refcount_t refcnt;
|
||||
int nr;
|
||||
int err_thread;
|
||||
struct thread_map_data map[];
|
||||
};
|
||||
|
||||
struct perf_thread_map *perf_thread_map__realloc(struct perf_thread_map *map, int nr);
|
||||
|
||||
#endif /* __LIBPERF_INTERNAL_THREADMAP_H */
|
||||
36
tools/lib/perf/include/internal/xyarray.h
Normal file
36
tools/lib/perf/include/internal/xyarray.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef __LIBPERF_INTERNAL_XYARRAY_H
|
||||
#define __LIBPERF_INTERNAL_XYARRAY_H
|
||||
|
||||
#include <linux/compiler.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
struct xyarray {
|
||||
size_t row_size;
|
||||
size_t entry_size;
|
||||
size_t entries;
|
||||
size_t max_x;
|
||||
size_t max_y;
|
||||
char contents[] __aligned(8);
|
||||
};
|
||||
|
||||
struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size);
|
||||
void xyarray__delete(struct xyarray *xy);
|
||||
void xyarray__reset(struct xyarray *xy);
|
||||
|
||||
static inline void *xyarray__entry(struct xyarray *xy, int x, int y)
|
||||
{
|
||||
return &xy->contents[x * xy->row_size + y * xy->entry_size];
|
||||
}
|
||||
|
||||
static inline int xyarray__max_y(struct xyarray *xy)
|
||||
{
|
||||
return xy->max_y;
|
||||
}
|
||||
|
||||
static inline int xyarray__max_x(struct xyarray *xy)
|
||||
{
|
||||
return xy->max_x;
|
||||
}
|
||||
|
||||
#endif /* __LIBPERF_INTERNAL_XYARRAY_H */
|
||||
25
tools/lib/perf/include/perf/core.h
Normal file
25
tools/lib/perf/include/perf/core.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef __LIBPERF_CORE_H
|
||||
#define __LIBPERF_CORE_H
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifndef LIBPERF_API
|
||||
#define LIBPERF_API __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
enum libperf_print_level {
|
||||
LIBPERF_ERR,
|
||||
LIBPERF_WARN,
|
||||
LIBPERF_INFO,
|
||||
LIBPERF_DEBUG,
|
||||
LIBPERF_DEBUG2,
|
||||
LIBPERF_DEBUG3,
|
||||
};
|
||||
|
||||
typedef int (*libperf_print_fn_t)(enum libperf_print_level level,
|
||||
const char *, va_list ap);
|
||||
|
||||
LIBPERF_API void libperf_init(libperf_print_fn_t fn);
|
||||
|
||||
#endif /* __LIBPERF_CORE_H */
|
||||
28
tools/lib/perf/include/perf/cpumap.h
Normal file
28
tools/lib/perf/include/perf/cpumap.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef __LIBPERF_CPUMAP_H
|
||||
#define __LIBPERF_CPUMAP_H
|
||||
|
||||
#include <perf/core.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct perf_cpu_map;
|
||||
|
||||
LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void);
|
||||
LIBPERF_API struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list);
|
||||
LIBPERF_API struct perf_cpu_map *perf_cpu_map__read(FILE *file);
|
||||
LIBPERF_API struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map);
|
||||
LIBPERF_API struct perf_cpu_map *perf_cpu_map__merge(struct perf_cpu_map *orig,
|
||||
struct perf_cpu_map *other);
|
||||
LIBPERF_API void perf_cpu_map__put(struct perf_cpu_map *map);
|
||||
LIBPERF_API int perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx);
|
||||
LIBPERF_API int perf_cpu_map__nr(const struct perf_cpu_map *cpus);
|
||||
LIBPERF_API bool perf_cpu_map__empty(const struct perf_cpu_map *map);
|
||||
LIBPERF_API int perf_cpu_map__max(struct perf_cpu_map *map);
|
||||
|
||||
#define perf_cpu_map__for_each_cpu(cpu, idx, cpus) \
|
||||
for ((idx) = 0, (cpu) = perf_cpu_map__cpu(cpus, idx); \
|
||||
(idx) < perf_cpu_map__nr(cpus); \
|
||||
(idx)++, (cpu) = perf_cpu_map__cpu(cpus, idx))
|
||||
|
||||
#endif /* __LIBPERF_CPUMAP_H */
|
||||
385
tools/lib/perf/include/perf/event.h
Normal file
385
tools/lib/perf/include/perf/event.h
Normal file
@@ -0,0 +1,385 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef __LIBPERF_EVENT_H
|
||||
#define __LIBPERF_EVENT_H
|
||||
|
||||
#include <linux/perf_event.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/limits.h>
|
||||
#include <linux/bpf.h>
|
||||
#include <sys/types.h> /* pid_t */
|
||||
|
||||
struct perf_record_mmap {
|
||||
struct perf_event_header header;
|
||||
__u32 pid, tid;
|
||||
__u64 start;
|
||||
__u64 len;
|
||||
__u64 pgoff;
|
||||
char filename[PATH_MAX];
|
||||
};
|
||||
|
||||
struct perf_record_mmap2 {
|
||||
struct perf_event_header header;
|
||||
__u32 pid, tid;
|
||||
__u64 start;
|
||||
__u64 len;
|
||||
__u64 pgoff;
|
||||
__u32 maj;
|
||||
__u32 min;
|
||||
__u64 ino;
|
||||
__u64 ino_generation;
|
||||
__u32 prot;
|
||||
__u32 flags;
|
||||
char filename[PATH_MAX];
|
||||
};
|
||||
|
||||
struct perf_record_comm {
|
||||
struct perf_event_header header;
|
||||
__u32 pid, tid;
|
||||
char comm[16];
|
||||
};
|
||||
|
||||
struct perf_record_namespaces {
|
||||
struct perf_event_header header;
|
||||
__u32 pid, tid;
|
||||
__u64 nr_namespaces;
|
||||
struct perf_ns_link_info link_info[];
|
||||
};
|
||||
|
||||
struct perf_record_fork {
|
||||
struct perf_event_header header;
|
||||
__u32 pid, ppid;
|
||||
__u32 tid, ptid;
|
||||
__u64 time;
|
||||
};
|
||||
|
||||
struct perf_record_lost {
|
||||
struct perf_event_header header;
|
||||
__u64 id;
|
||||
__u64 lost;
|
||||
};
|
||||
|
||||
struct perf_record_lost_samples {
|
||||
struct perf_event_header header;
|
||||
__u64 lost;
|
||||
};
|
||||
|
||||
/*
|
||||
* PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID
|
||||
*/
|
||||
struct perf_record_read {
|
||||
struct perf_event_header header;
|
||||
__u32 pid, tid;
|
||||
__u64 value;
|
||||
__u64 time_enabled;
|
||||
__u64 time_running;
|
||||
__u64 id;
|
||||
};
|
||||
|
||||
struct perf_record_throttle {
|
||||
struct perf_event_header header;
|
||||
__u64 time;
|
||||
__u64 id;
|
||||
__u64 stream_id;
|
||||
};
|
||||
|
||||
#ifndef KSYM_NAME_LEN
|
||||
#define KSYM_NAME_LEN 256
|
||||
#endif
|
||||
|
||||
struct perf_record_ksymbol {
|
||||
struct perf_event_header header;
|
||||
__u64 addr;
|
||||
__u32 len;
|
||||
__u16 ksym_type;
|
||||
__u16 flags;
|
||||
char name[KSYM_NAME_LEN];
|
||||
};
|
||||
|
||||
struct perf_record_bpf_event {
|
||||
struct perf_event_header header;
|
||||
__u16 type;
|
||||
__u16 flags;
|
||||
__u32 id;
|
||||
|
||||
/* for bpf_prog types */
|
||||
__u8 tag[BPF_TAG_SIZE]; // prog tag
|
||||
};
|
||||
|
||||
struct perf_record_sample {
|
||||
struct perf_event_header header;
|
||||
__u64 array[];
|
||||
};
|
||||
|
||||
struct perf_record_switch {
|
||||
struct perf_event_header header;
|
||||
__u32 next_prev_pid;
|
||||
__u32 next_prev_tid;
|
||||
};
|
||||
|
||||
struct perf_record_header_attr {
|
||||
struct perf_event_header header;
|
||||
struct perf_event_attr attr;
|
||||
__u64 id[];
|
||||
};
|
||||
|
||||
enum {
|
||||
PERF_CPU_MAP__CPUS = 0,
|
||||
PERF_CPU_MAP__MASK = 1,
|
||||
};
|
||||
|
||||
struct cpu_map_entries {
|
||||
__u16 nr;
|
||||
__u16 cpu[];
|
||||
};
|
||||
|
||||
struct perf_record_record_cpu_map {
|
||||
__u16 nr;
|
||||
__u16 long_size;
|
||||
unsigned long mask[];
|
||||
};
|
||||
|
||||
struct perf_record_cpu_map_data {
|
||||
__u16 type;
|
||||
char data[];
|
||||
};
|
||||
|
||||
struct perf_record_cpu_map {
|
||||
struct perf_event_header header;
|
||||
struct perf_record_cpu_map_data data;
|
||||
};
|
||||
|
||||
enum {
|
||||
PERF_EVENT_UPDATE__UNIT = 0,
|
||||
PERF_EVENT_UPDATE__SCALE = 1,
|
||||
PERF_EVENT_UPDATE__NAME = 2,
|
||||
PERF_EVENT_UPDATE__CPUS = 3,
|
||||
};
|
||||
|
||||
struct perf_record_event_update_cpus {
|
||||
struct perf_record_cpu_map_data cpus;
|
||||
};
|
||||
|
||||
struct perf_record_event_update_scale {
|
||||
double scale;
|
||||
};
|
||||
|
||||
struct perf_record_event_update {
|
||||
struct perf_event_header header;
|
||||
__u64 type;
|
||||
__u64 id;
|
||||
char data[];
|
||||
};
|
||||
|
||||
#define MAX_EVENT_NAME 64
|
||||
|
||||
struct perf_trace_event_type {
|
||||
__u64 event_id;
|
||||
char name[MAX_EVENT_NAME];
|
||||
};
|
||||
|
||||
struct perf_record_header_event_type {
|
||||
struct perf_event_header header;
|
||||
struct perf_trace_event_type event_type;
|
||||
};
|
||||
|
||||
struct perf_record_header_tracing_data {
|
||||
struct perf_event_header header;
|
||||
__u32 size;
|
||||
};
|
||||
|
||||
struct perf_record_header_build_id {
|
||||
struct perf_event_header header;
|
||||
pid_t pid;
|
||||
__u8 build_id[24];
|
||||
char filename[];
|
||||
};
|
||||
|
||||
struct id_index_entry {
|
||||
__u64 id;
|
||||
__u64 idx;
|
||||
__u64 cpu;
|
||||
__u64 tid;
|
||||
};
|
||||
|
||||
struct perf_record_id_index {
|
||||
struct perf_event_header header;
|
||||
__u64 nr;
|
||||
struct id_index_entry entries[0];
|
||||
};
|
||||
|
||||
struct perf_record_auxtrace_info {
|
||||
struct perf_event_header header;
|
||||
__u32 type;
|
||||
__u32 reserved__; /* For alignment */
|
||||
__u64 priv[];
|
||||
};
|
||||
|
||||
struct perf_record_auxtrace {
|
||||
struct perf_event_header header;
|
||||
__u64 size;
|
||||
__u64 offset;
|
||||
__u64 reference;
|
||||
__u32 idx;
|
||||
__u32 tid;
|
||||
__u32 cpu;
|
||||
__u32 reserved__; /* For alignment */
|
||||
};
|
||||
|
||||
#define MAX_AUXTRACE_ERROR_MSG 64
|
||||
|
||||
struct perf_record_auxtrace_error {
|
||||
struct perf_event_header header;
|
||||
__u32 type;
|
||||
__u32 code;
|
||||
__u32 cpu;
|
||||
__u32 pid;
|
||||
__u32 tid;
|
||||
__u32 fmt;
|
||||
__u64 ip;
|
||||
__u64 time;
|
||||
char msg[MAX_AUXTRACE_ERROR_MSG];
|
||||
};
|
||||
|
||||
struct perf_record_aux {
|
||||
struct perf_event_header header;
|
||||
__u64 aux_offset;
|
||||
__u64 aux_size;
|
||||
__u64 flags;
|
||||
};
|
||||
|
||||
struct perf_record_itrace_start {
|
||||
struct perf_event_header header;
|
||||
__u32 pid;
|
||||
__u32 tid;
|
||||
};
|
||||
|
||||
struct perf_record_thread_map_entry {
|
||||
__u64 pid;
|
||||
char comm[16];
|
||||
};
|
||||
|
||||
struct perf_record_thread_map {
|
||||
struct perf_event_header header;
|
||||
__u64 nr;
|
||||
struct perf_record_thread_map_entry entries[];
|
||||
};
|
||||
|
||||
enum {
|
||||
PERF_STAT_CONFIG_TERM__AGGR_MODE = 0,
|
||||
PERF_STAT_CONFIG_TERM__INTERVAL = 1,
|
||||
PERF_STAT_CONFIG_TERM__SCALE = 2,
|
||||
PERF_STAT_CONFIG_TERM__MAX = 3,
|
||||
};
|
||||
|
||||
struct perf_record_stat_config_entry {
|
||||
__u64 tag;
|
||||
__u64 val;
|
||||
};
|
||||
|
||||
struct perf_record_stat_config {
|
||||
struct perf_event_header header;
|
||||
__u64 nr;
|
||||
struct perf_record_stat_config_entry data[];
|
||||
};
|
||||
|
||||
struct perf_record_stat {
|
||||
struct perf_event_header header;
|
||||
|
||||
__u64 id;
|
||||
__u32 cpu;
|
||||
__u32 thread;
|
||||
|
||||
union {
|
||||
struct {
|
||||
__u64 val;
|
||||
__u64 ena;
|
||||
__u64 run;
|
||||
};
|
||||
__u64 values[3];
|
||||
};
|
||||
};
|
||||
|
||||
struct perf_record_stat_round {
|
||||
struct perf_event_header header;
|
||||
__u64 type;
|
||||
__u64 time;
|
||||
};
|
||||
|
||||
struct perf_record_time_conv {
|
||||
struct perf_event_header header;
|
||||
__u64 time_shift;
|
||||
__u64 time_mult;
|
||||
__u64 time_zero;
|
||||
};
|
||||
|
||||
struct perf_record_header_feature {
|
||||
struct perf_event_header header;
|
||||
__u64 feat_id;
|
||||
char data[];
|
||||
};
|
||||
|
||||
struct perf_record_compressed {
|
||||
struct perf_event_header header;
|
||||
char data[];
|
||||
};
|
||||
|
||||
enum perf_user_event_type { /* above any possible kernel type */
|
||||
PERF_RECORD_USER_TYPE_START = 64,
|
||||
PERF_RECORD_HEADER_ATTR = 64,
|
||||
PERF_RECORD_HEADER_EVENT_TYPE = 65, /* deprecated */
|
||||
PERF_RECORD_HEADER_TRACING_DATA = 66,
|
||||
PERF_RECORD_HEADER_BUILD_ID = 67,
|
||||
PERF_RECORD_FINISHED_ROUND = 68,
|
||||
PERF_RECORD_ID_INDEX = 69,
|
||||
PERF_RECORD_AUXTRACE_INFO = 70,
|
||||
PERF_RECORD_AUXTRACE = 71,
|
||||
PERF_RECORD_AUXTRACE_ERROR = 72,
|
||||
PERF_RECORD_THREAD_MAP = 73,
|
||||
PERF_RECORD_CPU_MAP = 74,
|
||||
PERF_RECORD_STAT_CONFIG = 75,
|
||||
PERF_RECORD_STAT = 76,
|
||||
PERF_RECORD_STAT_ROUND = 77,
|
||||
PERF_RECORD_EVENT_UPDATE = 78,
|
||||
PERF_RECORD_TIME_CONV = 79,
|
||||
PERF_RECORD_HEADER_FEATURE = 80,
|
||||
PERF_RECORD_COMPRESSED = 81,
|
||||
PERF_RECORD_HEADER_MAX
|
||||
};
|
||||
|
||||
union perf_event {
|
||||
struct perf_event_header header;
|
||||
struct perf_record_mmap mmap;
|
||||
struct perf_record_mmap2 mmap2;
|
||||
struct perf_record_comm comm;
|
||||
struct perf_record_namespaces namespaces;
|
||||
struct perf_record_fork fork;
|
||||
struct perf_record_lost lost;
|
||||
struct perf_record_lost_samples lost_samples;
|
||||
struct perf_record_read read;
|
||||
struct perf_record_throttle throttle;
|
||||
struct perf_record_sample sample;
|
||||
struct perf_record_bpf_event bpf;
|
||||
struct perf_record_ksymbol ksymbol;
|
||||
struct perf_record_header_attr attr;
|
||||
struct perf_record_event_update event_update;
|
||||
struct perf_record_header_event_type event_type;
|
||||
struct perf_record_header_tracing_data tracing_data;
|
||||
struct perf_record_header_build_id build_id;
|
||||
struct perf_record_id_index id_index;
|
||||
struct perf_record_auxtrace_info auxtrace_info;
|
||||
struct perf_record_auxtrace auxtrace;
|
||||
struct perf_record_auxtrace_error auxtrace_error;
|
||||
struct perf_record_aux aux;
|
||||
struct perf_record_itrace_start itrace_start;
|
||||
struct perf_record_switch context_switch;
|
||||
struct perf_record_thread_map thread_map;
|
||||
struct perf_record_cpu_map cpu_map;
|
||||
struct perf_record_stat_config stat_config;
|
||||
struct perf_record_stat stat;
|
||||
struct perf_record_stat_round stat_round;
|
||||
struct perf_record_time_conv time_conv;
|
||||
struct perf_record_header_feature feat;
|
||||
struct perf_record_compressed pack;
|
||||
};
|
||||
|
||||
#endif /* __LIBPERF_EVENT_H */
|
||||
49
tools/lib/perf/include/perf/evlist.h
Normal file
49
tools/lib/perf/include/perf/evlist.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef __LIBPERF_EVLIST_H
|
||||
#define __LIBPERF_EVLIST_H
|
||||
|
||||
#include <perf/core.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct perf_evlist;
|
||||
struct perf_evsel;
|
||||
struct perf_cpu_map;
|
||||
struct perf_thread_map;
|
||||
|
||||
LIBPERF_API void perf_evlist__add(struct perf_evlist *evlist,
|
||||
struct perf_evsel *evsel);
|
||||
LIBPERF_API void perf_evlist__remove(struct perf_evlist *evlist,
|
||||
struct perf_evsel *evsel);
|
||||
LIBPERF_API struct perf_evlist *perf_evlist__new(void);
|
||||
LIBPERF_API void perf_evlist__delete(struct perf_evlist *evlist);
|
||||
LIBPERF_API struct perf_evsel* perf_evlist__next(struct perf_evlist *evlist,
|
||||
struct perf_evsel *evsel);
|
||||
LIBPERF_API int perf_evlist__open(struct perf_evlist *evlist);
|
||||
LIBPERF_API void perf_evlist__close(struct perf_evlist *evlist);
|
||||
LIBPERF_API void perf_evlist__enable(struct perf_evlist *evlist);
|
||||
LIBPERF_API void perf_evlist__disable(struct perf_evlist *evlist);
|
||||
|
||||
#define perf_evlist__for_each_evsel(evlist, pos) \
|
||||
for ((pos) = perf_evlist__next((evlist), NULL); \
|
||||
(pos) != NULL; \
|
||||
(pos) = perf_evlist__next((evlist), (pos)))
|
||||
|
||||
LIBPERF_API void perf_evlist__set_maps(struct perf_evlist *evlist,
|
||||
struct perf_cpu_map *cpus,
|
||||
struct perf_thread_map *threads);
|
||||
LIBPERF_API int perf_evlist__poll(struct perf_evlist *evlist, int timeout);
|
||||
LIBPERF_API int perf_evlist__filter_pollfd(struct perf_evlist *evlist,
|
||||
short revents_and_mask);
|
||||
|
||||
LIBPERF_API int perf_evlist__mmap(struct perf_evlist *evlist, int pages);
|
||||
LIBPERF_API void perf_evlist__munmap(struct perf_evlist *evlist);
|
||||
|
||||
LIBPERF_API struct perf_mmap *perf_evlist__next_mmap(struct perf_evlist *evlist,
|
||||
struct perf_mmap *map,
|
||||
bool overwrite);
|
||||
#define perf_evlist__for_each_mmap(evlist, pos, overwrite) \
|
||||
for ((pos) = perf_evlist__next_mmap((evlist), NULL, overwrite); \
|
||||
(pos) != NULL; \
|
||||
(pos) = perf_evlist__next_mmap((evlist), (pos), overwrite))
|
||||
|
||||
#endif /* __LIBPERF_EVLIST_H */
|
||||
40
tools/lib/perf/include/perf/evsel.h
Normal file
40
tools/lib/perf/include/perf/evsel.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef __LIBPERF_EVSEL_H
|
||||
#define __LIBPERF_EVSEL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <perf/core.h>
|
||||
|
||||
struct perf_evsel;
|
||||
struct perf_event_attr;
|
||||
struct perf_cpu_map;
|
||||
struct perf_thread_map;
|
||||
|
||||
struct perf_counts_values {
|
||||
union {
|
||||
struct {
|
||||
uint64_t val;
|
||||
uint64_t ena;
|
||||
uint64_t run;
|
||||
};
|
||||
uint64_t values[3];
|
||||
};
|
||||
};
|
||||
|
||||
LIBPERF_API struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr);
|
||||
LIBPERF_API void perf_evsel__delete(struct perf_evsel *evsel);
|
||||
LIBPERF_API int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
|
||||
struct perf_thread_map *threads);
|
||||
LIBPERF_API void perf_evsel__close(struct perf_evsel *evsel);
|
||||
LIBPERF_API void perf_evsel__close_cpu(struct perf_evsel *evsel, int cpu);
|
||||
LIBPERF_API int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread,
|
||||
struct perf_counts_values *count);
|
||||
LIBPERF_API int perf_evsel__enable(struct perf_evsel *evsel);
|
||||
LIBPERF_API int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu);
|
||||
LIBPERF_API int perf_evsel__disable(struct perf_evsel *evsel);
|
||||
LIBPERF_API int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu);
|
||||
LIBPERF_API struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel);
|
||||
LIBPERF_API struct perf_thread_map *perf_evsel__threads(struct perf_evsel *evsel);
|
||||
LIBPERF_API struct perf_event_attr *perf_evsel__attr(struct perf_evsel *evsel);
|
||||
|
||||
#endif /* __LIBPERF_EVSEL_H */
|
||||
15
tools/lib/perf/include/perf/mmap.h
Normal file
15
tools/lib/perf/include/perf/mmap.h
Normal file
@@ -0,0 +1,15 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef __LIBPERF_MMAP_H
|
||||
#define __LIBPERF_MMAP_H
|
||||
|
||||
#include <perf/core.h>
|
||||
|
||||
struct perf_mmap;
|
||||
union perf_event;
|
||||
|
||||
LIBPERF_API void perf_mmap__consume(struct perf_mmap *map);
|
||||
LIBPERF_API int perf_mmap__read_init(struct perf_mmap *map);
|
||||
LIBPERF_API void perf_mmap__read_done(struct perf_mmap *map);
|
||||
LIBPERF_API union perf_event *perf_mmap__read_event(struct perf_mmap *map);
|
||||
|
||||
#endif /* __LIBPERF_MMAP_H */
|
||||
20
tools/lib/perf/include/perf/threadmap.h
Normal file
20
tools/lib/perf/include/perf/threadmap.h
Normal file
@@ -0,0 +1,20 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef __LIBPERF_THREADMAP_H
|
||||
#define __LIBPERF_THREADMAP_H
|
||||
|
||||
#include <perf/core.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
struct perf_thread_map;
|
||||
|
||||
LIBPERF_API struct perf_thread_map *perf_thread_map__new_dummy(void);
|
||||
|
||||
LIBPERF_API void perf_thread_map__set_pid(struct perf_thread_map *map, int thread, pid_t pid);
|
||||
LIBPERF_API char *perf_thread_map__comm(struct perf_thread_map *map, int thread);
|
||||
LIBPERF_API int perf_thread_map__nr(struct perf_thread_map *threads);
|
||||
LIBPERF_API pid_t perf_thread_map__pid(struct perf_thread_map *map, int thread);
|
||||
|
||||
LIBPERF_API struct perf_thread_map *perf_thread_map__get(struct perf_thread_map *map);
|
||||
LIBPERF_API void perf_thread_map__put(struct perf_thread_map *map);
|
||||
|
||||
#endif /* __LIBPERF_THREADMAP_H */
|
||||
Reference in New Issue
Block a user