blob: 5ae107a52c54ec8289e2a2483edf32b744429ed1 (
plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
|
#!/bin/sh
##############################################################################
# Copyright (c) 2015 Ericsson AB and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
set -e
# Commandline arguments
PAYLOAD_OP=$1
shift
DURATION=$1
shift
EVENTS=("$@")
OUTPUT_FILE=/tmp/perfout.txt
# run perf test
run_perf()
{
COMMA_SEP_E=$( IFS=$','; echo "${EVENTS[*]}" )
if [[ $PAYLOAD_OP == dd* ]]
then
sudo perf stat -o $OUTPUT_FILE -e ${COMMA_SEP_E[@]} $PAYLOAD_OP &
sleep $DURATION
sudo killall -q -u root dd
else
sudo perf stat -o $OUTPUT_FILE -e ${COMMA_SEP_E[@]} $PAYLOAD_OP
fi
}
# write the result to stdout in json format
output_json()
{
EVENTS+=('time')
last_pos=$(( ${#EVENTS[*]} - 1 ))
last=${EVENTS[$last_pos]}
echo -n {
for EVENT in ${EVENTS[@]}
do
value=$(cat $OUTPUT_FILE | grep $EVENT | awk 'match($0,/[0-9]+|[0-9]+\.[0-9]*/, a) { print a[0]}')
if [[ $EVENT != $last ]]
then
echo -n \"$EVENT\": $value,
else
echo -n \"$EVENT\": $value
fi
done
echo }
}
# main entry
main()
{
run_perf > /dev/null 2>&1
sleep 1
output_json
}
main
|