Last active
December 18, 2015 22:39
-
-
Save johnskopis/5856117 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)) |
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
http://docs.python.org/2/library/struct.html