From nobody Tue Apr 30 07:56:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1517935002702768.8042798123666; Tue, 6 Feb 2018 08:36:42 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A150725BB3; Tue, 6 Feb 2018 16:36:41 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C672E60C4A; Tue, 6 Feb 2018 16:36:40 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 636954A46D; Tue, 6 Feb 2018 16:36:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w16GabrQ006891 for ; Tue, 6 Feb 2018 11:36:37 -0500 Received: by smtp.corp.redhat.com (Postfix) id D0F3460471; Tue, 6 Feb 2018 16:36:37 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id AB5D76046C; Tue, 6 Feb 2018 16:36:32 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 6 Feb 2018 16:36:31 +0000 Message-Id: <20180206163631.32190-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH perl] Remove use of Data::Dumper from example programs X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 06 Feb 2018 16:36:42 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Using Data::Dumper in examples does not help devs understand the data structures that the Perl APIs are returning. Change to explicit field accesses to illustrate it better Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-By: Laine Stump --- Virt.xs | 1 - examples/dhcp-leases.pl | 2 -- examples/dom-fsinfo.pl | 8 +++----- examples/dom-ifinfo.pl | 14 +++++++++----- examples/dom-stats.pl | 9 +++------ examples/node-info.pl | 26 +++++++++++++++++++------- 6 files changed, 34 insertions(+), 26 deletions(-) diff --git a/Virt.xs b/Virt.xs index 7d2f1a7..1254df2 100644 --- a/Virt.xs +++ b/Virt.xs @@ -3358,7 +3358,6 @@ void get_all_domain_stats(con, stats, doms_sv=3D&PL_s= v_undef, flags=3D0) if (SvOK(doms_sv)) { doms_av =3D (AV*)SvRV(doms_sv); ndoms =3D av_len(doms_av) + 1; - fprintf(stderr, "Len %d\n", ndoms); } else { ndoms =3D 0; } diff --git a/examples/dhcp-leases.pl b/examples/dhcp-leases.pl index af9bd41..a2202d9 100644 --- a/examples/dhcp-leases.pl +++ b/examples/dhcp-leases.pl @@ -1,8 +1,6 @@ #!/usr/bin/perl =20 -use Acme::ChuckNorris; use Sys::Virt; -use Data::Dumper; =20 my $c =3D Sys::Virt->new(uri =3D> "qemu:///system", readonly =3D> 1); diff --git a/examples/dom-fsinfo.pl b/examples/dom-fsinfo.pl index 7763f78..46c64e9 100644 --- a/examples/dom-fsinfo.pl +++ b/examples/dom-fsinfo.pl @@ -1,6 +1,5 @@ #!/usr/bin/perl =20 - use strict; use warnings; =20 @@ -15,7 +14,6 @@ my $dom =3D $c->get_domain_by_name(shift @ARGV); =20 my @fs =3D $dom->get_fs_info(); =20 -use Data::Dumper; - -print Dumper($fs[0]); -print Dumper($fs[1]); +foreach my $fs (@fs) { + printf "%s (%s) at %s\n", $fs->{name}, $fs->{fstype}, $fs->{mountpoint= }; +} diff --git a/examples/dom-ifinfo.pl b/examples/dom-ifinfo.pl index e10579b..66eb157 100644 --- a/examples/dom-ifinfo.pl +++ b/examples/dom-ifinfo.pl @@ -1,6 +1,5 @@ #!/usr/bin/perl =20 - use strict; use warnings; =20 @@ -13,9 +12,14 @@ my $c =3D Sys::Virt->new(uri =3D> $uri); =20 my $dom =3D $c->get_domain_by_name(shift @ARGV); =20 -my @fs =3D $dom->get_interface_addresses( +my @nics =3D $dom->get_interface_addresses( Sys::Virt::Domain::INTERFACE_ADDRESSES_SRC_LEASE); =20 -use Data::Dumper; - -print Dumper(@fs); +foreach my $nic (@nics) { + print "Interface ", $nic->{name}, "\n"; + print " MAC: ", $nic->{hwaddr}, "\n"; + foreach my $addr (@{$nic->{addrs}}) { + print " IP: ", $addr->{addr}, "\n"; + } + print "\n"; +} diff --git a/examples/dom-stats.pl b/examples/dom-stats.pl index 13d8fb7..1da0089 100644 --- a/examples/dom-stats.pl +++ b/examples/dom-stats.pl @@ -20,10 +20,7 @@ my @stats =3D $c->get_all_domain_stats(Sys::Virt::Domain= ::STATS_STATE, \@doms, Sys::Virt::Domain::GET_ALL_STATS_ENFORCE_STATS); =20 -use Data::Dumper; - -print Dumper(\@stats); - -for (my $i =3D 0 ; $i <=3D $#stats ; $i++) { - print $stats[$i]->{'dom'}->get_name(), ": ", $stats[$i]->{'data'}->{'s= tate.state'}, "\n"; +foreach my $stats (@stats) { + print "Guest ", $stats->{'dom'}->get_name(), "\n"; + print " State: ", $stats->{'data'}->{'state.state'}, "\n"; } diff --git a/examples/node-info.pl b/examples/node-info.pl index 89bc9ba..9655ab4 100644 --- a/examples/node-info.pl +++ b/examples/node-info.pl @@ -13,13 +13,25 @@ my $info =3D $hv->get_node_info(); =20 my @models =3D $hv->get_cpu_model_names($info->{model}); =20 -print join ("\n", sort{ lc $a cmp lc $b } @models), "\n"; - -my @info =3D $hv->get_node_free_pages([2048], 0, 0); - -use Data::Dumper; -print Dumper(\@info); - +print "Available CPU model names:\n"; +print join ("\n", map { " " . $_ } sort{ lc $a cmp lc $b } @models), "\n"; + +my @pagesizes =3D ( + 4, 2048, 1048576 + ); + +my @info =3D $hv->get_node_free_pages(\@pagesizes, 0, 0); + +print "Free pages per NUMA node:\n"; +foreach my $info (@info) { + print " Node: ", $info->{cell}, "\n"; + print " Free: "; + for (my $i =3D 0; $i <=3D $#pagesizes; $i++) { + my $pagesize =3D $pagesizes[$i]; + printf "%d @ %d KB, ", $info->{pages}->{$pagesize}, $pagesize; + } + print "\n"; +} =20 my $xml =3D $hv->get_domain_capabilities(undef, "x86_64", undef, "kvm"); print $xml; --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list