Linux Perf
event.c File Reference
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <uapi/linux/mman.h>
#include <api/fs/fs.h>
#include <linux/perf_event.h>
#include "event.h"
#include "debug.h"
#include "hist.h"
#include "machine.h"
#include "sort.h"
#include "string2.h"
#include "strlist.h"
#include "thread.h"
#include "thread_map.h"
#include "sane_ctype.h"
#include "symbol/kallsyms.h"
#include "asm/bug.h"
#include "stat.h"
Include dependency graph for event.c:

Go to the source code of this file.

Classes

struct  synthesize_threads_arg
 
struct  process_symbol_args
 

Macros

#define ADD(__term, __val)
 
#define CASE(__term, __val)
 

Functions

const char * perf_event__name (unsigned int id)
 
static const char * perf_ns__name (unsigned int id)
 
int perf_tool__process_synth_event (struct perf_tool *tool, union perf_event *event, struct machine *machine, perf_event__handler_t process)
 
static int perf_event__get_comm_ids (pid_t pid, char *comm, size_t len, pid_t *tgid, pid_t *ppid)
 
static int perf_event__prepare_comm (union perf_event *event, pid_t pid, struct machine *machine, pid_t *tgid, pid_t *ppid)
 
pid_t perf_event__synthesize_comm (struct perf_tool *tool, union perf_event *event, pid_t pid, perf_event__handler_t process, struct machine *machine)
 
static void perf_event__get_ns_link_info (pid_t pid, const char *ns, struct perf_ns_link_info *ns_link_info)
 
int perf_event__synthesize_namespaces (struct perf_tool *tool, union perf_event *event, pid_t pid, pid_t tgid, perf_event__handler_t process, struct machine *machine)
 
static int perf_event__synthesize_fork (struct perf_tool *tool, union perf_event *event, pid_t pid, pid_t tgid, pid_t ppid, perf_event__handler_t process, struct machine *machine)
 
int perf_event__synthesize_mmap_events (struct perf_tool *tool, union perf_event *event, pid_t pid, pid_t tgid, perf_event__handler_t process, struct machine *machine, bool mmap_data, unsigned int proc_map_timeout)
 
int perf_event__synthesize_modules (struct perf_tool *tool, perf_event__handler_t process, struct machine *machine)
 
static int __event__synthesize_thread (union perf_event *comm_event, union perf_event *mmap_event, union perf_event *fork_event, union perf_event *namespaces_event, pid_t pid, int full, perf_event__handler_t process, struct perf_tool *tool, struct machine *machine, bool mmap_data, unsigned int proc_map_timeout)
 
int perf_event__synthesize_thread_map (struct perf_tool *tool, struct thread_map *threads, perf_event__handler_t process, struct machine *machine, bool mmap_data, unsigned int proc_map_timeout)
 
static int __perf_event__synthesize_threads (struct perf_tool *tool, perf_event__handler_t process, struct machine *machine, bool mmap_data, unsigned int proc_map_timeout, struct dirent **dirent, int start, int num)
 
static void * synthesize_threads_worker (void *arg)
 
int perf_event__synthesize_threads (struct perf_tool *tool, perf_event__handler_t process, struct machine *machine, bool mmap_data, unsigned int proc_map_timeout, unsigned int nr_threads_synthesize)
 
static int find_symbol_cb (void *arg, const char *name, char type, u64 start)
 
int kallsyms__get_function_start (const char *kallsyms_filename, const char *symbol_name, u64 *addr)
 
int __weak perf_event__synthesize_extra_kmaps (struct perf_tool *tool __maybe_unused, perf_event__handler_t process __maybe_unused, struct machine *machine __maybe_unused)
 
static int __perf_event__synthesize_kernel_mmap (struct perf_tool *tool, perf_event__handler_t process, struct machine *machine)
 
int perf_event__synthesize_kernel_mmap (struct perf_tool *tool, perf_event__handler_t process, struct machine *machine)
 
