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
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);
 }
_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to