blob: 898834e5ac293527a222023749b62be94a3d23da [file] [log] [blame]
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001#!/usr/bin/env bash
2#
3# Copyright (c) 2011, Intel Corporation.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05004#
Brad Bishopc342db32019-05-15 21:57:59 -04005# SPDX-License-Identifier: GPL-2.0-or-later
Brad Bishop6e60e8b2018-02-01 10:27:11 -05006#
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
37set -o nounset
38set -o errexit
39
40BS_DIR="tmp/buildstats"
41N=10
42STATS="utime"
43SUM=""
44OUTDATA_FILE="$PWD/buildstats-plot.out"
45
46function usage {
47 CMD=$(basename $0)
48 cat <<EOM
49Usage: $CMD [-b buildstats_dir] [-t do_task]
50 -b buildstats The path where the folder resides
51 (default: "$BS_DIR")
52 -n N Top N recipes to display. Ignored if -S is present
53 (default: "$N")
54 -s stats The stats to be matched. If more that one stat, units
55 should be the same because data is plot as histogram.
56 (see buildstats.sh -h for all options) or any other defined
57 (build)stat separated by colons, i.e. stime:utime
58 (default: "$STATS")
59 -S Sum values for a particular stat for found recipes
60 -o Output data file.
61 (default: "$OUTDATA_FILE")
62 -h Display this help message
63EOM
64}
65
66# Parse and validate arguments
67while getopts "b:n:s:o:Sh" OPT; do
68 case $OPT in
69 b)
70 BS_DIR="$OPTARG"
71 ;;
72 n)
73 N="$OPTARG"
74 ;;
75 s)
76 STATS="$OPTARG"
77 ;;
78 S)
79 SUM="y"
80 ;;
81 o)
82 OUTDATA_FILE="$OPTARG"
83 ;;
84 h)
85 usage
86 exit 0
87 ;;
88 *)
89 usage
90 exit 1
91 ;;
92 esac
93done
94
95# Get number of stats
96IFS=':'; statsarray=(${STATS}); unset IFS
97nstats=${#statsarray[@]}
98
99# Get script folder, use to run buildstats.sh
100CD=$(dirname $0)
101
102# Parse buildstats recipes to produce a single table
103OUTBUILDSTATS="$PWD/buildstats.log"
104$CD/buildstats.sh -H -s "$STATS" -H > $OUTBUILDSTATS
105
106# Get headers
107HEADERS=$(cat $OUTBUILDSTATS | sed -n -e '1s/ /-/g' -e '1s/:/ /gp')
108
109echo -e "set boxwidth 0.9 relative"
110echo -e "set style data histograms"
111echo -e "set style fill solid 1.0 border lt -1"
112echo -e "set xtics rotate by 45 right"
113
114# Get output data
115if [ -z "$SUM" ]; then
116 cat $OUTBUILDSTATS | sed -e '1d' | sort -k3 -n -r | head -$N > $OUTDATA_FILE
117 # include task at recipe column
118 sed -i -e "1i\
119${HEADERS}" $OUTDATA_FILE
120 echo -e "set title \"Top task/recipes\""
121 echo -e "plot for [COL=3:`expr 3 + ${nstats} - 1`] '${OUTDATA_FILE}' using COL:xtic(stringcolumn(1).' '.stringcolumn(2)) title columnheader(COL)"
122else
123
124 # Construct datatamash sum argument (sum 3 sum 4 ...)
125 declare -a sumargs
126 j=0
127 for i in `seq $nstats`; do
128 sumargs[j]=sum; j=$(( $j + 1 ))
129 sumargs[j]=`expr 3 + $i - 1`; j=$(( $j + 1 ))
130 done
131
132 # Do the processing with datamash
133 cat $OUTBUILDSTATS | sed -e '1d' | datamash -t ' ' -g1 ${sumargs[*]} | sort -k2 -n -r > $OUTDATA_FILE
134
135 # Include headers into resulted file, so we can include gnuplot xtics
136 HEADERS=$(echo $HEADERS | sed -e 's/recipe//1')
137 sed -i -e "1i\
138${HEADERS}" $OUTDATA_FILE
139
140 # Plot
141 echo -e "set title \"Sum stats values per task for all recipes\""
142 echo -e "plot for [COL=2:`expr 2 + ${nstats} - 1`] '${OUTDATA_FILE}' using COL:xtic(1) title columnheader(COL)"
143fi
144