int perf_event__synthesize_thread_map2 (struct perf_tool *tool, struct thread_map *threads, perf_event__handler_t process, struct machine *machine)
 
static void synthesize_cpus (struct cpu_map_entries *cpus, struct cpu_map *map)
 
static void synthesize_mask (struct cpu_map_mask *mask, struct cpu_map *map, int max)
 
static size_t cpus_size (struct cpu_map *map)
 
static size_t mask_size (struct cpu_map *map, int *max)
 
void * cpu_map_data__alloc (struct cpu_map *map, size_t *size, u16 *type, int *max)
 
void cpu_map_data__synthesize (struct cpu_map_data *data, struct cpu_map *map, u16 type, int max)
 
static struct cpu_map_eventcpu_map_event__new (struct cpu_map *map)
 
int perf_event__synthesize_cpu_map (struct perf_tool *tool, struct cpu_map *map, perf_event__handler_t process, struct machine *machine)
 
int perf_event__synthesize_stat_config (struct perf_tool *tool, struct perf_stat_config *config, perf_event__handler_t process, struct machine *machine)
 
int perf_event__synthesize_stat (struct perf_tool *tool, u32 cpu, u32 thread, u64 id, struct perf_counts_values *count, perf_event__handler_t process, struct machine *machine)
 
int perf_event__synthesize_stat_round (struct perf_tool *tool, u64 evtime, u64 type, perf_event__handler_t process, struct machine *machine)
 
void perf_event__read_stat_config (struct perf_stat_config *config, struct stat_config_event *event)
 
size_t perf_event__fprintf_comm (union perf_event *event, FILE *fp)
 
size_t perf_event__fprintf_namespaces (union perf_event *event, FILE *fp)
 
