Skip to content

Commit

Permalink
funccount: Do not prepopulate location cache
Browse files Browse the repository at this point in the history
Avoiding the prepopulation of the location cache allows us
to get rid of the `zero()` call at the end of each interval,
which would hang the program at full CPU. Replaced the
prepopulation with a `lookup_or_init` and the `zero()` call
with a call to `clear()`.
  • Loading branch information
goldshtn committed Oct 20, 2016
1 parent 06fb0fa commit 4e9289b
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions tools/funccount.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,9 @@ def load(self):
trace_count_text = """
int PROBE_FUNCTION(void *ctx) {
FILTER
u64 loc = LOCATION;
u64 *val = counts.lookup(&loc); // prepopulated on Python side
if (val) {
(*val)++;
}
u64 loc = LOCATION, zero = 0;
u64 *val = counts.lookup_or_init(&loc, &zero);
(*val)++;
return 0;
}
"""
Expand All @@ -200,11 +198,6 @@ def load(self):
self.bpf = BPF(text=bpf_text,
usdt_contexts=[self.usdt] if self.usdt else [])

# Initialize all map entries to zero
counts = self.bpf["counts"]
for location, function in self.trace_functions.items():
counts[counts.Key(location)] = counts.Leaf()

class Tool(object):
def __init__(self):
examples = """examples:
Expand Down Expand Up @@ -267,7 +260,7 @@ def run(self):
continue
print("%-36s %8d" %
(self.probe.trace_functions[k.value], v.value))
counts.zero()
counts.clear()

if exiting:
print("Detaching...")
Expand Down

0 comments on commit 4e9289b

Please sign in to comment.