forked from tikv/pprof-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.rs
67 lines (55 loc) · 1.55 KB
/
mod.rs
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
// Copyright 2022 TiKV Project Authors. Licensed under Apache-2.0.
use libc::c_void;
use std::path::PathBuf;
pub trait Symbol: Sized {
fn name(&self) -> Option<Vec<u8>>;
fn addr(&self) -> Option<*mut c_void>;
fn lineno(&self) -> Option<u32>;
fn filename(&self) -> Option<PathBuf>;
}
impl Symbol for backtrace::Symbol {
fn name(&self) -> Option<Vec<u8>> {
self.name().map(|name| name.as_bytes().to_vec())
}
fn addr(&self) -> Option<*mut libc::c_void> {
self.addr()
}
fn lineno(&self) -> Option<u32> {
self.lineno()
}
fn filename(&self) -> Option<std::path::PathBuf> {
self.filename().map(|filename| filename.to_owned())
}
}
pub trait Frame: Sized + Clone {
type S: Symbol;
fn resolve_symbol<F: FnMut(&Self::S)>(&self, cb: F);
fn symbol_address(&self) -> *mut c_void;
fn ip(&self) -> usize;
}
pub trait Trace {
type Frame;
fn trace<F: FnMut(&Self::Frame) -> bool>(_: *mut libc::c_void, cb: F)
where
Self: Sized;
}
#[cfg(not(all(
any(target_arch = "x86_64", target_arch = "aarch64"),
feature = "frame-pointer"
)))]
mod backtrace_rs;
#[cfg(not(all(
any(target_arch = "x86_64", target_arch = "aarch64"),
feature = "frame-pointer"
)))]
pub use backtrace_rs::Trace as TraceImpl;
#[cfg(all(
any(target_arch = "x86_64", target_arch = "aarch64"),
feature = "frame-pointer"
))]
pub mod frame_pointer;
#[cfg(all(
any(target_arch = "x86_64", target_arch = "aarch64"),
feature = "frame-pointer"
))]
pub use frame_pointer::Trace as TraceImpl;