Skip to content

Instantly share code, notes, and snippets.

@stephenmcd
Created August 3, 2012 02:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephenmcd/3243788 to your computer and use it in GitHub Desktop.
Save stephenmcd/3243788 to your computer and use it in GitHub Desktop.
Quick cache stats scraper using django-debug-toolbar's cache panel.
#!/usr/bin/env python
import os
import sys
import urllib
name, url, num = sys.argv[1:]
print name, url, num
first = not os.path.exists("output.csv")
f = open("output.csv", "a")
for i in range(int(num)):
html = urllib.urlopen(url).read().split("id=\"djDebugCachePanel")[1] \
.split("<tbody>")[0].split("</tbody>")[0]
lines = [l.split(">")[1].split("<")[0].split("&")[0] for l in
html.splitlines() if l.strip().startswith(("<th", "<td"))][:-5]
headings = ["Name"] + lines[::2]
values = [name] + lines[1::2]
if first and i == 0:
f.write(",".join(headings) + "\n")
f.write(",".join(values) + "\n")
f.close()
@stephenmcd
Copy link
Author

Sample output:

Name Total Calls Total Time       Hits   Misses  gets   sets  deletes  get_many
Blah 225         309.119462967ms  147    39      186    39    0        0
Blah 186         186.858654022ms  186    0       186    0     0        0
Blah 186         185.238838196ms  186    0       186    0     0        0

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