added performance stats
This commit is contained in:
parent
b72be28ad0
commit
6a29e28106
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "irradiate"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
authors = ["ultraviolet"]
|
||||
edition = "2018"
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Irradiate v0.1
|
||||
# Irradiate v0.2
|
||||
#### Evelene Ultraviolet
|
||||
#### July 2019
|
||||
#### AGPL v3
|
||||
|
@ -62,3 +62,9 @@ resemblance they bear to the originals considered as a happy accident.
|
|||
|
||||
All this being said: if you ever *do* run Irradiate on some important system of device file and something funny
|
||||
or cool happens... let us know, yeah?
|
||||
|
||||
---
|
||||
|
||||
### Changelog
|
||||
**2019 July 1**: Initial commit in working form
|
||||
**2019 July 7**: Added timing stats
|
||||
|
|
30
src/main.rs
30
src/main.rs
|
@ -1,11 +1,15 @@
|
|||
// Irradiate, a program to introduce randomly distributed noise into files
|
||||
// Irradiate v0.2
|
||||
// Evelene Ultraviolet
|
||||
// Ellie Photodiode
|
||||
// Ariane Mechanism
|
||||
// Amelia Rainfall
|
||||
// July 2019
|
||||
|
||||
use std::io::prelude::*;
|
||||
use std::io::stdout;
|
||||
use std::io::SeekFrom;
|
||||
use std::fs::OpenOptions;
|
||||
use std::time::{Duration,Instant};
|
||||
use std::process::exit;
|
||||
|
||||
extern crate rand;
|
||||
|
@ -30,8 +34,9 @@ fn flip_bit(byte:&mut u8, index:usize) {
|
|||
|
||||
fn main() {
|
||||
let args = lapp::parse_args("
|
||||
Irradiate file corruptor v0.2
|
||||
<filename> (string) name of file on which to operate
|
||||
-n, --count (default 100) integer number of bits to affect in the file
|
||||
-n, --count (default 10) integer number of bits to affect in the file
|
||||
-0, --zero never set affected bits to 1, only set them to 0.
|
||||
-1, --one never set affected bits to 0, only set them to 1.
|
||||
-f, --flip invert affected bits, ensuring that the file contains an exact number of errors
|
||||
|
@ -95,10 +100,19 @@ fn main() {
|
|||
},
|
||||
};
|
||||
|
||||
let mut total_seektime:Duration = Duration::new(0,0);
|
||||
let mut total_readtime:Duration = Duration::new(0,0);
|
||||
let mut total_writtime:Duration = Duration::new(0,0);
|
||||
|
||||
let mut seekstart:Instant;
|
||||
let mut readstart:Instant;
|
||||
let mut writstart:Instant;
|
||||
|
||||
print!("\rirradiating [ 0%]");
|
||||
for rep in 0..reps {
|
||||
// go to a randomly-selected location, between the holdoff position and the file end.
|
||||
let position = rng.gen_range(holdoff, infile_len);
|
||||
seekstart = Instant::now();
|
||||
match infile.seek(SeekFrom::Start(position)) {
|
||||
Ok(_) => (),
|
||||
Err(why) => {
|
||||
|
@ -106,7 +120,9 @@ fn main() {
|
|||
exit(1);
|
||||
},
|
||||
};
|
||||
total_seektime += seekstart.elapsed();
|
||||
// read data into the buffer
|
||||
readstart = Instant::now();
|
||||
match infile.read(&mut buffer) {
|
||||
Ok(n) => match n {
|
||||
0 => break,
|
||||
|
@ -117,7 +133,9 @@ fn main() {
|
|||
exit(1);
|
||||
},
|
||||
};
|
||||
total_readtime += readstart.elapsed();
|
||||
// go back to the same position from which we read the data
|
||||
seekstart = Instant::now();
|
||||
match infile.seek(SeekFrom::Start(position)) {
|
||||
Ok(_) => (),
|
||||
Err(why) => {
|
||||
|
@ -125,6 +143,7 @@ fn main() {
|
|||
exit(1);
|
||||
},
|
||||
};
|
||||
total_seektime += seekstart.elapsed();
|
||||
// set a random bit of this byte
|
||||
let bit = rng.gen_range(0,8);
|
||||
if one_only {
|
||||
|
@ -137,6 +156,7 @@ fn main() {
|
|||
set_bit(&mut buffer[0], bit, rng.gen::<bool>());
|
||||
}
|
||||
// write the modified data back to the file
|
||||
writstart = Instant::now();
|
||||
match infile.write_all(&buffer) {
|
||||
Ok(_) => (),
|
||||
Err(why) => {
|
||||
|
@ -144,6 +164,8 @@ fn main() {
|
|||
exit(1);
|
||||
},
|
||||
};
|
||||
let _ = infile.flush();
|
||||
total_writtime += writstart.elapsed();
|
||||
// update the progress meter
|
||||
while milestones[current_milestone] <= rep && current_milestone < 98 {
|
||||
print!("\rirradiating [{:3}%]", current_milestone);
|
||||
|
@ -154,4 +176,8 @@ fn main() {
|
|||
}
|
||||
print!("\rirradiating [100%]");
|
||||
println!();
|
||||
println!("irradiating done.");
|
||||
println!("time seeking: {} s", (total_seektime.as_micros() as f32)/1000000.0);
|
||||
println!("time reading: {} s", (total_readtime.as_micros() as f32)/1000000.0);
|
||||
println!("time writing: {} s", (total_writtime.as_micros() as f32)/1000000.0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue