Linux Perf
builtin-record.c File Reference
#include "builtin.h"
#include "perf.h"
#include "util/build-id.h"
#include "util/util.h"
#include <subcmd/parse-options.h>
#include "util/parse-events.h"
#include "util/config.h"
#include "util/callchain.h"
#include "util/cgroup.h"
#include "util/header.h"
#include "util/event.h"
#include "util/evlist.h"
#include "util/evsel.h"
#include "util/debug.h"
#include "util/drv_configs.h"
#include "util/session.h"
#include "util/tool.h"
#include "util/symbol.h"
#include "util/cpumap.h"
#include "util/thread_map.h"
#include "util/data.h"
#include "util/perf_regs.h"
#include "util/auxtrace.h"
#include "util/tsc.h"
#include "util/parse-branch-options.h"
#include "util/parse-regs-options.h"
#include "util/llvm-utils.h"
#include "util/bpf-loader.h"
#include "util/trigger.h"
#include "util/perf-hooks.h"
#include "util/time-utils.h"
#include "util/units.h"
#include "asm/bug.h"
#include <errno.h>
#include <inttypes.h>
#include <locale.h>
#include <poll.h>
#include <unistd.h>
#include <sched.h>
#include <signal.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <linux/time64.h>
Include dependency graph for builtin-record.c:

Go to the source code of this file.

Classes

struct  switch_output
 
struct  record
 
struct  clockid_map
 

Macros

#define CLOCKID_MAP(n, c)   { .name = n, .clockid = (c), }
 
#define CLOCKID_END   { .name = NULL, }
 
#define CLOCK_MONOTONIC_RAW   4
 
#define CLOCK_BOOTTIME   7
 
#define CLOCK_TAI   11
 
#define set_nobuild(s, l, c)   set_option_nobuild(record_options, s, l, "NO_LIBBPF=1", c)
 
#define REASON   "NO_DWARF=1"
 
#define set_nobuild(s, l, c)   set_option_nobuild(record_options, s, l, REASON, c)
 

Functions

static DEFINE_TRIGGER (auxtrace_snapshot_trigger)
 
static DEFINE_TRIGGER (switch_output_trigger)
 
static bool switch_output_signal (struct record *rec)
 
static bool switch_output_size (struct record *rec)
 
static bool switch_output_time (struct record *rec)
 
static int record__write (struct record *rec, void *bf, size_t size)
 
static int process_synthesized_event (struct perf_tool *tool, union perf_event *event, struct perf_sample *sample __maybe_unused, struct machine *machine __maybe_unused)
 
static int record__pushfn (void *to, void *bf, size_t size)
 
static void sig_handler (int sig)
 
static void sigsegv_handler (int sig)
 
static void record__sig_exit (void)
 
static int record__auxtrace_mmap_read (struct record *rec __maybe_unused, struct auxtrace_mmap *mm __maybe_unused)
 
static void record__read_auxtrace_snapshot (struct record *rec __maybe_unused)
 
static int auxtrace_record__snapshot_start (struct auxtrace_record *itr __maybe_unused)
 
static int record__auxtrace_init (struct record *rec __maybe_unused)
 
static int record__mmap_evlist (struct record *rec, struct perf_evlist *evlist)
 
static int record__mmap (struct record *rec)
 
static int record__open (struct record *rec)
 
static int process_sample_event (struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, struct perf_evsel *evsel, struct machine *machine)
 
static int process_buildids (struct record *rec)
 
static void perf_event__synthesize_guest_os (struct machine *machine, void *data)
 
static int record__mmap_read_evlist (struct record *rec, struct perf_evlist *evlist, bool overwrite)
 
static int record__mmap_read_all (struct record *rec)
 
static void record__init_features (struct record *rec)
 
static void record__finish_output (struct record *rec)
 
static int record__synthesize_workload (struct record *rec, bool tail)
 
static int record__synthesize (struct record *rec, bool tail)
 
static int record__switch_output (struct record *rec, bool at_exit)
 
static void workload_exec_failed_signal (int signo __maybe_unused, siginfo_t *info, void *ucontext __maybe_unused)
 
static void snapshot_sig_handler (int sig)
 
static void alarm_sig_handler (int sig)
 
int __weak perf_event__synth_time_conv (const struct perf_event_mmap_page *pc __maybe_unused, struct perf_tool *tool __maybe_unused, perf_event__handler_t process __maybe_unused, struct machine *machine __maybe_unused)
 
static const struct perf_event_mmap_page * perf_evlist__pick_pc (struct perf_evlist *evlist)
 
static const struct perf_event_mmap_page * record__pick_pc (struct record *rec)
 
static int __cmd_record (struct record *rec, int argc, const char **argv)
 
