Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (c) 2011, Intel Corporation. |
| 4 | # All rights reserved. |
| 5 | # |
| 6 | # This program is free software; you can redistribute it and/or modify |
| 7 | # it under the terms of the GNU General Public License as published by |
| 8 | # the Free Software Foundation; either version 2 of the License, or |
| 9 | # (at your option) any later version. |
| 10 | # |
| 11 | # This program is distributed in the hope that it will be useful, |
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | # GNU General Public License for more details. |
| 15 | # |
| 16 | # You should have received a copy of the GNU General Public License |
| 17 | # along with this program; if not, write to the Free Software |
| 18 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 | # |
| 20 | # DESCRIPTION |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 21 | # Given 'buildstats' data (generate by bitbake when setting |
| 22 | # USER_CLASSES ?= "buildstats" on local.conf), task names and a stats values |
| 23 | # (these are the ones preset on the buildstats files), outputs |
| 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 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 26 | # |
| 27 | # Some useful pipelines |
| 28 | # |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 29 | # 1. Tasks with largest stime (Amount of time that this process has been scheduled |
| 30 | # in kernel mode) values |
| 31 | # $ buildstats.sh -b <buildstats> -s stime | sort -k3 -n -r | head |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 32 | # |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 33 | # 2. Min, max, sum utime (Amount of time that this process has been scheduled |
| 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 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 36 | # |
| 37 | # AUTHORS |
| 38 | # Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com> |
| 39 | # |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 40 | |
| 41 | # Stats, by type |
| 42 | TIME="utime:stime:cutime:cstime" |
| 43 | IO="IO wchar:IO write_bytes:IO syscr:IO read_bytes:IO rchar:IO syscw:IO cancelled_write_bytes" |
| 44 | RUSAGE="rusage ru_utime:rusage ru_stime:rusage ru_maxrss:rusage ru_minflt:rusage ru_majflt:\ |
| 45 | rusage ru_inblock:rusage ru_oublock:rusage ru_nvcsw:rusage ru_nivcsw" |
| 46 | |
| 47 | CHILD_RUSAGE="Child rusage ru_utime:Child rusage ru_stime:Child rusage ru_maxrss:Child rusage ru_minflt:\ |
| 48 | Child rusage ru_majflt:Child rusage ru_inblock:Child rusage ru_oublock:Child rusage ru_nvcsw:\ |
| 49 | Child rusage ru_nivcsw" |
| 50 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 51 | BS_DIR="tmp/buildstats" |
| 52 | TASKS="compile:configure:fetch:install:patch:populate_lic:populate_sysroot:unpack" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 53 | STATS="$TIME" |
| 54 | HEADER="" # No header by default |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 55 | |
| 56 | function usage { |
| 57 | CMD=$(basename $0) |
| 58 | cat <<EOM |
| 59 | Usage: $CMD [-b buildstats_dir] [-t do_task] |
| 60 | -b buildstats The path where the folder resides |
| 61 | (default: "$BS_DIR") |
| 62 | -t tasks The tasks to be computed |
| 63 | (default: "$TASKS") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 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 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 72 | -h Display this help message |
| 73 | EOM |
| 74 | } |
| 75 | |
| 76 | # Parse and validate arguments |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 77 | while getopts "b:t:s:Hh" OPT; do |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 78 | case $OPT in |
| 79 | b) |
| 80 | BS_DIR="$OPTARG" |
| 81 | ;; |
| 82 | t) |
| 83 | TASKS="$OPTARG" |
| 84 | ;; |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 85 | s) |
| 86 | STATS="$OPTARG" |
| 87 | ;; |
| 88 | H) |
| 89 | HEADER="y" |
| 90 | ;; |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 91 | h) |
| 92 | usage |
| 93 | exit 0 |
| 94 | ;; |
| 95 | *) |
| 96 | usage |
| 97 | exit 1 |
| 98 | ;; |
| 99 | esac |
| 100 | done |
| 101 | |
| 102 | # Ensure the buildstats folder exists |
| 103 | if [ ! -d "$BS_DIR" ]; then |
| 104 | echo "ERROR: $BS_DIR does not exist" |
| 105 | usage |
| 106 | exit 1 |
| 107 | fi |
| 108 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 109 | stats="" |
| 110 | IFS=":" |
| 111 | for 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 |
| 128 | done |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 129 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 130 | # remove possible colon at the beginning |
| 131 | stats="$(echo "$stats" | sed -e 's/^://1')" |
| 132 | |
| 133 | # Provide a header if required by the user |
| 134 | [ -n "$HEADER" ] && { echo "task:recipe:$stats"; } |
| 135 | |
| 136 | for task in ${TASKS}; do |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 137 | task="do_${task}" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 138 | for file in $(find ${BS_DIR} -type f -name ${task} | awk 'BEGIN{ ORS=""; OFS=":" } { print $0,"" }'); do |
| 139 | recipe="$(basename $(dirname $file))" |
| 140 | times="" |
| 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}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 154 | done |
| 155 | done |