]> git.lizzy.rs Git - rust.git/blob - src/etc/cpu-usage-over-time-plot.sh
Rollup merge of #96763 - Abdur-rahmaanJ:patch-1, r=Mark-Simulacrum
[rust.git] / src / etc / cpu-usage-over-time-plot.sh
1 #!/bin/bash
2
3 # A small script to help visualizing CPU usage over time data collected on CI
4 # using `gnuplot`.
5 #
6 # This script is expected to be called with two arguments. The first is the full
7 # commit SHA of the build you're interested in, and the second is the name of
8 # the builder. For example:
9 #
10 #  ./src/etc/cpu-usage-over-time-plot.sh 7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c x86_64-gnu
11 #
12 # That will generate `$builder.png` in the current directory which you can open
13 # up to see a hopefully pretty graph.
14 #
15 # Improvements to this script are greatly appreciated!
16
17 if [[ $# != 2 ]]; then
18     echo "expected 2 arguments, received $#"
19     echo "example usage: './src/etc/cpu-usage-over-time-plot.sh \
20 7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c \
21 x86_64-gnu'"
22     exit 1
23 fi
24
25 set -ex
26
27 bucket=rust-lang-ci2
28 commit=$1
29 builder=$2
30
31 curl -O https://$bucket.s3.amazonaws.com/rustc-builds/$commit/cpu-$builder.csv
32
33 gnuplot <<-EOF
34 reset
35 set timefmt '%Y-%m-%dT%H:%M:%S'
36 set xdata time
37 set ylabel "CPU Usage %"
38 set xlabel "Time"
39 set datafile sep ','
40 set term png size 3000,1000
41 set output "$builder-$commit-cpu-usage-plot.png"
42 set grid
43
44 f(x) = mean_y
45 fit f(x) 'cpu-$builder.csv' using 1:(100-\$2) via mean_y
46
47 set label 1 gprintf("Average = %g%%", mean_y) center font ",18"
48 set label 1 at graph 0.50, 0.25
49 set xtics rotate by 45 offset -2,-2.4 300
50 set ytics 10
51 set boxwidth 0.5
52
53 plot \\
54     mean_y with lines linetype 1 linecolor rgb "#ff0000" title "average", "cpu-$builder.csv" \\
55     using 1:(100-\$2) with points pointtype 7 pointsize 0.4 title "$builder", "" \\
56     using 1:(100-\$2) smooth bezier linewidth 3 title "bezier"
57 EOF
58
59 rm "cpu-$builder.csv"