static void callchain_debug (struct callchain_param *callchain)
 
int record_opts__parse_callchain (struct record_opts *record, struct callchain_param *callchain, const char *arg, bool unset)
 
int record_parse_callchain_opt (const struct option *opt, const char *arg, int unset)
 
int record_callchain_opt (const struct option *opt, const char *arg __maybe_unused, int unset __maybe_unused)
 
static int perf_record_config (const char *var, const char *value, void *cb)
 
static int parse_clockid (const struct option *opt, const char *str, int unset)
 
static int record__parse_mmap_pages (const struct option *opt, const char *str, int unset __maybe_unused)
 
static void switch_output_size_warn (struct record *rec)
 
static int switch_output_setup (struct record *rec)
 
int cmd_record (int argc, const char **argv)
 

Variables

static volatile int auxtrace_record__snapshot_started
 
static volatile int done
 
static volatile int signr = -1
 
static volatile int child_finished
 
static struct perf_event_header finished_round_event
 
static volatile int workload_exec_errno
 
static const struct clockid_map clockids []
 
static const char *const __record_usage []
 
const char *const * record_usage = __record_usage
 
static struct record record
 
const char record_callchain_help []
 
static bool dry_run
 
static struct option __record_options []
 
struct option * record_options = __record_options
 

Macro Definition Documentation

◆ CLOCK_BOOTTIME

#define CLOCK_BOOTTIME   7

Definition at line 1312 of file builtin-record.c.

◆ CLOCK_MONOTONIC_RAW

#define CLOCK_MONOTONIC_RAW   4

Definition at line 1309 of file builtin-record.c.

◆ CLOCK_TAI

#define CLOCK_TAI   11

Definition at line 1315 of file builtin-record.c.

◆ CLOCKID_END

#define CLOCKID_END   { .name = NULL, }

Definition at line 1302 of file builtin-record.c.

◆ CLOCKID_MAP

#define CLOCKID_MAP (   n,
 
)    { .name = n, .clockid = (c), }

Definition at line 1299 of file builtin-record.c.

◆ REASON

#define REASON   "NO_DWARF=1"

◆ set_nobuild [1/2]

#define set_nobuild (   s,
  l,
 
)    set_option_nobuild(record_options, s, l, "NO_LIBBPF=1", c)

◆ set_nobuild [2/2]

#define set_nobuild (   s,
  l,
 
)    set_option_nobuild(record_options, s, l, REASON, c)

Function Documentation

◆ __cmd_record()

static int __cmd_record ( struct record rec,
int  argc,
const char **  argv 
)
static

Definition at line 854 of file builtin-record.c.

Here is the call graph for this function:

◆ alarm_sig_handler()

static void alarm_sig_handler ( int sig  __maybe_unused)
static

Definition at line 1896 of file builtin-record.c.

Here is the call graph for this function:

◆ auxtrace_record__snapshot_start()

static int auxtrace_record__snapshot_start ( struct auxtrace_record *itr  __maybe_unused)
inlinestatic

Definition at line 309 of file builtin-record.c.

◆ callchain_debug()

static void callchain_debug ( struct callchain_param callchain)
static

Definition at line 1213 of file builtin-record.c.

◆ cmd_record()

int cmd_record ( int  argc,
const char **  argv 
)

Definition at line 1686 of file builtin-record.c.

Here is the call graph for this function:

◆ DEFINE_TRIGGER() [1/2]

static DEFINE_TRIGGER ( auxtrace_snapshot_trigger  )
static

◆ DEFINE_TRIGGER() [2/2]

static DEFINE_TRIGGER ( switch_output_trigger  )
static

◆ parse_clockid()

static int parse_clockid ( const struct option *  opt,
const char *  str,
int  unset 
)
static

Definition at line 1337 of file builtin-record.c.

Here is the call graph for this function:

◆ perf_event__synth_time_conv()

int __weak perf_event__synth_time_conv ( const struct perf_event_mmap_page *pc  __maybe_unused,
struct perf_tool *tool  __maybe_unused,
perf_event__handler_t process  __maybe_unused,
struct machine *machine  __maybe_unused 
)

Definition at line 713 of file builtin-record.c.

◆ perf_event__synthesize_guest_os()

static void perf_event__synthesize_guest_os ( struct machine machine,
void *  data 
)
static

Definition at line 479 of file builtin-record.c.

Here is the call graph for this function:

◆ perf_evlist__pick_pc()

static const struct perf_event_mmap_page* perf_evlist__pick_pc ( struct perf_evlist evlist)
static

Definition at line 722 of file builtin-record.c.

◆ perf_record_config()

static int perf_record_config ( const char *  var,
const char *  value,
void *  cb 
)
static

Definition at line 1271 of file builtin-record.c.

