mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-29 06:13:20 +00:00
proc_get_jiffies to accept pid directly
No need to accept the mutable proc here.
This commit is contained in:
parent
f577c221eb
commit
7d537eefbb
3 changed files with 7 additions and 8 deletions
|
@ -34,7 +34,7 @@ static int cpu_use(const job_t *j) {
|
|||
struct timeval t;
|
||||
unsigned long jiffies;
|
||||
gettimeofday(&t, nullptr);
|
||||
jiffies = proc_get_jiffies(p.get());
|
||||
jiffies = proc_get_jiffies(p->pid);
|
||||
|
||||
double t1 = 1000000.0 * p->last_time.tv_sec + p->last_time.tv_usec;
|
||||
double t2 = 1000000.0 * t.tv_sec + t.tv_usec;
|
||||
|
|
|
@ -724,9 +724,8 @@ bool job_reap(parser_t &parser, bool allow_interactive) {
|
|||
}
|
||||
|
||||
/// Get the CPU time for the specified process.
|
||||
unsigned long proc_get_jiffies(process_t *p) {
|
||||
if (!have_proc_stat()) return 0;
|
||||
if (p->pid <= 0) return 0;
|
||||
unsigned long proc_get_jiffies(pid_t inpid) {
|
||||
if (inpid <= 0 || !have_proc_stat()) return 0;
|
||||
|
||||
char state;
|
||||
int pid, ppid, pgrp, session, tty_nr, tpgid, exit_signal, processor;
|
||||
|
@ -739,7 +738,7 @@ unsigned long proc_get_jiffies(process_t *p) {
|
|||
/// Maximum length of a /proc/[PID]/stat filename.
|
||||
constexpr size_t FN_SIZE = 256;
|
||||
char fn[FN_SIZE];
|
||||
std::snprintf(fn, FN_SIZE, "/proc/%d/stat", p->pid);
|
||||
std::snprintf(fn, FN_SIZE, "/proc/%d/stat", inpid);
|
||||
// Don't use autoclose_fd here, we will fdopen() and then fclose() instead.
|
||||
int fd = open_cloexec(fn, O_RDONLY);
|
||||
if (fd < 0) return 0;
|
||||
|
@ -767,7 +766,7 @@ void proc_update_jiffies(parser_t &parser) {
|
|||
for (const auto &job : parser.jobs()) {
|
||||
for (process_ptr_t &p : job->processes) {
|
||||
gettimeofday(&p->last_time, nullptr);
|
||||
p->last_jiffies = proc_get_jiffies(p.get());
|
||||
p->last_jiffies = proc_get_jiffies(p->pid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -509,9 +509,9 @@ job_list_t jobs_requiring_warning_on_exit(const parser_t &parser);
|
|||
/// jobs_requiring_warning_on_exit().
|
||||
void print_exit_warning_for_jobs(const job_list_t &jobs);
|
||||
|
||||
/// Use the procfs filesystem to look up how many jiffies of cpu time was used by this process. This
|
||||
/// 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.
|
||||
unsigned long proc_get_jiffies(process_t *p);
|
||||
unsigned long proc_get_jiffies(pid_t inpid);
|
||||
|
||||
/// Update process time usage for all processes by calling the proc_get_jiffies function for every
|
||||
/// process of every job.
|
||||
|
|
Loading…
Reference in a new issue