Skip to content

Commit 17474c3

Browse files
author
shadow3aaa
committed
文档
1 parent 1889de5 commit 17474c3

File tree

3 files changed

+50
-8
lines changed

3 files changed

+50
-8
lines changed

frame-analyzer/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ anyhow = "1"
1616
libc = "0.2"
1717
thiserror = "1.0.58"
1818
ctor = "0.2.8"
19+
ctrlc = "3.4.4"
1920
mio = { version = "0.8.11", features = ["os-ext"] }
2021

2122
[build-dependencies]

frame-analyzer/src/ebpf.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ fn ebpf_workround() {
3535
pub fn load_bpf() -> Result<Bpf> {
3636
// This will include eBPF object file as raw bytes at compile-time and load it at runtime.
3737
#[cfg(debug_assertions)]
38-
let bpf = Bpf::load(include_bytes_aligned!(
39-
concat!(env!("OUT_DIR"), "/ebpf_target/bpfel-unknown-none/debug/frame-analyzer-ebpf")
40-
))?;
38+
let bpf = Bpf::load(include_bytes_aligned!(concat!(
39+
env!("OUT_DIR"),
40+
"/ebpf_target/bpfel-unknown-none/debug/frame-analyzer-ebpf"
41+
)))?;
4142
#[cfg(not(debug_assertions))]
42-
let bpf = Bpf::load(include_bytes_aligned!(
43-
concat!(env!("OUT_DIR"), "/ebpf_target/bpfel-unknown-none/release/frame-analyzer-ebpf")
44-
))?;
43+
let bpf = Bpf::load(include_bytes_aligned!(concat!(
44+
env!("OUT_DIR"),
45+
"/ebpf_target/bpfel-unknown-none/release/frame-analyzer-ebpf"
46+
)))?;
4547

4648
Ok(bpf)
4749
}

frame-analyzer/src/lib.rs

+41-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,48 @@
1616
* You should have received a copy of the GNU General Public License
1717
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
*/
19-
#![deny(clippy::all, clippy::pedantic)]
20-
#![warn(clippy::nursery)]
19+
#![warn(clippy::nursery, clippy::all, clippy::pedantic)]
2120
#![allow(clippy::module_name_repetitions)]
21+
//! # frame-analyzer
22+
//!
23+
//! - This crate is used to monitor the frametime of the target app on the android device
24+
//! - Based on the EBPF and UPROBE implementations, you may need higher privileges (e.g. root) to use this crate properly
25+
//! - This IS NOT a bin crate, it uses some tricks (see [source](https://github.com/shadow3aaa/frame-analyzer-ebpf?tab=readme-ov-file)) to get it to work like a normal lib crate, even though it includes an EBPF program
26+
//!
27+
//! # Examples
28+
//!
29+
//! ```should_panic
30+
//! # use std::sync::{
31+
//! # atomic::{AtomicBool, Ordering},
32+
//! # Arc,
33+
//! # };
34+
//!
35+
//! # use frame_analyzer::Analyzer;
36+
//!
37+
//! # fn main() -> anyhow::Result<()> {
38+
//! # let app_pid = 1;
39+
//! let pid = app_pid;
40+
//! let mut analyzer = Analyzer::new()?;
41+
//! analyzer.attach_app(pid)?;
42+
//!
43+
//! let running = Arc::new(AtomicBool::new(true));
44+
//!
45+
//! {
46+
//! let running = running.clone();
47+
//! ctrlc::set_handler(move || {
48+
//! running.store(false, Ordering::Release);
49+
//! })?;
50+
//! }
51+
//!
52+
//! while running.load(Ordering::Acquire) {
53+
//! if let Some((pid, frametime)) = analyzer.recv() {
54+
//! println!("process: {pid}, frametime: {frametime:?}");
55+
//! }
56+
//! }
57+
//!
58+
//! # Ok(())
59+
//! }
60+
//! ```
2261
mod analyze_target;
2362
mod ebpf;
2463
mod error;

0 commit comments

Comments
 (0)