[−][src]Struct perf_event::Counter
A counter for one kind of kernel or hardware event.
A Counter
represents a single performance monitoring counter. You select
what sort of event you'd like to count when the Counter
is created, then
you can enable and disable the counter, call its read
method to
retrieve the current count, and reset it to zero.
A Counter
's value is always a u64
.
For example, this counts the number of instructions retired (completed)
during a call to println!
.
use perf_event::Builder; fn main() -> std::io::Result<()> { let mut counter = Builder::new().build()?; let vec = (0..=51).collect::<Vec<_>>(); counter.enable()?; println!("{:?}", vec); counter.disable()?; println!("{} instructions retired", counter.read()?); Ok(()) }
It is often useful to count several different quantities over the same
period of time. For example, if you want to measure the average number of
clock cycles used per instruction, you must count both clock cycles and
instructions retired, for the same range of execution. The Group
type
lets you enable, disable, read, and reset any number of counters
simultaneously.
When a counter is dropped, its kernel resources are freed along with it.
Implementations
impl Counter
[src]
pub fn id(&self) -> u64
[src]
Return this counter's kernel-assigned unique id.
This can be useful when iterating over Counts
.
pub fn enable(&mut self) -> Result<()>
[src]
Allow this Counter
to begin counting its designated event.
This does not affect whatever value the Counter
had previously; new
events add to the current count. To clear a Counter
, use the
reset
method.
Note that Group
also has an enable
method, which enables all
its member Counter
s as a single atomic operation.
pub fn disable(&mut self) -> Result<()>
[src]
Make this Counter
stop counting its designated event. Its count is
unaffected.
Note that Group
also has a disable
method, which disables all
its member Counter
s as a single atomic operation.
pub fn reset(&mut self) -> Result<()>
[src]
Reset the value of this Counter
to zero.
Note that Group
also has a reset
method, which resets all
its member Counter
s as a single atomic operation.
pub fn read(&mut self) -> Result<u64>
[src]
Return this Counter
's current value as a u64
.
Note that Group
also has a read
method, which reads all
its member Counter
s' values at once.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Counter
impl Send for Counter
impl Sync for Counter
impl Unpin for Counter
impl UnwindSafe for Counter
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,