feat: log tmux call execution time to logs

This commit is contained in:
sxyazi 2025-03-05 14:36:48 +08:00
parent 68cd02816d
commit 821296f5ac
No known key found for this signature in database
4 changed files with 44 additions and 14 deletions

View file

@ -1,4 +1,4 @@
use tracing::warn;
use tracing::debug;
use yazi_shared::env_exists;
use crate::Mux;
@ -63,7 +63,7 @@ impl Brand {
"xterm-ghostty" => return Some(B::Ghostty),
"rio" => return Some(B::Rio),
"rxvt-unicode-256color" => return Some(B::Urxvt),
_ => warn!("[Adapter] Unknown TERM: {term}"),
_ => {}
}
match program.as_str() {
"iTerm.app" => return Some(B::Iterm2),
@ -76,11 +76,11 @@ impl Brand {
"Hyper" => return Some(B::Hyper),
"mintty" => return Some(B::Mintty),
"Apple_Terminal" => return Some(B::Apple),
_ => warn!("[Adapter] Unknown TERM_PROGRAM: {program}"),
_ => {}
}
match vars.into_iter().find(|&(s, _)| env_exists(s)) {
Some((_, brand)) => return Some(brand),
None => warn!("[Adapter] No special environment variables detected"),
if let Some((var, brand)) = vars.into_iter().find(|&(s, _)| env_exists(s)) {
debug!("Detected special environment variable: {var}");
return Some(brand);
}
None

View file

@ -1,5 +1,6 @@
use anyhow::Result;
use tracing::error;
use yazi_macro::time;
use crate::{CLOSE, ESCAPE, Emulator, START, TMUX};
@ -18,14 +19,18 @@ impl Mux {
}
pub fn tmux_passthrough() {
let child = std::process::Command::new("tmux")
let output = time!(
"Running `tmux set -p allow-passthrough on`",
std::process::Command::new("tmux")
.args(["set", "-p", "allow-passthrough", "on"])
.stdin(std::process::Stdio::null())
.stdout(std::process::Stdio::null())
.stderr(std::process::Stdio::piped())
.spawn();
.spawn()
.and_then(|c| c.wait_with_output())
);
match child.and_then(|c| c.wait_with_output()) {
match output {
Ok(o) if o.status.success() => {}
Ok(o) => {
error!(
@ -68,9 +73,14 @@ impl Mux {
if !TMUX.get() {
return (term, program);
}
let Ok(output) = std::process::Command::new("tmux").arg("show-environment").output() else {
let Ok(output) = time!(
"Running `tmux show-environment`",
std::process::Command::new("tmux").arg("show-environment").output()
) else {
return (term, program);
};
for line in String::from_utf8_lossy(&output.stdout).lines() {
if let Some((k, v)) = line.trim().split_once('=') {
match k {

View file

@ -1,5 +1,6 @@
mod asset;
mod event;
mod log;
mod module;
mod platform;
mod stdio;

19
yazi-macro/src/log.rs Normal file
View file

@ -0,0 +1,19 @@
#[macro_export]
macro_rules! time {
($expr:expr) => {
time!($expr, stringify!($expr))
};
($label:expr, $expr:expr) => {
time!($expr, "{}", $label)
};
($expr:expr, $fmt:expr, $($args:tt)*) => {{
if tracing::enabled!(tracing::Level::DEBUG) {
let start = std::time::Instant::now();
let result = $expr;
tracing::debug!("{} took {:?}", format_args!($fmt, $($args)*), start.elapsed());
result
} else {
$expr
}
}};
}