-
Notifications
You must be signed in to change notification settings - Fork 1
/
straceCount
executable file
·56 lines (45 loc) · 1.31 KB
/
straceCount
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
selfName=$0
processStraceOutputScriptPath="./.processStraceOutput.awk"
textParcingProgram="gawk"
readonly failure=0
readonly success=1
function testCommandInstalled {
if [ $# -ne 1 ]; then
return $failure
fi
local paths
IFS=$':' paths=( $PATH )
for path in ${paths[@]}
do
if [ -f "$path/$1" ]; then
return $success
fi
done
return $failure
}
testCommandInstalled $textParcingProgram
if [ `echo $?` -ne $success ]; then
echo "straceCount: gawk is used for parcing strace output. Please, install gawk."
exit -1
fi
if [ -z "$1" ]
then
echo -e " Wrong number of argument\n"\
"Please, choose a command to analyze\n"\
"Usage is: $selfName <command> <command arguments .. >"
exit -1
fi
StraceArguments=( $* )
# Extra file descriptor is used to redirect standard output.
# If standart output of traced process will be in 'arr' variable,
# it can overflow it. Moreover, standard output is useless for strace summary.
exec 3>&1
# It is often useful to interrupt process from keyboard
# We should contunue execution of script after strace returns
trap "echo 'straceCount: termination of strace via Ctrl-C or SIGINT'" SIGINT
IFS=$'\n' arr=( `{ strace -c ${StraceArguments[@]} 1>&3; } 2>&1` )
trap -- SIGINT
exec 3>&-
elemNum=${#arr[@]}
printf "%s\n" "${arr[@]}" | gawk -f$processStraceOutputScriptPath 1>&2