public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* Linux VFS cache hit rate script v2
@ 2011-04-30  2:35 Jake Maul
  0 siblings, 0 replies; only message in thread
From: Jake Maul @ 2011-04-30  2:35 UTC (permalink / raw)
  To: systemtap

[-- 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"

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-04-30  2:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-30  2:35 Linux VFS cache hit rate script v2 Jake Maul

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).