24 #include <subcmd/parse-options.h> 26 #include <linux/list.h> 81 static int perf_event__drop_oe(
struct perf_tool *
tool __maybe_unused,
115 #ifdef HAVE_AUXTRACE_SUPPORT 124 ssz = read(fd, buf,
min(size, (off_t)
sizeof(buf)));
171 return event->auxtrace.size;
181 pr_err(
"AUX area tracing not supported\n");
230 return f(tool, event, sample, evsel, machine);
252 static int perf_event__jit_repipe_mmap(
struct perf_tool *tool,
279 struct machine *machine)
290 static int perf_event__jit_repipe_mmap2(
struct perf_tool *tool,
293 struct machine *machine)
317 struct machine *machine)
330 struct machine *machine)
343 struct machine *machine)
355 struct machine *machine)
404 struct machine *machine)
406 u16 misc = PERF_RECORD_MISC_USER;
415 misc = PERF_RECORD_MISC_KERNEL;
431 struct machine *machine)
437 if (thread == NULL) {
438 pr_err(
"problem processing %d event, skipping it.\n",
453 #ifdef HAVE_LIBELF_SUPPORT 455 "install a debug package?\n",
472 struct machine *machine __maybe_unused)
478 if (sample->
tid == ent->
tid) {
479 list_del_init(&ent->
node);
492 struct machine *machine)
502 "Not enough memory to process sched switch event!");
516 struct machine *machine)
531 event_sw = &ent->
event[0];
537 evsel->
attr.read_format, &sample_sw);
548 u64 sample_type,
const char *sample_msg)
550 struct perf_event_attr *
attr = &evsel->
attr;
553 if (!(attr->sample_type & sample_type)) {
554 pr_err(
"Samples for %s event do not have %s attribute set.",
566 struct machine *machine __maybe_unused)
584 return evsel->
attr.mmap || evsel->
attr.mmap2 || evsel->
attr.comm ||
588 #define COMPAT_MASK (PERF_SAMPLE_ID | PERF_SAMPLE_TID | PERF_SAMPLE_TIME | \ 589 PERF_SAMPLE_ID | PERF_SAMPLE_CPU | PERF_SAMPLE_IDENTIFIER) 615 return ok && cnt == 1;
640 u64 output_data_offset;
662 if (!strcmp(name,
"sched:sched_switch")) {
667 }
else if (!strcmp(name,
"sched:sched_process_exit"))
669 else if (!strncmp(name,
"sched:sched_stat_", 17))
686 output_data_offset = 4096;
695 lseek(fd, output_data_offset, SEEK_SET);
774 .samples = LIST_HEAD_INIT(inject.
samples),
787 struct option options[] = {
788 OPT_BOOLEAN(
'b',
"build-ids", &inject.
build_ids,
789 "Inject build-ids into the output stream"),
790 OPT_STRING(
'i',
"input", &inject.
input_name,
"file",
794 OPT_BOOLEAN(
's',
"sched-stat", &inject.
sched_stat,
795 "Merge sched-stat and sched-switch for getting events " 796 "where and how long tasks slept"),
798 OPT_BOOLEAN(
'j',
"jit", &inject.
jit_mode,
"merge jitdump files into perf.data file"),
800 OPT_INCR(
'v',
"verbose", &
verbose,
801 "be more verbose (show build ids, etc)"),
803 "kallsyms pathname"),
804 OPT_BOOLEAN(
'f',
"force", &data.
force,
"don't complain, do it"),
806 NULL,
"opts",
"Instruction Tracing options",
808 OPT_BOOLEAN(0,
"strip", &inject.
strip,
809 "strip non-synthesized events (use with --itrace)"),
812 const char *
const inject_usage[] = {
813 "perf inject [<options>]",
817 set_option_nobuild(options,
'j',
"jit",
"NO_LIBELF=1",
true);
819 argc = parse_options(argc, argv, options, inject_usage, 0);
825 usage_with_options(inject_usage, options);
828 pr_err(
"--strip option requires --itrace option\n");
833 perror(
"failed to create output file");
856 inject.
tool.
mmap2 = perf_event__jit_repipe_mmap2;
857 inject.
tool.
mmap = perf_event__jit_repipe_mmap;
static int copy_bytes(int from, off_t from_offs, int to, off_t to_offs, u64 len)
static int perf_event__drop_aux(struct perf_tool *tool, union perf_event *event __maybe_unused, struct perf_sample *sample, struct machine *machine __maybe_unused)
int color_fprintf(FILE *fp, const char *color, const char *fmt,...)
struct perf_evlist * evlist
static int perf_event__repipe_fork(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, struct machine *machine)
int perf_event__process_mmap(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
int jit_process(struct perf_session *session, struct perf_data *output, struct machine *machine, char *filename, pid_t pid, u64 *nbytes)
struct perf_evsel * perf_evlist__id2evsel_strict(struct perf_evlist *evlist, u64 id)
struct map * thread__find_map(struct thread *thread, u8 cpumode, u64 addr, struct addr_location *al)
union perf_event event[0]
int filename__read_build_id(const char *filename, void *bf, size_t size)
static int __cmd_inject(struct perf_inject *inject)
struct itrace_synth_opts * itrace_synth_opts
struct perf_data_file file
void perf_evsel__delete(struct perf_evsel *evsel)
void perf_evlist__remove(struct perf_evlist *evlist, struct perf_evsel *evsel)
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_exit(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
int perf_event__process_fork(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
struct itrace_synth_opts itrace_synth_opts
static void sig_handler(int sig __maybe_unused)
static int perf_event__repipe_sample(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, struct perf_evsel *evsel, struct machine *machine)
void perf_session__delete(struct perf_session *session)
static int perf_event__repipe_mmap(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, struct machine *machine)
static int perf_event__repipe_tracing_data(struct perf_tool *tool, union perf_event *event, struct perf_session *session)
int dsos__hit_all(struct perf_session *session)
static int perf_event__repipe_exit(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, struct machine *machine)
#define evlist__for_each_entry_safe(evlist, tmp, evsel)
static int perf_inject__sched_process_exit(struct perf_tool *tool, union perf_event *event __maybe_unused, struct perf_sample *sample, struct perf_evsel *evsel __maybe_unused, struct machine *machine __maybe_unused)
int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct perf_evsel *evsel __maybe_unused, struct machine *machine)
static int dso__read_build_id(struct dso *dso)
static int perf_event__inject_buildid(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, struct perf_evsel *evsel __maybe_unused, struct machine *machine)
static void strip_init(struct perf_inject *inject)
int perf_event__synthesize_sample(union perf_event *event, u64 type, u64 read_format, const struct perf_sample *sample)
struct perf_evlist * evlist
static int perf_inject__sched_switch(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, struct perf_evsel *evsel, struct machine *machine)
#define pr_debug(fmt,...)
int perf_data__open(struct perf_data *data)
#define evlist__for_each_entry(evlist, evsel)
static int perf_event__repipe_mmap2(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, struct machine *machine)
static int perf_event__repipe_namespaces(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, struct machine *machine)
int itrace_parse_synth_opts(const struct option *opt, const char *str, int unset)
void auxtrace_index__free(struct list_head *head)
s64 perf_event__process_auxtrace(struct perf_tool *tool, union perf_event *event, struct perf_session *session)
int perf_event__process_auxtrace_info(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_session *session)
u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample, const char *name)
int(* inject_handler)(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, struct perf_evsel *evsel, struct machine *machine)
static int output_bytes(struct perf_inject *inject, void *buf, size_t sz)
enum dso_kernel_type kernel
static int perf_data__fd(struct perf_data *data)
x86 movsq based memcpy() in arch/x86/lib/memcpy_64.S") MEMCPY_FN(memcpy_erms
const char * perf_evsel__name(struct perf_evsel *evsel)
struct perf_event_header header
static int perf_event__drop(struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, struct perf_sample *sample __maybe_unused, struct machine *machine __maybe_unused)
static int perf_data__is_pipe(struct perf_data *data)
struct perf_session * perf_session__new(struct perf_data *data, bool repipe, struct perf_tool *tool)
int perf_event__process_mmap2(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
const char * kallsyms_name
void thread__put(struct thread *thread)
static s64 perf_event__repipe_auxtrace(struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, struct perf_session *session __maybe_unused)
int perf_session__process_events(struct perf_session *session)
u8 build_id[BUILD_ID_SIZE]
struct list_head auxtrace_index
int cmd_inject(int argc, const char **argv)
static bool has_tracking(struct perf_evsel *evsel)
struct auxtrace_event auxtrace
struct perf_session * session
ssize_t perf_data__write(struct perf_data *data, void *buf, size_t size)
static int drop_sample(struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, struct perf_sample *sample __maybe_unused, struct perf_evsel *evsel __maybe_unused, struct machine *machine __maybe_unused)
struct perf_header header
int auxtrace_index__auxtrace_event(struct list_head *head, union perf_event *event, off_t file_offset)
int symbol__init(struct perf_env *env)
int perf_event__process_id_index(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_session *session)
static int perf_event__repipe_comm(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, struct machine *machine)
static int perf_event__repipe(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample __maybe_unused, struct machine *machine __maybe_unused)
static int perf_inject__sched_stat(struct perf_tool *tool, union perf_event *event __maybe_unused, struct perf_sample *sample, struct perf_evsel *evsel, struct machine *machine)
static int perf_event__repipe_attr(struct perf_tool *tool, union perf_event *event, struct perf_evlist **pevlist)
static int perf_event__repipe_op2_synth(struct perf_tool *tool, union perf_event *event, struct perf_session *session __maybe_unused)
int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event, struct perf_sample *data)
static int dso__inject_build_id(struct dso *dso, struct perf_tool *tool, struct machine *machine)
static bool ok_to_remove(struct perf_evlist *evlist, struct perf_evsel *evsel_to_remove)
#define pr_warning(fmt,...)
static int perf_event__repipe_oe_synth(struct perf_tool *tool, union perf_event *event, struct ordered_events *oe __maybe_unused)
int perf_event__process_namespaces(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine)
int map__load(struct map *map)
static int perf_evsel__check_stype(struct perf_evsel *evsel, u64 sample_type, const char *sample_msg)
struct thread * machine__findnew_thread(struct machine *machine, pid_t pid, pid_t tid)
struct perf_event_attr attr
static int perf_event__repipe_id_index(struct perf_tool *tool, union perf_event *event, struct perf_session *session)
static void strip_fini(struct perf_inject *inject)
static int perf_event__repipe_synth(struct perf_tool *tool, union perf_event *event)