Skip to content

Instantly share code, notes, and snippets.

@epcnt19
Last active December 19, 2018 13:13
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 epcnt19/00525fa2729dd7e3270a61f12d4d0d4c to your computer and use it in GitHub Desktop.
Save epcnt19/00525fa2729dd7e3270a61f12d4d0d4c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from __future__ import print_function
from bcc import BPF
b = BPF(text="""
#define EXIT_REASON 10
BPF_HASH(start, u8, u8);
TRACEPOINT_PROBE(kvm, kvm_exit) {
u8 e = EXIT_REASON;
u8 one = 1;
if (args->exit_reason == EXIT_REASON) {
bpf_trace_printk("KVM_EXIT exit_reason : 0x%x\\n", args->exit_reason);
start.update(&e, &one);
}
return 0;
}
TRACEPOINT_PROBE(kvm, kvm_entry) {
u8 e = EXIT_REASON;
u8 zero = 0;
u8 *s = start.lookup(&e);
if (s != NULL && *s == 1) {
bpf_trace_printk("KVM_ENTRY vcpu_id : 0x%x\\n", args->vcpu_id);
start.update(&e, &zero);
}
return 0;
}
TRACEPOINT_PROBE(kvm, kvm_cpuid) {
u8 e = EXIT_REASON;
u8 zero = 0;
u8 *s = start.lookup(&e);
if(s != NULL && *s == 1){
bpf_trace_printk("KVM_CPUID rax : 0x%x, rbx : 0x%x, rcx : 0x%x\\n",args->rax,args->rbx,args->rcx);
}
return 0;
};
""")
print("%-18s %-16s %-6s %s" % ("TIME(s)", "COMM", "PID", "EVENT"))
while 1:
try:
(task, pid, cpu, flags, ts, msg) = b.trace_fields()
except ValueError:
continue
print("%-18.9f %-16s %-6d %s" % (ts, task, pid, msg))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment