blob: ffe4b98db8f0883b3071dbc6a63a7cb50301da90 [file] [log] [blame]
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -02001#ifndef __PERF_SESSION_H
2#define __PERF_SESSION_H
3
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -03004#include "hist.h"
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -02005#include "event.h"
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -02006#include "header.h"
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -02007#include "symbol.h"
Arnaldo Carvalho de Melo4aa65632009-12-13 19:50:29 -02008#include "thread.h"
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -02009#include <linux/rbtree.h>
Arnaldo Carvalho de Melof823e442009-12-14 15:06:01 -020010#include "../../../include/linux/perf_event.h"
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -020011
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +020012struct sample_queue;
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -020013struct ip_callchain;
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -020014struct thread;
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020015
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +020016struct ordered_samples {
17 u64 last_flush;
Frederic Weisbeckerd6b17be2010-05-03 15:14:33 +020018 u64 next_flush;
19 u64 max_timestamp;
Thomas Gleixnera1225de2010-11-30 17:49:33 +000020 struct list_head samples;
Thomas Gleixner020bb752010-11-30 17:49:53 +000021 struct list_head sample_cache;
Thomas Gleixner5c891f32010-11-30 17:49:55 +000022 struct list_head to_free;
23 struct sample_queue *sample_buffer;
Thomas Gleixnera1225de2010-11-30 17:49:33 +000024 struct sample_queue *last_sample;
Thomas Gleixner5c891f32010-11-30 17:49:55 +000025 int sample_buffer_idx;
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +020026};
27
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020028struct perf_session {
29 struct perf_header header;
30 unsigned long size;
Arnaldo Carvalho de Meloec913362009-12-13 19:50:27 -020031 unsigned long mmap_window;
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -020032 struct rb_root threads;
Arnaldo Carvalho de Melo720a3ae2010-06-17 08:37:44 -030033 struct list_head dead_threads;
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -020034 struct thread *last_match;
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -030035 struct machine host_machine;
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -030036 struct rb_root machines;
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -030037 struct rb_root hists_tree;
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -030038 /*
39 * FIXME: should point to the first entry in hists_tree and
40 * be a hists instance. Right now its only 'report'
41 * that is using ->hists_tree while all the rest use
42 * ->hists.
43 */
44 struct hists hists;
Arnaldo Carvalho de Meloc0198792009-12-14 14:23:00 -020045 u64 sample_type;
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020046 int fd;
Tom Zanussi8dc58102010-04-01 23:59:15 -050047 bool fd_pipe;
Tom Zanussi454c4072010-05-01 01:41:20 -050048 bool repipe;
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -020049 bool sample_id_all;
50 u16 id_hdr_size;
Arnaldo Carvalho de Meloec913362009-12-13 19:50:27 -020051 int cwdlen;
52 char *cwd;
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +020053 struct ordered_samples ordered_samples;
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020054 char filename[0];
55};
56
Frederic Weisbeckerd6b17be2010-05-03 15:14:33 +020057struct perf_event_ops;
58
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -020059typedef int (*event_op)(event_t *self, struct sample_data *sample,
60 struct perf_session *session);
61typedef int (*event_synth_op)(event_t *self, struct perf_session *session);
Frederic Weisbeckerd6b17be2010-05-03 15:14:33 +020062typedef int (*event_op2)(event_t *self, struct perf_session *session,
63 struct perf_event_ops *ops);
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -020064
65struct perf_event_ops {
Frederic Weisbeckerd6b17be2010-05-03 15:14:33 +020066 event_op sample,
67 mmap,
68 comm,
69 fork,
70 exit,
71 lost,
72 read,
73 throttle,
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -020074 unthrottle;
75 event_synth_op attr,
Frederic Weisbeckerd6b17be2010-05-03 15:14:33 +020076 event_type,
77 tracing_data,
78 build_id;
79 event_op2 finished_round;
80 bool ordered_samples;
Ian Munsie21ef97f2010-12-10 14:09:16 +110081 bool ordering_requires_timestamps;
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -020082};
83
Ian Munsie21ef97f2010-12-10 14:09:16 +110084struct perf_session *perf_session__new(const char *filename, int mode,
85 bool force, bool repipe,
86 struct perf_event_ops *ops);
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020087void perf_session__delete(struct perf_session *self);
88
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -020089void perf_event_header__bswap(struct perf_event_header *self);
90
Arnaldo Carvalho de Melo6122e4e2010-02-03 16:52:05 -020091int __perf_session__process_events(struct perf_session *self,
92 u64 data_offset, u64 data_size, u64 size,
93 struct perf_event_ops *ops);
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -020094int perf_session__process_events(struct perf_session *self,
Arnaldo Carvalho de Meloec913362009-12-13 19:50:27 -020095 struct perf_event_ops *event_ops);
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -020096
Arnaldo Carvalho de Melob3c9ac02010-03-24 16:40:18 -030097struct map_symbol *perf_session__resolve_callchain(struct perf_session *self,
98 struct thread *thread,
99 struct ip_callchain *chain,
100 struct symbol **parent);
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -0200101
Arnaldo Carvalho de Melod549c7692009-12-27 21:37:02 -0200102bool perf_session__has_traces(struct perf_session *self, const char *msg);
Arnaldo Carvalho de Melo27295592009-12-27 21:37:01 -0200103
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800104int perf_session__set_kallsyms_ref_reloc_sym(struct map **maps,
Arnaldo Carvalho de Melo56b03f32010-01-05 16:50:31 -0200105 const char *symbol_name,
106 u64 addr);
Arnaldo Carvalho de Melo56b03f32010-01-05 16:50:31 -0200107
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -0200108void mem_bswap_64(void *src, int byte_size);
109
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800110int perf_session__create_kernel_maps(struct perf_session *self);
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300111
Tom Zanussi8dc58102010-04-01 23:59:15 -0500112int do_read(int fd, void *buf, size_t size);
113void perf_session__update_sample_type(struct perf_session *self);
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200114void perf_session__set_sample_id_all(struct perf_session *session, bool value);
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -0200115void perf_session__set_sample_type(struct perf_session *session, u64 type);
Arnaldo Carvalho de Melo720a3ae2010-06-17 08:37:44 -0300116void perf_session__remove_thread(struct perf_session *self, struct thread *th);
Tom Zanussi8dc58102010-04-01 23:59:15 -0500117
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300118static inline
119struct machine *perf_session__find_host_machine(struct perf_session *self)
120{
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -0300121 return &self->host_machine;
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300122}
123
124static inline
125struct machine *perf_session__find_machine(struct perf_session *self, pid_t pid)
126{
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -0300127 if (pid == HOST_KERNEL_ID)
128 return &self->host_machine;
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300129 return machines__find(&self->machines, pid);
130}
131
132static inline
133struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t pid)
134{
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -0300135 if (pid == HOST_KERNEL_ID)
136 return &self->host_machine;
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300137 return machines__findnew(&self->machines, pid);
138}
139
140static inline
141void perf_session__process_machines(struct perf_session *self,
142 machine__process_t process)
143{
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -0300144 process(&self->host_machine, self);
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300145 return machines__process(&self->machines, process, self);
146}
Arnaldo Carvalho de Melocbf69682010-04-27 21:22:44 -0300147
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -0300148size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp);
Arnaldo Carvalho de Melocbf69682010-04-27 21:22:44 -0300149
Arnaldo Carvalho de Melof8690972010-05-19 13:41:23 -0300150size_t perf_session__fprintf_dsos_buildid(struct perf_session *self,
151 FILE *fp, bool with_hits);
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -0300152
153static inline
154size_t perf_session__fprintf_nr_events(struct perf_session *self, FILE *fp)
155{
156 return hists__fprintf_nr_events(&self->hists, fp);
157}
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200158#endif /* __PERF_SESSION_H */