summaryrefslogtreecommitdiffstats
path: root/sys/kern/tty_info.c
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2009-05-17 12:30:25 +0000
committered <ed@FreeBSD.org>2009-05-17 12:30:25 +0000
commit69acbef6caa4bc0026ef1639c14b98ee11234ac9 (patch)
tree028a49451b8440107a953504081e23ba7d8cc522 /sys/kern/tty_info.c
parent2839add31a27ec3605bac4184fa375a0c8b441a4 (diff)
downloadFreeBSD-src-69acbef6caa4bc0026ef1639c14b98ee11234ac9.zip
FreeBSD-src-69acbef6caa4bc0026ef1639c14b98ee11234ac9.tar.gz
Several cleanups to tty_info(), better known as Ctrl-T.
- Only pick up PROC_LOCK once, which means we can drop the PGRP_LOCK right after picking up PROC_LOCK for the first time. - Print the process real time, making it consistent with tools like time(1). - Use `p' and `td' to reference the process/thread we are going to print. Only use pick-variables inside the loops. We already did this for the threads, but not the processes.
Diffstat (limited to 'sys/kern/tty_info.c')
-rw-r--r--sys/kern/tty_info.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/sys/kern/tty_info.c b/sys/kern/tty_info.c
index fc3a5cf..8894fe7 100644
--- a/sys/kern/tty_info.c
+++ b/sys/kern/tty_info.c
@@ -213,9 +213,9 @@ proc_compare(struct proc *p1, struct proc *p2)
void
tty_info(struct tty *tp)
{
- struct timeval utime, stime;
- struct proc *p, *pick;
- struct thread *td, *picktd;
+ struct timeval rtime, utime, stime;
+ struct proc *p, *ppick;
+ struct thread *td, *tdpick;
const char *stateprefix, *state;
long rss;
int load, pctcpu;
@@ -254,17 +254,17 @@ tty_info(struct tty *tp)
* whole list. However, we're guaranteed not to reference an exited
* thread or proc since we hold the tty locked.
*/
- pick = NULL;
- LIST_FOREACH(p, &tp->t_pgrp->pg_members, p_pglist)
- if (proc_compare(pick, p))
- pick = p;
+ p = NULL;
+ LIST_FOREACH(ppick, &tp->t_pgrp->pg_members, p_pglist)
+ if (proc_compare(p, ppick))
+ p = ppick;
- PROC_LOCK(pick);
- picktd = NULL;
- FOREACH_THREAD_IN_PROC(pick, td)
- if (thread_compare(picktd, td))
- picktd = td;
- td = picktd;
+ PROC_LOCK(p);
+ PGRP_UNLOCK(tp->t_pgrp);
+ td = NULL;
+ FOREACH_THREAD_IN_PROC(p, tdpick)
+ if (thread_compare(td, tdpick))
+ td = tdpick;
stateprefix = "";
thread_lock(td);
if (TD_IS_RUNNING(td))
@@ -284,28 +284,28 @@ tty_info(struct tty *tp)
state = "suspended";
else if (TD_AWAITING_INTR(td))
state = "intrwait";
- else if (pick->p_state == PRS_ZOMBIE)
+ else if (p->p_state == PRS_ZOMBIE)
state = "zombie";
else
state = "unknown";
pctcpu = (sched_pctcpu(td) * 10000 + FSCALE / 2) >> FSHIFT;
thread_unlock(td);
- if (pick->p_state == PRS_NEW || pick->p_state == PRS_ZOMBIE)
+ if (p->p_state == PRS_NEW || p->p_state == PRS_ZOMBIE)
rss = 0;
else
- rss = pgtok(vmspace_resident_count(pick->p_vmspace));
- PROC_UNLOCK(pick);
- PROC_LOCK(pick);
- PGRP_UNLOCK(tp->t_pgrp);
- rufetchcalc(pick, &ru, &utime, &stime);
- pid = pick->p_pid;
- strlcpy(comm, pick->p_comm, sizeof comm);
- PROC_UNLOCK(pick);
+ rss = pgtok(vmspace_resident_count(p->p_vmspace));
+ microuptime(&rtime);
+ timevalsub(&rtime, &p->p_stats->p_start);
+ rufetchcalc(p, &ru, &utime, &stime);
+ pid = p->p_pid;
+ strlcpy(comm, p->p_comm, sizeof comm);
+ PROC_UNLOCK(p);
- /* Print command, pid, state, utime, stime, %cpu, and rss. */
+ /* Print command, pid, state, rtime, utime, stime, %cpu, and rss. */
ttyprintf(tp,
- " cmd: %s %d [%s%s] %ld.%02ldu %ld.%02lds %d%% %ldk\n",
+ " cmd: %s %d [%s%s] %ld.%02ldr %ld.%02ldu %ld.%02lds %d%% %ldk\n",
comm, pid, stateprefix, state,
+ (long)rtime.tv_sec, rtime.tv_usec / 10000,
(long)utime.tv_sec, utime.tv_usec / 10000,
(long)stime.tv_sec, stime.tv_usec / 10000,
pctcpu / 100, rss);
OpenPOWER on IntegriCloud