From ba021c8f932a18430b36d931f333a27c2ec38db1 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sun, 11 Sep 2022 11:37:26 -0400 Subject: [PATCH] Fix wake detection, add more debug logging --- README.md | 2 +- backend/Cargo.lock | 2 +- backend/Cargo.toml | 2 +- backend/build.sh | 8 ++++---- backend/src/resume_worker.rs | 5 ++++- backend/src/settings/general.rs | 8 ++++++-- package.json | 2 +- 7 files changed, 18 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 6769603..1baa6d6 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ You will need that installed for this plugin to work. - Set GPU frequencies and power (fastPPT & slowPPT) - Cap battery charge rate (when awake) - Display supplementary battery info -- Keep settings between restarts (stored in `~/.config/powertools/.json`) +- Keep settings between restarts (stored in `~/.config/powertools/.json`) ## Install diff --git a/backend/Cargo.lock b/backend/Cargo.lock index ae33d44..718fc0a 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -567,7 +567,7 @@ dependencies = [ [[package]] name = "powertools-rs" -version = "1.0.1" +version = "1.0.3" dependencies = [ "log", "serde", diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 8775574..1fda63f 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "powertools-rs" -version = "1.0.2" +version = "1.0.3" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/backend/build.sh b/backend/build.sh index f2fab87..94cd216 100755 --- a/backend/build.sh +++ b/backend/build.sh @@ -1,10 +1,10 @@ #!/bin/bash -cargo build --release --target x86_64-unknown-linux-musl -#cargo build --target x86_64-unknown-linux-musl +#cargo build --release --target x86_64-unknown-linux-musl +cargo build --target x86_64-unknown-linux-musl #cross build --release mkdir -p ../bin -cp ./target/x86_64-unknown-linux-musl/release/powertools-rs ../bin/backend -#cp ./target/x86_64-unknown-linux-musl/debug/powertools-rs ../bin/backend +#cp ./target/x86_64-unknown-linux-musl/release/powertools-rs ../bin/backend +cp ./target/x86_64-unknown-linux-musl/debug/powertools-rs ../bin/backend #cp ./target/release/powertools-rs ../bin/backend diff --git a/backend/src/resume_worker.rs b/backend/src/resume_worker.rs index b0eca6f..40bed26 100644 --- a/backend/src/resume_worker.rs +++ b/backend/src/resume_worker.rs @@ -12,17 +12,20 @@ pub fn spawn(settings: Settings) -> JoinHandle<()> { let duration = Duration::from_millis(5000); let mut start = Instant::now(); loop { - thread::sleep(duration); let old_start = start.elapsed(); start = Instant::now(); if old_start.as_secs_f64() > duration.as_secs_f64() * (1.0 + ALLOWED_ERROR) { // has just resumed from sleep + log::info!("Resume detected"); unwrap_maybe_fatal(settings.on_resume(), "On resume failure"); log::debug!( "OnResume completed after sleeping for {}s", old_start.as_secs_f32() ); + } else { + log::debug!("OnResume got sleep period of {}s", old_start.as_secs_f32()); } + thread::sleep(duration); } //log::warn!("resume_worker completed!"); }) diff --git a/backend/src/settings/general.rs b/backend/src/settings/general.rs index 8fe0975..96122d9 100644 --- a/backend/src/settings/general.rs +++ b/backend/src/settings/general.rs @@ -171,14 +171,18 @@ impl Settings { impl OnResume for Settings { fn on_resume(&self) -> Result<(), SettingError> { + log::debug!("Locking settings for on_resume"); unwrap_lock(self.battery.lock(), "battery").on_resume()?; + log::debug!("Got battery lock"); { - let mut cpu_lock = unwrap_lock(self.cpus.lock(), "cpu"); - for cpu in cpu_lock.iter_mut() { + let cpu_lock = unwrap_lock(self.cpus.lock(), "cpu"); + log::debug!("Got cpus lock"); + for cpu in cpu_lock.iter() { cpu.on_resume()?; } } unwrap_lock(self.gpu.lock(), "gpu").on_resume()?; + log::debug!("Got gpu lock"); Ok(()) } } diff --git a/package.json b/package.json index 88ea563..6ec7639 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "PowerTools", - "version": "1.0.2", + "version": "1.0.3", "description": "Power tweaks for power users", "scripts": { "build": "shx rm -rf dist && rollup -c",