Skip to content

Commit f9b9361

Browse files
committed
app: add tracing::instrument on some functions
1 parent 7106571 commit f9b9361

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

crates/companion-app/src/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::path::{Path, PathBuf};
22

33
use bincode::{Decode, Encode, serde::Compat};
44
use serde::{Deserialize, Serialize};
5-
use tracing::{debug, error, trace};
5+
use tracing::{debug, error, instrument, trace};
66
use uuid::Uuid;
77

88
const ENCODE_CONFIG: bincode::config::Configuration =
@@ -43,6 +43,7 @@ pub struct Profile {
4343
}
4444

4545
impl Config {
46+
#[instrument(name = "Config::new")]
4647
pub fn new() -> Result<Self, ConfigError> {
4748
let Some(config_path) = config_path() else {
4849
error!("config dir not found");

crates/companion-app/src/game.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use notify::event::ModifyKind;
1616
#[cfg(target_os = "linux")]
1717
use notify::event::RemoveKind;
1818
use notify::{Event, EventKind, RecommendedWatcher, RecursiveMode, Watcher};
19-
use tracing::{debug, error, trace, warn};
19+
use tracing::{debug, error, instrument, trace, warn};
2020

2121
#[cfg(target_os = "linux")]
2222
const LINUX_STEAM_GAME_DIR: &str =
@@ -40,6 +40,7 @@ impl Display for InstallType {
4040
}
4141
}
4242

43+
#[instrument]
4344
pub fn detect_install() -> Result<(InstallType, PathBuf), DetectError> {
4445
let Some(home) = home_dir() else {
4546
return Err(DetectError::NoHome);
@@ -65,6 +66,7 @@ pub fn detect_install() -> Result<(InstallType, PathBuf), DetectError> {
6566

6667
for (ty, path) in search {
6768
if path.exists() {
69+
trace!("found game path: {}", path.display());
6870
return Ok((ty, path));
6971
}
7072
}
@@ -74,6 +76,7 @@ pub fn detect_install() -> Result<(InstallType, PathBuf), DetectError> {
7476
}
7577

7678
/// Find profiles names
79+
#[instrument]
7780
pub fn find_profiles(path: &Path) -> Result<Vec<String>, FindProfilesError> {
7881
let entries = std::fs::read_dir(path)?
7982
.map(|res| res.map(|e| e.path()))
@@ -98,6 +101,7 @@ pub fn save_file_for_profile(path: &Path, name: &OsStr) -> PathBuf {
98101
path.join(name).join("data.owsave")
99102
}
100103

104+
#[instrument(skip_all, fields(path = install_dir.display().to_string()))]
101105
pub fn file_watcher(
102106
install_dir: PathBuf,
103107
#[rustfmt::skip]

crates/companion-app/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::time::Duration;
1616
use iced::task::Handle;
1717
use iced::widget::{self, Column, Space, button, column, container, row, text};
1818
use iced::{Element, Fill, Font, Subscription, Task, Theme, clipboard, font};
19-
use tracing::{debug, error, trace};
19+
use tracing::{debug, error, instrument, trace};
2020
use uuid::Uuid;
2121

2222
use config::Config;
@@ -52,6 +52,7 @@ pub fn main() -> iced::Result {
5252
.run_with(|| (State::new(), Task::done(Message::Auth { force: false })))
5353
}
5454

55+
#[instrument(skip(state))]
5556
fn update(state: &mut State, message: Message) -> Task<Message> {
5657
let none = Task::none();
5758

@@ -235,6 +236,7 @@ fn update(state: &mut State, message: Message) -> Task<Message> {
235236
none
236237
}
237238

239+
#[instrument(skip(state))]
238240
fn view(state: &State) -> Element<'_, Message> {
239241
if let Some(ref err) = state.error {
240242
let inner: Element<_> = match err {
@@ -370,6 +372,7 @@ fn view(state: &State) -> Element<'_, Message> {
370372
.into()
371373
}
372374

375+
#[instrument(skip(state))]
373376
fn subscription(state: &State) -> Subscription<Message> {
374377
if !state.server_ok {
375378
return Subscription::none();
@@ -443,6 +446,7 @@ struct State {
443446
}
444447

445448
impl State {
449+
#[instrument(name = "State::new")]
446450
fn new() -> Self {
447451
let install_dir = match game::detect_install() {
448452
Ok(dir) => dir,

0 commit comments

Comments
 (0)