aboutsummaryrefslogtreecommitdiff
path: root/heatmaps/perf-to-inst-page.sh
blob: 5be1a2b934aeedda66981c5eacb2bda6dc3d003d (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
60
61
62
63
64
65
66
67
68
#! /bin/bash -u
# Copyright 2015 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# This script takes the out.txt, generated by heatmap_generator.py
# and sorted into a heatmap data file (inst-histo.txt) and then
# call gnu plot to draw the heat map and the time map.
# A heat map shows the overall hotness of instructions being executed
# while the time map shows the hotness of instruction at different time.
#
# Usage:
# ./perf-to-inst-page.sh HEATMAP_TITLE
# HEATMAP_TITLE: the title to display on the heatmap

HEAT_PNG="heat_map.png"
TIMELINE_PNG="timeline.png"
HEATMAP_TITLE=$1
ENABLE_HUGEPAGE=$2

heatmap_command="
set terminal png size 600,450
set xlabel \"Instruction Virtual Address (MB)\"
set ylabel \"Sample Occurance\"
set grid

set output \"${HEAT_PNG}\"
set title \"${HEATMAP_TITLE}\"
"

if [[ "${ENABLE_HUGEPAGE}" = "hugepage" ]]; then
  hugepage_hist="inst-histo-hp.txt"
  smallpage_hist="inst-histo-sp.txt"
  cat out.txt | grep hugepage | awk '{print $3}' \
    | sort -n | uniq -c > "${hugepage_hist}"
  cat out.txt | grep smallpage | awk '{print $3}' \
    | sort -n | uniq -c > "${smallpage_hist}"
  # generate inst heat map
  heatmap_in_hugepage=("'${hugepage_hist}' using \
(\$2/1024/1024):1 with impulses notitle lt rgb 'red'")
  heatmap_outside_hugepage=("'${smallpage_hist}' using \
(\$2/1024/1024):1 with impulses notitle lt rgb 'blue'")
  echo "
  ${heatmap_command}
  plot ${heatmap_in_hugepage}, ${heatmap_outside_hugepage}
  " | gnuplot
else
  awk '{print $3}' out.txt | sort -n | uniq -c > inst-histo.txt
  # generate inst heat map
  echo "
  ${heatmap_command}
  plot 'inst-histo.txt' using (\$2/1024/1024):1 with impulses notitle
  " | gnuplot
fi

# generate instruction page access timeline
num=$(awk 'END {print NR+1}' out.txt)

echo "
set terminal png size 600,450
set xlabel \"time (sec)\"
set ylabel \"Instruction Virtual Address (MB)\"

set output \"${TIMELINE_PNG}\"
set title \"instruction page accessd timeline\"

plot 'out.txt' using (\$0/$num*10):(\$3/1024/1024) with dots notitle
" | gnuplot