summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-08-16 21:27:58 +0100
committerPatrick Simianer <p@simianer.de>2014-08-16 21:27:58 +0100
commita3fee2abd19ed0aedebc0f3949fb969f2ce7836e (patch)
tree47b36fa96b5f2c85f49c92e3bd8f53010cf059a4
parentbad18ebfd358e4352643831040e45ad5435eff48 (diff)
memusg, to_ascii
-rwxr-xr-x[l---------]memusg13
-rwxr-xr-xmemusg_git/memusg46
-rwxr-xr-xto_ascii13
3 files changed, 25 insertions, 47 deletions
diff --git a/memusg b/memusg
index 5419241..a69daaa 120000..100755
--- a/memusg
+++ b/memusg
@@ -1 +1,12 @@
-memusg_git/memusg \ No newline at end of file
+#!/bin/bash
+
+
+"$@" &
+pid=$! peak=0
+while true; do
+ sleep 1
+ sample="$(ps -o rss= $pid 2> /dev/null)" || break
+ let peak='sample > peak ? sample : peak'
+done
+echo "$(( ${peak%% *} / 1024)) m"
+
diff --git a/memusg_git/memusg b/memusg_git/memusg
deleted file mode 100755
index 9044a99..0000000
--- a/memusg_git/memusg
+++ /dev/null
@@ -1,46 +0,0 @@
-#!/usr/bin/env bash
-# memusg -- Measure memory usage of processes
-# Usage: memusg COMMAND [ARGS]...
-#
-# Author: Jaeho Shin <netj@sparcs.org>
-# Created: 2010-08-16
-set -um
-
-# check input
-[ $# -gt 0 ] || { sed -n '2,/^#$/ s/^# //p' <"$0"; exit 1; }
-
-# TODO support more options: peak, footprint, sampling rate, etc.
-
-pgid=`ps -o pgid= $$`
-# make sure we're in a separate process group
-if [ $pgid = $(ps -o pgid= $(ps -o ppid= $$)) ]; then
- cmd=
- set -- "$0" "$@"
- for a; do cmd+="'${a//"'"/"'\\''"}' "; done
- exec bash -i -c "$cmd"
-fi
-
-# detect operating system and prepare measurement
-case `uname` in
- Darwin|*BSD) sizes() { /bin/ps -o rss= -g $1; } ;;
- Linux) sizes() { /bin/ps -o rss= -$1; } ;;
- *) echo "`uname`: unsupported operating system" >&2; exit 2 ;;
-esac
-
-# monitor the memory usage in the background.
-(
-peak=0
-while sizes=`sizes $pgid`
-do
- set -- $sizes
- sample=$((${@/#/+}))
- let peak="sample > peak ? sample : peak"
- sleep 0.1
-done
-echo "memusg: peak=$peak" >&2
-) &
-monpid=$!
-
-
-# run the given command
-exec "$@"
diff --git a/to_ascii b/to_ascii
new file mode 100755
index 0000000..6c1d23e
--- /dev/null
+++ b/to_ascii
@@ -0,0 +1,13 @@
+#!/usr/bin/env ruby
+
+
+while line = STDIN.gets
+ encoding_options = {
+ :invalid => :replace,
+ :undef => :replace,
+ :replace => '?',
+ :universal_newline => true
+ }
+ puts line.encode 'ASCII', encoding_options
+end
+