Skip to content

Commit

Permalink
[cachetop] fix stats computation per processes. (iovisor#635)
Browse files Browse the repository at this point in the history
The current logic was only initializing page accesses, mark dirty.. at
the beginning of the method, preventing counters to be ever reset for
each PIDs.

Piggyback iovisor#615 (comment)

Tested by running both tools manually.
  • Loading branch information
chantra authored and palmtenor committed Jul 31, 2016
1 parent 014196b commit eb379c8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 35 deletions.
16 changes: 4 additions & 12 deletions tools/cachestat.py
Expand Up @@ -139,24 +139,16 @@ def usage():
for k, v in sorted(counts.items(), key=lambda counts: counts[1].value):

if re.match('mark_page_accessed', b.ksym(k.ip)) is not None:
mpa = v.value
if mpa < 0:
mpa = 0
mpa = max(0, v.value)

if re.match('mark_buffer_dirty', b.ksym(k.ip)) is not None:
mbd = v.value
if mbd < 0:
mbd = 0
mbd = max(0, v.value)

if re.match('add_to_page_cache_lru', b.ksym(k.ip)) is not None:
apcl = v.value
if apcl < 0:
apcl = 0
apcl = max(0, v.value)

if re.match('account_page_dirtied', b.ksym(k.ip)) is not None:
apd = v.value
if apd < 0:
apd = 0
apd = max(0, v.value)

# access = total cache access incl. reads(mpa) and writes(mbd)
# misses = total of add to lru which we do when we write(mbd)
Expand Down
38 changes: 15 additions & 23 deletions tools/cachetop.py
Expand Up @@ -69,44 +69,36 @@ def get_processes_stats(
cached
list of tuple with per process cache stats
'''
rtaccess = 0
wtaccess = 0
mpa = 0
mbd = 0
apcl = 0
apd = 0
access = 0
misses = 0
rhits = 0
whits = 0

counts = bpf.get_table("counts")
stats = defaultdict(lambda: defaultdict(int))
for k, v in counts.items():
stats["%d-%d-%s" % (k.pid, k.uid, k.comm)][k.ip] = v.value
stats_list = []

for pid, count in sorted(stats.items(), key=lambda stat: stat[0]):
rtaccess = 0
wtaccess = 0
mpa = 0
mbd = 0
apcl = 0
apd = 0
access = 0
misses = 0
rhits = 0
whits = 0

for k, v in count.items():
if re.match('mark_page_accessed', bpf.ksym(k)) is not None:
mpa = v
if mpa < 0:
mpa = 0
mpa = max(0, v)

if re.match('mark_buffer_dirty', bpf.ksym(k)) is not None:
mbd = v
if mbd < 0:
mbd = 0
mbd = max(0, v)

if re.match('add_to_page_cache_lru', bpf.ksym(k)) is not None:
apcl = v
if apcl < 0:
apcl = 0
apcl = max(0, v)

if re.match('account_page_dirtied', bpf.ksym(k)) is not None:
apd = v
if apd < 0:
apd = 0
apd = max(0, v)

# access = total cache access incl. reads(mpa) and writes(mbd)
# misses = total of add to lru which we do when we write(mbd)
Expand Down

0 comments on commit eb379c8

Please sign in to comment.