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; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 20 | struct list_head samples_head; |
| 21 | struct sample_queue *last_inserted; |
| 22 | }; |
| 23 | |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 24 | struct perf_session { |
| 25 | struct perf_header header; |
| 26 | unsigned long size; |
Arnaldo Carvalho de Melo | ec91336 | 2009-12-13 19:50:27 -0200 | [diff] [blame] | 27 | unsigned long mmap_window; |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 28 | struct rb_root threads; |
| 29 | struct thread *last_match; |
Arnaldo Carvalho de Melo | 1f626bc | 2010-05-09 19:57:08 -0300 | [diff] [blame] | 30 | struct machine host_machine; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 31 | struct rb_root machines; |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 32 | struct rb_root hists_tree; |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 33 | /* |
| 34 | * FIXME: should point to the first entry in hists_tree and |
| 35 | * be a hists instance. Right now its only 'report' |
| 36 | * that is using ->hists_tree while all the rest use |
| 37 | * ->hists. |
| 38 | */ |
| 39 | struct hists hists; |
Arnaldo Carvalho de Melo | c019879 | 2009-12-14 14:23:00 -0200 | [diff] [blame] | 40 | u64 sample_type; |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 41 | int fd; |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 42 | bool fd_pipe; |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 43 | bool repipe; |
Arnaldo Carvalho de Melo | ec91336 | 2009-12-13 19:50:27 -0200 | [diff] [blame] | 44 | int cwdlen; |
| 45 | char *cwd; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 46 | struct ordered_samples ordered_samples; |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 47 | char filename[0]; |
| 48 | }; |
| 49 | |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 50 | struct perf_event_ops; |
| 51 | |
Arnaldo Carvalho de Melo | 301a0b0 | 2009-12-13 19:50:25 -0200 | [diff] [blame] | 52 | typedef int (*event_op)(event_t *self, struct perf_session *session); |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 53 | typedef int (*event_op2)(event_t *self, struct perf_session *session, |
| 54 | struct perf_event_ops *ops); |
Arnaldo Carvalho de Melo | 301a0b0 | 2009-12-13 19:50:25 -0200 | [diff] [blame] | 55 | |
| 56 | struct perf_event_ops { |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 57 | event_op sample, |
| 58 | mmap, |
| 59 | comm, |
| 60 | fork, |
| 61 | exit, |
| 62 | lost, |
| 63 | read, |
| 64 | throttle, |
| 65 | unthrottle, |
| 66 | attr, |
| 67 | event_type, |
| 68 | tracing_data, |
| 69 | build_id; |
| 70 | event_op2 finished_round; |
| 71 | bool ordered_samples; |
Arnaldo Carvalho de Melo | 301a0b0 | 2009-12-13 19:50:25 -0200 | [diff] [blame] | 72 | }; |
| 73 | |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 74 | struct perf_session *perf_session__new(const char *filename, int mode, bool force, bool repipe); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 75 | void perf_session__delete(struct perf_session *self); |
| 76 | |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 77 | void perf_event_header__bswap(struct perf_event_header *self); |
| 78 | |
Arnaldo Carvalho de Melo | 6122e4e | 2010-02-03 16:52:05 -0200 | [diff] [blame] | 79 | int __perf_session__process_events(struct perf_session *self, |
| 80 | u64 data_offset, u64 data_size, u64 size, |
| 81 | struct perf_event_ops *ops); |
Arnaldo Carvalho de Melo | 301a0b0 | 2009-12-13 19:50:25 -0200 | [diff] [blame] | 82 | int perf_session__process_events(struct perf_session *self, |
Arnaldo Carvalho de Melo | ec91336 | 2009-12-13 19:50:27 -0200 | [diff] [blame] | 83 | struct perf_event_ops *event_ops); |
Arnaldo Carvalho de Melo | 301a0b0 | 2009-12-13 19:50:25 -0200 | [diff] [blame] | 84 | |
Arnaldo Carvalho de Melo | b3c9ac0 | 2010-03-24 16:40:18 -0300 | [diff] [blame] | 85 | struct map_symbol *perf_session__resolve_callchain(struct perf_session *self, |
| 86 | struct thread *thread, |
| 87 | struct ip_callchain *chain, |
| 88 | struct symbol **parent); |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 89 | |
Arnaldo Carvalho de Melo | d549c76 | 2009-12-27 21:37:02 -0200 | [diff] [blame] | 90 | 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] | 91 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 92 | 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] | 93 | const char *symbol_name, |
| 94 | u64 addr); |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 95 | |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 96 | void mem_bswap_64(void *src, int byte_size); |
| 97 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 98 | int perf_session__create_kernel_maps(struct perf_session *self); |
Arnaldo Carvalho de Melo | f9224c5 | 2010-03-11 20:12:44 -0300 | [diff] [blame] | 99 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 100 | int do_read(int fd, void *buf, size_t size); |
| 101 | void perf_session__update_sample_type(struct perf_session *self); |
| 102 | |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 103 | static inline |
| 104 | struct machine *perf_session__find_host_machine(struct perf_session *self) |
| 105 | { |
Arnaldo Carvalho de Melo | 1f626bc | 2010-05-09 19:57:08 -0300 | [diff] [blame] | 106 | return &self->host_machine; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | static inline |
| 110 | struct machine *perf_session__find_machine(struct perf_session *self, pid_t pid) |
| 111 | { |
Arnaldo Carvalho de Melo | 1f626bc | 2010-05-09 19:57:08 -0300 | [diff] [blame] | 112 | if (pid == HOST_KERNEL_ID) |
| 113 | return &self->host_machine; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 114 | return machines__find(&self->machines, pid); |
| 115 | } |
| 116 | |
| 117 | static inline |
| 118 | struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t pid) |
| 119 | { |
Arnaldo Carvalho de Melo | 1f626bc | 2010-05-09 19:57:08 -0300 | [diff] [blame] | 120 | if (pid == HOST_KERNEL_ID) |
| 121 | return &self->host_machine; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 122 | return machines__findnew(&self->machines, pid); |
| 123 | } |
| 124 | |
| 125 | static inline |
| 126 | void perf_session__process_machines(struct perf_session *self, |
| 127 | machine__process_t process) |
| 128 | { |
Arnaldo Carvalho de Melo | 1f626bc | 2010-05-09 19:57:08 -0300 | [diff] [blame] | 129 | process(&self->host_machine, self); |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 130 | return machines__process(&self->machines, process, self); |
| 131 | } |
Arnaldo Carvalho de Melo | cbf6968 | 2010-04-27 21:22:44 -0300 | [diff] [blame] | 132 | |
Arnaldo Carvalho de Melo | 1f626bc | 2010-05-09 19:57:08 -0300 | [diff] [blame] | 133 | 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] | 134 | |
| 135 | static inline |
| 136 | size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, FILE *fp, |
| 137 | bool with_hits) |
| 138 | { |
| 139 | return machines__fprintf_dsos_buildid(&self->machines, fp, with_hits); |
| 140 | } |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 141 | |
| 142 | static inline |
| 143 | size_t perf_session__fprintf_nr_events(struct perf_session *self, FILE *fp) |
| 144 | { |
| 145 | return hists__fprintf_nr_events(&self->hists, fp); |
| 146 | } |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 147 | #endif /* __PERF_SESSION_H */ |