Skip to content

Commit

Permalink
Merge pull request OptimatistOpenSource#19 from Thaumy/add-reset
Browse files Browse the repository at this point in the history
Introduce `reset` fn for sampling mode and tracing mode
  • Loading branch information
Thaumy authored Feb 3, 2024
2 parents bfc71b4 + 5d5dbc7 commit aac8ea5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/perf_event/sampling/group/fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ impl FixedSamplerGroup {
self.inner().disable()
}

pub fn reset(&self) -> io::Result<()> {
self.inner().reset()
}

pub fn next_record(&mut self, guard: &SamplerGuard) -> Option<Record> {
self.inner_mut().next_record(guard.event_id())
}
Expand Down
13 changes: 13 additions & 0 deletions src/perf_event/sampling/group/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ impl Inner {
)
}

pub fn reset(&self) -> io::Result<()> {
self.leader().map_or_else(
|| Err(io::Error::new(ErrorKind::Other, "Group has no members")),
|leader| {
ioctl_wrapped(
&leader.file,
PERF_EVENT_IOCTL_RESET,
Some(PERF_IOC_FLAG_GROUP),
)
},
)
}

pub fn next_record(&mut self, event_id: u64) -> Option<Record> {
self.members
.get_mut(&event_id)
Expand Down
4 changes: 4 additions & 0 deletions src/perf_event/sampling/single/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ impl Sampler {
ioctl_wrapped::<()>(&self.file, PERF_EVENT_IOCTL_DISABLE, None)
}

pub fn reset(&self) -> io::Result<()> {
ioctl_wrapped::<()>(&self.file, PERF_EVENT_IOCTL_RESET, None)
}

#[cfg(feature = "linux-4.7")]
pub fn pause(&self) -> io::Result<()> {
ioctl_wrapped(&self.file, PERF_EVENT_IOCTL_PAUSE_OUTPUT, Some(1i32))
Expand Down
4 changes: 4 additions & 0 deletions src/perf_event/tracing/tracer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ impl Tracer {
self.sampler.disable()
}

pub fn reset(&self) -> io::Result<()> {
self.sampler.reset()
}

#[cfg(feature = "linux-4.7")]
pub fn pause(&self) -> io::Result<()> {
self.sampler.pause()
Expand Down

0 comments on commit aac8ea5

Please sign in to comment.