3 ##############################################################################
4 # Copyright (c) 2015 Ericsson AB and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
14 # Commandline arguments
20 OUTPUT_FILE=/tmp/perfout.txt
25 COMMA_SEP_E=$( IFS=$','; echo "${EVENTS[*]}" )
27 if [[ $PAYLOAD_OP == dd* ]]
29 sudo perf stat -o $OUTPUT_FILE -e ${COMMA_SEP_E[@]} $PAYLOAD_OP &
31 sudo killall -q -u root dd
33 sudo perf stat -o $OUTPUT_FILE -e ${COMMA_SEP_E[@]} $PAYLOAD_OP
37 # write the result to stdout in json format
42 last_pos=$(( ${#EVENTS[*]} - 1 ))
43 last=${EVENTS[$last_pos]}
46 for EVENT in ${EVENTS[@]}
48 value=$(cat $OUTPUT_FILE | grep $EVENT | awk 'match($0,/[0-9]+|[0-9]+\.[0-9]*/, a) { print a[0]}')
50 if [[ $EVENT != $last ]]
52 echo -n \"$EVENT\": $value,
54 echo -n \"$EVENT\": $value
63 run_perf > /dev/null 2>&1