From owner-svn-src-user@freebsd.org Wed Nov 4 09:16:14 2015 Return-Path: Delivered-To: svn-src-user@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 57BF9A2545A for ; Wed, 4 Nov 2015 09:16:14 +0000 (UTC) (envelope-from pho@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0160E1A0F; Wed, 4 Nov 2015 09:16:13 +0000 (UTC) (envelope-from pho@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tA49GCxM016093; Wed, 4 Nov 2015 09:16:12 GMT (envelope-from pho@FreeBSD.org) Received: (from pho@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tA49GC5Z016091; Wed, 4 Nov 2015 09:16:12 GMT (envelope-from pho@FreeBSD.org) Message-Id: <201511040916.tA49GC5Z016091@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pho set sender to pho@FreeBSD.org using -f From: Peter Holm Date: Wed, 4 Nov 2015 09:16:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r290355 - user/pho/stress2/tools X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Nov 2015 09:16:14 -0000 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.