Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devel/timing diagnostic #7

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Important security discovery, performance profiling
  • Loading branch information
meltyness committed Oct 17, 2024
commit becb1f52f92079db93e81571dac7af3cda60fb61
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ incremental = true
md5 = "0.7.0"
precis-profiles = "0.1.11"
ctrlc = "3.4.5"
libc = "0.2"

[lints.rust]
non_camel_case_types = "allow"
Expand Down
31 changes: 30 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// (C) 2024 - T.J. Hampton
//

use libc::{mlockall, madvise, MCL_CURRENT, MCL_FUTURE, MCL_ONFAULT, MADV_WILLNEED};

use std::env;
use std::process::exit;
use std::process::Command;
Expand Down Expand Up @@ -46,14 +48,26 @@ struct RTKnownClient {

}

fn prefetch_memory_region(start_addr: *const u8, length: usize) {
let result = unsafe { madvise(start_addr as *mut _, length, MADV_WILLNEED) };

if result != 0 {
eprintln!("madvise failed");
} else {
println!("Memory region prefetched successfully");
}
}

static mut runs: f64 = 0.0;
static mut running_avg: f64 = 0.0;
static mut first_run: Option<Instant> = None;

/// # Panics
///
/// Panics if the server cannot open on the specified hostaddr
///
pub fn main() {

let mut server_settings = RTServerSettings::new(65535,
true,
"cat /dev/null",
Expand Down Expand Up @@ -112,14 +126,29 @@ pub fn main() {
unsafe {
ctrlc::set_handler(move || {
println!("Ratchet Debug: Average processing time over {} runs: {:#?}", rt_get_runs(), Duration::from_secs_f64(rt_get_avg() / rt_get_runs()));
println!("Ratchet Debug: total rate: {} runs / sec", runs / (Instant::now() - first_run.unwrap()).as_secs_f64());
exit(0);
})
.expect("Error setting Ctrl-C handler");
}

let result = unsafe { mlockall(MCL_CURRENT | MCL_FUTURE | MCL_ONFAULT) };
if result != 0 {
eprintln!("mlockall failed with error code: {}", result);
} else {
println!("mlockall succeeded");
}

for stream in listener.incoming() {
let start_time = Instant::now();
unsafe { runs = runs + 1.0;}
unsafe { runs = runs + 1.0;
match first_run {
Some(_) => (),
None => {
first_run = Some(start_time.clone())
},
}
}

// Stage 0: Check that this is a valid stream, produce some logs about the event.
let mut stream = match stream {
Expand Down
2 changes: 1 addition & 1 deletion tests/resources/hammerit.pl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


if ($tac->authen($username_to_use, $password_to_use, 2)) {
print "Success!\n" if rand(1000) > 995;
print "Success!\n" if rand(1000) > 900;
$tac->close();
#exit;
} else {
Expand Down