summaryrefslogtreecommitdiffstats
path: root/scripts/contrib/bb-perf/buildstats.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/contrib/bb-perf/buildstats.sh')
-rwxr-xr-xscripts/contrib/bb-perf/buildstats.sh99
1 files changed, 82 insertions, 17 deletions
diff --git a/scripts/contrib/bb-perf/buildstats.sh b/scripts/contrib/bb-perf/buildstats.sh
index 96158a9650..8d7e2488f0 100755
--- a/scripts/contrib/bb-perf/buildstats.sh
+++ b/scripts/contrib/bb-perf/buildstats.sh
@@ -18,24 +18,40 @@
18# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19# 19#
20# DESCRIPTION 20# DESCRIPTION
21# Given a 'buildstats' path (created by bitbake when setting 21# Given 'buildstats' data (generate by bitbake when setting
22# USER_CLASSES ?= "buildstats" on local.conf) and task names, outputs 22# USER_CLASSES ?= "buildstats" on local.conf), task names and a stats values
23# '<task> <recipe> <elapsed time>' for all recipes. Elapsed times are in 23# (these are the ones preset on the buildstats files), outputs
24# seconds, and task should be given without the 'do_' prefix. 24# '<task> <recipe> <value_1> <value_2> ... <value_n>'. The units are the ones
25# defined at buildstats, which in turn takes data from /proc/[pid] files
25# 26#
26# Some useful pipelines 27# Some useful pipelines
27# 28#
28# 1. Tasks with largest elapsed times 29# 1. Tasks with largest stime (Amount of time that this process has been scheduled
29# $ buildstats.sh -b <buildstats> | sort -k3 -n -r | head 30# in kernel mode) values
31# $ buildstats.sh -b <buildstats> -s stime | sort -k3 -n -r | head
30# 32#
31# 2. Min, max, sum per task (in needs GNU datamash) 33# 2. Min, max, sum utime (Amount of time that this process has been scheduled
32# $ buildstats.sh -b <buildstats> | datamash -t' ' -g1 min 3 max 3 sum 3 | sort -k4 -n -r 34# in user mode) per task (in needs GNU datamash)
35# $ buildstats.sh -b <buildstats> -s utime | datamash -t' ' -g1 min 3 max 3 sum 3 | sort -k4 -n -r
33# 36#
34# AUTHORS 37# AUTHORS
35# Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com> 38# Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com>
36# 39#
40
41# Stats, by type
42TIME="utime:stime:cutime:cstime"
43IO="IO wchar:IO write_bytes:IO syscr:IO read_bytes:IO rchar:IO syscw:IO cancelled_write_bytes"
44RUSAGE="rusage ru_utime:rusage ru_stime:rusage ru_maxrss:rusage ru_minflt:rusage ru_majflt:\
45rusage ru_inblock:rusage ru_oublock:rusage ru_nvcsw:rusage ru_nivcsw"
46
47CHILD_RUSAGE="Child rusage ru_utime:Child rusage ru_stime:Child rusage ru_maxrss:Child rusage ru_minflt:\
48Child rusage ru_majflt:Child rusage ru_inblock:Child rusage ru_oublock:Child rusage ru_nvcsw:\
49Child rusage ru_nivcsw"
50
37BS_DIR="tmp/buildstats" 51BS_DIR="tmp/buildstats"
38TASKS="compile:configure:fetch:install:patch:populate_lic:populate_sysroot:unpack" 52TASKS="compile:configure:fetch:install:patch:populate_lic:populate_sysroot:unpack"
53STATS="$TIME"
54HEADER="" # No header by default
39 55
40function usage { 56function usage {
41CMD=$(basename $0) 57CMD=$(basename $0)
@@ -45,12 +61,20 @@ Usage: $CMD [-b buildstats_dir] [-t do_task]
45 (default: "$BS_DIR") 61 (default: "$BS_DIR")
46 -t tasks The tasks to be computed 62 -t tasks The tasks to be computed
47 (default: "$TASKS") 63 (default: "$TASKS")
64 -s stats The stats to be matched. Options: TIME, IO, RUSAGE, CHILD_RUSAGE
65 or any other defined buildstat separated by colons, i.e. stime:utime
66 (default: "$STATS")
67 Default stat sets:
68 TIME=$TIME
69 IO=$IO
70 RUSAGE=$RUSAGE
71 CHILD_RUSAGE=$CHILD_RUSAGE
48 -h Display this help message 72 -h Display this help message
49EOM 73EOM
50} 74}
51 75
52# Parse and validate arguments 76# Parse and validate arguments
53while getopts "b:t:h" OPT; do 77while getopts "b:t:s:Hh" OPT; do
54 case $OPT in 78 case $OPT in
55 b) 79 b)
56 BS_DIR="$OPTARG" 80 BS_DIR="$OPTARG"
@@ -58,6 +82,12 @@ while getopts "b:t:h" OPT; do
58 t) 82 t)
59 TASKS="$OPTARG" 83 TASKS="$OPTARG"
60 ;; 84 ;;
85 s)
86 STATS="$OPTARG"
87 ;;
88 H)
89 HEADER="y"
90 ;;
61 h) 91 h)
62 usage 92 usage
63 exit 0 93 exit 0
@@ -76,15 +106,50 @@ if [ ! -d "$BS_DIR" ]; then
76 exit 1 106 exit 1
77fi 107fi
78 108
79RECIPE_FIELD=1 109stats=""
80TIME_FIELD=4 110IFS=":"
111for stat in ${STATS}; do
112 case $stat in
113 TIME)
114 stats="${stats}:${TIME}"
115 ;;
116 IO)
117 stats="${stats}:${IO}"
118 ;;
119 RUSAGE)
120 stats="${stats}:${RUSAGE}"
121 ;;
122 CHILD_RUSAGE)
123 stats="${stats}:${CHILD_RUSAGE}"
124 ;;
125 *)
126 stats="${STATS}"
127 esac
128done
129
130# remove possible colon at the beginning
131stats="$(echo "$stats" | sed -e 's/^://1')"
132
133# Provide a header if required by the user
134[ -n "$HEADER" ] && { echo "task:recipe:$stats"; }
81 135
82tasks=(${TASKS//:/ }) 136for task in ${TASKS}; do
83for task in "${tasks[@]}"; do
84 task="do_${task}" 137 task="do_${task}"
85 for file in $(find ${BS_DIR} -type f -name ${task}); do 138 for file in $(find ${BS_DIR} -type f -name ${task} | awk 'BEGIN{ ORS=""; OFS=":" } { print $0,"" }'); do
86 recipe=$(sed -n -e "/$task/p" ${file} | cut -d ':' -f${RECIPE_FIELD}) 139 recipe="$(basename $(dirname $file))"
87 time=$(sed -n -e "/$task/p" ${file} | cut -d ':' -f${TIME_FIELD} | cut -d ' ' -f2) 140 times=""
88 echo "${task} ${recipe} ${time}" 141 for stat in ${stats}; do
142 [ -z "$stat" ] && { echo "empty stats"; }
143 time=$(sed -n -e "s/^\($stat\): \\(.*\\)/\\2/p" $file)
144 # in case the stat is not present, set the value as NA
145 [ -z "$time" ] && { time="NA"; }
146 # Append it to times
147 if [ -z "$times" ]; then
148 times="${time}"
149 else
150 times="${times} ${time}"
151 fi
152 done
153 echo "${task} ${recipe} ${times}"
89 done 154 done
90done 155done