session.h 3.8 KB
Newer Older
1 2 3
#ifndef __PERF_SESSION_H
#define __PERF_SESSION_H

4
#include "event.h"
5
#include "header.h"
6
#include "symbol.h"
7
#include "thread.h"
8
#include <linux/rbtree.h>
9
#include "../../../include/linux/perf_event.h"
10

11
struct sample_queue;
12
struct ip_callchain;
13
struct thread;
14

15 16
struct ordered_samples {
	u64			last_flush;
17 18
	u64			next_flush;
	u64			max_timestamp;
19 20 21 22
	struct list_head	samples_head;
	struct sample_queue	*last_inserted;
};

23 24 25
struct perf_session {
	struct perf_header	header;
	unsigned long		size;
26
	unsigned long		mmap_window;
27 28
	struct rb_root		threads;
	struct thread		*last_match;
29
	struct machine		host_machine;
30
	struct rb_root		machines;
31
	struct events_stats	events_stats;
32
	struct rb_root		stats_by_id;
33
	unsigned long		event_total[PERF_RECORD_MAX];
34
	unsigned long		unknown_events;
35
	struct rb_root		hists;
36
	u64			sample_type;
37
	int			fd;
38
	bool			fd_pipe;
T
Tom Zanussi 已提交
39
	bool			repipe;
40 41
	int			cwdlen;
	char			*cwd;
42
	struct ordered_samples	ordered_samples;
43 44 45
	char filename[0];
};

46 47
struct perf_event_ops;

48
typedef int (*event_op)(event_t *self, struct perf_session *session);
49 50
typedef int (*event_op2)(event_t *self, struct perf_session *session,
			 struct perf_event_ops *ops);
51 52

struct perf_event_ops {
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
	event_op	sample,
			mmap,
			comm,
			fork,
			exit,
			lost,
			read,
			throttle,
			unthrottle,
			attr,
			event_type,
			tracing_data,
			build_id;
	event_op2	finished_round;
	bool		ordered_samples;
68 69
};

T
Tom Zanussi 已提交
70
struct perf_session *perf_session__new(const char *filename, int mode, bool force, bool repipe);
71 72
void perf_session__delete(struct perf_session *self);

73 74
void perf_event_header__bswap(struct perf_event_header *self);

75 76 77
int __perf_session__process_events(struct perf_session *self,
				   u64 data_offset, u64 data_size, u64 size,
				   struct perf_event_ops *ops);
78
int perf_session__process_events(struct perf_session *self,
79
				 struct perf_event_ops *event_ops);
80

81 82 83 84
struct map_symbol *perf_session__resolve_callchain(struct perf_session *self,
						   struct thread *thread,
						   struct ip_callchain *chain,
						   struct symbol **parent);
85

86
bool perf_session__has_traces(struct perf_session *self, const char *msg);
87

88
int perf_session__set_kallsyms_ref_reloc_sym(struct map **maps,
89 90 91
					     const char *symbol_name,
					     u64 addr);

92 93
void mem_bswap_64(void *src, int byte_size);

94
int perf_session__create_kernel_maps(struct perf_session *self);
95

96 97 98
int do_read(int fd, void *buf, size_t size);
void perf_session__update_sample_type(struct perf_session *self);

99
#ifdef NO_NEWT_SUPPORT
100 101
static inline int perf_session__browse_hists(struct rb_root *hists __used,
					      u64 nr_hists __used,
102
					      u64 session_total __used,
103 104
					     const char *helpline __used,
					     const char *input_name __used)
105 106 107
{
	return 0;
}
108
#else
109
int perf_session__browse_hists(struct rb_root *hists, u64 nr_hists,
110 111
			       u64 session_total, const char *helpline,
			       const char *input_name);
112
#endif
113 114 115 116

static inline
struct machine *perf_session__find_host_machine(struct perf_session *self)
{
117
	return &self->host_machine;
118 119 120 121 122
}

static inline
struct machine *perf_session__find_machine(struct perf_session *self, pid_t pid)
{
123 124
	if (pid == HOST_KERNEL_ID)
		return &self->host_machine;
125 126 127 128 129 130
	return machines__find(&self->machines, pid);
}

static inline
struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t pid)
{
131 132
	if (pid == HOST_KERNEL_ID)
		return &self->host_machine;
133 134 135 136 137 138 139
	return machines__findnew(&self->machines, pid);
}

static inline
void perf_session__process_machines(struct perf_session *self,
				    machine__process_t process)
{
140
	process(&self->host_machine, self);
141 142
	return machines__process(&self->machines, process, self);
}
143

144
size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp);
145 146 147 148 149 150 151

static inline
size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, FILE *fp,
					  bool with_hits)
{
	return machines__fprintf_dsos_buildid(&self->machines, fp, with_hits);
}
152
#endif /* __PERF_SESSION_H */