Skip to content

Commit

Permalink
llcstat: print a nicer error message when hardware events are missing
Browse files Browse the repository at this point in the history
Hardware events such as CACHE_MISSES and CACHE_REFERENCES are usually
not available on virtual machine. Print a more useful message when
this happen.
  • Loading branch information
jeromemarchand committed Aug 7, 2018
1 parent 8b17dc3 commit d274b66
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions tools/llcstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,16 @@
exit()

b = BPF(text=bpf_text)
b.attach_perf_event(
ev_type=PerfType.HARDWARE, ev_config=PerfHWConfig.CACHE_MISSES,
fn_name="on_cache_miss", sample_period=args.sample_period)
b.attach_perf_event(
ev_type=PerfType.HARDWARE, ev_config=PerfHWConfig.CACHE_REFERENCES,
fn_name="on_cache_ref", sample_period=args.sample_period)
try:
b.attach_perf_event(
ev_type=PerfType.HARDWARE, ev_config=PerfHWConfig.CACHE_MISSES,
fn_name="on_cache_miss", sample_period=args.sample_period)
b.attach_perf_event(
ev_type=PerfType.HARDWARE, ev_config=PerfHWConfig.CACHE_REFERENCES,
fn_name="on_cache_ref", sample_period=args.sample_period)
except:
print("Failed to attach to a hardware event. Is this a virtual machine?")
exit()

print("Running for {} seconds or hit Ctrl-C to end.".format(args.duration))

Expand Down

0 comments on commit d274b66

Please sign in to comment.