Inline have_proc_stat

Closes #12319
This commit is contained in:
xtqqczze
2026-01-13 01:45:26 +00:00
committed by Johannes Altmanninger
parent c84c006f42
commit efbf8b0203
3 changed files with 9 additions and 12 deletions

View File

@@ -6,7 +6,7 @@
use crate::job_group::{JobId, MaybeJobId};
use crate::localization::{wgettext, wgettext_fmt};
use crate::parser::Parser;
use crate::proc::{Job, clock_ticks_to_seconds, have_proc_stat, proc_get_jiffies};
use crate::proc::{HAVE_PROC_STAT, Job, clock_ticks_to_seconds, proc_get_jiffies};
use crate::wgetopt::{ArgType, WGetopter, WOption, wopt};
use crate::wutil::fish_wcstoi;
use fish_widestring::{L, WExt, WString, wstr};
@@ -53,7 +53,7 @@ fn builtin_jobs_print(j: &Job, mode: JobsPrintMode, header: bool, streams: &mut
if header {
// Print table header before first job.
out += wgettext!("Job\tGroup\t");
if have_proc_stat() {
if *HAVE_PROC_STAT {
out += wgettext!("CPU\t");
}
out += wgettext!("State\tCommand\n");
@@ -61,7 +61,7 @@ fn builtin_jobs_print(j: &Job, mode: JobsPrintMode, header: bool, streams: &mut
sprintf!(=> &mut out, "%d\t%s\t", j.job_id(), pgid);
if have_proc_stat() {
if *HAVE_PROC_STAT {
sprintf!(=> &mut out, "%.0f%%\t", 100.0 * cpu_use(j));
}

View File

@@ -1010,7 +1010,7 @@ pub fn print_exit_warning_for_jobs(jobs: &JobList) {
/// Use the procfs filesystem to look up how many jiffies of cpu time was used by a given pid. This
/// function is only available on systems with the procfs file entry 'stat', i.e. Linux.
pub fn proc_get_jiffies(inpid: Pid) -> ClockTicks {
if !have_proc_stat() {
if !*HAVE_PROC_STAT {
return 0;
}
@@ -1609,12 +1609,9 @@ fn process_clean_after_marking(parser: &Parser, interactive: bool) -> bool {
printed
}
pub fn have_proc_stat() -> bool {
// Check for /proc/self/stat to see if we are running with Linux-style procfs.
static HAVE_PROC_STAT_RESULT: LazyLock<bool> =
LazyLock::new(|| fs::metadata("/proc/self/stat").is_ok());
*HAVE_PROC_STAT_RESULT
}
/// Check for /proc/self/stat to see if we are running with Linux-style procfs.
pub static HAVE_PROC_STAT: LazyLock<bool> =
LazyLock::new(|| fs::metadata("/proc/self/stat").is_ok());
/// The signals that signify crashes to us.
const CRASHSIGNALS: [libc::c_int; 6] = [SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV, SIGSYS];

View File

@@ -116,7 +116,7 @@
use crate::parser::{BlockType, EvalRes, Parser};
use crate::prelude::*;
use crate::proc::{
have_proc_stat, hup_jobs, is_interactive_session, job_reap, jobs_requiring_warning_on_exit,
HAVE_PROC_STAT, hup_jobs, is_interactive_session, job_reap, jobs_requiring_warning_on_exit,
print_exit_warning_for_jobs, proc_update_jiffies,
};
use crate::screen::is_dumb;
@@ -6321,7 +6321,7 @@ fn reader_run_command(parser: &Parser, cmd: &wstr) -> EvalRes {
// Provide value for `status current-commandline`
parser.libdata_mut().status_vars.commandline = L!("").to_owned();
if have_proc_stat() {
if *HAVE_PROC_STAT {
proc_update_jiffies(parser);
}