diff options
author | Richard Braun <rbraun@sceen.net> | 2014-01-16 23:59:00 +0100 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2014-01-16 23:59:00 +0100 |
commit | 9bebcd38f42da289a3eaf9f473a9529f8d3c4664 (patch) | |
tree | f043005ce43b176c57f9b773817381271c217506 /libps/procstat.c | |
parent | 9a7776ddef6626536f21c09090b8329168a053ce (diff) |
libps: fix task/thread times fetching
Introduce PSTAT_TIMES to force the retrieval of both PSTAT_TASK_BASIC
and PSTAT_THREAD_BASIC. Task basic info contain the user and system
times of terminated threads which the code wrongly assumes is always
present along with process info.
* libps/procstat.c (add_preconditions): Set both PSTAT_TASK_BASIC and
PSTAT_THREAD_BASIC as preconditions for PSTAT_TIMES.
(summarize_thread_basic_info): Add terminated threads times only if
task basic info are available.
(set_procinfo_flags): Provide summarize_thread_basic_info with flags of
available info.
(proc_stat_set_flags): Set PSTAT_TIMES as available if it was needed and
any of PSTAT_TASK_BASIC or PSTAT_THREAD_BASIC could be fetched.
* libps/ps.h (PSTAT_TIMES): New macro.
* libps/spec.c (ps_get_usr_time): Indicate the getter needs PSTAT_TIMES
instead of PSTAT_THREAD_BASIC.
(ps_sys_time_getter): Likewise.
(ps_tot_time_getter): Likewise.
Diffstat (limited to 'libps/procstat.c')
-rw-r--r-- | libps/procstat.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/libps/procstat.c b/libps/procstat.c index e732f751..0d4a565b 100644 --- a/libps/procstat.c +++ b/libps/procstat.c @@ -294,6 +294,8 @@ add_preconditions (ps_flags_t flags, struct ps_context *context) /* We just request the resources require for both the thread and task versions, as the extraneous info won't be possible to acquire anyway. */ flags |= PSTAT_TASK_BASIC | PSTAT_THREAD_BASIC; + if (flags & PSTAT_TIMES) + flags |= PSTAT_TASK_BASIC | PSTAT_THREAD_BASIC; if (flags & (PSTAT_CTTYID | PSTAT_CWDIR | PSTAT_AUTH | PSTAT_UMASK) && !(flags & PSTAT_NO_MSGPORT)) { @@ -348,11 +350,10 @@ should_suppress_msgport (struct proc_stat *ps) thread take precedence over waiting ones, and if there are any other incompatible states, simply using a bogus value of -1. */ static struct thread_basic_info * -summarize_thread_basic_info (struct procinfo *pi) +summarize_thread_basic_info (struct procinfo *pi, ps_flags_t have) { int i; unsigned num_threads = 0, num_run_threads = 0; - task_basic_info_t taskinfo = &pi->taskinfo; thread_basic_info_t tbi = malloc (sizeof (struct thread_basic_info)); int run_base_priority = 0, run_cur_priority = 0; int total_base_priority = 0, total_cur_priority = 0; @@ -427,11 +428,14 @@ summarize_thread_basic_info (struct procinfo *pi) } } - /* Include the run time of terminated threads. */ - tbi->user_time.seconds += taskinfo->user_time.seconds; - tbi->user_time.microseconds += taskinfo->user_time.microseconds; - tbi->system_time.seconds += taskinfo->system_time.seconds; - tbi->system_time.microseconds += taskinfo->system_time.microseconds; + /* For tasks, include the run time of terminated threads. */ + if (have & PSTAT_TASK_BASIC) + { + tbi->user_time.seconds += pi->taskinfo.user_time.seconds; + tbi->user_time.microseconds += pi->taskinfo.user_time.microseconds; + tbi->system_time.seconds += pi->taskinfo.system_time.seconds; + tbi->system_time.microseconds += pi->taskinfo.system_time.microseconds; + } tbi->user_time.seconds += tbi->user_time.microseconds / 1000000; tbi->user_time.microseconds %= 1000000; @@ -655,7 +659,7 @@ set_procinfo_flags (struct proc_stat *ps, ps_flags_t need, ps_flags_t have) if (had & PSTAT_THREAD_BASIC) free (ps->thread_basic_info); if (have & PSTAT_THREAD_BASIC) - ps->thread_basic_info = summarize_thread_basic_info (pi); + ps->thread_basic_info = summarize_thread_basic_info (pi, have); if (had & PSTAT_THREAD_SCHED) free (ps->thread_sched_info); if (have & PSTAT_THREAD_SCHED) @@ -1007,6 +1011,10 @@ proc_stat_set_flags (struct proc_stat *ps, ps_flags_t flags) MGET (PSTAT_NUM_PORTS, PSTAT_PID, proc_getnports (server, ps->pid, &ps->num_ports)); + /* User and system times. */ + if ((need & PSTAT_TIMES) && (have & (PSTAT_TASK_BASIC | PSTAT_THREAD_BASIC))) + have |= PSTAT_TIMES; + /* Update PS's flag state. We haven't tried user flags yet, so don't mark them as having failed. We do this before checking user bits so that the user fetch hook sees PS in a consistent state. */ |