[pve-devel] [POC qemu-server 5/6] add timing for testing

Fabian Ebner f.ebner at proxmox.com
Thu Apr 8 12:33:15 CEST 2021


Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 PVE/QemuServer.pm | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index fa2aad9..0287a80 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -22,7 +22,7 @@ use JSON;
 use MIME::Base64;
 use POSIX;
 use Storable qw(dclone);
-use Time::HiRes qw(gettimeofday);
+use Time::HiRes qw(gettimeofday tv_interval);
 use URI::Escape;
 use UUID;
 
@@ -7743,16 +7743,34 @@ sub upgrade_qemu {
     my $ramfs = "/run/pve/${vmid}_ramfs";
     my $statefile = "${ramfs}/state";
 
+    # for testing
+    my $start;
+
+    my $print_elapsed = sub {
+	my ($what) = @_;
+	my $end = [gettimeofday()];
+	my $elapsed = tv_interval($start, $end);
+	print "elapsed: '$elapsed' for $what\n";
+	$start = [gettimeofday()];
+    };
+
+    $start = [gettimeofday()];
+
     mkpath($ramfs);
 
     run_command(['mount', '-t', 'ramfs', 'ramfs', $ramfs]);
     run_command(['truncate', '-s', "${size}M", $statefile]);
 
+    $print_elapsed->("preparing ramfs");
+
     eval {
 	eval {
 	    set_migration_caps($vmid, 1); #TODO needed here?
+	    $print_elapsed->("setting migration caps");
 	    mon_cmd($vmid, "savevm-start", statefile => $statefile);
+	    $print_elapsed->("issuing savevm-start");
 	    savevm_monitor($vmid);
+	    $print_elapsed->("saving state");
 	};
 	if (my $err = $@) {
 	    eval { mon_cmd($vmid, "savevm-end"); };
@@ -7761,6 +7779,7 @@ sub upgrade_qemu {
 	}
 
 	mon_cmd($vmid, "quit");
+	$print_elapsed->("issuing quit");
 
 	my $start_params = {
 	    statefile => $statefile,
@@ -7769,6 +7788,7 @@ sub upgrade_qemu {
 
 	# TODO forcecpu, spice ticket?
 	vm_start_nolock($storecfg, $vmid, $conf, $start_params, {});
+	$print_elapsed->("starting vm");
 
 	# TODO save state to disk if there's an error with start?
     };
-- 
2.20.1






More information about the pve-devel mailing list