#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum CallgrindClientRequest
{
#[doc(hidden)]
DumpStatistics,
#[doc(hidden)]
ZeroStatistics,
ToggleCollection,
#[doc(hidden)]
DumpStatisticsAt
{
profile_dump_c_string: *const c_char,
},
#[doc(hidden)]
StartInstrumentation,
#[doc(hidden)]
StopInstrumentation,
}
impl CallgrindClientRequest
{
#[inline(always)]
pub fn now(self) -> u64
{
use self::CallgrindClientRequest::*;
const Base: u64 = ((b'C' as u64) << 24) + ((b'T' as u64) << 16);
let (typeValue, firstArgument) = match self
{
DumpStatistics => (Base, 0),
ZeroStatistics => (Base + 1, 0),
ToggleCollection => (Base + 2, 0),
DumpStatisticsAt { profile_dump_c_string } => (Base + 3, profile_dump_c_string as usize as u64),
StartInstrumentation => (Base + 4, 0),
StopInstrumentation => (Base + 5, 0),
};
unsafe
{
do_client_request(0, &[typeValue, firstArgument, 0, 0, 0, 0])
}
}
#[inline(always)]
pub fn start()
{
use self::CallgrindClientRequest::*;
ZeroStatistics.now();
StartInstrumentation.now();
}
#[inline(always)]
pub fn stop(name: Option<&str>)
{
use self::CallgrindClientRequest::*;
StopInstrumentation.now();
if let Some(name) = name
{
let name = CString::new(name).unwrap();
Self::dump_statistics(name.as_ptr());
}
else
{
DumpStatistics.now();
}
}
#[inline(always)]
fn dump_statistics(profile_dump_c_string: *const c_char)
{
CallgrindClientRequest::DumpStatisticsAt
{
profile_dump_c_string
}.now();
}
}