Skip to content

Commit

Permalink
perf: record/compare tracepoint events
Browse files Browse the repository at this point in the history
  • Loading branch information
Wu Fengguang committed Dec 11, 2011
1 parent 63e8c91 commit 3d3989a
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 1 deletion.
83 changes: 83 additions & 0 deletions compare.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,66 @@
$io_vars = [ "dev", "rrqm_s", "wrqm_s", "r_s", "w_s", "rkB_s", "wkB_s", "avgrq_sz", "avgqu_sz", "await", "svctm", "util" ]
$nfs_vars = [ "nr_commits", "nr_writes", "write_total", "commit_size", "write_size", "write_queue_time", "write_rtt_time", "write_execute_time", "commit_queue_time", "commit_rtt_time", "commit_execute_time" ]

$perf_vars = [
"cpu-cycles",
"cycles",
"stalled-cycles-frontend",
"idle-cycles-frontend",
"stalled-cycles-backend",
"idle-cycles-backend",
"instructions",
"cache-references",
"cache-misses",
"branch-instructions",
"branches",
"branch-misses",
"bus-cycles",
"cpu-clock",
"task-clock",
"page-faults",
"faults",
"minor-faults",
"major-faults",
"context-switches",
"cs",
"cpu-migrations",
"migrations",
"alignment-faults",
"emulation-faults",
"L1-dcache-loads",
"L1-dcache-load-misses",
"L1-dcache-stores",
"L1-dcache-store-misses",
"L1-dcache-prefetches",
"L1-dcache-prefetch-misses",
"L1-icache-loads",
"L1-icache-load-misses",
"L1-icache-prefetches",
"L1-icache-prefetch-misses",
"LLC-loads",
"LLC-load-misses",
"LLC-stores",
"LLC-store-misses",
"LLC-prefetches",
"LLC-prefetch-misses",
"dTLB-loads",
"dTLB-load-misses",
"dTLB-stores",
"dTLB-store-misses",
"dTLB-prefetches",
"dTLB-prefetch-misses",
"iTLB-loads",
"iTLB-load-misses",
"branch-loads",
"branch-load-misses",
"node-loads",
"node-load-misses",
"node-stores",
"node-store-misses",
"node-prefetches",
"node-prefetch-misses",
]

$nfs_nr_commits = 0
$nfs_nr_writes = 0

Expand Down Expand Up @@ -160,6 +220,26 @@ def nfs_stats(path)
end
end

def is_perf_event(name)
return true if name.index(":")
return true if $perf_vars.index(name)
return false
end

def perf_stats(path)
$perf_event = {}
file = "#{path}/perf-stat"
return if not File.exist?(file)

stat = File.new(file).readlines
stat.each do |line|
v, e = line.split("\t")
e.chomp!
$perf_event[e] = v.to_i
# printf "#{e}=#{v}\n"
end
end

def write_bw(path)
cache = "#{path}/write-bandwidth"
if File.exist?(cache)
Expand Down Expand Up @@ -194,6 +274,9 @@ def add_dd(path)
elsif $evaluate.index("io_") == 0
iostat_disk(path)
eval "bw = $#{$evaluate}"
elsif is_perf_event($evaluate)
perf_stats(path)
bw = $perf_event[$evaluate]
else
vmstat(path)
eval "bw = $#{$evaluate}"
Expand Down
7 changes: 7 additions & 0 deletions fs-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ fs_options() {
mntopt+=",logbsize=262144"
mkfsopt="-f -l size=131072b -d agcount=$nr_devices"
}
fs_events='xfs:*,workqueue:*'
;;
ext*)
[[ $fs =~ :wb ]] && mntopt="-o data=writeback"
[[ $fs =~ :jsize=8 ]] && mkfsopt="-J size=8"

[[ $fstype = ext3 ]] && fs_events='ext3:*,jbd:*'
[[ $fstype = ext4 ]] && fs_events='ext4:*,jbd2:*'
;;
btrfs)
fs_events='btrfs:*'
;;
nfs)
mntopt="-o v3,nolock"
Expand Down
10 changes: 9 additions & 1 deletion trace-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ enable_tracepoints() {
echo 1 > /debug/tracing/events/writeback/balance_dirty_pages/enable
echo 1 > /debug/tracing/events/writeback/bdi_dirty_ratelimit/enable
echo 1 > /debug/tracing/events/writeback/global_dirty_state/enable

echo 1 > /debug/tracing/events/writeback/bdi_dirty_state/enable
echo 1 > /debug/tracing/events/writeback/task_io/enable

Expand Down Expand Up @@ -39,7 +40,6 @@ log_start() {
# echo deadline > /sys/block/$IOSTAT_DISK/queue/scheduler
cat /sys/block/sd?/queue/scheduler > scheduler
grep $MNT /proc/self/mountinfo > mountinfo
[[ $fstype = 'xfs' ]] && xfs_info $MNT > xfsinfo

cp /proc/vmstat vmstat-begin
cp /proc/slabinfo slabinfo-begin
Expand All @@ -61,6 +61,13 @@ log_start() {
ssh $nfs_server "cat /debug/tracing/trace_pipe | bzip2" > trace-nfss.bz2 &
echo $! > pid-trace-nfss
fi

perf_events='writeback:*,block:*'
[[ $fs_events ]] && perf_events+=",$fs_events"
ulimit -n 100000
mkfifo /tmp/perf_wait
perf stat -x' ' -a -e "$perf_events" cat /tmp/perf_wait 1>&2 2> perf-stat &

mkfifo /tmp/trace_fifo
mkfifo /tmp/trace_fifo2
tee /tmp/trace_fifo2 < /debug/tracing/trace_pipe > /tmp/trace_fifo &
Expand All @@ -74,6 +81,7 @@ log_start() {
}

log_end() {
: > /tmp/perf_wait
kill $(cat pid-*)
kill $(cat pid)
rm pid-*
Expand Down

0 comments on commit 3d3989a

Please sign in to comment.