public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
From: Jake Maul <jakemaul@gmail.com>
To: systemtap@sourceware.org
Subject: Linux VFS cache hit rate script v2
Date: Sat, 30 Apr 2011 02:35:00 -0000	[thread overview]
Message-ID: <BANLkTimqUv_Xx5f2FnCwyZ3p9Gg3fb-jxw@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1181 bytes --]

Hello all,

Based on the list's feedback about the previous script (particularly
in relation to the "N/A" assumption), as well as a modified version
from Dave Wright, I have rewritten this script as attached. Also
included is a new 'probe end' block, inspired by 'entropo' from
Serverfault (http://serverfault.com/questions/157612/is-there-a-way-to-get-cache-hit-miss-ratios-for-block-devices-in-linux).
Note that this link is where I first started out from a couple weeks
ago.

This seems to offer much more repeatable and sane results, although
it's not without fault. For instance, it's possible for an
ioblock.request probe to register without a corresponding
vfs.read.return hit. Hence, there's a check in here for cache_bytes <
0, which should (in theory) not be necessary. Fortunately, in my
testing it appears to be a very small discrepancy, so I feel mostly
safe about just pretending it didn't happen- it seems to be dwarfed by
real I/O, and I probably wouldn't have noticed it if I wasn't testing
on a totally-idle server.

http://sourceware.org/systemtap/wiki/WSCacheHitRate is updated as
well, including props for those who've helped out in some way. :)

Thanks,
Jake

[-- Attachment #2: cache-hit-rate.stp --]
[-- Type: application/octet-stream, Size: 1607 bytes --]

#!/usr/bin/env stap

global total_bytes, disk_bytes, counter, overall_cache_bytes, overall_disk_bytes

probe vfs.read.return {
	if (bytes_to_read > 0 && devname != "N/A") {
		total_bytes += bytes_to_read
	}
}

probe ioblock.request {
	mydevname = substr(devname,0,3)
	if (rw == 0 && size > 0 && devname != "N/A" && mydevname != "dm-") {
	 	disk_bytes += size
	#	printf("%10d %s %s\n", size, mydevname, devname)
	}
  
}

probe begin {
	printf("Starting...\n")
}

# print VFS hits and misses every 5 second, plus the hit rate in %
probe timer.s(5) {
	if (counter%15 == 0) {
		printf ("\n%18s %18s %18s %10s %10s\n", 
			"Total Reads (KB)", "Cache Reads (KB)", "Disk Reads (KB)", "Miss Rate", "Hit Rate")
	}
	counter++

	cache_bytes = total_bytes - disk_bytes
	if (cache_bytes < 0)
		cache_bytes = 0
	if (cache_bytes+disk_bytes > 0) {
		hitrate =  10000 * cache_bytes / (cache_bytes+disk_bytes)
		missrate = 10000 * disk_bytes / (cache_bytes+disk_bytes)
	} else {
		hitrate = 0
		missrate = 0
	}
	printf ("%18d %18d %18d %6d.%02d%% %6d.%02d%%\n",
		total_bytes/1024, cache_bytes/1024, disk_bytes/1024,
		missrate/100, missrate%100, hitrate/100, hitrate%100)
	overall_cache_bytes += cache_bytes
	overall_disk_bytes += disk_bytes
	total_bytes = 0
	disk_bytes = 0
}

probe end {
	avg_hitrate =  10000 * overall_cache_bytes / (overall_cache_bytes+overall_disk_bytes)
	avg_missrate =  10000 * overall_disk_bytes / (overall_cache_bytes+overall_disk_bytes)
	printf("\n%s: %d.%02d\n%s: %d.%02d\n", 
		" Average Hit Rate", avg_hitrate/100, avg_hitrate%100, 
		"Average Miss Rate", avg_missrate/100, avg_missrate%100)
}

[-- Attachment #3: cache-hit-rate.meta --]
[-- Type: application/octet-stream, Size: 532 bytes --]

title: VFS Cache Hit Rate
name: cache-hit-rate.stp
version: 1.1
author: Jake Maul
keywords: io profiling vfs cache
subsystem: io
status: production
exit: user-controlled
output: timed interval (vmstat-like)
scope: system-wide
description:  The cache-hit-rate.stp script compares ioblock.request and vfs.read.return probe hits, and uses them to determine how much data was read directly from disk vs how much was read from the Linux VFS cache.
test_check: stap -p4 cache-hit-rate.stp
test_installcheck: stap iostats.stp -c "sleep 6"

                 reply	other threads:[~2011-04-30  2:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BANLkTimqUv_Xx5f2FnCwyZ3p9Gg3fb-jxw@mail.gmail.com \
    --to=jakemaul@gmail.com \
    --cc=systemtap@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).