mirror of
https://github.com/Zenithsiz/ftmemsim.git
synced 2026-02-03 17:52:16 +00:00
Added example random-rw to generate traces.
This commit is contained in:
parent
2f621c7a1c
commit
39e30d0b4a
28
Cargo.lock
generated
28
Cargo.lock
generated
@ -718,6 +718,12 @@ version = "0.3.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.57"
|
||||
@ -742,6 +748,18 @@ version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
@ -750,6 +768,16 @@ name = "rand_core"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "random-rw"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
|
||||
@ -8,6 +8,7 @@ members = [
|
||||
"ftmemsim-graphs",
|
||||
"util/parse-lackey",
|
||||
"examples/simple-rw",
|
||||
"examples/random-rw",
|
||||
]
|
||||
|
||||
[workspace.dependencies]
|
||||
@ -26,6 +27,7 @@ bincode = "2.0.0-rc.3"
|
||||
gzp = "0.11.3"
|
||||
gnuplot = "0.0.38"
|
||||
palette = "0.7.2"
|
||||
rand = "0.8.5"
|
||||
|
||||
# Workspace members
|
||||
ftmemsim = { path = "ftmemsim" }
|
||||
|
||||
8
examples/random-rw/Cargo.toml
Normal file
8
examples/random-rw/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "random-rw"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
rand = { workspace = true }
|
||||
25
examples/random-rw/run.sh
Executable file
25
examples/random-rw/run.sh
Executable file
@ -0,0 +1,25 @@
|
||||
#!/bin/env bash
|
||||
|
||||
# Prepare the `lackey` parser
|
||||
# Note: We always compile the `lackey` parser in release, as it might be too slow otherwise
|
||||
cargo build --manifest-path "../../Cargo.toml" --release --package "parse-lackey"
|
||||
parse_lackey="../../target/release/parse-lackey"
|
||||
|
||||
|
||||
# Profile to run the example
|
||||
#PROFILE="dev"
|
||||
#PROFILE_PATH="debug"
|
||||
PROFILE="release"
|
||||
PROFILE_PATH="release"
|
||||
|
||||
# Compile the example
|
||||
cargo build --profile "$PROFILE"
|
||||
|
||||
# Then run valgrind on the example and pipe it to the `lackey` parser
|
||||
valgrind \
|
||||
--tool=lackey \
|
||||
--trace-mem=yes \
|
||||
--log-fd=1 \
|
||||
"../../target/$PROFILE_PATH/random-rw" \
|
||||
|
|
||||
$parse_lackey
|
||||
47
examples/random-rw/src/main.rs
Normal file
47
examples/random-rw/src/main.rs
Normal file
@ -0,0 +1,47 @@
|
||||
//! Random read-write test binary
|
||||
|
||||
// Imports
|
||||
use {
|
||||
rand::seq::SliceRandom,
|
||||
std::{hint, ptr},
|
||||
};
|
||||
|
||||
// TODO: Make these runtime constants?
|
||||
const PASSES: usize = 2;
|
||||
const WRITES_PER_PASS: usize = 100;
|
||||
const READS_PER_PASS: usize = 150;
|
||||
|
||||
fn main() {
|
||||
let mut v = vec![0u8; 128 * PAGE_SIZE];
|
||||
|
||||
// Note: We `step_by` the page size because we only care about initializing a single page.
|
||||
// TODO: Ensure we're not accidentally measuring creation of `v_{writes, reads}`. We unfortunately
|
||||
// cannot (easily) re-use the memory on each pass.
|
||||
for _ in 0..PASSES {
|
||||
let mut v_writes = v.iter_mut().step_by(PAGE_SIZE).collect::<Vec<_>>();
|
||||
v_writes.shuffle(&mut rand::thread_rng());
|
||||
for x in v_writes.drain(..) {
|
||||
for _ in 0..WRITES_PER_PASS {
|
||||
// SAFETY: Target is valid for writes.
|
||||
// Note: We simply want to avoid the write being elided
|
||||
unsafe {
|
||||
ptr::write_volatile(x, hint::black_box(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut v_reads = v.iter().step_by(PAGE_SIZE).collect::<Vec<_>>();
|
||||
v_reads.shuffle(&mut rand::thread_rng());
|
||||
for x in v_reads.drain(..) {
|
||||
for _ in 0..READS_PER_PASS {
|
||||
// SAFETY: Target is valid for reads.
|
||||
// Note: We simply want to avoid the write being elided
|
||||
unsafe {
|
||||
hint::black_box(ptr::read_volatile(x));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const PAGE_SIZE: usize = 4096;
|
||||
Loading…
x
Reference in New Issue
Block a user