1*86d7f5d3SJohn Marino#!/bin/sh 2*86d7f5d3SJohn Marino 3*86d7f5d3SJohn Marino# 4*86d7f5d3SJohn Marino# Copyright (c) 2008 Peter Holm <pho@FreeBSD.org> 5*86d7f5d3SJohn Marino# All rights reserved. 6*86d7f5d3SJohn Marino# 7*86d7f5d3SJohn Marino# Redistribution and use in source and binary forms, with or without 8*86d7f5d3SJohn Marino# modification, are permitted provided that the following conditions 9*86d7f5d3SJohn Marino# are met: 10*86d7f5d3SJohn Marino# 1. Redistributions of source code must retain the above copyright 11*86d7f5d3SJohn Marino# notice, this list of conditions and the following disclaimer. 12*86d7f5d3SJohn Marino# 2. Redistributions in binary form must reproduce the above copyright 13*86d7f5d3SJohn Marino# notice, this list of conditions and the following disclaimer in the 14*86d7f5d3SJohn Marino# documentation and/or other materials provided with the distribution. 15*86d7f5d3SJohn Marino# 16*86d7f5d3SJohn Marino# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17*86d7f5d3SJohn Marino# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*86d7f5d3SJohn Marino# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*86d7f5d3SJohn Marino# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20*86d7f5d3SJohn Marino# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21*86d7f5d3SJohn Marino# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22*86d7f5d3SJohn Marino# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23*86d7f5d3SJohn Marino# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24*86d7f5d3SJohn Marino# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25*86d7f5d3SJohn Marino# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26*86d7f5d3SJohn Marino# SUCH DAMAGE. 27*86d7f5d3SJohn Marino# 28*86d7f5d3SJohn Marino# $FreeBSD$ 29*86d7f5d3SJohn Marino# 30*86d7f5d3SJohn Marino 31*86d7f5d3SJohn Marino# Script to catch possible leaks in vm, malloc and mbufs 32*86d7f5d3SJohn Marino# Report values growing in 10 consecuitive samples 33*86d7f5d3SJohn Marino 34*86d7f5d3SJohn Marinoi=0 35*86d7f5d3SJohn Marinowhile true; do 36*86d7f5d3SJohn Marino # Check for leaks in vm.zone 37*86d7f5d3SJohn Marino 38*86d7f5d3SJohn Marino# ITEM SIZE LIMIT USED FREE REQUESTS 39*86d7f5d3SJohn Marino# 40*86d7f5d3SJohn Marino# UMA Kegs: 140, 0, 66, 6, 66 41*86d7f5d3SJohn Marino# UMA Zones: 120, 0, 66, 24, 66 42*86d7f5d3SJohn Marino 43*86d7f5d3SJohn Marino 44*86d7f5d3SJohn Marino vmstat -z | sed '1,3d;s/://g' | \ 45*86d7f5d3SJohn Marino sed 's/ */ /g;s/\([0-9]\) *\([0-9]\)/\1,\2/g;s/ \([0-9]\)/,\1/;s/^ *//' | \ 46*86d7f5d3SJohn Marino awk -F, ' 47*86d7f5d3SJohn Marino/^..*$/{ 48*86d7f5d3SJohn Marino gsub("^ *", "", $1); 49*86d7f5d3SJohn Marino size=$4; 50*86d7f5d3SJohn Marino printf "vmstat -z %s,%s\n", $1, size; 51*86d7f5d3SJohn Marino} 52*86d7f5d3SJohn Marino' 53*86d7f5d3SJohn Marino # vmstat -m 54*86d7f5d3SJohn Marino 55*86d7f5d3SJohn Marino # Type InUse MemUse HighUse Requests Size(s) 56*86d7f5d3SJohn Marino # DEVFS3 168 21K - 169 128 57*86d7f5d3SJohn Marino # DEVFS1 157 40K - 157 256 58*86d7f5d3SJohn Marino # DEVFS 12 1K - 13 16,128 59*86d7f5d3SJohn Marino vmstat -m | \ 60*86d7f5d3SJohn Marino sed '1,1d;s/K .*//;s/ [0-9][0-9]* //;s/ */ /g;s/^ *//;s/ /_/g;s/_\([0-9][0-9]*$\)/ \1/' | \ 61*86d7f5d3SJohn Marino awk '{printf "vmstat -m %s, %d\n", $1, $2}' 62*86d7f5d3SJohn Marino 63*86d7f5d3SJohn Marino # Check for leaks in mbufs 64*86d7f5d3SJohn Marino 65*86d7f5d3SJohn Marino# $ netstat -m 66*86d7f5d3SJohn Marino# 1233/597/1830 mbufs in use (current/cache/total) 67*86d7f5d3SJohn Marino# 1232/196/1428/8896 mbuf clusters in use (current/cache/total/max) 68*86d7f5d3SJohn Marino# 1232/74 mbuf+clusters out of packet secondary zone in use (current/cache) 69*86d7f5d3SJohn Marino# 0/0/0/0 4k (page size) jumbo clusters in use (current/cache/total/max) 70*86d7f5d3SJohn Marino# 0/0/0/0 9k jumbo clusters in use (current/cache/total/max) 71*86d7f5d3SJohn Marino# 0/0/0/0 16k jumbo clusters in use (current/cache/total/max) 72*86d7f5d3SJohn Marino# 2772K/541K/3313K bytes allocated to network (current/cache/total) 73*86d7f5d3SJohn Marino# 508/7778/5734 requests for mbufs denied (mbufs/clusters/mbuf+clusters) 74*86d7f5d3SJohn Marino# 0/0/0 requests for jumbo clusters denied (4k/9k/16k) 75*86d7f5d3SJohn Marino# 0/6/2480 sfbufs in use (current/peak/max) 76*86d7f5d3SJohn Marino# 0 requests for sfbufs denied 77*86d7f5d3SJohn Marino# 0 requests for sfbufs delayed 78*86d7f5d3SJohn Marino# 0 requests for I/O initiated by sendfile 79*86d7f5d3SJohn Marino# 251 calls to protocol drain routines 80*86d7f5d3SJohn Marino 81*86d7f5d3SJohn Marino 82*86d7f5d3SJohn Marino netstat -m | head -10 | sed 's#/# #g;s/k / /;s/K / /' | awk ' 83*86d7f5d3SJohn Marino/mbufs / {mbufs=$1}; 84*86d7f5d3SJohn Marino/ clusters/ {clusters=$2}; 85*86d7f5d3SJohn Marino/sfbufs in use/ {sfbufs=$3}; 86*86d7f5d3SJohn Marino/allocated/ {allocated=$1} 87*86d7f5d3SJohn MarinoEND { 88*86d7f5d3SJohn Marino print "mbufs,", mbufs; 89*86d7f5d3SJohn Marino print "clusters,", clusters; 90*86d7f5d3SJohn Marino print "sfbufs,", sfbufs; 91*86d7f5d3SJohn Marino print "allocatedToNetwork,", allocated; 92*86d7f5d3SJohn Marino} 93*86d7f5d3SJohn Marino' 94*86d7f5d3SJohn Marino sysctl vm.kvm_free | tail -1 | sed 's/:/,/' 95*86d7f5d3SJohn Marino sleep 10 96*86d7f5d3SJohn Marinodone | awk -F, ' 97*86d7f5d3SJohn Marino{ 98*86d7f5d3SJohn Marino# Pairs of "name, value" are passed to this awk script 99*86d7f5d3SJohn Marino name=$1; 100*86d7f5d3SJohn Marino size=$2; 101*86d7f5d3SJohn Marino# print "name, size :", name, size; 102*86d7f5d3SJohn Marino if (NF != 2) 103*86d7f5d3SJohn Marino print "Number of fields for ", name, "is ", NF; 104*86d7f5d3SJohn Marino if (size > s[name]) { 105*86d7f5d3SJohn Marino n[name]++; 106*86d7f5d3SJohn Marino if (n[name] > 10) { 107*86d7f5d3SJohn Marino cmd="date '+%T'"; 108*86d7f5d3SJohn Marino cmd | getline t; 109*86d7f5d3SJohn Marino close(cmd); 110*86d7f5d3SJohn Marino printf "%s \"%s\" may be leaking, size %d\n", t, name, size; 111*86d7f5d3SJohn Marino n[name] = 0; 112*86d7f5d3SJohn Marino } 113*86d7f5d3SJohn Marino s[name] = size; 114*86d7f5d3SJohn Marino } else { 115*86d7f5d3SJohn Marino if (n[name] > 0) 116*86d7f5d3SJohn Marino n[name]--; 117*86d7f5d3SJohn Marino } 118*86d7f5d3SJohn Marino}' 119