From nobody Tue Nov 26 13:25:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 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=1573483566; cv=none; d=zoho.com; s=zohoarc; b=m09G2M55PfLQtmIW7X3nElb2NbJfvHQo3Tx7Q9I3vDDYnNafhe0/9T97hiymp8Az+hWNHa0QoWaowG/0gYJeEFer0lK++hm9wQna306PE4NHPcxwdlPLLhOiQdh7VjBsRLvc38kZB20GN7XR29AQAAE+Mc3wM7XX83GlqoOs4rQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573483566; 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; bh=9xx9t91Pc34b3dXUUSRFXWxMDqwi2bsM8Qz3pPOU1Es=; b=ToLalnrLpjX+5UyU7TMjEB3slzpcAPbTv6Wd0N82Kb0EJeGpPHolCUiuCXhd//HQ3+BOpeJkkaTRkdbOT5h0m3gQx0NokUeD55gUuLVeK7F7PZVUz1rJM62sVnIUoRyvOw3nJ6Oe4orteWtytpwNhny8cZKkfl+9Coh1oRSdWV4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1573483566390135.12072237097698; Mon, 11 Nov 2019 06:46:06 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-73-u9ADSBE5PqaFfG9L_RkL_w-1; Mon, 11 Nov 2019 09:45:20 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id B9B70100551C; Mon, 11 Nov 2019 14:45:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7C4FE4145; Mon, 11 Nov 2019 14:45:13 +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 0C32A1803509; Mon, 11 Nov 2019 14:45:13 +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 xABEiuxq020400 for ; Mon, 11 Nov 2019 09:44:56 -0500 Received: by smtp.corp.redhat.com (Postfix) id B547E5D9C9; Mon, 11 Nov 2019 14:44:56 +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 252A918340; Mon, 11 Nov 2019 14:44:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573483565; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=9xx9t91Pc34b3dXUUSRFXWxMDqwi2bsM8Qz3pPOU1Es=; b=DomlqMPtmvxTCFAGDk18/eMruSpZY/jtGen2YnfJNY0DSxTNLz3JDCOETzI6xH3IodczYX XnL501LNq0GPKpGgdiWEkwZagftsk9bFb+uyQ5TSdBcQzJGoGQ138SFaoTrAgZH2/T1R7p ThM549yYU+nyoY668yQ0laf24/ywspo= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Mon, 11 Nov 2019 14:38:11 +0000 Message-Id: <20191111143826.16050-9-berrange@redhat.com> In-Reply-To: <20191111143826.16050-1-berrange@redhat.com> References: <20191111143826.16050-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 v5 08/23] 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: , 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-MC-Unique: u9ADSBE5PqaFfG9L_RkL_w-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: J=C3=A1n Tomko Tested-by: Cole Robinson --- Makefile.am | 1 + scripts/dtrace2systemtap.py | 143 ++++++++++++++++++++++++++++++++++++ src/Makefile.am | 10 +-- src/dtrace2systemtap.pl | 130 -------------------------------- 4 files changed, 147 insertions(+), 137 deletions(-) create mode 100755 scripts/dtrace2systemtap.py delete mode 100755 src/dtrace2systemtap.pl diff --git a/Makefile.am b/Makefile.am index 1c7b8045c2..e50a29635b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -50,6 +50,7 @@ EXTRA_DIST =3D \ scripts/check-spacing.py \ scripts/check-symfile.py \ scripts/check-symsorting.py \ + scripts/dtrace2systemtap.py \ scripts/header-ifdef.py \ scripts/minimize-po.py \ scripts/mock-noinline.py \ diff --git a/scripts/dtrace2systemtap.py b/scripts/dtrace2systemtap.py new file mode 100755 index 0000000000..922713e599 --- /dev/null +++ b/scripts/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.search(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.search(r'''^\#\s*prefix:\s*(\S+)$''', line) + if m is not None: + files[file]["prefix"] =3D m.group(1) + continue + + m =3D re.search(r'''^\#\s*binary:\s*(\S+)$''', line) + if m is not None: + files[file]["binary"] =3D m.group(1) + continue + + m =3D re.search(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.search(r'''probe\s+([a-zA-Z0-9_]+)\((.*?)(\);)?$''', = line) + 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.search(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.search(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("") diff --git a/src/Makefile.am b/src/Makefile.am index 929eef784c..085c193013 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -530,7 +530,6 @@ if WITH_DTRACE_PROBES libvirt_la_BUILT_LIBADD +=3D libvirt_probes.lo libvirt_la_DEPENDENCIES +=3D libvirt_probes.lo libvirt_probes.o nodist_libvirt_la_SOURCES =3D libvirt_probes.h -DTRACE2SYSTEMTAP_FLAGS =3D --with-modules =20 BUILT_SOURCES +=3D libvirt_probes.h libvirt_probes.stp libvirt_functions.s= tp =20 @@ -565,10 +564,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 $(top_srcdir)/scripts/dtrace2systemtap.py \ $(top_builddir)/config.status - $(AM_V_GEN)$(PERL) -w $(srcdir)/dtrace2systemtap.pl \ - $(DTRACE2SYSTEMTAP_FLAGS) $(bindir) $(sbindir) $(libdir) $< > $@ + $(AM_V_GEN)$(RUNUTF8) $(PYTHON) $(top_srcdir)/scripts/dtrace2systemtap.py= \ + $(bindir) $(sbindir) $(libdir) $< > $@ =20 CLEANFILES +=3D libvirt_probes.h libvirt_probes.o libvirt_probes.lo \ libvirt_functions.stp libvirt_probes.stp @@ -689,9 +688,6 @@ endif LIBVIRT_INIT_SCRIPT_SYSTEMD endif WITH_LIBVIRTD =20 =20 -EXTRA_DIST +=3D dtrace2systemtap.pl - - if WITH_LIBVIRTD libexec_PROGRAMS +=3D libvirt_iohelper libvirt_iohelper_SOURCES =3D $(UTIL_IO_HELPER_SOURCES) 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"; -} --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list