int perf_event__process_comm (struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
 
int perf_event__process_namespaces (struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
 
int perf_event__process_lost (struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
 
int perf_event__process_aux (struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample __maybe_unused, struct machine *machine)
 
int perf_event__process_itrace_start (struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample __maybe_unused, struct machine *machine)
 
int perf_event__process_lost_samples (struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
 
int perf_event__process_switch (struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample __maybe_unused, struct machine *machine)
 
size_t perf_event__fprintf_mmap (union perf_event *event, FILE *fp)
 
size_t perf_event__fprintf_mmap2 (union perf_event *event, FILE *fp)
 
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)
 
int perf_event__process_mmap (struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
 
int perf_event__process_mmap2 (struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
 
size_t perf_event__fprintf_task (union perf_event *event, FILE *fp)
 
int perf_event__process_fork (struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
 
int perf_event__process_exit (struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
 
size_t perf_event__fprintf_aux (union perf_event *event, FILE *fp)
 
size_t perf_event__fprintf_itrace_start (union perf_event *event, FILE *fp)
 
size_t perf_event__fprintf_switch (union perf_event *event, FILE *fp)
 
static size_t perf_event__fprintf_lost (union perf_event *event, FILE *fp)
 
size_t perf_event__fprintf (union perf_event *event, FILE *fp)
 
int perf_event__process (struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
 
struct mapthread__find_map (struct thread *thread, u8 cpumode, u64 addr, struct addr_location *al)
 
struct symbolthread__find_symbol (struct thread *thread, u8 cpumode, u64 addr, struct addr_location *al)
 
int machine__resolve (struct machine *machine, struct addr_location *al, struct perf_sample *sample)
 
void addr_location__put (struct addr_location *al)
 
bool is_bts_event (struct perf_event_attr *attr)
 
bool sample_addr_correlates_sym (struct perf_event_attr *attr)
 
void thread__resolve (struct thread *thread, struct addr_location *al, struct perf_sample *sample)
 

Variables

static const char * perf_event__names []
 
static const char * perf_ns__names []
 

Macro Definition Documentation

◆ ADD

#define ADD (   __term,
  __val 
)
Value:
event->data[i].tag = PERF_STAT_CONFIG_TERM__##__term; \
event->data[i].val = __val; \
i++;

◆ CASE

#define CASE (   __term,
  __val 
)
Value:
case PERF_STAT_CONFIG_TERM__##__term: \
config->__val = event->data[i].val; \
break;

Function Documentation

◆ __event__synthesize_thread()

static int __event__synthesize_thread ( union perf_event comm_event,
union perf_event mmap_event,
union perf_event fork_event,
union perf_event namespaces_event,
pid_t  pid,
int  full,
perf_event__handler_t  process,
struct perf_tool tool,
struct machine machine,
bool  mmap_data,
unsigned int  proc_map_timeout 
)
static

Definition at line 515 of file event.c.

Here is the call graph for this function:

◆ __perf_event__synthesize_kernel_mmap()

static int __perf_event__synthesize_kernel_mmap ( struct perf_tool tool,
perf_event__handler_t  process,
struct machine machine 
)
static

Definition at line 898 of file event.c.

Here is the call graph for this function:

◆ __perf_event__synthesize_threads()

static int __perf_event__synthesize_threads ( struct perf_tool tool,
perf_event__handler_t  process,
struct machine machine,
bool  mmap_data,
unsigned int  proc_map_timeout,
struct dirent **  dirent,
int  start,
int  num 
)
static

Definition at line 681 of file event.c.

Here is the call graph for this function:

◆ addr_location__put()

void addr_location__put ( struct addr_location al)

Definition at line 1661 of file event.c.

◆ cpu_map_data__alloc()

void* cpu_map_data__alloc ( struct cpu_map map,
size_t *  size,
u16 *  type,
int *  max 
)

Definition at line 1047 of file event.c.

Here is the call graph for this function:

◆ cpu_map_data__synthesize()

void cpu_map_data__synthesize ( struct cpu_map_data data,
struct cpu_map map,
u16  type,
int  max 
)

Definition at line 1080 of file event.c.

Here is the call graph for this function:

◆ cpu_map_event__new()

static struct cpu_map_event* cpu_map_event__new ( struct cpu_map map)
static

Definition at line 1096 of file event.c.

Here is the call graph for this function:

◆ cpus_size()

static size_t cpus_size ( struct cpu_map map)
static

Definition at line 1025 of file event.c.

◆ find_symbol_cb()

static int find_symbol_cb ( void *  arg,
const char *  name,
char  type,
u64  start 
)
static

Definition at line 862 of file event.c.

◆ is_bts_event()

bool is_bts_event ( struct perf_event_attr *  attr)

Definition at line 1666 of file event.c.

◆ kallsyms__get_function_start()

int kallsyms__get_function_start ( const char *  kallsyms_filename,
const char *  symbol_name,
u64 *  addr 
)

Definition at line 879 of file event.c.

Here is the call graph for this function:

◆ machine__resolve()

int machine__resolve ( struct machine machine,
struct addr_location al,
struct perf_sample sample 
)

Definition at line 1601 of file event.c.

Here is the call graph for this function:

◆ mask_size()

static size_t mask_size ( struct cpu_map map,
int *  max 
)
static

Definition at line 1030 of file event.c.

◆ perf_event__fprintf()

size_t perf_event__fprintf ( union perf_event event,
FILE *  fp 
)

Definition at line 1461 of file event.c.

Here is the call graph for this function:

◆ perf_event__fprintf_aux()

size_t perf_event__fprintf_aux ( union perf_event event,
FILE *  fp 
)

Definition at line 1424 of file event.c.

◆ perf_event__fprintf_comm()

size_t perf_event__fprintf_comm ( union perf_event event,
FILE *  fp 
)

Definition at line 1234 of file event.c.

◆ perf_event__fprintf_cpu_map()

size_t perf_event__fprintf_cpu_map ( union perf_event event,
FILE *  fp 
)

Definition at line 1369 of file event.c.

Here is the call graph for this function:

◆ perf_event__fprintf_itrace_start()

size_t perf_event__fprintf_itrace_start ( union perf_event event,
FILE *  fp 
)

Definition at line 1434 of file event.c.

◆ perf_event__fprintf_lost()

static size_t perf_event__fprintf_lost ( union perf_event event,
FILE *  fp 
)
static

Definition at line 1456 of file event.c.

◆ perf_event__fprintf_mmap()

size_t perf_event__fprintf_mmap ( union perf_event event,
FILE *  fp 
)

Definition at line 1329 of file event.c.

◆ perf_event__fprintf_mmap2()

size_t perf_event__fprintf_mmap2 ( union perf_event event,
FILE *  fp 
)

Definition at line 1338 of file event.c.

◆ perf_event__fprintf_namespaces()

size_t perf_event__fprintf_namespaces ( union perf_event event,
FILE *  fp 
)

Definition at line 1246 of file event.c.

Here is the call graph for this function:

◆ perf_event__fprintf_switch()

size_t perf_event__fprintf_switch ( union perf_event event,
FILE *  fp 
)

Definition at line 1440 of file event.c.

◆ perf_event__fprintf_task()

size_t perf_event__fprintf_task ( union perf_event event,
FILE *  fp 
)

Definition at line 1401 of file event.c.

◆ perf_event__fprintf_thread_map()

size_t perf_event__fprintf_thread_map ( union perf_event event,
FILE *  fp 
)

Definition at line 1353 of file event.c.

Here is the call graph for this function:

◆ perf_event__get_comm_ids()

static int perf_event__get_comm_ids ( pid_t  pid,
char *  comm,
size_t  len,
pid_t *  tgid,
pid_t *  ppid 
)
static

Definition at line 113 of file event.c.

Here is the call graph for this function:

◆ perf_event__get_ns_link_info()

static void perf_event__get_ns_link_info ( pid_t  pid,
const char *  ns,
struct perf_ns_link_info *  ns_link_info 
)
static

Definition at line 236 of file event.c.

◆ perf_event__name()

const char* perf_event__name ( unsigned int  id)

Definition at line 75 of file event.c.

◆ perf_event__prepare_comm()

static int perf_event__prepare_comm ( union perf_event event,
pid_t  pid,
struct machine machine,
pid_t *  tgid,
pid_t *  ppid 
)
static

Definition at line 183 of file event.c.

Here is the call graph for this function:

◆ perf_event__process()

int perf_event__process ( struct perf_tool *tool  __maybe_unused,
union perf_event event,
struct perf_sample sample,
struct machine machine 
)

Definition at line 1503 of file event.c.

Here is the call graph for this function:

◆ perf_event__process_aux()

int perf_event__process_aux ( struct perf_tool *tool  __maybe_unused,
union perf_event event,
struct perf_sample *sample  __maybe_unused,
struct machine machine 
)

Definition at line 1297 of file event.c.

Here is the call graph for this function:

◆ perf_event__process_comm()

int perf_event__process_comm ( struct perf_tool *tool  __maybe_unused,
union perf_event event,
struct perf_sample sample,
struct machine machine 
)

Definition at line 1273 of file event.c.

Here is the call graph for this function:

◆ perf_event__process_exit()

int perf_event__process_exit ( struct perf_tool *tool  __maybe_unused,
union perf_event event,
struct perf_sample sample,
struct machine machine 
)

Definition at line 1416 of file event.c.

Here is the call graph for this function:

◆ perf_event__process_fork()

int perf_event__process_fork ( struct perf_tool *tool  __maybe_unused,
union perf_event event,
struct perf_sample sample,
struct machine machine 
)

Definition at line 1408 of file event.c.

Here is the call graph for this function:

◆ perf_event__process_itrace_start()

int perf_event__process_itrace_start ( struct perf_tool *tool  __maybe_unused,
union perf_event event,
struct perf_sample *sample  __maybe_unused,
struct machine machine 
)

Definition at line 1305 of file event.c.

Here is the call graph for this function:

◆ perf_event__process_lost()

int perf_event__process_lost ( struct perf_tool *tool  __maybe_unused,
union perf_event event,
struct perf_sample sample,
struct machine machine 
)

Definition at line 1289 of file event.c.

Here is the call graph for this function:

◆ perf_event__process_lost_samples()

int perf_event__process_lost_samples ( struct perf_tool *tool  __maybe_unused,
union perf_event event,
struct perf_sample sample,
struct machine machine 
)

Definition at line 1313 of file event.c.

Here is the call graph for this function:

◆ perf_event__process_mmap()

int perf_event__process_mmap ( struct perf_tool *tool  __maybe_unused,
union perf_event event,
struct perf_sample sample,
struct machine machine 
)

Definition at line 1385 of file event.c.

Here is the call graph for this function:

◆ perf_event__process_mmap2()

int perf_event__process_mmap2 ( struct perf_tool *tool  __maybe_unused,
union perf_event event,
struct perf_sample sample,
struct machine machine 
)

Definition at line 1393 of file event.c.

Here is the call graph for this function:

◆ perf_event__process_namespaces()

int perf_event__process_namespaces ( struct perf_tool *tool  __maybe_unused,
union perf_event event,
struct perf_sample sample,
struct machine machine 
)

Definition at line 1281 of file event.c.

Here is the call graph for this function:

◆ perf_event__process_switch()

int perf_event__process_switch ( struct perf_tool *tool  __maybe_unused,
union perf_event event,
struct perf_sample *sample  __maybe_unused,
struct machine machine 
)

Definition at line 1321 of file event.c.

Here is the call graph for this function:

◆ perf_event__read_stat_config()

void perf_event__read_stat_config ( struct perf_stat_config config,
struct stat_config_event event 
)

Definition at line 1210 of file event.c.

◆ perf_event__synthesize_comm()

pid_t perf_event__synthesize_comm ( struct perf_tool tool,
union perf_event event,
pid_t  pid,
perf_event__handler_t  process,
struct machine machine 
)

Definition at line 220 of file event.c.

Here is the call graph for this function:

◆ perf_event__synthesize_cpu_map()

int perf_event__synthesize_cpu_map ( struct perf_tool tool,
struct cpu_map map,
perf_event__handler_t  process,
struct machine machine 
)

Definition at line 1115 of file event.c.

Here is the call graph for this function:

◆ perf_event__synthesize_extra_kmaps()

int __weak perf_event__synthesize_extra_kmaps ( struct perf_tool *tool  __maybe_unused,
perf_event__handler_t process  __maybe_unused,
struct machine *machine  __maybe_unused 
)

Definition at line 891 of file event.c.

◆ perf_event__synthesize_fork()

static int perf_event__synthesize_fork ( struct perf_tool tool,
union perf_event event,
pid_t  pid,
pid_t  tgid,
pid_t  ppid,
perf_event__handler_t  process,
struct machine machine 
)
static

Definition at line 288 of file event.c.

Here is the call graph for this function:

◆ perf_event__synthesize_kernel_mmap()

int perf_event__synthesize_kernel_mmap ( struct perf_tool tool,
perf_event__handler_t  process,
struct machine machine 
)

Definition at line 953 of file event.c.

Here is the call graph for this function:

◆ perf_event__synthesize_mmap_events()

int perf_event__synthesize_mmap_events ( struct perf_tool tool,
union perf_event event,
pid_t  pid,
pid_t  tgid,
perf_event__handler_t  process,
struct machine machine,
bool  mmap_data,
unsigned int  proc_map_timeout 
)

Definition at line 320 of file event.c.

Here is the call graph for this function:

◆ perf_event__synthesize_modules()

int perf_event__synthesize_modules ( struct perf_tool tool,
perf_event__handler_t  process,
struct machine machine 
)

Definition at line 461 of file event.c.

Here is the call graph for this function:

◆ perf_event__synthesize_namespaces()

int perf_event__synthesize_namespaces ( struct perf_tool tool,
union perf_event event,
pid_t  pid,
pid_t  tgid,
perf_event__handler_t  process,
struct machine machine 
)

Definition at line 249 of file event.c.

Here is the call graph for this function:

◆ perf_event__synthesize_stat()

int perf_event__synthesize_stat ( struct perf_tool tool,
u32  cpu,
u32  thread,
u64  id,
struct perf_counts_values count,
perf_event__handler_t  process,
struct machine machine 
)

Definition at line 1171 of file event.c.

◆ perf_event__synthesize_stat_config()

int perf_event__synthesize_stat_config ( struct perf_tool tool,
struct perf_stat_config config,
perf_event__handler_t  process,
struct machine machine 
)

Definition at line 1133 of file event.c.

Here is the call graph for this function:

◆ perf_event__synthesize_stat_round()

int perf_event__synthesize_stat_round ( struct perf_tool tool,
u64  evtime,
u64  type,
perf_event__handler_t  process,
struct machine machine 
)

Definition at line 1193 of file event.c.

◆ perf_event__synthesize_thread_map()

int perf_event__synthesize_thread_map ( struct perf_tool tool,
struct thread_map threads,
perf_event__handler_t  process,
struct machine machine,
bool  mmap_data,
unsigned int  proc_map_timeout 
)

Definition at line 603 of file event.c.

Here is the call graph for this function:

◆ perf_event__synthesize_thread_map2()

int perf_event__synthesize_thread_map2 ( struct perf_tool tool,
struct thread_map threads,
perf_event__handler_t  process,
struct machine machine 
)

Definition at line 966 of file event.c.

Here is the call graph for this function:

◆ perf_event__synthesize_threads()

int perf_event__synthesize_threads ( struct perf_tool tool,
perf_event__handler_t  process,
struct machine machine,
bool  mmap_data,
unsigned int  proc_map_timeout,
unsigned int  nr_threads_synthesize 
)

Definition at line 767 of file event.c.

Here is the call graph for this function:

◆ perf_ns__name()

static const char* perf_ns__name ( unsigned int  id)
static

Definition at line 84 of file event.c.

◆ perf_tool__process_synth_event()

int perf_tool__process_synth_event ( struct perf_tool tool,
union perf_event event,
struct machine machine,
perf_event__handler_t  process 
)

Definition at line 91 of file event.c.

◆ sample_addr_correlates_sym()

bool sample_addr_correlates_sym ( struct perf_event_attr *  attr)

Definition at line 1673 of file event.c.

Here is the call graph for this function:

◆ synthesize_cpus()

static void synthesize_cpus ( struct cpu_map_entries cpus,
struct cpu_map map 
)
static

Definition at line 1002 of file event.c.

◆ synthesize_mask()

static void synthesize_mask ( struct cpu_map_mask mask,
struct cpu_map map,
int  max 
)
static

Definition at line 1013 of file event.c.

◆ synthesize_threads_worker()

static void* synthesize_threads_worker ( void *  arg)
static

Definition at line 756 of file event.c.

Here is the call graph for this function:

◆ thread__find_map()

struct map* thread__find_map ( struct thread thread,
u8  cpumode,
u64  addr,
struct addr_location al 
)

Definition at line 1511 of file event.c.

Here is the call graph for this function:

◆ thread__find_symbol()

struct symbol* thread__find_symbol ( struct thread thread,
u8  cpumode,
u64  addr,
struct addr_location al 
)

Definition at line 1588 of file event.c.

Here is the call graph for this function:

◆ thread__resolve()

void thread__resolve ( struct thread thread,
struct addr_location al,
struct perf_sample sample 
)

Definition at line 1687 of file event.c.

Here is the call graph for this function:

Variable Documentation

◆ perf_event__names

const char* perf_event__names[]
static

Definition at line 28 of file event.c.

◆ perf_ns__names

const char* perf_ns__names[]
static
Initial value:
= {
[NET_NS_INDEX] = "net",
[UTS_NS_INDEX] = "uts",
[IPC_NS_INDEX] = "ipc",
[PID_NS_INDEX] = "pid",
[USER_NS_INDEX] = "user",
[MNT_NS_INDEX] = "mnt",
[CGROUP_NS_INDEX] = "cgroup",
}

Definition at line 65 of file event.c.