File: prof

package info (click to toggle)
veryfasttree 4.0.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,308 kB
  • sloc: cpp: 7,403; python: 209; sh: 38; makefile: 36
file content (23 lines) | stat: -rw-r--r-- 358 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env bash

if [ "$#" -lt 3 ]; then
  echo "Usage: FREQ FILE CMD [ARGS]" >&2
  exit 1
fi

freq=$1
file=$2

${@:3} & 
PID=$!

printf "" > $file
while out="$(top -b -n 2 -d 0.2 -p $PID 2>/dev/null)"; do
	if ps -p $PID > /dev/null; then
		echo "$out" | tail -1 | awk '{print $5" "$6" "$7" "$10" "$9}' >> $file
		sleep $freq
	else
		break
	fi
done
wait