Skip to content

Commit

Permalink
Use cargo features to toggle profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
copy committed Aug 31, 2020
1 parent 0680c1a commit 0cf700e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ publish = false
[dev-dependencies]
quickcheck = "0.6.2"

[features]
default = []
profiler = []

[lib]
crate-type = ["cdylib"]
path = "src/rust/lib.rs"
Expand Down
11 changes: 9 additions & 2 deletions src/rust/cpu2/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
6 changes: 3 additions & 3 deletions src/rust/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

0 comments on commit 0cf700e

Please sign in to comment.