Permalink
Browse files

[svn] Added some debug helpers

  • Loading branch information...
1 parent 81ac502 commit ae0d8451f00a8323543bd018c12e04b77708b3d2 rasmus committed Feb 14, 2008
Showing with 65 additions and 0 deletions.
  1. +42 −0 debug/functions.sh
  2. +23 −0 debug/log_usage.sh
View
@@ -0,0 +1,42 @@
+get_rss() { # int (int pid) - returns resident size in KB
+ PID=$1
+ if [ "$(uname -s)" == "Darwin" ]; then
+ cat /proc/$PID/task/basic_info/resident_size|sed -E 's/[^0-9]//g';
+ else # assume linux
+ cat /proc/$PID/status|grep VmRSS:|sed -r 's/[^0-9]//g'
+ fi
+}
+
+sleep_fine() {
+ python -c 'import time;time.sleep('$1')'
+}
+
+ps_find_pid() { # (string grep_for_to_find)
+ ps x|grep "$1"|grep -v "grep $1"|sed 's/^ *//g'|cut -d ' ' -f 1
+}
+
+lighty_start() { # (string in_directory)
+ cd "$1"
+ lighttpd -f lighttpd.conf
+ sleep 1
+ read LIGTHY_PID < server.pid
+}
+
+lighty_stop() {
+ if [ "$LIGTHY_PID" != "" ]; then
+ kill $LIGTHY_PID
+ sleep 2
+ kill -9 $LIGTHY_PID 2> /dev/null
+ rm -f server.pid
+ fi
+}
+
+make_request() { # (string extra_opts_to_curl)
+ R=$(curl -i --silent $1 localhost:8080/receive)
+ if [ "$(echo "$R"|grep 'HTTP/1.1 200 OK')" == "" ]; then
+ echo 'Non-200 response: '$R >&2
+ lighty_stop
+ exit 1
+ fi
+}
+
View
@@ -0,0 +1,23 @@
+#!/bin/sh
+#
+# Example usage:
+# ./log_usage.sh 1234|tee smisk_usage.log
+#
+cd $(dirname "$0")
+. functions.sh
+
+if [ $# -lt 2 ]; then
+ echo "usage: $0 PID INTERVAL" >&2
+ exit 1
+fi
+PID=$1
+INTERVAL=$2
+if [ ! -d /proc/$PID ]; then
+ echo "/proc/$PID not found - wrong PID?" >&2
+ echo "usage: $0 PID" >&2
+ exit 1
+fi
+while true; do
+ get_rss $PID;
+ sleep $INTERVAL;
+done

0 comments on commit ae0d845

Please sign in to comment.