Here is the call graph for this function:

◆ process_buildids()

static int process_buildids ( struct record rec)
static

Definition at line 448 of file builtin-record.c.

Here is the call graph for this function:

◆ process_sample_event()

static int process_sample_event ( struct perf_tool tool,
union perf_event event,
struct perf_sample sample,
struct perf_evsel evsel,
struct machine machine 
)
static

Definition at line 428 of file builtin-record.c.

Here is the call graph for this function:

◆ process_synthesized_event()

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

Definition at line 124 of file builtin-record.c.

Here is the call graph for this function:

◆ record__auxtrace_init()

static int record__auxtrace_init ( struct record *rec  __maybe_unused)
static

Definition at line 314 of file builtin-record.c.

◆ record__auxtrace_mmap_read()

static int record__auxtrace_mmap_read ( struct record *rec  __maybe_unused,
struct auxtrace_mmap *mm  __maybe_unused 
)
inlinestatic

Definition at line 297 of file builtin-record.c.

◆ record__finish_output()

static void record__finish_output ( struct record rec)
static

Definition at line 596 of file builtin-record.c.

Here is the call graph for this function:

◆ record__init_features()

static void record__init_features ( struct record rec)
static

Definition at line 572 of file builtin-record.c.

Here is the call graph for this function:

◆ record__mmap()

static int record__mmap ( struct record rec)
static

Definition at line 350 of file builtin-record.c.

Here is the call graph for this function:

◆ record__mmap_evlist()

static int record__mmap_evlist ( struct record rec,
struct perf_evlist evlist 
)
static

Definition at line 321 of file builtin-record.c.

Here is the call graph for this function:

◆ record__mmap_read_all()

static int record__mmap_read_all ( struct record rec)
static

Definition at line 561 of file builtin-record.c.

Here is the call graph for this function:

◆ record__mmap_read_evlist()

static int record__mmap_read_evlist ( struct record rec,
struct perf_evlist evlist,
bool  overwrite 
)
static

Definition at line 513 of file builtin-record.c.

Here is the call graph for this function:

◆ record__open()

static int record__open ( struct record rec)
static

Definition at line 355 of file builtin-record.c.

Here is the call graph for this function:

◆ record__parse_mmap_pages()

static int record__parse_mmap_pages ( const struct option *  opt,
const char *  str,
int unset  __maybe_unused 
)
static

Definition at line 1378 of file builtin-record.c.

Here is the call graph for this function:

◆ record__pick_pc()

static const struct perf_event_mmap_page* record__pick_pc ( struct record rec)
static

Definition at line 733 of file builtin-record.c.

Here is the call graph for this function:

◆ record__pushfn()

static int record__pushfn ( void *  to,
void *  bf,
size_t  size 
)
static

Definition at line 133 of file builtin-record.c.

Here is the call graph for this function:

◆ record__read_auxtrace_snapshot()

static void record__read_auxtrace_snapshot ( struct record *rec  __maybe_unused)
inlinestatic

Definition at line 304 of file builtin-record.c.

◆ record__sig_exit()

static void record__sig_exit ( void  )
static

Definition at line 161 of file builtin-record.c.

Here is the call graph for this function:

◆ record__switch_output()

static int record__switch_output ( struct record rec,
bool  at_exit 
)
static

Definition at line 642 of file builtin-record.c.

Here is the call graph for this function:

◆ record__synthesize()

static int record__synthesize ( struct record rec,
bool  tail 
)
static

Definition at line 743 of file builtin-record.c.

Here is the call graph for this function:

◆ record__synthesize_workload()

static int record__synthesize_workload ( struct record rec,
bool  tail 
)
static

Definition at line 618 of file builtin-record.c.

Here is the call graph for this function:

◆ record__write()

static int record__write ( struct record rec,
void *  bf,
size_t  size 
)
static

Definition at line 109 of file builtin-record.c.

Here is the call graph for this function:

◆ record_callchain_opt()

int record_callchain_opt ( const struct option *  opt,
const char *arg  __maybe_unused,
int unset  __maybe_unused 
)

Definition at line 1256 of file builtin-record.c.

Here is the call graph for this function:

◆ record_opts__parse_callchain()

int record_opts__parse_callchain ( struct record_opts record,
struct callchain_param callchain,
const char *  arg,
bool  unset 
)

Definition at line 1224 of file builtin-record.c.

Here is the call graph for this function:

◆ record_parse_callchain_opt()

int record_parse_callchain_opt ( const struct option *  opt,
const char *  arg,
int  unset 
)

Definition at line 1249 of file builtin-record.c.

Here is the call graph for this function:

◆ sig_handler()

static void sig_handler ( int sig  )
static

