Skip to content

Commit

Permalink
2.0.1
Browse files Browse the repository at this point in the history
- Added actual versioning,
- Fixed issue where M1 Macbooks wouldn't run the GPU code (may have fixed other GPU 
- Added hours to the count down and count up timers,
- Added sequential ordering back
- Adding versioning to Cargo.toml
  • Loading branch information
day-mon authored Feb 6, 2023
2 parents 7bc4836 + 68bcc03 commit bacb263
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[package]
name = "easy-stress-rs"
version = "0.1.0"
version = "2.0.1"
authors = ["Damon Montague Jr"]
repository = "https://github.com/day-mon/easy-stress-rs"
edition = "2021"

[dependencies]
Expand Down
13 changes: 6 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ mod prompt;

use std::io::{stdout, Write};
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize};
use std::sync::atomic::Ordering::Relaxed;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::{panic, thread};
use std::any::Any;
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -102,8 +101,8 @@ fn main() -> InquireResult<()> {
true => CustomType::<u16>::new("How long would you like the stress test to last? (in minutes)")
.with_default(1)
.with_validator(prompt::duration_validator)
.with_help_message("Type in a number between 1 -> 65536")
.with_error_message("This number is too big. Number has to be in the range 1 -> 65536.")
.with_help_message("Type in a number between 1 -> 65535")
.with_error_message("This number is too big. Number has to be in the range 1 -> 65535.")
.prompt()
.ok(),
false => None
Expand Down Expand Up @@ -315,7 +314,7 @@ fn do_cpu_work(
{
// for the stressor functions check the asm
let mut iterations: u64 = 0;
while thread_running.load(Relaxed) == 0
while thread_running.load(Ordering::SeqCst) == 0
{
function();
iterations += 1;
Expand All @@ -334,11 +333,11 @@ fn do_cpu_work(
atomic_bool,
);

let stop_reason = match running.load(Relaxed) {
let stop_reason = match running.load(Ordering::SeqCst) {
1 => "Time Limit exceeded",
2 => "Temperature exceeded",
3 => "Ctrl-C caught",
_ => panic!("This should have never happened. {} is not a valid option", running.load(Relaxed))
_ => panic!("This should have never happened. {} is not a valid option", running.load(Ordering::SeqCst))
}.to_string();

let mut total_iterations = 0;
Expand Down
38 changes: 21 additions & 17 deletions src/reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use crate::sensors;

pub const CARRIAGE_RETURN: char = '\r';

pub struct BackgroundReport {
pub struct BackgroundReport
{
pub average_cpu_temp: Option<f32>,
pub min_cpu_temp: Option<f32>,
pub max_cpu_temp: Option<f32>,
Expand All @@ -27,7 +28,7 @@ pub fn watch_in_background(
let mut max_cpu_temp = 0f32;


while running.load(Ordering::Relaxed) == 0 {
while running.load(Ordering::SeqCst) == 0 {

let temp = sensors::cpu_temp(system, true);

Expand All @@ -46,15 +47,15 @@ pub fn watch_in_background(

if let Some(stop_temp) = stop_temperature {
if temp > stop_temp as f32 {
running.store(2, Ordering::Relaxed)
running.store(2, Ordering::SeqCst)
}
}
}


if let Some(duration) = duration {
if start_time.elapsed() > duration {
running.store(1, Ordering::Relaxed)
running.store(1, Ordering::SeqCst)
}
}

Expand Down Expand Up @@ -83,26 +84,29 @@ pub fn prettify_output(
None => start_time.elapsed().as_secs(),
};

let time_string = if time_left > 60 {
format!(
let time_string = match time_left {
time if time > 3600 => format!(
"🕛: {}h {}m {}s",
time / 3600,
(time % 3600) / 60,
time % 60
),
time if time > 60 => format!(
"🕛: {}m {}s",
time_left / 60,
time_left % 60
)
} else {
format!("🕛: {time_left}s")
time / 60,
time % 60
),
time => format!("🕛: {time}s"),
};

display_string.push_str(time_string.as_str());

if let Some(temp) = current_temp {
display_string.push_str(" 🌡️: ");
let temp_text = if temp > 80.0 {
format!("{temp}°C").red().to_string()
} else if temp > 60.0 {
format!("{temp}°C").yellow().to_string()
} else {
format!("{temp}°C").green().to_string()
let temp_text = match temp {
temp if temp > 80.0 => format!("{temp}°C").red().to_string(),
temp if temp > 60.0 => format!("{temp}°C").yellow().to_string(),
_ => format!("{temp}°C").green().to_string(),
};
display_string.push_str(temp_text.as_str());
}
Expand Down
16 changes: 13 additions & 3 deletions src/stressors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::{Display, Formatter};
use ocl::{Platform, Device, Context, Queue, Program, Kernel, Buffer};
use ocl::core::{DeviceInfo, DeviceInfoResult};

use ocl::{Buffer, Context, Device, Kernel, Platform, Program, Queue};
use ocl::core::{DeviceInfo, DeviceInfoResult};

#[derive(Clone, Eq, PartialEq)]
pub enum Stressor {
Expand Down Expand Up @@ -311,12 +311,22 @@ impl OpenCLProgram {
Ok(OpenCLProgram { program, kernel, wg_size })
}

pub fn run(&self) -> ocl::Result<()> {
pub fn run(&self) -> Result<(), String> {
unsafe {
self.kernel
.cmd()
.global_work_size((self.wg_size[0], self.wg_size[1], self.wg_size[2]))
.enq()
}.map_err(|e| e.to_string())?;


match self.kernel.default_queue() {
Some(queue) => {
queue.flush().map_err(|e| e.to_string())?;
Ok(())
},
None => Err("No default queue".to_string()),
}

}
}

0 comments on commit bacb263

Please sign in to comment.