9 use Time
::HiRes
qw( gettimeofday tv_interval );
25 my $unit = @{['s', 'ms', 'us', 'ns', 'ps']}[$unit_index];
27 return wantarray ?
($sec, $unit) : "$sec $unit";
34 my ($name, $loops, $code) = @_;
36 return if !defined($loops) || $loops <= 0;
40 my $t0 = [gettimeofday
];
42 for (my $i = 0; $i<$loops; $i++) {
46 my $elapsed = tv_interval
($t0, [gettimeofday
]);
48 my $total = sec_to_unit
($elapsed);
49 my $per_loop = $elapsed/$loops;
50 $loop = sec_to_unit
($per_loop);
52 $results->{$name} = [ $elapsed * 1000, $per_loop * 1000 ];
54 print STDERR
"elapsed['$name' x $loops]: $total => $loop/loop\n";
60 my $loops = shift // 3;
61 my $vmid = shift // 0;
62 my $prop = shift // 'lock';
64 perf
('cfg-get-prop', $loops, sub {
65 my $res = PVE
::Cluster
::get_guest_config_property
($prop, $vmid);
68 PVE
::Cluster
::cfs_update
();
69 perf
('perl-manual', $loops, sub {
72 # modeled after the manager API cluster/resource call
73 my $vmlist = PVE
::Cluster
::get_vmlist
() || {};
74 my $idlist = $vmlist->{ids
} || {};
75 foreach my $vmid (keys %$idlist) {
77 my $data = $idlist->{$vmid};
78 my $typedir = $data->{type
} eq 'qemu' ?
'qemu-server' : 'lxc';
80 my $conf = PVE
::Cluster
::cfs_read_file
("nodes/$data->{node}/$typedir/$vmid.conf");
82 my $v = $conf->{$prop};
83 $res->{$vmid} = { $prop => $v } if defined($v);
86 #PVE::Cluster::get_tasklist('dev5');
88 my $a = $results->{'cfg-get-prop'};
89 my $b = $results->{'perl-manual'};
90 printf("$loops\t%.2f\t%.2f\t%.2f\t%.2f\n", $a->[0], $a->[1], $b->[0], $b->[1]);
92 #print "res: " . Dumper($res) ."\n";