Use cargo features to toggle profiler

This commit is contained in:
Fabian 2018-08-24 20:24:11 -05:00
parent 0680c1a2c4
commit 0cf700edee
3 changed files with 16 additions and 5 deletions

View file

@ -6,6 +6,10 @@ publish = false
[dev-dependencies]
quickcheck = "0.6.2"
[features]
default = []
profiler = []
[lib]
crate-type = ["cdylib"]
path = "src/rust/lib.rs"

View file

@ -109,11 +109,18 @@ pub unsafe fn profiler_stat_increment(mut stat: stat_name) -> () {
}
#[no_mangle]
pub unsafe fn profiler_stat_increment_by(mut stat: stat_name, mut by: i32) -> () {
profiler_stat_arr[stat as usize].count += by;
if cfg!(feature = "profiler") {
profiler_stat_arr[stat as usize].count += by;
}
}
#[no_mangle]
pub unsafe fn profiler_stat_get(mut stat: stat_name) -> i32 {
return profiler_stat_arr[stat as usize].count;
if cfg!(feature = "profiler") {
profiler_stat_arr[stat as usize].count
}
else {
0
}
}
#[no_mangle]
pub unsafe fn profiler_stat_increment_do_run() -> () { profiler_stat_increment(S_DO_RUN); }

View file

@ -49,15 +49,15 @@ pub enum stat {
S_TLB_GLOBAL_FULL,
}
#[cfg(debug_assertions)]
#[cfg(feature = "profiler")]
mod unsafe_extern {
extern "C" {
pub fn profiler_stat_increment(stat: ::profiler::stat);
}
}
#[cfg(debug_assertions)]
#[cfg(feature = "profiler")]
pub fn stat_increment(stat: stat) { unsafe { unsafe_extern::profiler_stat_increment(stat) } }
#[cfg(not(debug_assertions))]
#[cfg(not(feature = "profiler"))]
pub fn stat_increment(_stat: stat) {}