• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
17if [[ $# != 2 ]]; then
18    echo "expected 2 arguments, received $#"
19    echo "example usage: './src/etc/cpu-usage-over-time-plot.sh \
207737e0b5c4103216d6fd8cf941b7ab9bdbaace7c \
21x86_64-gnu'"
22    exit 1
23fi
24
25set -ex
26
27bucket=rust-lang-ci2
28commit=$1
29builder=$2
30
31curl -O https://$bucket.s3.amazonaws.com/rustc-builds/$commit/cpu-$builder.csv
32
33gnuplot <<-EOF
34reset
35set timefmt '%Y-%m-%dT%H:%M:%S'
36set xdata time
37set ylabel "CPU Usage %"
38set xlabel "Time"
39set datafile sep ','
40set term png size 3000,1000
41set output "$builder-$commit-cpu-usage-plot.png"
42set grid
43
44f(x) = mean_y
45fit f(x) 'cpu-$builder.csv' using 1:(100-\$2) via mean_y
46
47set label 1 gprintf("Average = %g%%", mean_y) center font ",18"
48set label 1 at graph 0.50, 0.25
49set xtics rotate by 45 offset -2,-2.4 300
50set ytics 10
51set boxwidth 0.5
52
53plot \\
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"
57EOF
58
59rm "cpu-$builder.csv"
60