forked from OpenCloudOS/perf-prof
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor.h
268 lines (220 loc) · 7.02 KB
/
monitor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#ifndef __MONITOR_H
#define __MONITOR_H
#include <stdio.h>
#include <perf/core.h>
#include <perf/cpumap.h>
#include <perf/threadmap.h>
#include <perf/evlist.h>
#include <perf/evsel.h>
#include <perf/mmap.h>
#include <perf/event.h>
#include <parse-options.h>
#include <tep.h>
#include <localtime.h>
#include <linux/epoll.h>
/* perf sample has 16 bits size limit */
#define PERF_SAMPLE_MAX_SIZE (1 << 16)
struct monitor;
void monitor_register(struct monitor *m);
struct monitor * monitor_find(char *name);
struct monitor *monitor_next(struct monitor *m);
int monitor_nr_instance(void);
int monitor_instance_cpu(int ins);
int monitor_instance_thread(int ins);
int monitor_instance_oncpu(void);
struct monitor *current_monitor(void);
int main_epoll_add(int fd, unsigned int events, void *ptr, handle_event handle);
int main_epoll_del(int fd);
void help(void);
int get_present_cpus(void);
void print_time(FILE *fp);
int get_tsc_khz(void);
#define X86_VENDOR_INTEL 0
#define X86_VENDOR_AMD 1
#define X86_VENDOR_HYGON 2
struct cpuinfo_x86 {
int vendor;
int family;
int model;
int stepping;
};
int get_cpuinfo(struct cpuinfo_x86 *info);
static inline int get_cpu_vendor(void) {
return get_cpuinfo(NULL);
};
int in_guest(void);
int callchain_flags(int default_flags);
int exclude_callchain_user(int dflt_flags);
int exclude_callchain_kernel(int dflt_flags);
void print_lost_fn(union perf_event *event, int ins);
int perf_event_process_record(union perf_event *event, int instance, bool writable, bool converted);
#define PROFILER_REGISTER_NAME(p, name) \
__attribute__((constructor)) static void __monitor_register_##name(void) \
{ \
monitor_register(p); \
}
#define PROFILER_REGISTER(p) PROFILER_REGISTER_NAME((&p), p)
#define MONITOR_REGISTER(m) PROFILER_REGISTER(m)
#define PROGRAME "perf-prof"
#define VERBOSE_NOTICE 1 // -v
#define VERBOSE_EVENT 2 // -vv
#define VERBOSE_ALL 3 // -vvv
#define MAX_SLOTS 26
struct hist {
unsigned int slots[MAX_SLOTS];
};
struct env {
int trigger_freq;
char *cpumask;
int interval;
int freq;
long exit_n;
char *pids;
char *tids;
char *cgroups;
char *event;
char **events;
int nr_events;
char *filter;
char *key;
char *impl;
char *output;
bool interruptible;
bool uninterruptible;
bool only_print_greater_than;
unsigned long greater_than; // unit: ns, percent
unsigned long lower_than; // unit: ns
bool callchain;
int mmap_pages;
bool exclude_user;
bool exclude_kernel;
bool exclude_guest;
bool exclude_host;
bool user_callchain, user_callchain_set;
bool kernel_callchain, kernel_callchain_set;
// ebpf
int irqs_disabled;
int tif_need_resched;
int exclude_pid;
int nr_running_min;
int nr_running_max;
// ebpf end
char *tp_alloc;
char *tp_free;
char *symbols;
char *flame_graph;
char *heatmap;
bool syscalls;
bool perins;
bool test;
bool detail;
// detail_arg
unsigned long before_event1;// unit: ns
unsigned long after_event2; // unit: ns
bool samecpu;
bool samepid;
bool sametid;
bool samekey;
char *device;
int ldlat;
bool overwrite;
unsigned long sample_period;
bool only_comm;
bool cycle;
bool tsc;
u64 tsc_offset;
/* kvmmmu */
bool spte;
bool mmio;
/* order */
bool order;
unsigned long order_mem;
/* help */
struct monitor *help_monitor;
int verbose;
};
struct help_ctx {
int nr_list;
struct tp_list **tp_list;
struct env *env;
};
typedef struct monitor {
struct monitor *next;
const char *name;
const char **desc;
const char **argv;
int pages;
int reinit;
bool dup; //dup event
bool order; // default enable order
struct perf_cpu_map *cpus;
struct perf_thread_map *threads;
void (*help)(struct help_ctx *ctx);
int (*argc_init)(int argc, char *argv[]);
int (*init)(struct perf_evlist *evlist, struct env *env);
int (*filter)(struct perf_evlist *evlist, struct env *env);
void (*enabled)(struct perf_evlist *evlist);
void (*deinit)(struct perf_evlist *evlist);
void (*sigusr1)(int signum);
void (*interval)(void);
// return 0:continue; 1:break;
int (*read)(struct perf_evsel *evsel, struct perf_counts_values *count, int instance);
/* PERF_RECORD_* */
//PERF_RECORD_LOST = 2,
void (*lost)(union perf_event *event, int instance, u64 lost_time);
//PERF_RECORD_COMM = 3,
void (*comm)(union perf_event *event, int instance);
//PERF_RECORD_EXIT = 4,
void (*exit)(union perf_event *event, int instance);
//PERF_RECORD_THROTTLE = 5,
//PERF_RECORD_UNTHROTTLE = 6,
void (*throttle)(union perf_event *event, int instance);
void (*unthrottle)(union perf_event *event, int instance);
//PERF_RECORD_FORK = 7,
void (*fork)(union perf_event *event, int instance);
//PERF_RECORD_SAMPLE = 9,
void (*sample)(union perf_event *event, int instance);
//PERF_RECORD_SWITCH = 14,
//PERF_RECORD_SWITCH_CPU_WIDE = 15,
void (*context_switch)(union perf_event *event, int instance);
void (*context_switch_cpu)(union perf_event *event, int instance);
//PERF_RECORD_NAMESPACES = 16,
void (*namespace)(union perf_event *event, int instance);
}profiler;
#define PROFILER_DESC(name, arg, ...) \
{PROGRAME " " name " " arg, "", __VA_ARGS__, NULL}
#define PROFILER_ARGV(name, ...) \
{PROGRAME, "-h", __VA_ARGS__, NULL}
#define PROFILER_ARGV_OPTION \
"OPTION:", \
"cpus", "pids", "tids", "cgroups", \
"interval", "output", "order", "order-mem", "mmap-pages", "exit-N", "tsc", "tsc-offset", \
"version", "verbose", "quiet", "help"
#define PROFILER_ARGV_FILTER \
"FILTER OPTION:", \
"exclude-host", "exclude-guest", "exclude-user", "exclude-kernel", \
"user-callchain", "kernel-callchain", \
"irqs_disabled", "tif_need_resched", "exclude_pid", "nr_running_min", "nr_running_max"
#define PROFILER_ARGV_CALLCHAIN_FILTER \
"FILTER OPTION:", "user-callchain", "kernel-callchain"
#define PROFILER_ARGV_PROFILER \
"PROFILER OPTION:" \
profiler *order(profiler *p);
bool current_is_order(void);
profiler *current_base_profiler(void);
bool using_order(profiler *p);
void reduce_wakeup_times(profiler *p, struct perf_event_attr *attr);
//help.c
void common_help(struct help_ctx *ctx, bool enabled, bool cpus, bool pids, bool interval, bool order, bool pages, bool verbose);
#include <filter/filter.h>
//convert.c
u64 rdtsc(void);
int perf_event_convert_init(struct perf_evlist *evlist, struct env *env);
void perf_event_convert_read_tsc_conversion(struct perf_mmap *map);
union perf_event *perf_event_convert(union perf_event *event, bool writable);
//sched.c
void sched_init(int nr_list, struct tp_list **tp_list);
void sched_reinit(int nr_list, struct tp_list **tp_list);
void sched_event(void *raw, int size, int cpu);
bool sched_wakeup_unnecessary(void *raw, int size);
#endif