Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 Nov 2007 07:38:26 -0500
From:      Skip Ford <skip@menantico.com>
To:        Robert Watson <rwatson@FreeBSD.org>
Cc:        hackers@FreeBSD.org
Subject:   Re: Updated procstat(1)
Message-ID:  <20071128123826.GA813@menantico.com>
In-Reply-To: <20071128110550.GA2216@menantico.com>
References:  <20071127171228.N94692@fledge.watson.org> <20071128054208.GA813@menantico.com> <20071128092434.J94692@fledge.watson.org> <20071128110550.GA2216@menantico.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--9jxsPFA5p3P2qPhR
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Skip Ford wrote:
> Robert Watson wrote:
>> On Wed, 28 Nov 2007, Skip Ford wrote:
>> 
>>>>- "-a" now means "all processes",
>>>
>>>Thanks. :-)  I'm a little surprised.  You seemed pretty dedicated to a 
>>>per-process tool.
>> 
>> I was, but then I read your e-mail and became convinced that the first 
>> patch that would be submitted against procstat(1) would be a "-a" patch. :-)
> 
> Yep, would've happened.  Now the first patch submitted will be a
> "-w interval" patch... :-)

I couldn't resist implementing a crude interval arg just for kicks.
Here's the output of find(1) every second.  This is so cool:

$ procstat -k -w 1 948
  PID	 TID COMM		  KSTACK
  948 100099 find		  mi_switch thread_suspend_check userret syscall Xint0x80_syscall
  948 100099 find		  mi_switch sleepq_switch sleepq_wait _sleep bwait bufwait breadn bread ffs_read VOP_READ_APV ufs_readdir VOP_READDIR_APV getdirentries syscall Xint0x80_syscall
  948 100099 find		  mi_switch turnstile_wait _mtx_lock_sleep fdalloc falloc kern_open open syscall Xint0x80_syscall
  948 100099 find		  mi_switch sleepq_switch sleepq_wait _sleep bwait bufwait breadn bread ffs_read VOP_READ_APV ufs_readdir VOP_READDIR_APV getdirentries syscall Xint0x80_syscall
  948 100099 find		  mi_switch critical_exit intr_execute_handlers atpic_handle_intr Xatpic_intr0
  948 100099 find		  mi_switch ast doreti_ast
  948 100099 find		  mi_switch sleepq_switch sleepq_wait _sleep bwait bufwait breadn bread ffs_read VOP_READ_APV ufs_readdir VOP_READDIR_APV getdirentries syscall Xint0x80_syscall
  948 100099 find		  mi_switch turnstile_wait _mtx_lock_sleep fdalloc falloc kern_open open syscall Xint0x80_syscall
  948 100099 find		  mi_switch critical_exit intr_execute_handlers atpic_handle_intr Xatpic_intr0 priv_check vn_stat vn_statfile kern_fstat fstat syscall Xint0x80_syscall
  948 100099 find		  mi_switch sleepq_switch sleepq_wait _sleep bwait bufwait breadn bread ffs_vget ufs_lookup VOP_CACHEDLOOKUP_APV vfs_cache_lookup VOP_LOOKUP_APV lookup namei kern_lstat lstat syscall
  948 100099 find		  mi_switch sleepq_switch sleepq_wait _sleep bwait bufwait breadn bread ffs_read VOP_READ_APV ufs_readdir VOP_READDIR_APV getdirentries syscall Xint0x80_syscall

For someone who isn't intimately familiar with the kernel, this is really
a nice feature for this tool.

I'm attaching the very crude interval patch just because it seems rude
not to, but you probably either don't want it or will do it differently
and either is perfectly fine.  If you do implement it on your own, don't
bother printing a header per screenful since it would be most useful for
kstacks and that output usually spills over to multiple lines anyway.

-- 
Skip

--9jxsPFA5p3P2qPhR
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="procstat_interval.diff"

diff -u src~/usr.bin/procstat/procstat.c src/usr.bin/procstat/procstat.c
--- src~/usr.bin/procstat/procstat.c	2007-11-27 10:23:39.000000000 -0500
+++ src/usr.bin/procstat/procstat.c	2007-11-28 07:01:23.000000000 -0500
@@ -106,13 +106,14 @@
 main(int argc, char *argv[])
 {
 	struct kinfo_proc *kipp;
-	int ch, i, name[4], tmp;
+	int ch, i, name[4], tmp, interval;
 	size_t len;
 	long l;
 	pid_t pid;
 	char *dummy;
 
-	while ((ch = getopt(argc, argv, "abcfkhstv")) != -1) {
+	interval = 0;
+	while ((ch = getopt(argc, argv, "abcfkhstvw:")) != -1) {
 		switch (ch) {
 		case 'a':
 			aflag = 1;
@@ -150,6 +151,10 @@
 			vflag = 1;
 			break;
 
+		case 'w':
+			interval = atoi(optarg);
+			break;
+
 		case '?':
 		default:
 			usage();
@@ -166,6 +171,7 @@
 	/* Must specify at least one of -a and a list of pids. */
 	if (!aflag && argc < 1)
 		usage();
+loop:
 	if (aflag) {
 		name[0] = CTL_KERN;
 		name[1] = KERN_PROC;
@@ -233,5 +239,11 @@
 		/* Suppress header after first process. */
 		hflag = 1;
 	}
+
+	if (interval) {
+		sleep(interval);
+		goto loop;
+	}
+
 	exit(0);
 }

--9jxsPFA5p3P2qPhR--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20071128123826.GA813>