Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 1 | #ifndef __PERF_SESSION_H |
| 2 | #define __PERF_SESSION_H |
| 3 | |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 4 | #include "hist.h" |
Arnaldo Carvalho de Melo | 301a0b0 | 2009-12-13 19:50:25 -0200 | [diff] [blame] | 5 | #include "event.h" |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 6 | #include "header.h" |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 7 | #include "symbol.h" |
Arnaldo Carvalho de Melo | 4aa6563 | 2009-12-13 19:50:29 -0200 | [diff] [blame] | 8 | #include "thread.h" |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 9 | #include <linux/rbtree.h> |
Arnaldo Carvalho de Melo | f823e44 | 2009-12-14 15:06:01 -0200 | [diff] [blame] | 10 | #include "../../../include/linux/perf_event.h" |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 11 | |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 12 | struct sample_queue; |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 13 | struct ip_callchain; |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 14 | struct thread; |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 15 | |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 16 | struct ordered_samples { |
| 17 | u64 last_flush; |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 18 | u64 next_flush; |
| 19 | u64 max_timestamp; |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 20 | struct list_head samples; |
Thomas Gleixner | 020bb75 | 2010-11-30 17:49:53 +0000 | [diff] [blame] | 21 | struct list_head sample_cache; |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 22 | struct list_head to_free; |
| 23 | struct sample_queue *sample_buffer; |
Thomas Gleixner | a1225de | 2010-11-30 17:49:33 +0000 | [diff] [blame] | 24 | struct sample_queue *last_sample; |
Thomas Gleixner | 5c891f3 | 2010-11-30 17:49:55 +0000 | [diff] [blame] | 25 | int sample_buffer_idx; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 26 | }; |
| 27 | |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 28 | struct perf_session { |
| 29 | struct perf_header header; |
| 30 | unsigned long size; |
Arnaldo Carvalho de Melo | ec91336 | 2009-12-13 19:50:27 -0200 | [diff] [blame] | 31 | unsigned long mmap_window; |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 32 | struct rb_root threads; |
Arnaldo Carvalho de Melo | 720a3ae | 2010-06-17 08:37:44 -0300 | [diff] [blame] | 33 | struct list_head dead_threads; |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 34 | struct thread *last_match; |
Arnaldo Carvalho de Melo | 1f626bc | 2010-05-09 19:57:08 -0300 | [diff] [blame] | 35 | struct machine host_machine; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 36 | struct rb_root machines; |
Arnaldo Carvalho de Melo | e248de3 | 2011-03-05 21:40:06 -0300 | [diff] [blame] | 37 | struct perf_evlist *evlist; |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 38 | /* |
Arnaldo Carvalho de Melo | e248de3 | 2011-03-05 21:40:06 -0300 | [diff] [blame] | 39 | * FIXME: Need to split this up further, we need global |
| 40 | * stats + per event stats. 'perf diff' also needs |
| 41 | * to properly support multiple events in a single |
| 42 | * perf.data file. |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 43 | */ |
| 44 | struct hists hists; |
Arnaldo Carvalho de Melo | c019879 | 2009-12-14 14:23:00 -0200 | [diff] [blame] | 45 | u64 sample_type; |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 46 | int fd; |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 47 | bool fd_pipe; |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 48 | bool repipe; |
Arnaldo Carvalho de Melo | 9c90a61 | 2010-12-02 10:25:28 -0200 | [diff] [blame] | 49 | bool sample_id_all; |
| 50 | u16 id_hdr_size; |
Arnaldo Carvalho de Melo | ec91336 | 2009-12-13 19:50:27 -0200 | [diff] [blame] | 51 | int cwdlen; |
| 52 | char *cwd; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 53 | struct ordered_samples ordered_samples; |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 54 | struct callchain_cursor callchain_cursor; |
| 55 | char filename[0]; |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 56 | }; |
| 57 | |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 58 | struct perf_evsel; |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 59 | struct perf_event_ops; |
| 60 | |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 61 | typedef int (*event_sample)(union perf_event *event, struct perf_sample *sample, |
| 62 | struct perf_evsel *evsel, struct perf_session *session); |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 63 | typedef int (*event_op)(union perf_event *self, struct perf_sample *sample, |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 64 | struct perf_session *session); |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 65 | typedef int (*event_synth_op)(union perf_event *self, |
| 66 | struct perf_session *session); |
| 67 | typedef int (*event_op2)(union perf_event *self, struct perf_session *session, |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 68 | struct perf_event_ops *ops); |
Arnaldo Carvalho de Melo | 301a0b0 | 2009-12-13 19:50:25 -0200 | [diff] [blame] | 69 | |
| 70 | struct perf_event_ops { |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 71 | event_sample sample; |
| 72 | event_op mmap, |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 73 | comm, |
| 74 | fork, |
| 75 | exit, |
| 76 | lost, |
| 77 | read, |
| 78 | throttle, |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 79 | unthrottle; |
| 80 | event_synth_op attr, |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 81 | event_type, |
| 82 | tracing_data, |
| 83 | build_id; |
| 84 | event_op2 finished_round; |
| 85 | bool ordered_samples; |
Ian Munsie | 21ef97f | 2010-12-10 14:09:16 +1100 | [diff] [blame] | 86 | bool ordering_requires_timestamps; |
Arnaldo Carvalho de Melo | 301a0b0 | 2009-12-13 19:50:25 -0200 | [diff] [blame] | 87 | }; |
| 88 | |
Ian Munsie | 21ef97f | 2010-12-10 14:09:16 +1100 | [diff] [blame] | 89 | struct perf_session *perf_session__new(const char *filename, int mode, |
| 90 | bool force, bool repipe, |
| 91 | struct perf_event_ops *ops); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 92 | void perf_session__delete(struct perf_session *self); |
| 93 | |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 94 | void perf_event_header__bswap(struct perf_event_header *self); |
| 95 | |
Arnaldo Carvalho de Melo | 6122e4e | 2010-02-03 16:52:05 -0200 | [diff] [blame] | 96 | int __perf_session__process_events(struct perf_session *self, |
| 97 | u64 data_offset, u64 data_size, u64 size, |
| 98 | struct perf_event_ops *ops); |
Arnaldo Carvalho de Melo | 301a0b0 | 2009-12-13 19:50:25 -0200 | [diff] [blame] | 99 | int perf_session__process_events(struct perf_session *self, |
Arnaldo Carvalho de Melo | ec91336 | 2009-12-13 19:50:27 -0200 | [diff] [blame] | 100 | struct perf_event_ops *event_ops); |
Arnaldo Carvalho de Melo | 301a0b0 | 2009-12-13 19:50:25 -0200 | [diff] [blame] | 101 | |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 102 | int perf_session__resolve_callchain(struct perf_session *self, |
| 103 | struct thread *thread, |
| 104 | struct ip_callchain *chain, |
| 105 | struct symbol **parent); |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 106 | |
Arnaldo Carvalho de Melo | d549c76 | 2009-12-27 21:37:02 -0200 | [diff] [blame] | 107 | bool perf_session__has_traces(struct perf_session *self, const char *msg); |
Arnaldo Carvalho de Melo | 2729559 | 2009-12-27 21:37:01 -0200 | [diff] [blame] | 108 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 109 | int perf_session__set_kallsyms_ref_reloc_sym(struct map **maps, |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 110 | const char *symbol_name, |
| 111 | u64 addr); |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 112 | |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 113 | void mem_bswap_64(void *src, int byte_size); |
| 114 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 115 | int perf_session__create_kernel_maps(struct perf_session *self); |
Arnaldo Carvalho de Melo | f9224c5 | 2010-03-11 20:12:44 -0300 | [diff] [blame] | 116 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 117 | void perf_session__update_sample_type(struct perf_session *self); |
Arnaldo Carvalho de Melo | 720a3ae | 2010-06-17 08:37:44 -0300 | [diff] [blame] | 118 | void perf_session__remove_thread(struct perf_session *self, struct thread *th); |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 119 | |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 120 | static inline |
| 121 | struct machine *perf_session__find_host_machine(struct perf_session *self) |
| 122 | { |
Arnaldo Carvalho de Melo | 1f626bc | 2010-05-09 19:57:08 -0300 | [diff] [blame] | 123 | return &self->host_machine; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | static inline |
| 127 | struct machine *perf_session__find_machine(struct perf_session *self, pid_t pid) |
| 128 | { |
Arnaldo Carvalho de Melo | 1f626bc | 2010-05-09 19:57:08 -0300 | [diff] [blame] | 129 | if (pid == HOST_KERNEL_ID) |
| 130 | return &self->host_machine; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 131 | return machines__find(&self->machines, pid); |
| 132 | } |
| 133 | |
| 134 | static inline |
| 135 | struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t pid) |
| 136 | { |
Arnaldo Carvalho de Melo | 1f626bc | 2010-05-09 19:57:08 -0300 | [diff] [blame] | 137 | if (pid == HOST_KERNEL_ID) |
| 138 | return &self->host_machine; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 139 | return machines__findnew(&self->machines, pid); |
| 140 | } |
| 141 | |
| 142 | static inline |
| 143 | void perf_session__process_machines(struct perf_session *self, |
| 144 | machine__process_t process) |
| 145 | { |
Arnaldo Carvalho de Melo | 1f626bc | 2010-05-09 19:57:08 -0300 | [diff] [blame] | 146 | process(&self->host_machine, self); |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 147 | return machines__process(&self->machines, process, self); |
| 148 | } |
Arnaldo Carvalho de Melo | cbf6968 | 2010-04-27 21:22:44 -0300 | [diff] [blame] | 149 | |
Arnaldo Carvalho de Melo | 1f626bc | 2010-05-09 19:57:08 -0300 | [diff] [blame] | 150 | size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp); |
Arnaldo Carvalho de Melo | cbf6968 | 2010-04-27 21:22:44 -0300 | [diff] [blame] | 151 | |
Arnaldo Carvalho de Melo | f869097 | 2010-05-19 13:41:23 -0300 | [diff] [blame] | 152 | size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, |
| 153 | FILE *fp, bool with_hits); |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 154 | |
Arnaldo Carvalho de Melo | e248de3 | 2011-03-05 21:40:06 -0300 | [diff] [blame] | 155 | size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp); |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 156 | |
| 157 | static inline int perf_session__parse_sample(struct perf_session *session, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 158 | const union perf_event *event, |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 159 | struct perf_sample *sample) |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 160 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 161 | return perf_event__parse_sample(event, session->sample_type, |
| 162 | session->sample_id_all, sample); |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 163 | } |
| 164 | |
David Ahern | 9cbdb70 | 2011-04-06 21:54:20 -0600 | [diff] [blame] | 165 | struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session, |
| 166 | unsigned int type); |
| 167 | |
David Ahern | c0230b2 | 2011-03-09 22:23:27 -0700 | [diff] [blame] | 168 | void perf_session__print_symbols(union perf_event *event, |
| 169 | struct perf_sample *sample, |
| 170 | struct perf_session *session); |
| 171 | |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 172 | #endif /* __PERF_SESSION_H */ |