def main(trace=False): vm = QemuNG(disk_path=r"../vms/ubuntu-20.img", guest_ip="10.10.0.43", host_ip="10.10.0.44") vm.ethernet_dev = vm.QEMU_VIRTIO if trace: vm.exe = ORIG_QEMU_TRACE vm.setup() vm.run() input("Press any enter to close VM") vm.teardown()
def main(directory=None, netperf_msg_size=None): trace_dir = get_dir(directory) if netperf_msg_size is None: netperf_msg_size = MSG_SIZE if ORIG_QEMU != TMP_QEMU: shutil.copyfile(ORIG_QEMU, TMP_QEMU) os.makedirs(trace_dir, exist_ok=True) netserver_start() logger.info("msg size = %s", netperf_msg_size) vm = QemuNG(disk_path=r"../vms/ubuntu-20.img", guest_ip="10.10.0.43", host_ip="10.10.0.44") vm.ethernet_dev = Qemu.QEMU_VIRTIO # vm.qemu_config["latency_itr"] = 0 vm.e1000_options["NG_notify_batch"] = "on" vm.BOOTUP_WAIT = 15 # vm.addiotional_guest_command = 'sudo ethtool -C eth0 rx-usecs 3000' local_trace = Trace(localRoot, os.path.join(trace_dir, "trace_host")) local_trace.setup() local_trace.set_buffer_size(100000) local_trace.enable_event("kvm/kvm_write_tsc_offset") # local_trace.enable_event("kvm/kvm_set_irq") # local_trace.enable_event("kvm/kvm_msi_set_irq") # local_trace.enable_event("kvm/kvm_inj_virq") # local_trace.enable_event("kvm/kvm_ioapic_set_irq") # local_trace.enable_event("kvm/kvm_exit") # local_trace.enable_event("kvm/kvm_entry") # local_trace.enable_event("kvm/kvm_userspace_exit") local_trace.set_event_filter( "sched/sched_switch", r'prev_comm ~ "*qemu*" || next_comm ~ "*qemu*"') # local_trace.enable_event("sched/sched_switch") local_trace.set_event_filter("sched/sched_wakeup", '\"comm~*qemu*\"') # local_trace.enable_event("sched/sched_wakeup") local_trace.set_event_filter("sched/sched_waking", '\"comm~*qemu*\"') # local_trace.enable_event("sched/sched_waking") # objdump -tT /tmp/qemu-system-x86_64 |grep .text|grep virtio_queue_notify_vq ## local_trace.uprobe_add("p:virtio_queue_notify_vq /tmp/qemu-system-x86_64:0x1bfba6") # local_trace.uprobe_add_event("p", "virtio_queue_notify_vq", TMP_QEMU, "virtio_queue_notify_vq") # objdump -tT /tmp/qemu-system-x86_64 |grep .text|grep kvm_vcpu_ioctl ## local_trace.uprobe_add("p:kvm_vcpu_ioctl /tmp/qemu-system-x86_64:0x16a886 cmd=%si") # local_trace.uprobe_add_event("p", "kvm_vcpu_ioctl", TMP_QEMU, "kvm_vcpu_ioctl", "cmd=%si") # local_trace.uprobe_add_event("p", "tap_write_packet", TMP_QEMU, "tap_write_packet") # local_trace.uprobe_add_event("p", "tap_recv_packets", TMP_QEMU, "tap_send") # local_trace.uprobe_add_event("r", "tap_recv_packets_end", TMP_QEMU, "tap_send") # local_trace.uprobe_add_event("p", "virtio_irq", TMP_QEMU, "virtio_irq") # local_trace.uprobe_add_event("p", "virtio_queue_notify_vq", TMP_QEMU, "virtio_queue_notify_vq") # local_trace.uprobe_add_event("p", "e1000_set_kick", TMP_QEMU, "e1000_set_kick") # local_trace.uprobe_add_event("p", "e1000_receive_batch_finished", TMP_QEMU, "e1000_receive_batch_finished") local_trace.uprobe_enable() local_trace.empty_trace() local_trace.trace_on() # local_trace.trace_to_local_file() vm.setup() vm.run() remote_trace = Trace(vm.root, os.path.join(trace_dir, "trace_guest")) remote_trace.setup() remote_trace.set_buffer_size(100000) # remote_trace.enable_event("tcp") # remote_trace.enable_event("net") # remote_trace.enable_event("irq") # remote_trace.enable_event("irq_vectors") # remote_trace.enable_event("napi") # remote_trace.enable_event("power/cpu_idle") # remote_trace.enable_event("syscalls/sys_enter_sendto") # remote_trace.enable_event("syscalls/sys_enter_recvfrom") remote_trace.enable_event("net/net_dev_xmit") # remote_trace.enable_event("irq/irq_handler_entry") # remote_trace.enable_event("e1000/e1000_pre_mem_op") # remote_trace.enable_event("e1000/e1000_post_mem_op") # remote_trace.enable_event("e1000/e1000_set_tdt") # remote_trace.enable_event("e1000/e1000_post_set_tdt") # remote_trace.kprobe_add("p:notify_begin virtqueue_kick") # remote_trace.kprobe_add("r:notify_end virtqueue_kick") # remote_trace.kprobe_enable() remote_trace.trace_on() netperf = NetPerfTCP(None, runtime=2) run_command_async("tcpdump -i tap0 -s 100 -w {} -W 1 -G 7".format( os.path.join(trace_dir, "virtio.cap"))) remote_trace.trace_marker(TRACE_BEGIN_MSG) netperf_perf = netperf.run_netperf(vm, msg_size=netperf_msg_size) remote_trace.trace_marker(TRACE_END_MSG) print("Netperf performance: %s" % (netperf_perf, )) logger.info("Netperf performance: %s", netperf_perf) remote_trace.trace_off() remote_trace.disable_all_events() local_trace.trace_off() local_trace.disable_all_events() netperf_perf = netperf.run_netperf(vm, msg_size=netperf_msg_size) print("Base Netperf performance: %s" % (netperf_perf, )) logger.info("Base Netperf performance: %s", netperf_perf) local_trace.read_trace_once(to_file=True) remote_trace.read_trace_once(to_file=True) # local_trace.trace_to_local_file_stop() local_trace.disable_all_events() # input("Press Enter to exit") vm.teardown() netserver_stop()