Skip to content

Commit

Permalink
add examples to instrument RustyHermit applications
Browse files Browse the repository at this point in the history
  • Loading branch information
stlankes committed Jan 31, 2021
1 parent 535454b commit 40276a0
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 3 deletions.
8 changes: 6 additions & 2 deletions examples/demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,24 @@ default-features = false
[target.'cfg(target_os = "linux")'.dependencies]
syscalls = { version = "0.2", default-features = false }

[dependencies.rftrace-frontend]
version = "0.1.0"
optional = true

[features]
default = ["pci", "acpi", "smp"]
vga = ["hermit-sys/vga"]
pci = ["hermit-sys/pci"]
acpi = ["hermit-sys/acpi"]
fsgsbase = ["hermit-sys/fsgsbase"]
smp = ["hermit-sys/smp"]
instrument = ["hermit-sys/instrument"]
instrument = ["hermit-sys/instrument", "rftrace-frontend"]

[profile.release]
opt-level = 3
debug = false
rpath = false
lto = true
lto = false
debug-assertions = false

[profile.dev]
Expand Down
13 changes: 13 additions & 0 deletions examples/demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@
extern crate hermit_sys;
extern crate num_cpus;
extern crate rayon;
#[cfg(feature = "instrument")]
extern crate rftrace_frontend;
#[cfg(target_os = "linux")]
#[macro_use]
extern crate syscalls;

mod tests;

#[cfg(feature = "instrument")]
use rftrace_frontend::Events;
use tests::*;

fn test_result<T>(result: Result<(), T>) -> &'static str {
Expand All @@ -29,6 +33,11 @@ fn test_result<T>(result: Result<(), T>) -> &'static str {
}

fn main() {
#[cfg(feature = "instrument")]
let events = rftrace_frontend::init(1000000, true);
#[cfg(feature = "instrument")]
rftrace_frontend::enable();

println!("Test {} ... {}", stringify!(hello), test_result(hello()));
println!(
"Test {} ... {}",
Expand Down Expand Up @@ -85,4 +94,8 @@ fn main() {
stringify!(thread_creation),
test_result(thread_creation())
);

#[cfg(feature = "instrument")]
rftrace_frontend::dump_full_uftrace(events, "trace", "rusty_demo", false)
.expect("Saving trace failed");
}
13 changes: 13 additions & 0 deletions examples/demo/src/matrix_multiplication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@
extern crate hermit_sys;
extern crate num_cpus;
extern crate rayon;
#[cfg(feature = "instrument")]
extern crate rftrace_frontend;
#[cfg(target_os = "linux")]
#[macro_use]
extern crate syscalls;

mod tests;

#[cfg(feature = "instrument")]
use rftrace_frontend::Events;
use tests::*;

fn test_result<T>(result: Result<(), T>) -> &'static str {
Expand All @@ -29,9 +33,18 @@ fn test_result<T>(result: Result<(), T>) -> &'static str {
}

fn main() {
#[cfg(feature = "instrument")]
let events = rftrace_frontend::init(1000000, true);
#[cfg(feature = "instrument")]
rftrace_frontend::enable();

println!(
"Test {} ... {}",
stringify!(test_matmul_strassen),
test_result(test_matmul_strassen())
);

#[cfg(feature = "instrument")]
rftrace_frontend::dump_full_uftrace(events, "trace", "matrix_multiplcation", false)
.expect("Saving trace failed");
}
13 changes: 13 additions & 0 deletions examples/demo/src/pi_sequential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@

#[cfg(target_os = "hermit")]
extern crate hermit_sys;
#[cfg(feature = "instrument")]
extern crate rftrace_frontend;
#[cfg(target_os = "linux")]
#[macro_use]
extern crate syscalls;

mod tests;

#[cfg(feature = "instrument")]
use rftrace_frontend::Events;
use tests::*;

fn test_result<T>(result: Result<(), T>) -> &'static str {
Expand All @@ -27,9 +31,18 @@ fn test_result<T>(result: Result<(), T>) -> &'static str {
}

fn main() {
#[cfg(feature = "instrument")]
let events = rftrace_frontend::init(1000000, true);
#[cfg(feature = "instrument")]
rftrace_frontend::enable();

println!(
"Test {} ... {}",
stringify!(pi_sequential),
test_result(pi_sequential(5000000))
);

#[cfg(feature = "instrument")]
rftrace_frontend::dump_full_uftrace(events, "trace", "pi_sequential", false)
.expect("Saving trace failed");
}
6 changes: 5 additions & 1 deletion examples/hello_world/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ path = "../../hermit-sys"
default-features = false
features = ["with_submodule"]

[dependencies.rftrace-frontend]
version = "0.1.0"
optional = true

[features]
default = ["pci", "acpi"]
vga = ["hermit-sys/vga"]
pci = ["hermit-sys/pci"]
acpi = ["hermit-sys/acpi"]
fsgsbase = ["hermit-sys/fsgsbase"]
smp = ["hermit-sys/smp"]
instrument = ["hermit-sys/instrument"]
instrument = ["hermit-sys/instrument", "rftrace-frontend"]

[profile.release]
opt-level = 3
Expand Down
11 changes: 11 additions & 0 deletions examples/hello_world/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@

#[cfg(target_os = "hermit")]
extern crate hermit_sys;
#[cfg(feature = "instrument")]
extern crate rftrace_frontend;

fn main() {
#[cfg(feature = "instrument")]
let events = rftrace_frontend::init(1000000, true);
#[cfg(feature = "instrument")]
rftrace_frontend::enable();

println!("Hello World!");

#[cfg(feature = "instrument")]
rftrace_frontend::dump_full_uftrace(events, "trace", "hello_world", true)
.expect("Saving trace failed");
}

0 comments on commit 40276a0

Please sign in to comment.