Crates.io | compiler-interrupts |
lib.rs | compiler-interrupts |
version | 1.0.1 |
source | src |
created_at | 2021-07-24 05:04:02.222344 |
updated_at | 2021-07-31 06:20:35.779898 |
description | Compiler Interrupts API for Rust |
homepage | https://github.com/bitslab/compiler-interrupts-rs |
repository | https://github.com/bitslab/compiler-interrupts-rs |
max_upload_size | |
id | 426642 |
size | 31,350 |
compiler-interrupts
provides Rust API for the Compiler Interrupts library.
Check out the Compiler Interrupts main repository for more info.
#[thread_local]
unstable feature,
this package currently requires nightly Rust.Add this to your Cargo.toml
.
[dependencies]
compiler-interrupts = "1.0"
Register the Compiler Interrupts handler in your program.
#![feature(thread_local)]
#[thread_local]
#[allow(non_upper_case_globals)]
static mut prev_ic: i64 = 0;
fn interrupt_handler(ic: i64) {
let interval;
unsafe {
// save the last interval
interval = ic - prev_ic;
// update the instruction count
prev_ic = ic;
}
if interval < 0 {
panic!("IR interval was negative")
}
println!(
"CI @ {}: last interval = {} IR",
std::thread::current().name().expect("invalid thread name"),
interval
);
}
fn main() {
// register the CI handler for 1000 IR and cycles interval
unsafe {
compiler_interrupts::register(1000, 1000, interrupt_handler);
}
// do something compute-intensive
for _ in 0..100 {}
println!("i can add an unsafe block, right?")
}
If you have cargo-compiler-interrupts
installed,
you can now run cargo build-ci
to start the compilation and integration.
Check out the documentation for more info about the API.
All issue reports, feature requests, pull requests and GitHub stars are welcomed and much appreciated.
Quan Tran (@quanshousio)
compiler-interrupts
is available under the MIT license.
See the LICENSE file for more info.