Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Nov 2015 09:16:12 +0000 (UTC)
From:      Peter Holm <pho@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r290355 - user/pho/stress2/tools
Message-ID:  <201511040916.tA49GC5Z016091@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pho
Date: Wed Nov  4 09:16:12 2015
New Revision: 290355
URL: https://svnweb.freebsd.org/changeset/base/290355

Log:
  Added options to vmstat.sh and added a user mode monitor.
  
  Sponsored by:	EMC / Isilon storage division

Added:
  user/pho/stress2/tools/uleak.sh   (contents, props changed)
Modified:
  user/pho/stress2/tools/vmstat.sh

Added: user/pho/stress2/tools/uleak.sh
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ user/pho/stress2/tools/uleak.sh	Wed Nov  4 09:16:12 2015	(r290355)
@@ -0,0 +1,71 @@
+#!/bin/sh
+
+#
+# Copyright (c) 2015 EMC Corp.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+#
+
+# Report user mode leaks.
+
+export COLUMNS=130
+i=0
+start=`date '+%s'`
+/bin/echo -n "           "
+ps -l | head -1
+trap break SIGINT
+
+while true; do
+	i=$((i + 1))
+	ps -axOvsz | sed 1,1d | awk -v loop=$i '{print $1 "," $2 "," loop}'
+	sleep 10
+done | awk -F, '
+{
+	pid=$1
+	size=$2
+	loop=$3
+	if (size > s[pid]) {
+		n[pid]++
+		if (n[pid] > 6) {
+			print pid
+			fflush
+			n[pid] = 0
+		}
+		s[pid] = size
+	}
+	l[pid] = loop
+
+	# Reap dead processes
+	for (p in s) {
+		if (l[p] < loop - 1) {
+			delete s[p]
+			delete n[p]
+		}
+	}
+}' | while read p; do
+	d=$(((`date '+%s'` - start) / 86400))
+	echo "$d `date '+%T'` `ps -lp$p | tail -1`"
+done
+echo

Modified: user/pho/stress2/tools/vmstat.sh
==============================================================================
--- user/pho/stress2/tools/vmstat.sh	Wed Nov  4 08:13:25 2015	(r290354)
+++ user/pho/stress2/tools/vmstat.sh	Wed Nov  4 09:16:12 2015	(r290355)
@@ -28,35 +28,54 @@
 # $FreeBSD$
 #
 
-# Memory leak detector: run vmstat -m & -z in a loop
+# Memory leak detector: run vmstat -m & -z in a loop.
 
-[ $# -eq 1 ] && debug="-v debug=1"
 export LANG=en_US.ISO8859-1
+while getopts dmz flag; do
+        case "$flag" in
+        d) debug="-v debug=1" ;;
+        m) optz=n ;;
+        z) optm=n ;;
+        *) echo "Usage $0 [-d] [-m] [-z]"
+           return 1 ;;
+        esac
+done
+
+start=`date '+%s'`
 OIFS=$IFS
 while true; do
 	#          Type InUse MemUse
-	vmstat -m | sed 1d | \
+	[ -z "$optm" ] && vmstat -m | sed 1d | \
 	    sed 's/\(.* \)\([0-9][0-9]*\)  *\(.*\)K .*/\1:\2:\3/' | \
 	    while IFS=: read -r p1 p2 p3; do
 		name=`echo $p1 | sed 's/^ *//;s/ *$//'`
-		memuse=$((p3 * 1024))
+		memuse=$p3
 		[ "$memuse" -ne 0 ] && echo "vmstat -m $name,$memuse"
 	done
 
 	# ITEM                   SIZE  LIMIT     USED
-	IFS=OIFS
-	vmstat -z | sed "1,2d;/^$/d" | while read l; do
-		IFS=':,'
+	[ -z "$optz" ] && vmstat -z | sed "1,2d;/^$/d;s/: /, /" |
+	    while read l; do
+		IFS=','
 		set $l
+		[ $# -ne 8 ] &&
+		    { echo "# args must be 8, but is $#in $l" 1>&2;
+		        continue; }
 		size=$2
 		used=$4
-		[ "$used" -ne 0 ] &&
-		    echo "vmstat -z $1,$((size * used))"
+		[ -z "$used" -o -z "$size" ] &&
+		    { echo "used/size not set $l" 1>&2; continue; }
+		tot=$((size * used / 1024))
+		[ $tot -ne 0 ] &&
+		   echo "vmstat -z $1,$tot"
 	done
+
+	echo "vm.cnt.v_wire_count, \
+	    $((`sysctl -n vm.stats.vm.v_wire_count` * 4))"
 	sleep 10
 done | awk $debug -F, '
 {
-# Pairs of "name, value" are passed to this awk script
+# Pairs of "name, value" are passed to this awk script.
 	name=$1;
 	size=$2;
 	if (size > s[name]) {
@@ -65,7 +84,7 @@ done | awk $debug -F, '
 			cmd | getline t;
 			close(cmd);
 			printf "%s \"%s\" %'\''dK\r\n", t,
-			    name, size / 1024;
+			    name, size;
 			n[name] = 0;
 		}
 		s[name] = size;
@@ -74,4 +93,8 @@ done | awk $debug -F, '
 			    name, s[name], n[name]
 	} else if (size < s[name] && n[name] > 0)
 		n[name]--
-}'
+}' | while read l; do
+	d=$(((`date '+%s'` - start) / 86400))
+	echo "$d $l"
+done
+# Note: the %'d is used to trigger a thousands-separator character.



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