Definition at line 145 of file builtin-record.c.

◆ sigsegv_handler()

static void sigsegv_handler ( int sig  )
static

Definition at line 155 of file builtin-record.c.

Here is the call graph for this function:

◆ snapshot_sig_handler()

static void snapshot_sig_handler ( int sig  __maybe_unused)
static

Definition at line 1881 of file builtin-record.c.

Here is the call graph for this function:

◆ switch_output_setup()

static int switch_output_setup ( struct record rec)
static

Definition at line 1438 of file builtin-record.c.

Here is the call graph for this function:

◆ switch_output_signal()

static bool switch_output_signal ( struct record rec)
static

Definition at line 90 of file builtin-record.c.

Here is the call graph for this function:

◆ switch_output_size()

static bool switch_output_size ( struct record rec)
static

Definition at line 96 of file builtin-record.c.

Here is the call graph for this function:

◆ switch_output_size_warn()

static void switch_output_size_warn ( struct record rec)
static

Definition at line 1421 of file builtin-record.c.

Here is the call graph for this function:

◆ switch_output_time()

static bool switch_output_time ( struct record rec)
static

Definition at line 103 of file builtin-record.c.

Here is the call graph for this function:

◆ workload_exec_failed_signal()

static void workload_exec_failed_signal ( int signo  __maybe_unused,
siginfo_t *  info,
void *ucontext  __maybe_unused 
)
static

Definition at line 700 of file builtin-record.c.

Here is the call graph for this function:

Variable Documentation

◆ __record_options

struct option __record_options[]
static

Definition at line 1547 of file builtin-record.c.

◆ __record_usage

const char* const __record_usage[]
static
Initial value:
= {
"perf record [<options>] [<command>]",
"perf record [<options>] -- <command> [<options>]",
NULL
}

Definition at line 1493 of file builtin-record.c.

◆ auxtrace_record__snapshot_started

volatile int auxtrace_record__snapshot_started
static

Definition at line 86 of file builtin-record.c.

◆ child_finished

volatile int child_finished
static

Definition at line 143 of file builtin-record.c.

◆ clockids

const struct clockid_map clockids[]
static
Initial value:
= {
CLOCKID_MAP("monotonic", CLOCK_MONOTONIC),
CLOCKID_MAP("monotonic_raw", CLOCK_MONOTONIC_RAW),
CLOCKID_MAP("realtime", CLOCK_REALTIME),
CLOCKID_MAP("mono", CLOCK_MONOTONIC),
CLOCKID_MAP("real", CLOCK_REALTIME),
}
#define CLOCK_BOOTTIME
#define CLOCK_TAI
#define CLOCK_MONOTONIC_RAW
#define CLOCKID_MAP(n, c)
#define CLOCKID_END

Definition at line 1318 of file builtin-record.c.

◆ done

volatile int done
static

Definition at line 141 of file builtin-record.c.

◆ dry_run

bool dry_run
static

Definition at line 1538 of file builtin-record.c.

◆ finished_round_event

struct perf_event_header finished_round_event
static
Initial value:
= {
.size = sizeof(struct perf_event_header),
}

Definition at line 508 of file builtin-record.c.

◆ record

struct record record
static
Initial value:
= {
.opts = {
.sample_time = true,
.mmap_pages = UINT_MAX,
.user_freq = UINT_MAX,
.user_interval = ULLONG_MAX,
.freq = 4000,
.target = {
.uses_mmap = true,
.default_per_cpu = true,
},
.proc_map_timeout = 500,
},
.tool = {
.ordered_events = true,
},
}
int perf_event__process_mmap(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
Definition: event.c:1385
static int process_sample_event(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, struct perf_evsel *evsel, struct machine *machine)
int perf_event__process_comm(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
Definition: event.c:1273
int perf_event__process_exit(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
Definition: event.c:1416
int perf_event__process_fork(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
Definition: event.c:1408
int perf_event__process_mmap2(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
Definition: event.c:1393
int perf_event__process_namespaces(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
Definition: event.c:1281

Definition at line 1510 of file builtin-record.c.

◆ record_callchain_help

const char record_callchain_help[]
Initial value:
"\n\t\t\t\tDefault: fp"
#define CALLCHAIN_RECORD_HELP
Definition: callchain.h:23

Definition at line 1535 of file builtin-record.c.

◆ record_options

struct option* record_options = __record_options

Definition at line 1684 of file builtin-record.c.

◆ record_usage

const char* const* record_usage = __record_usage

Definition at line 1498 of file builtin-record.c.

◆ signr

volatile int signr = -1
static

Definition at line 142 of file builtin-record.c.

◆ workload_exec_errno

volatile int workload_exec_errno
static

Definition at line 693 of file builtin-record.c.