Skip to content

Commit

Permalink
Merge pull request #426 from nokyan/trace-logs
Browse files Browse the repository at this point in the history
Add trace logging
  • Loading branch information
nokyan authored Dec 25, 2024
2 parents 41a270d + 9c9f594 commit ea3501c
Show file tree
Hide file tree
Showing 38 changed files with 540 additions and 133 deletions.
2 changes: 1 addition & 1 deletion lib/process_data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static NVIDIA_PROCESS_INFOS: Lazy<RwLock<HashMap<PciSlot, Vec<ProcessInfo>>>> =
#[nutype(
validate(less_or_equal = 19),
validate(greater_or_equal = -20),
derive(Debug, Default, Clone, Hash, PartialEq, Eq, Serialize, Deserialize, Copy, FromStr, Deref, TryFrom),
derive(Debug, Default, Clone, Hash, PartialEq, Eq, Serialize, Deserialize, Copy, FromStr, Deref, TryFrom, Display),
default = 0
)]
pub struct Niceness(i8);
Expand Down
31 changes: 18 additions & 13 deletions src/application.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use log::{debug, info};
use log::{debug, info, trace};

use adw::{prelude::*, subclass::prelude::*};
use glib::clone;
Expand Down Expand Up @@ -78,6 +78,8 @@ glib::wrapper! {

impl Application {
pub fn new() -> Self {
trace!("Creating Application GObject…");

glib::Object::builder::<Self>()
.property("application-id", Some(APP_ID))
.property("flags", gio::ApplicationFlags::empty())
Expand Down Expand Up @@ -283,19 +285,22 @@ impl Application {
}

pub fn run(&self) {
trace!("Starting the application");
info!("Resources ({APP_ID})");
info!("Version: {VERSION}");
info!("Datadir: {PKGDATADIR}");

let os_info = OsInfo::get();
debug!(
"Operating system: {}",
os_info.name.as_deref().unwrap_or("N/A")
);
debug!(
"Kernel version: {}",
os_info.kernel_version.as_deref().unwrap_or("N/A")
);
info!("Version: {VERSION} ({PROFILE})");
info!("Datadir: `{PKGDATADIR}`");

if log::log_enabled!(log::Level::Debug) {
let os_info = OsInfo::get();
debug!(
"Operating system: {}",
os_info.name.as_deref().unwrap_or("N/A")
);
debug!(
"Kernel version: {}",
os_info.kernel_version.as_deref().unwrap_or("N/A")
);
}

if PROFILE == "Devel" {
info!(
Expand Down
2 changes: 2 additions & 0 deletions src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::utils::IS_FLATPAK;
use clap::{command, Parser};
use gettextrs::{gettext, LocaleCategory};
use gtk::{gio, glib};
use log::trace;

use self::application::Application;
use self::config::{GETTEXT_PACKAGE, LOCALEDIR, RESOURCES_FILE};
Expand Down Expand Up @@ -65,6 +66,7 @@ pub fn main() {

// Initialize logger
pretty_env_logger::init();
trace!("Trace logs activated. Brace yourself for *lots* of logs. Slowdowns may occur.");

// reset XDG_DATA_DIRS to use absolute paths instead of relative paths because Flatpak seemingly cannot resolve them
// this must happen now because once the GTK app is loaded, it's too late
Expand Down
7 changes: 7 additions & 0 deletions src/ui/dialogs/app_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::utils::units::{convert_speed, convert_storage};
use adw::{prelude::*, subclass::prelude::*};
use gtk::gio::ThemedIcon;
use gtk::glib;
use log::trace;

mod imp {

Expand Down Expand Up @@ -99,6 +100,8 @@ impl Default for ResAppDialog {

impl ResAppDialog {
pub fn new() -> Self {
trace!("Creating ResAppDialog GObject…");

glib::Object::new::<Self>()
}

Expand All @@ -107,6 +110,8 @@ impl ResAppDialog {
}

pub fn setup_widgets(&self, app: &ApplicationEntry) {
trace!("Setting up ResAppDialog widgets…");

let imp = self.imp();

if app.id().is_none() // this will be the case for System Processes
Expand Down Expand Up @@ -153,6 +158,8 @@ impl ResAppDialog {
}

pub fn update(&self, app: &ApplicationEntry) {
trace!("Refreshing ResAppDialog…");

let imp = self.imp();

imp.cpu_usage
Expand Down
6 changes: 6 additions & 0 deletions src/ui/dialogs/process_dialog.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use adw::{prelude::*, subclass::prelude::*};
use gtk::glib::{self, GString};
use log::trace;

use crate::config::PROFILE;
use crate::i18n::i18n;
Expand Down Expand Up @@ -105,6 +106,7 @@ impl Default for ResProcessDialog {

impl ResProcessDialog {
pub fn new() -> Self {
trace!("Creating ResProcessDialog GObject…");
glib::Object::new::<Self>()
}

Expand All @@ -113,6 +115,8 @@ impl ResProcessDialog {
}

pub fn setup_widgets(&self, process: &ProcessEntry, user: &str) {
trace!("Setting up ResProcessDialog widgets…");

let imp = self.imp();

imp.name.set_label(&process.name());
Expand Down Expand Up @@ -148,6 +152,8 @@ impl ResProcessDialog {
}

pub fn update(&self, process: &ProcessEntry) {
trace!("Refreshing ResProcessDialog…");

let imp = self.imp();

imp.cpu_usage
Expand Down
6 changes: 6 additions & 0 deletions src/ui/dialogs/process_options_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
use adw::{prelude::*, subclass::prelude::*, ToastOverlay};
use async_channel::Sender;
use gtk::glib::{self, clone, MainContext};
use log::trace;
use process_data::Niceness;

mod imp {
Expand Down Expand Up @@ -87,6 +88,7 @@ impl Default for ResProcessOptionsDialog {

impl ResProcessOptionsDialog {
pub fn new() -> Self {
trace!("Creating ResProcessOptionsDialog GObject…");
glib::Object::new::<Self>()
}

Expand Down Expand Up @@ -118,6 +120,8 @@ impl ResProcessOptionsDialog {
}

pub fn setup_widgets(&self, process: &ProcessEntry) {
trace!("Setting up ResProcessOptionsDialog widgets…");

let imp = self.imp();

imp.name.set_label(&process.name());
Expand Down Expand Up @@ -168,6 +172,8 @@ impl ResProcessOptionsDialog {
sender: Sender<Action>,
toast_overlay: &ToastOverlay,
) {
trace!("Setting up ResProcessOptionsDialog signals…");

let imp = self.imp();

imp.select_all_button.connect_clicked(clone!(
Expand Down
7 changes: 7 additions & 0 deletions src/ui/dialogs/settings_dialog.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use adw::{prelude::*, subclass::prelude::*};
use gtk::glib;
use log::trace;

use crate::{
config::PROFILE,
Expand Down Expand Up @@ -155,6 +156,8 @@ impl Default for ResSettingsDialog {

impl ResSettingsDialog {
pub fn new() -> Self {
trace!("Creating ResSettingsDialog GObject…");

glib::Object::new::<Self>()
}

Expand All @@ -164,6 +167,8 @@ impl ResSettingsDialog {
}

pub fn setup_widgets(&self) {
trace!("Setting up ResSettingsDialog widgets…");

let imp = self.imp();
imp.prefix_combo_row
.set_selected((SETTINGS.base() as u8) as u32);
Expand Down Expand Up @@ -252,6 +257,8 @@ impl ResSettingsDialog {
}

pub fn setup_signals(&self) {
trace!("Setting up ResSettingsDialog signals…");

let imp = self.imp();
imp.prefix_combo_row
.connect_selected_item_notify(|combo_row| {
Expand Down
5 changes: 5 additions & 0 deletions src/ui/pages/applications/application_entry.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use gtk::glib::{self};
use log::trace;
use process_data::Containerization;

use crate::{
Expand Down Expand Up @@ -179,6 +180,8 @@ glib::wrapper! {

impl ApplicationEntry {
pub fn new(app: &App, apps_context: &AppsContext) -> Self {
trace!("Creating ApplicationEntry ({}) GObject…", app.display_name);

let containerization = match app.containerization {
Containerization::None => i18n("No"),
Containerization::Flatpak => i18n("Yes (Flatpak)"),
Expand All @@ -198,6 +201,8 @@ impl ApplicationEntry {
}

pub fn update(&self, app: &App, apps_context: &AppsContext) {
trace!("Refreshing ApplicationEntry ({})…", app.display_name);

self.set_cpu_usage(app.cpu_time_ratio(apps_context));
self.set_memory_usage(app.memory_usage(apps_context) as u64);
self.set_swap_usage(app.swap_usage(apps_context) as u64);
Expand Down
3 changes: 3 additions & 0 deletions src/ui/pages/applications/application_name_cell.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use adw::{glib::property::PropertySet, prelude::*, subclass::prelude::*};
use gtk::{gio::Icon, glib};
use log::trace;

mod imp {
use std::cell::{Cell, RefCell};
Expand Down Expand Up @@ -160,6 +161,8 @@ impl Default for ResApplicationNameCell {

impl ResApplicationNameCell {
pub fn new() -> Self {
trace!("Creating ResApplicationNameCell GObject…");

glib::Object::new::<Self>()
}
}
13 changes: 13 additions & 0 deletions src/ui/pages/battery.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use adw::{prelude::*, subclass::prelude::*};
use gtk::glib;
use log::trace;

use crate::config::PROFILE;
use crate::i18n::i18n;
Expand Down Expand Up @@ -168,6 +169,8 @@ impl ResBattery {
const MAIN_GRAPH_COLOR: [u8; 3] = [0x33, 0xd1, 0x7a];

pub fn new() -> Self {
trace!("Creating ResBattery GObject…");

glib::Object::new::<Self>()
}

Expand All @@ -177,6 +180,11 @@ impl ResBattery {
}

pub fn setup_widgets(&self, battery_data: &BatteryData) {
trace!(
"Setting up ResBattery ({:?}) widgets…",
battery_data.inner.sysfs_path
);

let imp = self.imp();
let battery = &battery_data.inner;

Expand Down Expand Up @@ -231,6 +239,11 @@ impl ResBattery {
}

pub fn refresh_page(&self, battery_data: BatteryData) {
trace!(
"Refreshing ResBattery ({:?})…",
battery_data.inner.sysfs_path
);

let imp = self.imp();

let mut usage_string = String::new();
Expand Down
Loading

0 comments on commit ea3501c

Please sign in to comment.