-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathtrace_helpers.h
57 lines (47 loc) · 1.96 KB
/
trace_helpers.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
/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
#ifndef __TRACE_HELPERS_H
#define __TRACE_HELPERS_H
#include <stdbool.h>
#define NSEC_PER_SEC 1000000000ULL
void print_log2_hist(unsigned int* vals, int vals_size, const char* val_type);
void print_linear_hist(unsigned int* vals,
int vals_size,
unsigned int base,
unsigned int step,
const char* val_type);
unsigned long long get_ktime_ns(void);
bool is_kernel_module(const char* name);
/*
* When attempting to use kprobe/kretprobe, please check out new fentry/fexit
* probes, as they provide better performance and usability. But in some
* situations we have to fallback to kprobe/kretprobe probes. This helper
* is used to detect fentry/fexit support for the specified kernel function.
*
* 1. A gap between kernel versions, kernel BTF is exposed
* starting from 5.4 kernel. but fentry/fexit is actually
* supported starting from 5.5.
* 2. Whether kernel supports module BTF or not
*
* *name* is the name of a kernel function to be attached to, which can be
* from vmlinux or a kernel module.
* *mod* is a hint that indicates the *name* may reside in module BTF,
* if NULL, it means *name* belongs to vmlinux.
*/
bool fentry_can_attach(const char* name, const char* mod);
/*
* The name of a kernel function to be attached to may be changed between
* kernel releases. This helper is used to confirm whether the target kernel
* uses a certain function name before attaching.
*
* It is achieved by scaning
* /sys/kernel/debug/tracing/available_filter_functions
* If this file does not exist, it fallbacks to parse /proc/kallsyms,
* which is slower.
*/
bool kprobe_exists(const char* name);
bool tracepoint_exists(const char* category, const char* event);
bool vmlinux_btf_exists(void);
bool module_btf_exists(const char* mod);
bool probe_tp_btf(const char* name);
bool probe_ringbuf();
#endif /* __TRACE_HELPERS_H */