summaryrefslogtreecommitdiffstats
path: root/src/etc/cpu-usage-over-time-plot.sh
blob: 2617378ba5fd2d5cec6186e005fedb2b9841ae5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash

# A small script to help visualizing CPU usage over time data collected on CI
# using `gnuplot`.
#
# This script is expected to be called with two arguments. The first is the full
# commit SHA of the build you're interested in, and the second is the name of
# the builder. For example:
#
#  ./src/etc/cpu-usage-over-time-plot.sh 7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c x86_64-gnu
#
# That will generate `$builder.png` in the current directory which you can open
# up to see a hopefully pretty graph.
#
# Improvements to this script are greatly appreciated!

if [[ $# != 2 ]]; then
    echo "expected 2 arguments, received $#"
    echo "example usage: './src/etc/cpu-usage-over-time-plot.sh \
7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c \
x86_64-gnu'"
    exit 1
fi

set -ex

bucket=rust-lang-ci2
commit=$1
builder=$2

curl -O https://$bucket.s3.amazonaws.com/rustc-builds/$commit/cpu-$builder.csv

gnuplot <<-EOF
reset
set timefmt '%Y-%m-%dT%H:%M:%S'
set xdata time
set ylabel "CPU Usage %"
set xlabel "Time"
set datafile sep ','
set term png size 3000,1000
set output "$builder-$commit-cpu-usage-plot.png"
set grid

f(x) = mean_y
fit f(x) 'cpu-$builder.csv' using 1:(100-\$2) via mean_y

set label 1 gprintf("Average = %g%%", mean_y) center font ",18"
set label 1 at graph 0.50, 0.25
set xtics rotate by 45 offset -2,-2.4 300
set ytics 10
set boxwidth 0.5

plot \\
    mean_y with lines linetype 1 linecolor rgb "#ff0000" title "average", "cpu-$builder.csv" \\
    using 1:(100-\$2) with points pointtype 7 pointsize 0.4 title "$builder", "" \\
    using 1:(100-\$2) smooth bezier linewidth 3 title "bezier"
EOF

rm "cpu-$builder.csv"