Skip to content

Commit

Permalink
Merge pull request #552 from JakeRoggenbuck/benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeRoggenbuck authored Dec 26, 2023
2 parents 2882f36 + 10e2741 commit 211b947
Show file tree
Hide file tree
Showing 12 changed files with 783 additions and 258 deletions.
889 changes: 690 additions & 199 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "autoclockspeed"
version = "0.1.11"
version = "0.1.12"
edition = "2021"
license = "MIT OR MPL-2.0"
description = "A utility to check stats about your CPU, and auto regulate clock speeds to help with either performance or battery life."
Expand All @@ -27,6 +27,14 @@ rand = "0.8.5"
globset = "0.4"
time = { version = "0.3", features = ["local-offset", "formatting"]}

[dev-dependencies]
criterion = { version = "0.4", features = ["html_reports"] }

[[bin]]
name = "acs"
path = "src/main.rs"
path = "src/bin/main.rs"


[[bench]]
name = "system_benchmark"
harness = false
29 changes: 29 additions & 0 deletions benches/system_benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use autoclockspeed::{power, system};
use criterion::{black_box, criterion_group, criterion_main, Criterion};

pub fn check_cpu_name_benchmark(c: &mut Criterion) {
c.bench_function("check_cpu_name", |b| b.iter(|| system::check_cpu_name()));
}

pub fn check_available_governors_benchmark(c: &mut Criterion) {
c.bench_function("check_available_governors", |b| {
b.iter(|| system::check_available_governors())
});
}

pub fn list_cpus_benchmark(c: &mut Criterion) {
c.bench_function("list_cpus", |b| b.iter(|| system::list_cpus()));
}

pub fn set_best_path_benchmark(c: &mut Criterion) {
c.bench_function("set_best_path", |b| b.iter(|| power::set_best_path()));
}

criterion_group!(
benches,
check_cpu_name_benchmark,
check_available_governors_benchmark,
list_cpus_benchmark,
set_best_path_benchmark
);
criterion_main!(benches);
32 changes: 4 additions & 28 deletions src/main.rs → src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,15 @@

#![allow(clippy::uninlined_format_args)]

use args::parse_args;
use config::get_config;
use error::Error;
use log::debug;

pub mod args;
pub mod config;
pub mod cpu;
pub mod csv;
pub mod daemon;
pub mod display;
pub mod error;
pub mod gov;
pub mod graph;
pub mod interactive;
pub mod interface;
pub mod logger;
pub mod network;
pub mod power;
pub mod proc;
pub mod settings;
pub mod setup;
pub mod sysfs;
pub mod system;
pub mod terminal;
pub mod thermal;
use autoclockspeed::args::parse_args;
use autoclockspeed::config::get_config;

fn main() {
env_logger::init();

setup::setup();
autoclockspeed::setup::setup();

let config: config::Config = get_config();
let config: autoclockspeed::config::Config = get_config();

parse_args(config);
}
6 changes: 3 additions & 3 deletions src/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use std::path::Path;

use crate::proc::ProcStat;

use super::gov::Gov;
use super::system::{calculate_cpu_percent, read_int, read_str};
use super::Error;
use crate::error::Error;
use crate::gov::Gov;
use crate::system::{calculate_cpu_percent, read_int, read_str};

/// Any trait relating to a CPU Core
pub trait Speed {
Expand Down
36 changes: 18 additions & 18 deletions src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,27 @@ use efcl::{color, Color};
use nix::unistd::Uid;
use serde::Serialize;

use super::config::Config;
use super::cpu::{Speed, CPU};
use super::gov::Gov;
use super::graph::{Graph, GraphType, Grapher};
use super::logger;
use super::logger::Interface;
use super::network::{hook, listen};
use super::power::battery::{has_battery, Battery};
use super::power::lid::{Lid, LidRetriever, LidState};
use super::power::{Power, PowerRetriever};
use super::settings::Settings;
use super::setup::{inside_docker_message, inside_wsl_message};
use super::system::{
check_available_governors, check_cpu_freq, check_cpu_temperature, check_cpu_usage,
get_highest_temp, inside_docker, inside_wsl, list_cpus,
};
use super::terminal::terminal_width;
use super::Error;
use crate::config::Config;
use crate::cpu::{Speed, CPU};
use crate::csv::{gen_writer, CSVWriter, Writer};
use crate::display::{print_battery_status, print_turbo_status};
use crate::error::Error;
use crate::gov::Gov;
use crate::graph::{Graph, GraphType, Grapher};
use crate::logger;
use crate::logger::Interface;
use crate::network::{hook, listen};
use crate::power::battery::{has_battery, Battery};
use crate::power::lid::{Lid, LidRetriever, LidState};
use crate::power::{Power, PowerRetriever};
use crate::proc::{parse_proc_file, read_proc_stat_file, ProcStat};
use crate::settings::Settings;
use crate::setup::{inside_docker_message, inside_wsl_message};
use crate::system::{
check_available_governors, check_cpu_freq, check_cpu_temperature, check_cpu_usage,
get_highest_temp, inside_docker, inside_wsl, list_cpus,
};
use crate::terminal::terminal_width;
use crate::warn_user;

/// Describes the state of the machine
Expand Down
21 changes: 21 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
pub mod args;
pub mod config;
pub mod cpu;
pub mod csv;
pub mod daemon;
pub mod display;
pub mod error;
pub mod gov;
pub mod graph;
pub mod interactive;
pub mod interface;
pub mod logger;
pub mod network;
pub mod power;
pub mod proc;
pub mod settings;
pub mod setup;
pub mod sysfs;
pub mod system;
pub mod terminal;
pub mod thermal;
4 changes: 2 additions & 2 deletions src/power.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::fs;
use std::path::Path;

use super::Error;
use crate::error::Error;

pub mod battery;
pub mod lid;

/// Called once at the start of read_power_source
/// Discover the path to the AC power_supply
fn set_best_path() -> Option<&'static str> {
pub fn set_best_path() -> Option<&'static str> {
// Only loaded once
static POWER_SOURCE_PATH: [&str; 4] = [
"/sys/class/power_supply/AC/online",
Expand Down
2 changes: 1 addition & 1 deletion src/power/battery.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::error::Error;
use crate::sysfs;
use crate::Error;
use std::any::Any;
use std::fs::read_dir;
use std::path::{Path, PathBuf};
Expand Down
2 changes: 1 addition & 1 deletion src/power/lid.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::Error;
use crate::error::Error;
use std::cmp::PartialEq;
use std::fmt;
use std::fs;
Expand Down
2 changes: 1 addition & 1 deletion src/sysfs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::Error;
use crate::error::Error;
use globset::Glob;
use std::fs;
use std::path::{Path, PathBuf};
Expand Down
6 changes: 3 additions & 3 deletions src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use std::string::String;
use std::{thread, time};

use crate::cpu::Speed;
use crate::debug;
use crate::proc::{parse_proc_file, read_proc_stat_file, ProcStat};
use log::debug;

use super::cpu::CPU;
use super::Error;
use crate::cpu::CPU;
use crate::error::Error;

/// Find the average frequency of all cores
///
Expand Down

0 comments on commit 211b947

Please sign in to comment.