This repository has been archived by the owner on Jun 4, 2023. It is now read-only.
forked from bchalios/vaccel-bindings
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prof: add bindings for vAccel profiling
Expose a type that wraps `vaccel_prof_region` and let us use the vAccel API to profile regions of code. Signed-off-by: Babis Chalios <[email protected]>
- Loading branch information
Showing
5 changed files
with
179 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use crate::ffi; | ||
use crate::{Error, Result}; | ||
|
||
use std::ffi::CString; | ||
|
||
/// A vAccel profile region | ||
/// | ||
/// This describes a region in a vAccel application | ||
/// for which we can gather stats | ||
#[derive(Debug)] | ||
pub struct ProfRegion { | ||
inner: ffi::vaccel_prof_region, | ||
} | ||
|
||
impl ProfRegion { | ||
/// Create a new profile region | ||
/// | ||
/// This will allocate and initialize a profile region | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `name` - The name of the region | ||
pub fn new(name: &str) -> Result<Self> { | ||
let c_name = CString::new(name).map_err(|_| Error::InvalidArgument)?; | ||
|
||
let mut inner = ffi::vaccel_prof_region::default(); | ||
|
||
match unsafe { ffi::vaccel_prof_region_init(&mut inner, c_name.as_c_str().as_ptr()) as u32 } | ||
{ | ||
ffi::VACCEL_OK => Ok(ProfRegion { inner }), | ||
err => Err(Error::Runtime(err)), | ||
} | ||
} | ||
|
||
pub fn enter(&mut self) -> Result<()> { | ||
match unsafe { ffi::vaccel_prof_region_start(&mut self.inner) as u32 } { | ||
ffi::VACCEL_OK => Ok(()), | ||
err => Err(Error::Runtime(err)), | ||
} | ||
} | ||
|
||
pub fn exit(&mut self) -> Result<()> { | ||
match unsafe { ffi::vaccel_prof_region_stop(&mut self.inner) as u32 } { | ||
ffi::VACCEL_OK => Ok(()), | ||
err => Err(Error::Runtime(err)), | ||
} | ||
} | ||
|
||
pub fn print(&self) -> Result<()> { | ||
match unsafe { ffi::vaccel_prof_region_print(&self.inner) as u32 } { | ||
ffi::VACCEL_OK => Ok(()), | ||
err => Err(Error::Runtime(err)), | ||
} | ||
} | ||
} | ||
|
||
impl Drop for ProfRegion { | ||
fn drop(&mut self) { | ||
unsafe { ffi::vaccel_prof_region_destroy(&mut self.inner) }; | ||
} | ||
} |
Submodule vaccelrt
updated
from dd6506 to a31df3