Skip to content

Commit

Permalink
Cargo fomat
Browse files Browse the repository at this point in the history
  • Loading branch information
Camerooooon committed May 29, 2022
1 parent 83fdc05 commit b3d4eeb
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/daemon.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::convert::TryInto;
use std::time::SystemTime;
use std::{thread, time};
use std::time::{SystemTime};

use colored::*;
use nix::unistd::Uid;
Expand Down Expand Up @@ -51,7 +51,7 @@ pub trait Checker {
// High Temperature Rule
fn start_high_temperature_rule(&mut self) -> Result<(), Error>;
fn end_high_temperature_rule(&mut self) -> Result<(), Error>;

// High CPU Usage Rule
fn start_cpu_usage_rule(&mut self) -> Result<(), Error>;
fn end_cpu_usage_rule(&mut self) -> Result<(), Error>;
Expand Down Expand Up @@ -163,7 +163,7 @@ fn print_turbo_status(cores: usize, no_animation: bool, term_width: usize, delay
Err(e) => eprintln!("Could not check turbo\n{:?}", e),
}
}

fn calculate_average_usage(cpus: &Vec<CPU>) -> Result<f32, Error> {
let mut sum = 0.0;
for cpu in cpus {
Expand Down Expand Up @@ -215,7 +215,6 @@ impl Checker for Daemon {
}

fn end_charging_rule(&mut self) -> Result<(), Error> {

if !self.charging && self.already_charging {
self.logger.log(
"Governor set to powersave because battery is not charging",
Expand All @@ -228,7 +227,10 @@ impl Checker for Daemon {
}

fn start_high_temperature_rule(&mut self) -> Result<(), Error> {
if !self.already_high_temp && !self.already_high_usage && self.temp_max > self.config.overheat_threshold {
if !self.already_high_temp
&& !self.already_high_usage
&& self.temp_max > self.config.overheat_threshold
{
self.logger.log(
"Governor set to powersave because CPU temperature is high",
logger::Severity::Log,
Expand Down Expand Up @@ -300,7 +302,6 @@ impl Checker for Daemon {
}
Ok(())
}


fn start_cpu_usage_rule(&mut self) -> Result<(), Error> {
if self.usage > 70.0 && self.last_below_cpu_usage_percent.is_none() {
Expand All @@ -309,7 +310,9 @@ impl Checker for Daemon {

match self.last_below_cpu_usage_percent {
Some(last) => {
if SystemTime::now().duration_since(last)?.as_secs() >= 15 && !self.already_high_usage {
if SystemTime::now().duration_since(last)?.as_secs() >= 15
&& !self.already_high_usage
{
self.logger.log(
&format!(
"Governor set to performance because cpu was over 70% overall usage for longer than 15 seconds",
Expand All @@ -318,20 +321,18 @@ impl Checker for Daemon {
);
self.already_high_usage = true;
}
},
None => {},
}
None => {}
}
Ok(())
}

fn end_cpu_usage_rule(&mut self) -> Result<(), Error> {
if self.usage < 70.0 && self.last_below_cpu_usage_percent.is_some() {
self.last_below_cpu_usage_percent = None;
self.already_high_usage = false;
self.logger.log(
&format!(
"Governor returning to default because usage dropped below 70%",
),
&format!("Governor returning to default because usage dropped below 70%",),
logger::Severity::Log,
);
}
Expand Down

0 comments on commit b3d4eeb

Please sign in to comment.