Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # Copyright (c) 2011, Intel Corporation. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 4 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 5 | # SPDX-License-Identifier: GPL-2.0-or-later |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 6 | # |
| 7 | # DESCRIPTION |
| 8 | # |
| 9 | # Produces script data to be consumed by gnuplot. There are two possible plots |
| 10 | # depending if either the -S parameter is present or not: |
| 11 | # |
| 12 | # * without -S: Produces a histogram listing top N recipes/tasks versus |
| 13 | # stats. The first stat defined in the -s parameter is the one taken |
| 14 | # into account for ranking |
| 15 | # * -S: Produces a histogram listing tasks versus stats. In this case, |
| 16 | # the value of each stat is the sum for that particular stat in all recipes found. |
| 17 | # Stats values are in descending order defined by the first stat defined on -s |
| 18 | # |
| 19 | # EXAMPLES |
| 20 | # |
| 21 | # 1. Top recipes' tasks taking into account utime |
| 22 | # |
| 23 | # $ buildstats-plot.sh -s utime | gnuplot -p |
| 24 | # |
| 25 | # 2. Tasks versus utime:stime |
| 26 | # |
| 27 | # $ buildstats-plot.sh -s utime:stime -S | gnuplot -p |
| 28 | # |
| 29 | # 3. Tasks versus IO write_bytes:IO read_bytes |
| 30 | # |
| 31 | # $ buildstats-plot.sh -s 'IO write_bytes:IO read_bytes' -S | gnuplot -p |
| 32 | # |
| 33 | # AUTHORS |
| 34 | # Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com> |
| 35 | # |
| 36 | |
| 37 | set -o nounset |
| 38 | set -o errexit |
| 39 | |
| 40 | BS_DIR="tmp/buildstats" |
| 41 | N=10 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 42 | RECIPE="" |
| 43 | TASKS="compile:configure:fetch:install:patch:populate_lic:populate_sysroot:unpack" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 44 | STATS="utime" |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 45 | ACCUMULATE="" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 46 | SUM="" |
| 47 | OUTDATA_FILE="$PWD/buildstats-plot.out" |
| 48 | |
| 49 | function usage { |
| 50 | CMD=$(basename $0) |
| 51 | cat <<EOM |
| 52 | Usage: $CMD [-b buildstats_dir] [-t do_task] |
| 53 | -b buildstats The path where the folder resides |
| 54 | (default: "$BS_DIR") |
| 55 | -n N Top N recipes to display. Ignored if -S is present |
| 56 | (default: "$N") |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 57 | -r recipe The recipe mask to be searched |
| 58 | -t tasks The tasks to be computed |
| 59 | (default: "$TASKS") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 60 | -s stats The stats to be matched. If more that one stat, units |
| 61 | should be the same because data is plot as histogram. |
| 62 | (see buildstats.sh -h for all options) or any other defined |
| 63 | (build)stat separated by colons, i.e. stime:utime |
| 64 | (default: "$STATS") |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 65 | -a Accumulate all stats values for found recipes |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 66 | -S Sum values for a particular stat for found recipes |
| 67 | -o Output data file. |
| 68 | (default: "$OUTDATA_FILE") |
| 69 | -h Display this help message |
| 70 | EOM |
| 71 | } |
| 72 | |
| 73 | # Parse and validate arguments |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 74 | while getopts "b:n:r:t:s:o:aSh" OPT; do |
| 75 | case $OPT in |
| 76 | b) |
| 77 | BS_DIR="$OPTARG" |
| 78 | ;; |
| 79 | n) |
| 80 | N="$OPTARG" |
| 81 | ;; |
| 82 | r) |
| 83 | RECIPE="-r $OPTARG" |
| 84 | ;; |
| 85 | t) |
| 86 | TASKS="$OPTARG" |
| 87 | ;; |
| 88 | s) |
| 89 | STATS="$OPTARG" |
| 90 | ;; |
| 91 | a) |
| 92 | ACCUMULATE="-a" |
| 93 | ;; |
| 94 | S) |
| 95 | SUM="y" |
| 96 | ;; |
| 97 | o) |
| 98 | OUTDATA_FILE="$OPTARG" |
| 99 | ;; |
| 100 | h) |
| 101 | usage |
| 102 | exit 0 |
| 103 | ;; |
| 104 | *) |
| 105 | usage |
| 106 | exit 1 |
| 107 | ;; |
| 108 | esac |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 109 | done |
| 110 | |
| 111 | # Get number of stats |
| 112 | IFS=':'; statsarray=(${STATS}); unset IFS |
| 113 | nstats=${#statsarray[@]} |
| 114 | |
| 115 | # Get script folder, use to run buildstats.sh |
| 116 | CD=$(dirname $0) |
| 117 | |
| 118 | # Parse buildstats recipes to produce a single table |
| 119 | OUTBUILDSTATS="$PWD/buildstats.log" |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 120 | $CD/buildstats.sh -b "$BS_DIR" -s "$STATS" -t "$TASKS" $RECIPE $ACCUMULATE -H > $OUTBUILDSTATS |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 121 | |
| 122 | # Get headers |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 123 | HEADERS=$(cat $OUTBUILDSTATS | sed -n -e 's/\(.*\)/"\1"/' -e '1s/ /\\\\\\\\ /g' -e 's/_/\\\\\\\\_/g' -e '1s/:/" "/gp') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 124 | |
| 125 | echo -e "set boxwidth 0.9 relative" |
| 126 | echo -e "set style data histograms" |
| 127 | echo -e "set style fill solid 1.0 border lt -1" |
| 128 | echo -e "set xtics rotate by 45 right" |
| 129 | |
| 130 | # Get output data |
| 131 | if [ -z "$SUM" ]; then |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 132 | cat $OUTBUILDSTATS | sed -e '1d' -e 's/_/\\\\_/g' | sort -k3 -n -r | head -$N > $OUTDATA_FILE |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 133 | # include task at recipe column |
| 134 | sed -i -e "1i\ |
| 135 | ${HEADERS}" $OUTDATA_FILE |
| 136 | echo -e "set title \"Top task/recipes\"" |
| 137 | echo -e "plot for [COL=3:`expr 3 + ${nstats} - 1`] '${OUTDATA_FILE}' using COL:xtic(stringcolumn(1).' '.stringcolumn(2)) title columnheader(COL)" |
| 138 | else |
| 139 | |
| 140 | # Construct datatamash sum argument (sum 3 sum 4 ...) |
| 141 | declare -a sumargs |
| 142 | j=0 |
| 143 | for i in `seq $nstats`; do |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 144 | sumargs[j]=sum; j=$(( $j + 1 )) |
| 145 | sumargs[j]=`expr 3 + $i - 1`; j=$(( $j + 1 )) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 146 | done |
| 147 | |
| 148 | # Do the processing with datamash |
| 149 | cat $OUTBUILDSTATS | sed -e '1d' | datamash -t ' ' -g1 ${sumargs[*]} | sort -k2 -n -r > $OUTDATA_FILE |
| 150 | |
| 151 | # Include headers into resulted file, so we can include gnuplot xtics |
| 152 | HEADERS=$(echo $HEADERS | sed -e 's/recipe//1') |
| 153 | sed -i -e "1i\ |
| 154 | ${HEADERS}" $OUTDATA_FILE |
| 155 | |
| 156 | # Plot |
| 157 | echo -e "set title \"Sum stats values per task for all recipes\"" |
| 158 | echo -e "plot for [COL=2:`expr 2 + ${nstats} - 1`] '${OUTDATA_FILE}' using COL:xtic(1) title columnheader(COL)" |
| 159 | fi |
| 160 | |