Skip to content

Instantly share code, notes, and snippets.

@johnskopis
Last active December 18, 2015 22:39
Show Gist options
  • Save johnskopis/5856117 to your computer and use it in GitHub Desktop.
Save johnskopis/5856117 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import struct
from collections import defaultdict
# mysql -Ne "select si.space, CONCAT(st.SCHEMA,'.', st.NAME, '/', si.name) from INNODB_SYS_INDEXES si, INNODB_SYS_TABLES st where st.TABLE_ID=si.TABLE_ID" information_schema > map
def read_map(map_file = './map'):
with open(map_file, 'r') as fd:
return dict((int(k), v) for k, v in [line.strip().split() for line in fd.readlines()])
def read_lru(lru_file = './ib_lru_dump'):
entries = defaultdict(lambda: 1)
total = 0
with open(lru_file, 'rb') as fd:
while True:
i = fd.read(8)
if i == "": break
space_id, page_no = struct.unpack('>II', i)
if space_id > 0 or page_no > 0:
entries[space_id] += 1
return entries
def to_gb(pages):
return pages*16/1024/1024
lookup = read_map()
data = read_lru()
total = sum(data.values())
for k, v in sorted(data.iteritems(), key = lambda(k, v): v):
if k in lookup:
print "%s %dGB (%f%%)" % (lookup[k], to_gb(v), float(v)/total*100)
else:
print "UNKNOWN%d: %d" % (k, v)
print "%d pages (%d GB) accounted for" % (total, to_gb(total))
@lann
Copy link

lann commented Jun 25, 2013

@johnskopis
Copy link
Author

ya, I just copied the mysql source. First attempt was wrong anyway, this works (thanks to http://www.mysqlperformanceblog.com/2010/01/20/xtradb-feature-save-restore-buffer-pool/)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment