From nobody Mon Feb 9 13:01:04 2026 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 ARC-Seal: i=1; a=rsa-sha256; t=1569337473; cv=none; d=zoho.com; s=zohoarc; b=HqwY//5R50EegPfufljKhySorFvqoWESuT3ZNxJdfrIT8Q/axEN1ApxVuZ+9sk8gwQPhFMr+QYfbhQGhyiAe1mmEAe3UEW1MXuIlC7BcRjNN1vUO5+yEt54iARtxkfkVw0h5JhkEe9iMSMnVuhaQS/FvLqtB+cJUImrcNVMoKTo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569337473; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=UAzLd1D00HSNQT8FxmD0GtjyyjVxJjgLaHU8aDQYsjE=; b=Q+G7NzC97wBzuMca0TEdhX0hR8K4NW/kXoDdQs1AK4Uo4nZguJHLpY5lQHQhPOqHBDa+Ha/Xuk0RWfXtU71wvUBgOjlpGbctpgy7DBtlaksADirtSUUNhluGXZDa+mva8GmeBwNoTp4ehR86REN8vY3rrDBBSqkD5s9o3CJEygs= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1569337473179163.86738819376603; Tue, 24 Sep 2019 08:04:33 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A77A3300CB2B; Tue, 24 Sep 2019 15:04:31 +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 83B465C21F; Tue, 24 Sep 2019 15:04:31 +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 484684EE50; Tue, 24 Sep 2019 15:04:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8OF4Tts027932 for ; Tue, 24 Sep 2019 11:04:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 51DB55DA21; Tue, 24 Sep 2019 15:04:29 +0000 (UTC) Received: from catbus.gsslab.fab.redhat.com (dhcp-32.gsslab.fab.redhat.com [10.33.9.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id B7A895D9D5; Tue, 24 Sep 2019 15:04:28 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 24 Sep 2019 15:58:52 +0100 Message-Id: <20190924145903.17123-12-berrange@redhat.com> In-Reply-To: <20190924145903.17123-1-berrange@redhat.com> References: <20190924145903.17123-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 11/22] src: rewrite systemtap probe generator in Python 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Tue, 24 Sep 2019 15:04:32 +0000 (UTC) As part of an goal to eliminate Perl from libvirt build tools, rewrite the dtrace2systemtap.pl tool in Python. This was a straight conversion, manually going line-by-line to change the syntax from Perl to Python. Thus the overall structure of the file and approach is the same. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/Makefile.am | 9 ++- src/dtrace2systemtap.pl | 130 ------------------------------------ src/dtrace2systemtap.py | 143 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+), 135 deletions(-) delete mode 100755 src/dtrace2systemtap.pl create mode 100755 src/dtrace2systemtap.py diff --git a/src/Makefile.am b/src/Makefile.am index d10bfdf448..5a1df7a93c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -604,7 +604,6 @@ nodist_libvirt_la_SOURCES =3D libvirt_probes.h if WITH_REMOTE nodist_libvirt_driver_remote_la_SOURCES =3D libvirt_probes.h endif WITH_REMOTE -DTRACE2SYSTEMTAP_FLAGS =3D --with-modules =20 BUILT_SOURCES +=3D libvirt_probes.h libvirt_probes.stp libvirt_functions.s= tp =20 @@ -639,10 +638,10 @@ RPC_PROBE_FILES +=3D $(srcdir)/rpc/virnetprotocol.x \ libvirt_functions.stp: $(RPC_PROBE_FILES) $(srcdir)/rpc/gensystemtap.pl $(AM_V_GEN)$(PERL) -w $(srcdir)/rpc/gensystemtap.pl $(RPC_PROBE_FILES) > = $@ =20 -%_probes.stp: %_probes.d $(srcdir)/dtrace2systemtap.pl \ +%_probes.stp: %_probes.d $(srcdir)/dtrace2systemtap.py \ $(top_builddir)/config.status - $(AM_V_GEN)$(PERL) -w $(srcdir)/dtrace2systemtap.pl \ - $(DTRACE2SYSTEMTAP_FLAGS) $(bindir) $(sbindir) $(libdir) $< > $@ + $(AM_V_GEN)$(RUNUTF8) $(PYTHON) $(srcdir)/dtrace2systemtap.py \ + $(bindir) $(sbindir) $(libdir) $< > $@ =20 CLEANFILES +=3D libvirt_probes.h libvirt_probes.o libvirt_probes.lo \ libvirt_functions.stp libvirt_probes.stp @@ -763,7 +762,7 @@ endif LIBVIRT_INIT_SCRIPT_SYSTEMD endif WITH_LIBVIRTD =20 =20 -EXTRA_DIST +=3D dtrace2systemtap.pl +EXTRA_DIST +=3D dtrace2systemtap.py =20 =20 if WITH_LIBVIRTD diff --git a/src/dtrace2systemtap.pl b/src/dtrace2systemtap.pl deleted file mode 100755 index c5fce248b4..0000000000 --- a/src/dtrace2systemtap.pl +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env perl -# -# Copyright (C) 2011-2012 Red Hat, Inc. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library. If not, see -# . -# -# -# Generate a set of systemtap probe definitions corresponding to -# DTrace probe markers in libvirt.so -# -# perl dtrace2systemtap.pl probes.d > libvirt_probes.stp -# - -use strict; -use warnings; - -my $file; -my @files; -my %files; - -my $with_modules =3D 0; -if ($ARGV[0] eq "--with-modules") { - # set if we want to honor the "module" setting in the .d file - $with_modules =3D 1; - shift @ARGV; -} - -my $bindir =3D shift @ARGV; -my $sbindir =3D shift @ARGV; -my $libdir =3D shift @ARGV; - -my $probe; -my $args; - -# Read the DTraceprobes definition -while (<>) { - next if m,^\s*$,; - - next if /^\s*provider\s+\w+\s*{\s*$/; - next if /^\s*};\s*$/; - - if (m,^\s*\#,) { - if (m,^\s*\#\s*file:\s*(\S+)\s*$,) { - $file =3D $1; - push @files, $file; - $files{$file} =3D { prefix =3D> undef, probes =3D> [] }; - } elsif (m,^\s*\#\s*prefix:\s*(\S+)\s*$,) { - $files{$file}->{prefix} =3D $1; - } elsif (m,^\s*\#\s*binary:\s*(\S+)\s*$,) { - $files{$file}->{binary} =3D $1; - } elsif (m,^\s*\#\s*module:\s*(\S+)\s*$,) { - $files{$file}->{module} =3D $1; - } else { - # ignore unknown comments - } - } else { - if (m,\s*probe\s+([a-zA-Z0-9_]+)\((.*?)(\);)?$,) { - $probe =3D $1; - $args =3D $2; - if ($3) { - push @{$files{$file}->{probes}}, [$probe, $args]; - $probe =3D $args =3D undef; - } - } elsif ($probe) { - if (m,^(.*?)(\);)?$,) { - $args .=3D $1; - if ($2) { - push @{$files{$file}->{probes}}, [$probe, $args]; - $probe =3D $args =3D undef; - } - } else { - die "unexpected data $_ on line $."; - } - } else { - die "unexpected data $_ on line $."; - } - } -} - -# Write out the SystemTap probes -foreach my $file (@files) { - my $prefix =3D $files{$file}->{prefix}; - my @probes =3D @{$files{$file}->{probes}}; - - print "# $file\n\n"; - foreach my $probe (@probes) { - my $name =3D $probe->[0]; - my $args =3D $probe->[1]; - - my $pname =3D $name; - $pname =3D~ s/${prefix}_/libvirt.$prefix./; - - my $binary =3D "$libdir/libvirt.so"; - if (exists $files{$file}->{binary}) { - $binary =3D $sbindir . "/" . $files{$file}->{binary}; - } - if ($with_modules && exists $files{$file}->{module}) { - $binary =3D $libdir . "/" . $files{$file}->{module}; - } - - print "probe $pname =3D process(\"$binary\").mark(\"$name\") {\n"; - - my @args =3D split /,/, $args; - for (my $i =3D 0 ; $i <=3D $#args ; $i++) { - my $arg =3D $args[$i]; - my $isstr =3D $arg =3D~ /char\s+\*/; - $arg =3D~ s/^.*\s\*?(\S+)$/$1/; - - if ($isstr) { - print " $arg =3D user_string(\$arg", $i + 1, ");\n"; - } else { - print " $arg =3D \$arg", $i + 1, ";\n"; - } - } - print "}\n\n"; - } - print "\n"; -} diff --git a/src/dtrace2systemtap.py b/src/dtrace2systemtap.py new file mode 100755 index 0000000000..8ee5632d6b --- /dev/null +++ b/src/dtrace2systemtap.py @@ -0,0 +1,143 @@ +#!/usr/bin/env python +# +# Copyright (C) 2011-2019 Red Hat, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see +# . +# +# +# Generate a set of systemtap probe definitions corresponding to +# DTrace probe markers in libvirt.so +# +# python dtrace2systemtap.py probes.d > libvirt_probes.stp +# + +from __future__ import print_function + +import re +import sys + +file =3D None +filelist =3D [] +files =3D {} + +bindir =3D sys.argv[1] +sbindir =3D sys.argv[2] +libdir =3D sys.argv[3] +dtrace =3D sys.argv[4] + +probe =3D None +args =3D None + +# Read the DTraceprobes definition + +with open(dtrace, "r") as fh: + lineno =3D 0 + for line in fh: + lineno =3D lineno + 1 + line =3D line.strip() + if line =3D=3D "": + continue + if line.find("provider ") !=3D -1 and line.find("{") !=3D -1: + continue + if line.find("};") !=3D -1: + continue + + if line.startswith("#"): + m =3D re.match(r'''^\#\s*file:\s*(\S+)$''', line) + if m is not None: + file =3D m.group(1) + filelist.append(file) + files[file] =3D {"prefix": None, "probes": []} + continue + + m =3D re.match(r'''^\#\s*prefix:\s*(\S+)$''', line) + if m is not None: + files[file]["prefix"] =3D m.group(1) + continue + + m =3D re.match(r'''^\#\s*binary:\s*(\S+)$''', line) + if m is not None: + files[file]["binary"] =3D m.group(1) + continue + + m =3D re.match(r'''^\#\s*module:\s*(\S+)$''', line) + if m is not None: + files[file]["module"] =3D m.group(1) + + # ignore unknown comments + else: + m =3D re.match(r'''probe\s+([a-zA-Z0-9_]+)\((.*?)(\);)?$''', l= ine) + if m is not None: + probe =3D m.group(1) + args =3D m.group(2) + if m.group(3) is not None: + files[file]["probes"].append([probe, args]) + probe =3D None + args =3D None + elif probe is not None: + m =3D re.match(r'''^(.*?)(\);)?$''', line) + if m is not None: + args =3D args + m.group(1) + if m.group(2) is not None: + files[file]["probes"].append([probe, args]) + probe =3D None + args =3D None + else: + raise Exception("unexpected data %s on line %d" % + (line, lineno)) + else: + raise Exception("unexpected data %s on line %d" % + (line, lineno)) + +# Write out the SystemTap probes +for file in filelist: + prefix =3D files[file]["prefix"] + probes =3D files[file]["probes"] + + print("# %s\n" % file) + for probe in probes: + name =3D probe[0] + args =3D probe[1] + + pname =3D name.replace(prefix + "_", "libvirt." + prefix + ".") + + binary =3D libdir + "/libvirt.so" + if "binary" in files[file]: + binary =3D sbindir + "/" + files[file]["binary"] + if "module" in files[file]: + binary =3D libdir + "/" + files[file]["module"] + + print("probe %s =3D process(\"%s\").mark(\"%s\") {" % + (pname, binary, name)) + + argbits =3D args.split(",") + for idx in range(len(argbits)): + arg =3D argbits[idx] + isstr =3D False + if arg.find("char *") !=3D -1: + isstr =3D True + + m =3D re.match(r'''^.*\s\*?(\S+)$''', arg) + if m is not None: + arg =3D m.group(1) + else: + raise Exception("Malformed arg %s" % arg) + + if isstr: + print(" %s =3D user_string($arg%d);" % (arg, idx + 1)) + else: + print(" %s =3D $arg%d;" % (arg, idx + 1)) + print("}\n") + print("") --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list