blob: 568fd08a478d295a31a9394adf8263c1234b86fa [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 Melo301a0b02009-12-13 19:50:25 -02004#include "event.h"
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -02005#include "header.h"
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -02006#include "symbol.h"
Arnaldo Carvalho de Melo4aa65632009-12-13 19:50:29 -02007#include "thread.h"
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -02008#include <linux/rbtree.h>
Arnaldo Carvalho de Melof823e442009-12-14 15:06:01 -02009#include "../../../include/linux/perf_event.h"
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -020010
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +020011struct sample_queue;
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -020012struct ip_callchain;
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -020013struct thread;
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020014
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +020015struct ordered_samples {
16 u64 last_flush;
Frederic Weisbeckerd6b17be2010-05-03 15:14:33 +020017 u64 next_flush;
18 u64 max_timestamp;
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +020019 struct list_head samples_head;
20 struct sample_queue *last_inserted;
21};
22
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020023struct perf_session {
24 struct perf_header header;
25 unsigned long size;
Arnaldo Carvalho de Meloec913362009-12-13 19:50:27 -020026 unsigned long mmap_window;
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -020027 struct rb_root threads;
28 struct thread *last_match;
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -030029 struct rb_root machines;
Arnaldo Carvalho de Melof823e442009-12-14 15:06:01 -020030 struct events_stats events_stats;
Eric B Munsoncb8f0932010-03-05 12:51:07 -030031 struct rb_root stats_by_id;
Arnaldo Carvalho de Melof823e442009-12-14 15:06:01 -020032 unsigned long event_total[PERF_RECORD_MAX];
Arnaldo Carvalho de Melo31d337c2009-12-27 21:37:03 -020033 unsigned long unknown_events;
Arnaldo Carvalho de Melo4e4f06e2009-12-14 13:10:39 -020034 struct rb_root hists;
Arnaldo Carvalho de Meloc0198792009-12-14 14:23:00 -020035 u64 sample_type;
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020036 int fd;
Tom Zanussi8dc58102010-04-01 23:59:15 -050037 bool fd_pipe;
Tom Zanussi454c4072010-05-01 01:41:20 -050038 bool repipe;
Arnaldo Carvalho de Meloec913362009-12-13 19:50:27 -020039 int cwdlen;
40 char *cwd;
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +020041 struct ordered_samples ordered_samples;
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020042 char filename[0];
43};
44
Frederic Weisbeckerd6b17be2010-05-03 15:14:33 +020045struct perf_event_ops;
46
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -020047typedef int (*event_op)(event_t *self, struct perf_session *session);
Frederic Weisbeckerd6b17be2010-05-03 15:14:33 +020048typedef int (*event_op2)(event_t *self, struct perf_session *session,
49 struct perf_event_ops *ops);
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -020050
51struct perf_event_ops {
Frederic Weisbeckerd6b17be2010-05-03 15:14:33 +020052 event_op sample,
53 mmap,
54 comm,
55 fork,
56 exit,
57 lost,
58 read,
59 throttle,
60 unthrottle,
61 attr,
62 event_type,
63 tracing_data,
64 build_id;
65 event_op2 finished_round;
66 bool ordered_samples;
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -020067};
68
Tom Zanussi454c4072010-05-01 01:41:20 -050069struct perf_session *perf_session__new(const char *filename, int mode, bool force, bool repipe);
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020070void perf_session__delete(struct perf_session *self);
71
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -020072void perf_event_header__bswap(struct perf_event_header *self);
73
Arnaldo Carvalho de Melo6122e4e2010-02-03 16:52:05 -020074int __perf_session__process_events(struct perf_session *self,
75 u64 data_offset, u64 data_size, u64 size,
76 struct perf_event_ops *ops);
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -020077int perf_session__process_events(struct perf_session *self,
Arnaldo Carvalho de Meloec913362009-12-13 19:50:27 -020078 struct perf_event_ops *event_ops);
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -020079
Arnaldo Carvalho de Melob3c9ac02010-03-24 16:40:18 -030080struct map_symbol *perf_session__resolve_callchain(struct perf_session *self,
81 struct thread *thread,
82 struct ip_callchain *chain,
83 struct symbol **parent);
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -020084
Arnaldo Carvalho de Melod549c7692009-12-27 21:37:02 -020085bool perf_session__has_traces(struct perf_session *self, const char *msg);
Arnaldo Carvalho de Melo27295592009-12-27 21:37:01 -020086
Zhang, Yanmina1645ce2010-04-19 13:32:50 +080087int perf_session__set_kallsyms_ref_reloc_sym(struct map **maps,
Arnaldo Carvalho de Melo56b03f32010-01-05 16:50:31 -020088 const char *symbol_name,
89 u64 addr);
Arnaldo Carvalho de Melo56b03f32010-01-05 16:50:31 -020090
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -020091void mem_bswap_64(void *src, int byte_size);
92
Zhang, Yanmina1645ce2010-04-19 13:32:50 +080093int perf_session__create_kernel_maps(struct perf_session *self);
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -030094
Tom Zanussi8dc58102010-04-01 23:59:15 -050095int do_read(int fd, void *buf, size_t size);
96void perf_session__update_sample_type(struct perf_session *self);
97
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -030098#ifdef NO_NEWT_SUPPORT
Arnaldo Carvalho de Melo5f4d3f82010-03-26 21:16:22 -030099static inline int perf_session__browse_hists(struct rb_root *hists __used,
100 u64 nr_hists __used,
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300101 u64 session_total __used,
Arnaldo Carvalho de Melo533c46c2010-04-03 11:54:35 -0300102 const char *helpline __used,
103 const char *input_name __used)
Arnaldo Carvalho de Melo5f4d3f82010-03-26 21:16:22 -0300104{
105 return 0;
106}
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300107#else
Arnaldo Carvalho de Melo5f4d3f82010-03-26 21:16:22 -0300108int perf_session__browse_hists(struct rb_root *hists, u64 nr_hists,
Arnaldo Carvalho de Melo533c46c2010-04-03 11:54:35 -0300109 u64 session_total, const char *helpline,
110 const char *input_name);
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300111#endif
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300112
113static inline
114struct machine *perf_session__find_host_machine(struct perf_session *self)
115{
116 return machines__find_host(&self->machines);
117}
118
119static inline
120struct machine *perf_session__find_machine(struct perf_session *self, pid_t pid)
121{
122 return machines__find(&self->machines, pid);
123}
124
125static inline
126struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t pid)
127{
128 return machines__findnew(&self->machines, pid);
129}
130
131static inline
132void perf_session__process_machines(struct perf_session *self,
133 machine__process_t process)
134{
135 return machines__process(&self->machines, process, self);
136}
Arnaldo Carvalho de Melocbf69682010-04-27 21:22:44 -0300137
138static inline
139size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp)
140{
141 return machines__fprintf_dsos(&self->machines, fp);
142}
143
144static inline
145size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, FILE *fp,
146 bool with_hits)
147{
148 return machines__fprintf_dsos_buildid(&self->machines, fp, with_hits);
149}
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200150#endif /* __PERF_SESSION_H */