source: trunk/misc/tools/memlog/memlog.sh @ 8813

Last change on this file since 8813 was 8427, checked in by davies, 12 years ago

Adding the trapezoidal channel validation test, and editing the ANUGA manual

File size: 1.2 KB
Line 
1#!/bin/bash
2################################################################################
3# A simple program to log memory usage of a command.
4#
5# Usage: memlog <cmd> [<params>]
6#
7# The logfile written is ./<cmd>.log and has the form:
8#     YYYYMMDD HH:MM:SS|<resident> <virtual>
9################################################################################
10
11PROGNAME=$(basename $0)
12
13######
14# Write to the log file
15######
16
17log()
18{
19    DT=$(date +"%Y%m%d %H:%M:%S:")
20    echo "$DT|$1 $2" >>$LOG
21}
22
23######
24# Give user some help
25######
26
27usage()
28{
29    echo "Usage: $PROGNAME <cmd> [<params>]"
30    echo "This will attempt to start the  '<cmd> [<params>]' program, and will"
31    echo "write a log file at ./<cmd>.log."
32    exit 10
33}
34
35######
36# Get parameters.
37######
38
39if [ $# -lt 1 ]; then
40    usage
41fi
42
43CMD=$*
44LOG="$1.log"
45
46######
47# Start command
48######
49
50$CMD &
51PID=$!
52
53######
54# Loop, getting $PID memory usage.
55######
56
57while true; do
58    sleep 1
59    DATA=$(ps -o rss,vsize -p $PID | tail -1)
60    RSS=$(echo $DATA | awk '{print $1}')
61    VSIZE=$(echo $DATA | awk '{print $2}')
62
63    # if child process finished, break out
64    if [ "$RSS" == "RSS" ]; then
65        break
66    fi
67
68    log $RSS $VSIZE
69done
Note: See TracBrowser for help on using the repository browser.