Skip to content

Commit

Permalink
Add a get_fd() help for sampling to support for other uses.
Browse files Browse the repository at this point in the history
  • Loading branch information
BrytonLee committed Apr 11, 2024
1 parent 8f4d85f commit f5c5b8c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/perf_event/sampling/single/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::syscall::{ioctl_wrapped, perf_event_open_wrapped};
use memmap2::{MmapMut, MmapOptions};
use std::fs::File;
use std::io;
use std::os::fd::FromRawFd;
use std::os::fd::{AsRawFd, FromRawFd};

use crate::config::{Cpu, Error, Process};
use crate::sampling::single::stat::sampler_stat;
Expand Down Expand Up @@ -145,4 +145,10 @@ impl Sampler {
pub fn stat(&mut self) -> io::Result<SamplerStat> {
sampler_stat(self)
}

/// Returns the underlying perf event fd for other uses.
/// For example attach a eBPF program to this event.
pub fn get_fd(&self) -> i32 {
self.file.as_raw_fd()
}
}

0 comments on commit f5c5b8c

Please sign in to comment.