import re import sys output = sys.argv[1] fp = open(output, 'r') cache_miss=0 cache_hit=0 total_fetch=0 buffered_bytes = 0 buffered_re = re.compile('Using existing buffer to read (.*) bytes') buffered_and_fetch = re.compile('Taking the rest (.*) and Fetching new buffer') #iocmd = re.compile('Sending IOCMD_SEEK_READ. \((.*)\)') iocmd = re.compile('Expected position: .+ @ .+ bytes readed. Returning (.*)') too_small_buffer = re.compile('Buffer .GE. than read-ahead buffer') for line in fp.readlines(): #if not line.startswith('[8]'): if not line.startswith('[58]'): continue if line.find('Initially fetching new buffer') >= 0: cache_miss += 1 continue m = buffered_and_fetch.search(line) if m: cache_miss += 1 cache_hit += 1 buffered_bytes += int(m.groups()[0]) continue m = buffered_re.search(line) if m: cache_hit += 1 buffered_bytes += int(m.groups()[0]) m = buffered_re.search(line) if m: cache_miss += 1 continue m = iocmd.search(line) if m: total_fetch += int(m.groups()[0]) total_cache=cache_hit+cache_miss if total_cache==0: ratio=1 else: ratio=cache_miss/float(cache_hit+cache_miss) if total_fetch==0: ratio2=0 else: ratio2=100*buffered_bytes/float(total_fetch) print "There were %i cache hits and %i cache misses (miss rate: %.2f%%)" % (cache_hit, cache_miss, 100*ratio) print "There were %i bytes read and %i buffered bytes used; efficiency: %.2f%%" % (total_fetch, buffered_bytes, ratio2)