Commit a2d669c5 authored by chantra's avatar chantra Committed by 4ast

[cachetop] fix stats computation per processes. (#635)

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 https://github.com/iovisor/bcc/pull/615#discussion_r71056842

Tested by running both tools manually.
parent 31ded520
...@@ -139,24 +139,16 @@ while 1: ...@@ -139,24 +139,16 @@ while 1:
for k, v in sorted(counts.items(), key=lambda counts: counts[1].value): 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: if re.match('mark_page_accessed', b.ksym(k.ip)) is not None:
mpa = v.value mpa = max(0, v.value)
if mpa < 0:
mpa = 0
if re.match('mark_buffer_dirty', b.ksym(k.ip)) is not None: if re.match('mark_buffer_dirty', b.ksym(k.ip)) is not None:
mbd = v.value mbd = max(0, v.value)
if mbd < 0:
mbd = 0
if re.match('add_to_page_cache_lru', b.ksym(k.ip)) is not None: if re.match('add_to_page_cache_lru', b.ksym(k.ip)) is not None:
apcl = v.value apcl = max(0, v.value)
if apcl < 0:
apcl = 0
if re.match('account_page_dirtied', b.ksym(k.ip)) is not None: if re.match('account_page_dirtied', b.ksym(k.ip)) is not None:
apd = v.value apd = max(0, v.value)
if apd < 0:
apd = 0
# access = total cache access incl. reads(mpa) and writes(mbd) # access = total cache access incl. reads(mpa) and writes(mbd)
# misses = total of add to lru which we do when we write(mbd) # misses = total of add to lru which we do when we write(mbd)
......
...@@ -69,6 +69,13 @@ def get_processes_stats( ...@@ -69,6 +69,13 @@ def get_processes_stats(
cached cached
list of tuple with per process cache stats list of tuple with per process cache stats
''' '''
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 rtaccess = 0
wtaccess = 0 wtaccess = 0
mpa = 0 mpa = 0
...@@ -80,33 +87,18 @@ def get_processes_stats( ...@@ -80,33 +87,18 @@ def get_processes_stats(
rhits = 0 rhits = 0
whits = 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]):
for k, v in count.items(): for k, v in count.items():
if re.match('mark_page_accessed', bpf.ksym(k)) is not None: if re.match('mark_page_accessed', bpf.ksym(k)) is not None:
mpa = v mpa = max(0, v)
if mpa < 0:
mpa = 0
if re.match('mark_buffer_dirty', bpf.ksym(k)) is not None: if re.match('mark_buffer_dirty', bpf.ksym(k)) is not None:
mbd = v mbd = max(0, v)
if mbd < 0:
mbd = 0
if re.match('add_to_page_cache_lru', bpf.ksym(k)) is not None: if re.match('add_to_page_cache_lru', bpf.ksym(k)) is not None:
apcl = v apcl = max(0, v)
if apcl < 0:
apcl = 0
if re.match('account_page_dirtied', bpf.ksym(k)) is not None: if re.match('account_page_dirtied', bpf.ksym(k)) is not None:
apd = v apd = max(0, v)
if apd < 0:
apd = 0
# access = total cache access incl. reads(mpa) and writes(mbd) # access = total cache access incl. reads(mpa) and writes(mbd)
# misses = total of add to lru which we do when we write(mbd) # misses = total of add to lru which we do when we write(mbd)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment