From patchwork Fri Oct 4 13:36:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 11174517 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 39E5D1902 for ; Fri, 4 Oct 2019 13:36:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0F899222C2 for ; Fri, 4 Oct 2019 13:36:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UcI6peMC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388272AbfJDNgz (ORCPT ); Fri, 4 Oct 2019 09:36:55 -0400 Received: from mail-wr1-f50.google.com ([209.85.221.50]:45552 "EHLO mail-wr1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388197AbfJDNgz (ORCPT ); Fri, 4 Oct 2019 09:36:55 -0400 Received: by mail-wr1-f50.google.com with SMTP id r5so7195685wrm.12 for ; Fri, 04 Oct 2019 06:36:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WRwdxbkoXQv7GO/PrgmAWRrVef7OWn2zVFHo3n/HC5o=; b=UcI6peMCwrQ0cFkP5C4z/e3dWZwRD2A8gZmpvXnBlEC+ziqrXn/Hy3P6KTFtKDUSbT a34zMOUdnB+eftAT1rfDtWN5Tyxd93/pB+vj7sOhftWnBTbd2n9SMH9rFjaRFgWTVOh6 3dr8iPN/yurFTocOaFV9sEW3gINjn7CZkcWPL+p3hfLK9tyI2uIxrcj5fARv7Kx0wwYs xombklBy8yup+Z/TKsKrtAWcuus65V1mZxtkH+N0iN+hIvkc3a6uTIC87lsWvNIscMan CmWsgki+sn4MZar1Leso22/ZDxqiZeG5Fci9ce6KKBJUPeArSMdq8D78zT7uojry4cbL H3rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WRwdxbkoXQv7GO/PrgmAWRrVef7OWn2zVFHo3n/HC5o=; b=W2Pr/EeWT2PKzxuNObOuNElil+C+b/BsdJWMTNei23RBH4K3yGfB8tSKzj2OOTj2/N KNs+XgmVWFE3Nm8PxbrLSLN99qnJ5S7l1dVZwUKRnpgo1Kr91/frj+caRzFCTl8gHGvo cdvO29PnvRePZB8aLa658apr+QQY6Oak6j2Y1tIKRaBKrIh2ZCC8xXSsIoD+VAEVxsPx xZyG1LUVhcBhsVdahpGzkC3lSgn5+uRl1raQLLbvXsADibrjklRfZM/WeiwjcVU2ZUih HOHNIEyh7618oDXQHGbpwy+wSFr28+itPtBcL5p79Dmkh/YFKbnHB1LS9RPqf4L9tNb0 X3+Q== X-Gm-Message-State: APjAAAVZ2CZAbTmxwOYirT6r5wiMvMVaGwDBw47o2mPLdfWDt7ILjDaS wmwyxRkRe7rS3qG7nu/cXfI9ASUk X-Google-Smtp-Source: APXvYqzgOkd6YR6uVH3OwCkObubyw3n1Mo1kl0DfDdR8GcnNyNaATMPDVE0R+aCY/yf8VumllbtPfw== X-Received: by 2002:a5d:4c48:: with SMTP id n8mr11369365wrt.192.1570196211827; Fri, 04 Oct 2019 06:36:51 -0700 (PDT) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id a10sm7029988wrm.52.2019.10.04.06.36.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Oct 2019 06:36:51 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 1/5] trace-cmd: Move libtraceevent plugins in its own directory. Date: Fri, 4 Oct 2019 16:36:43 +0300 Message-Id: <20191004133647.27759-2-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191004133647.27759-1-tz.stoyanov@gmail.com> References: <20191004133647.27759-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org All existing plugins are moved from plugins/ to plugins/traceevent/ directory, as all of them (except plugin_python) are designed to be used with the traceevent library. This change paves the way for implementing trace-cmd specific plugins. Signed-off-by: Tzvetomir Stoyanov (VMware) --- .gitignore | 2 +- Makefile | 28 +++++++++---------- lib/trace-cmd/Makefile | 2 -- {plugins => lib/traceevent/plugins}/Makefile | 6 ++-- .../traceevent/plugins}/plugin_blk.c | 0 .../traceevent/plugins}/plugin_cfg80211.c | 0 .../traceevent/plugins}/plugin_function.c | 0 .../traceevent/plugins}/plugin_futex.c | 0 .../traceevent/plugins}/plugin_hrtimer.c | 0 .../traceevent/plugins}/plugin_jbd2.c | 0 .../traceevent/plugins}/plugin_kmem.c | 0 .../traceevent/plugins}/plugin_kvm.c | 0 .../traceevent/plugins}/plugin_mac80211.c | 0 .../traceevent/plugins}/plugin_python.c | 0 .../traceevent/plugins}/plugin_sched_switch.c | 0 .../traceevent/plugins}/plugin_scsi.c | 0 .../traceevent/plugins}/plugin_tlb.c | 0 .../traceevent/plugins}/plugin_xen.c | 0 18 files changed, 18 insertions(+), 20 deletions(-) rename {plugins => lib/traceevent/plugins}/Makefile (93%) rename {plugins => lib/traceevent/plugins}/plugin_blk.c (100%) rename {plugins => lib/traceevent/plugins}/plugin_cfg80211.c (100%) rename {plugins => lib/traceevent/plugins}/plugin_function.c (100%) rename {plugins => lib/traceevent/plugins}/plugin_futex.c (100%) rename {plugins => lib/traceevent/plugins}/plugin_hrtimer.c (100%) rename {plugins => lib/traceevent/plugins}/plugin_jbd2.c (100%) rename {plugins => lib/traceevent/plugins}/plugin_kmem.c (100%) rename {plugins => lib/traceevent/plugins}/plugin_kvm.c (100%) rename {plugins => lib/traceevent/plugins}/plugin_mac80211.c (100%) rename {plugins => lib/traceevent/plugins}/plugin_python.c (100%) rename {plugins => lib/traceevent/plugins}/plugin_sched_switch.c (100%) rename {plugins => lib/traceevent/plugins}/plugin_scsi.c (100%) rename {plugins => lib/traceevent/plugins}/plugin_tlb.c (100%) rename {plugins => lib/traceevent/plugins}/plugin_xen.c (100%) diff --git a/.gitignore b/.gitignore index b7b405f..20bb5a3 100644 --- a/.gitignore +++ b/.gitignore @@ -18,5 +18,5 @@ ctracecmdgui_wrap.c tags TAGS cscope* -trace_plugin_dir +traceevent_plugin_dir trace_python_dir diff --git a/Makefile b/Makefile index dabdf8d..f336f7a 100644 --- a/Makefile +++ b/Makefile @@ -273,16 +273,16 @@ gui: force $(CMD_TARGETS) $(kshark-dir)/build/Makefile trace-cmd: force $(LIBTRACEEVENT_STATIC) $(LIBTRACECMD_STATIC) $(Q)$(MAKE) -C $(src)/tracecmd $(obj)/tracecmd/$@ -$(LIBTRACEEVENT_SHARED): force +$(LIBTRACEEVENT_SHARED): force $(obj)/lib/traceevent/plugins/traceevent_plugin_dir $(Q)$(MAKE) -C $(src)/lib/traceevent $@ -$(LIBTRACEEVENT_STATIC): force +$(LIBTRACEEVENT_STATIC): force $(obj)/lib/traceevent/plugins/traceevent_plugin_dir $(Q)$(MAKE) -C $(src)/lib/traceevent $@ -$(LIBTRACECMD_STATIC): force $(obj)/plugins/trace_plugin_dir +$(LIBTRACECMD_STATIC): force $(Q)$(MAKE) -C $(src)/lib/trace-cmd $@ -$(LIBTRACECMD_SHARED): force $(obj)/plugins/trace_plugin_dir +$(LIBTRACECMD_SHARED): force $(Q)$(MAKE) -C $(src)/lib/trace-cmd $@ libtraceevent.so: $(LIBTRACEEVENT_SHARED) @@ -292,14 +292,14 @@ libtracecmd.so: $(LIBTRACECMD_SHARED) libs: $(LIBTRACECMD_SHARED) $(LIBTRACEEVENT_SHARED) -plugins: force $(obj)/plugins/trace_plugin_dir $(obj)/plugins/trace_python_dir - $(Q)$(MAKE) -C $(src)/plugins +plugins: force $(obj)/lib/traceevent/plugins/traceevent_plugin_dir $(obj)/lib/traceevent/plugins/trace_python_dir + $(Q)$(MAKE) -C $(src)/lib/traceevent/plugins -$(obj)/plugins/trace_plugin_dir: force - $(Q)$(MAKE) -C $(src)/plugins $@ +$(obj)/lib/traceevent/plugins/traceevent_plugin_dir: force + $(Q)$(MAKE) -C $(src)/lib/traceevent/plugins $@ -$(obj)/plugins/trace_python_dir: force - $(Q)$(MAKE) -C $(src)/plugins $@ +$(obj)/lib/traceevent/plugins/trace_python_dir: force + $(Q)$(MAKE) -C $(src)/lib/traceevent/plugins $@ show_gui_make: @echo "Note: to build the gui, type \"make gui\"" @@ -325,7 +325,7 @@ cscope: force $(call find_tag_files) | cscope -b -q install_plugins: force - $(Q)$(MAKE) -C $(src)/plugins $@ + $(Q)$(MAKE) -C $(src)/lib/traceevent/plugins $@ install_python: force $(Q)$(MAKE) -C $(src)/python $@ @@ -372,7 +372,7 @@ clean: $(RM) tags TAGS cscope* $(MAKE) -C $(src)/lib/traceevent clean $(MAKE) -C $(src)/lib/trace-cmd clean - $(MAKE) -C $(src)/plugins clean + $(MAKE) -C $(src)/lib/traceevent/plugins clean $(MAKE) -C $(src)/python clean $(MAKE) -C $(src)/tracecmd clean if [ -f $(kshark-dir)/build/Makefile ]; then $(MAKE) -C $(kshark-dir)/build clean; fi @@ -421,8 +421,8 @@ python-gui: $(PYTHON_GUI) PHONY += python-plugin python-plugin: $(PYTHON_PLUGINS) -plugin_python.so: force $(obj)/plugins/trace_python_dir - $(Q)$(MAKE) -C $(src)/plugins $(obj)/plugins/plugin_python.so +plugin_python.so: force $(obj)/lib/traceevent/plugins/trace_python_dir + $(Q)$(MAKE) -C $(src)/lib/traceevent/plugins $(obj)/lib/traceevent/plugins/plugin_python.so dist: git archive --format=tar --prefix=trace-cmd-$(TRACECMD_VERSION)/ HEAD \ diff --git a/lib/trace-cmd/Makefile b/lib/trace-cmd/Makefile index 78875e4..3b4b5aa 100644 --- a/lib/trace-cmd/Makefile +++ b/lib/trace-cmd/Makefile @@ -40,8 +40,6 @@ $(bdir)/libtracecmd.so: $(OBJS) $(bdir)/%.o: %.c $(Q)$(call do_fpic_compile) -$(bdir)/trace-util.o: $(obj)/plugins/trace_plugin_dir - $(DEPS): $(bdir)/.%.d: %.c $(Q)$(CC) -M $(CPPFLAGS) $(CFLAGS) $< > $@ diff --git a/plugins/Makefile b/lib/traceevent/plugins/Makefile similarity index 93% rename from plugins/Makefile rename to lib/traceevent/plugins/Makefile index 4598e83..e0a7566 100644 --- a/plugins/Makefile +++ b/lib/traceevent/plugins/Makefile @@ -1,6 +1,6 @@ include $(src)/scripts/utils.mk -bdir:=$(obj)/plugins +bdir:=$(obj)/lib/traceevent/plugins PLUGIN_OBJS = PLUGIN_OBJS += plugin_jbd2.o @@ -61,7 +61,7 @@ install_plugins: $(PLUGINS_INSTALL) # and $(PYTHON_DIR) change. Without them, a full clean build would necessary # in order to get the binaries updated. -$(bdir)/trace_plugin_dir: $(bdir) force +$(bdir)/traceevent_plugin_dir: $(bdir) force $(Q)$(N)$(call update_dir, 'PLUGIN_DIR=$(PLUGIN_DIR)') $(bdir)/trace_python_dir: $(bdir) force @@ -75,7 +75,7 @@ ifneq ($(dep_includes),) endif clean: - $(RM) -f $(bdir)/*.a $(bdir)/*.so $(bdir)/*.o $(bdir)/.*.d $(bdir)/trace_plugin_dir $(bdir)/trace_python_dir + $(RM) -f $(bdir)/*.a $(bdir)/*.so $(bdir)/*.o $(bdir)/.*.d $(bdir)/traceevent_plugin_dir $(bdir)/trace_python_dir force: .PHONY: clean force diff --git a/plugins/plugin_blk.c b/lib/traceevent/plugins/plugin_blk.c similarity index 100% rename from plugins/plugin_blk.c rename to lib/traceevent/plugins/plugin_blk.c diff --git a/plugins/plugin_cfg80211.c b/lib/traceevent/plugins/plugin_cfg80211.c similarity index 100% rename from plugins/plugin_cfg80211.c rename to lib/traceevent/plugins/plugin_cfg80211.c diff --git a/plugins/plugin_function.c b/lib/traceevent/plugins/plugin_function.c similarity index 100% rename from plugins/plugin_function.c rename to lib/traceevent/plugins/plugin_function.c diff --git a/plugins/plugin_futex.c b/lib/traceevent/plugins/plugin_futex.c similarity index 100% rename from plugins/plugin_futex.c rename to lib/traceevent/plugins/plugin_futex.c diff --git a/plugins/plugin_hrtimer.c b/lib/traceevent/plugins/plugin_hrtimer.c similarity index 100% rename from plugins/plugin_hrtimer.c rename to lib/traceevent/plugins/plugin_hrtimer.c diff --git a/plugins/plugin_jbd2.c b/lib/traceevent/plugins/plugin_jbd2.c similarity index 100% rename from plugins/plugin_jbd2.c rename to lib/traceevent/plugins/plugin_jbd2.c diff --git a/plugins/plugin_kmem.c b/lib/traceevent/plugins/plugin_kmem.c similarity index 100% rename from plugins/plugin_kmem.c rename to lib/traceevent/plugins/plugin_kmem.c diff --git a/plugins/plugin_kvm.c b/lib/traceevent/plugins/plugin_kvm.c similarity index 100% rename from plugins/plugin_kvm.c rename to lib/traceevent/plugins/plugin_kvm.c diff --git a/plugins/plugin_mac80211.c b/lib/traceevent/plugins/plugin_mac80211.c similarity index 100% rename from plugins/plugin_mac80211.c rename to lib/traceevent/plugins/plugin_mac80211.c diff --git a/plugins/plugin_python.c b/lib/traceevent/plugins/plugin_python.c similarity index 100% rename from plugins/plugin_python.c rename to lib/traceevent/plugins/plugin_python.c diff --git a/plugins/plugin_sched_switch.c b/lib/traceevent/plugins/plugin_sched_switch.c similarity index 100% rename from plugins/plugin_sched_switch.c rename to lib/traceevent/plugins/plugin_sched_switch.c diff --git a/plugins/plugin_scsi.c b/lib/traceevent/plugins/plugin_scsi.c similarity index 100% rename from plugins/plugin_scsi.c rename to lib/traceevent/plugins/plugin_scsi.c diff --git a/plugins/plugin_tlb.c b/lib/traceevent/plugins/plugin_tlb.c similarity index 100% rename from plugins/plugin_tlb.c rename to lib/traceevent/plugins/plugin_tlb.c diff --git a/plugins/plugin_xen.c b/lib/traceevent/plugins/plugin_xen.c similarity index 100% rename from plugins/plugin_xen.c rename to lib/traceevent/plugins/plugin_xen.c From patchwork Fri Oct 4 13:36:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 11174515 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0652714DB for ; Fri, 4 Oct 2019 13:36:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D8408222C0 for ; Fri, 4 Oct 2019 13:36:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mb2hpcPS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388244AbfJDNgz (ORCPT ); Fri, 4 Oct 2019 09:36:55 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:36365 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388272AbfJDNgz (ORCPT ); Fri, 4 Oct 2019 09:36:55 -0400 Received: by mail-wr1-f66.google.com with SMTP id y19so7273577wrd.3 for ; Fri, 04 Oct 2019 06:36:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7HVPvMkHId7shPJR7QSW7ONG80bylQ1cwLiTUhTiNkw=; b=mb2hpcPSEGTDOBtb+fLRAV8tJCk27Qf2D203k0FYF0v6sKQduXmZBPoE52KX+oxbYg FnvBc2LS9ZkG5sPAFA2Ec7zMnkYaLSgod62OGwWrmXfcbOOFR6cZwX3jGS/WDAnRpobt g7F2zxNQx7cg21FKNMuJH77fpelvxt3aIGMwdSAezyCj6RiFqBYgoDUO7M8jDdEwYuD4 DM1gad/jdITNeEWDH3+tV3J46AfnTCtbIax5pkbStI0BjEyxhJLhF29Ozn1bwnhResT9 5rwzCphXyOI/ZpcSB8Rx3ioDm3QaH0GefKBgmpovFFWILvpkz7czf9FRLJfEQwr2x0xF 2QCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7HVPvMkHId7shPJR7QSW7ONG80bylQ1cwLiTUhTiNkw=; b=blscOD95XmeiEMcF7cz4hrbESEgoyxXqsMZxGdkrRr0ZvccN9mhkh7IUWkA2TkNL6+ 1FyAIgeV/eXcddyEfnoBMo4BuBleYgsCUXiu9f2wPhyDHdhT4mEeaYfO+tjNGikLNSOD efW9lKaGDmv9XRZ4NP+b7svHHhybNVz0lUMz8QGRymOSRVr+59WaZ5MRtkrCtzV+tltB 4DsQ8o9qg+LR1mBc1Qne6t+OPQJZN2b4suUA8PALDeUvrI9eoqsouOEzEt5sjAQzlMIb ZB7owPUbnxitjX2Zxr2o1oZXl+AkeIoBDHxus3t7kIzyEecdtcZPl/sg8p+3BU1AAG4x 4D6A== X-Gm-Message-State: APjAAAXgmjqgMiU39BmgMozeCKdQQ3kFg1be2lNUopiAMoui1BYBBbk1 Jv8WZ4v3oaV3mN76wDHUZp4= X-Google-Smtp-Source: APXvYqzFH0j5oKzS2twpbQNKUos09NspFyhzAKPnCiLNKOqkwNvimjG1N2lLtbxiHBIDdvb75XafgA== X-Received: by 2002:a5d:4f8e:: with SMTP id d14mr11708228wru.384.1570196212954; Fri, 04 Oct 2019 06:36:52 -0700 (PDT) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id a10sm7029988wrm.52.2019.10.04.06.36.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Oct 2019 06:36:52 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 2/5] trace-cmd: Rename plugin_python to plugin_python_loader. Date: Fri, 4 Oct 2019 16:36:44 +0300 Message-Id: <20191004133647.27759-3-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191004133647.27759-1-tz.stoyanov@gmail.com> References: <20191004133647.27759-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The plugin_python is renamed to plugin_python_loader, to make the name more closer to the actual plugin role. Signed-off-by: Tzvetomir Stoyanov (VMware) --- Makefile | 10 +--------- lib/traceevent/plugins/Makefile | 6 +++--- .../{plugin_python.c => plugin_python_loader.c} | 0 3 files changed, 4 insertions(+), 12 deletions(-) rename lib/traceevent/plugins/{plugin_python.c => plugin_python_loader.c} (100%) diff --git a/Makefile b/Makefile index f336f7a..e20eced 100644 --- a/Makefile +++ b/Makefile @@ -116,8 +116,7 @@ PYTHON_PKGCONFIG_VERS ?= $(PYTHON_VERS) # Can build python? ifeq ($(shell sh -c "pkg-config --cflags $(PYTHON_PKGCONFIG_VERS) > /dev/null 2>&1 && echo y"), y) - PYTHON_PLUGINS := plugin_python.so - BUILD_PYTHON := $(PYTHON) $(PYTHON_PLUGINS) + BUILD_PYTHON := $(PYTHON) BUILD_PYTHON_WORKS := 1 else BUILD_PYTHON := report_nopythondev @@ -125,7 +124,6 @@ else endif endif # NO_PYTHON -export PYTHON_PLUGINS export BUILD_PYTHON_WORKS export NO_PYTHON @@ -418,12 +416,6 @@ python: $(PYTHON) PHONY += python-gui python-gui: $(PYTHON_GUI) -PHONY += python-plugin -python-plugin: $(PYTHON_PLUGINS) - -plugin_python.so: force $(obj)/lib/traceevent/plugins/trace_python_dir - $(Q)$(MAKE) -C $(src)/lib/traceevent/plugins $(obj)/lib/traceevent/plugins/plugin_python.so - dist: git archive --format=tar --prefix=trace-cmd-$(TRACECMD_VERSION)/ HEAD \ > ../trace-cmd-$(TRACECMD_VERSION).tar diff --git a/lib/traceevent/plugins/Makefile b/lib/traceevent/plugins/Makefile index e0a7566..061d919 100644 --- a/lib/traceevent/plugins/Makefile +++ b/lib/traceevent/plugins/Makefile @@ -21,7 +21,7 @@ PLUGIN_OBJS := $(PLUGIN_OBJS:%.o=$(bdir)/%.o) PLUGIN_BUILD := $(PLUGIN_OBJS:$(bdir)/%.o=$(bdir)/%.so) PLUGINS := $(PLUGIN_BUILD) ifndef NO_PYTHON -PLUGINS += $(bdir)/plugin_python.so +PLUGINS += $(bdir)/plugin_python_loader.so endif DEPS := $(PLUGIN_OBJS:$(bdir)/%.o=$(bdir)/.%.d) @@ -44,10 +44,10 @@ $(DEPS): $(bdir)/.%.d: %.c $(PLUGIN_OBJS): $(bdir)/%.o : $(bdir)/.%.d -$(bdir)/plugin_python.o: $(bdir)/%.o : %.c $(bdir)/trace_python_dir +$(bdir)/plugin_python_loader.o: $(bdir)/%.o : %.c $(bdir)/trace_python_dir $(Q)$(do_compile_python_plugin_obj) -$(bdir)/plugin_python.so: $(bdir)/%.so: $(bdir)/%.o +$(bdir)/plugin_python_loader.so: $(bdir)/%.so: $(bdir)/%.o $(Q)$(do_python_plugin_build) PLUGINS_INSTALL = $(subst .so,.install,$(PLUGINS)) diff --git a/lib/traceevent/plugins/plugin_python.c b/lib/traceevent/plugins/plugin_python_loader.c similarity index 100% rename from lib/traceevent/plugins/plugin_python.c rename to lib/traceevent/plugins/plugin_python_loader.c From patchwork Fri Oct 4 13:36:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 11174519 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A20D114DB for ; Fri, 4 Oct 2019 13:36:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 769D320700 for ; Fri, 4 Oct 2019 13:36:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="D1aBIIna" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388393AbfJDNg5 (ORCPT ); Fri, 4 Oct 2019 09:36:57 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:35821 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388333AbfJDNg5 (ORCPT ); Fri, 4 Oct 2019 09:36:57 -0400 Received: by mail-wr1-f68.google.com with SMTP id v8so7280219wrt.2 for ; Fri, 04 Oct 2019 06:36:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+ixZqoFA1AJg8a6gd1rG3bObRYvFcofEgjducAR42T0=; b=D1aBIInap0A/dhsVohGMqezkRCEQsPCJcHhGGAcKTKS6a9U66acJi9Cu+USfVR2a0z JraUZnmio6vmMZs4ohfQUbZox3cLgvu+9wFROePHdMMFKRgcf8FQ9bTXwcj2lZnVWtEN VhJyc7+hPrb8v2BuPGf3FPKHEB2l0sJAQ1w25Y67sDGaSnFgpMzWP0ZhSR09nEZUJM3k VXW3M+mQFd4VqEr9pbzlNM+cVB0PDxdzj6PDZcSnaMcvBB4+Li8vSJ4XqjPXr6q3qP/8 CRseIxVYI8dFJcnesDF5eFgSE2hhv3s5UQUgsG5iW7cPkbTdi8d7dQJIF/Yb0/ydyLlc QLOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+ixZqoFA1AJg8a6gd1rG3bObRYvFcofEgjducAR42T0=; b=ujhj2HHA+LD2kxYrq3XuSL5Cv9MY9KvKREYB19fPDYtWl8+QwyD8uU/Hiwh6LUkOgv 8IpRa8OBosawUkpi8LwELE40ENzE5FmA5bt5RydmQTSJFVhf8rsDsz+pVrcqVCk2FhHr LNFhDvV+JeaSjJNafRCP+EJ0QOJyXt6CBwEiYYpqp/0g+tW3tMkUYJ7h+juQgveBMH6K 6WyCV1+wjg/eaxfXEn1XUcsZzq8t6WpuwXhvW2ASJKeXoWRN6KgajL8JVicYuiRenau3 pIYDLh1Y7AsVyAgF3BbquVWpk906asj1YGtc6TL2c7WynuYUiTfaT2D7cLjFIsj5kaal KlSA== X-Gm-Message-State: APjAAAVSamJxJlcqGRAQb7HVZNU+nld+mursCbvhwt80xJfGPdcqmI9P MDBDRKfWdKKpJoHCcLM7hNc= X-Google-Smtp-Source: APXvYqxuCVJ+dlzJ4mxZf1qHDOjbLujXnOgZ9tu0SqbXb9yHnP4hnI3yfdjFmbqADyVH5i1GW0yFIQ== X-Received: by 2002:a5d:63cb:: with SMTP id c11mr9564291wrw.281.1570196214023; Fri, 04 Oct 2019 06:36:54 -0700 (PDT) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id a10sm7029988wrm.52.2019.10.04.06.36.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Oct 2019 06:36:53 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 3/5] trace-cmd: Load libtraceevent plugins from build folder, if exists. Date: Fri, 4 Oct 2019 16:36:45 +0300 Message-Id: <20191004133647.27759-4-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191004133647.27759-1-tz.stoyanov@gmail.com> References: <20191004133647.27759-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org When a development version of trace-cmd is built and run on the machine, by default it loads only installed plugins, from system directories. Thus, the development plugins will not be loaded. To simplify the development process, a new logic is added: At plugins load time, check the location of trace-cmd application and look for "plugins" directory around it. If found, load plugins from it. Those plugins will be loaded last, so in case of duplication the "development" plugins win. A two new APIs are introduced to libtraceevent, in order to accomplish this logic: tep_load_plugins_dir() - loads tep plugins from a specific directory. tep_plugins_append() - Append two plugin lists. Signed-off-by: Tzvetomir Stoyanov (VMware) --- include/trace-cmd/trace-cmd.h | 2 ++ include/traceevent/event-parse.h | 3 +++ lib/trace-cmd/trace-input.c | 7 +---- lib/trace-cmd/trace-util.c | 46 ++++++++++++++++++++++++++++++++ lib/traceevent/event-plugin.c | 38 ++++++++++++++++++++++++++ tracecmd/trace-check-events.c | 7 +---- tracecmd/trace-list.c | 14 ++-------- 7 files changed, 93 insertions(+), 24 deletions(-) diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h index 092bd89..0593463 100644 --- a/include/trace-cmd/trace-cmd.h +++ b/include/trace-cmd/trace-cmd.h @@ -25,6 +25,8 @@ void tracecmd_parse_ftrace_printk(struct tep_handle *pevent, char *file, unsigne extern int tracecmd_disable_sys_plugins; extern int tracecmd_disable_plugins; +struct tep_plugin_list *trace_load_tep_plugins(struct tep_handle *tep); + char **tracecmd_event_systems(const char *tracing_dir); char **tracecmd_system_events(const char *tracing_dir, const char *system); struct tep_handle *tracecmd_local_events(const char *tracing_dir); diff --git a/include/traceevent/event-parse.h b/include/traceevent/event-parse.h index 99da5ef..b97a366 100644 --- a/include/traceevent/event-parse.h +++ b/include/traceevent/event-parse.h @@ -380,6 +380,9 @@ struct tep_plugin_list; #define INVALID_PLUGIN_LIST_OPTION ((char **)((unsigned long)-1)) struct tep_plugin_list *tep_load_plugins(struct tep_handle *tep); +struct tep_plugin_list *tep_load_plugins_dir(struct tep_handle *tep, char *path); +void tep_plugins_append(struct tep_plugin_list *list1, + struct tep_plugin_list *list2); void tep_unload_plugins(struct tep_plugin_list *plugin_list, struct tep_handle *tep); void tep_load_plugins_hook(struct tep_handle *tep, const char *suffix, diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 8cceb31..6e1fa2e 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -2850,15 +2850,10 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd) if (!handle->pevent) goto failed_read; - if (tracecmd_disable_plugins) - tep_set_flag(handle->pevent, TEP_DISABLE_PLUGINS); - if (tracecmd_disable_sys_plugins) - tep_set_flag(handle->pevent, TEP_DISABLE_SYS_PLUGINS); - /* register default ftrace functions first */ tracecmd_ftrace_overrides(handle, &handle->finfo); - handle->plugin_list = tep_load_plugins(handle->pevent); + handle->plugin_list = trace_load_tep_plugins(handle->pevent); tep_set_file_bigendian(handle->pevent, buf[0]); tep_set_local_bigendian(handle->pevent, tracecmd_host_bigendian()); diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c index b08e377..5a84fc3 100644 --- a/lib/trace-cmd/trace-util.c +++ b/lib/trace-cmd/trace-util.c @@ -884,6 +884,52 @@ void trace_util_free_plugin_files(char **files) free(files); } +static char *get_source_plugins_dir(void) +{ + char *p, path[PATH_MAX+1]; + int ret; + + ret = readlink("/proc/self/exe", path, PATH_MAX); + if (ret > PATH_MAX || ret < 0) + return NULL; + + dirname(path); + p = strrchr(path, '/'); + if (!p) + return NULL; + /* Check if we are in the the source tree */ + if (strcmp(p, "/tracecmd") != 0) + return NULL; + + strcpy(p, "/lib/traceevent/plugins"); + return strdup(path); +} + +struct tep_plugin_list* +trace_load_tep_plugins(struct tep_handle *tep) +{ + struct tep_plugin_list *list_dev; + struct tep_plugin_list *list; + char *path; + + if (tracecmd_disable_plugins) + tep_set_flag(tep, TEP_DISABLE_PLUGINS); + if (tracecmd_disable_sys_plugins) + tep_set_flag(tep, TEP_DISABLE_SYS_PLUGINS); + + list = tep_load_plugins(tep); + + path = get_source_plugins_dir(); + if (path) { + list_dev = tep_load_plugins_dir(tep, path); + tep_plugins_append(list_dev, list); + list = list_dev; + free(path); + } + + return list; +} + char *tracecmd_get_tracing_file(const char *name) { static const char *tracing; diff --git a/lib/traceevent/event-plugin.c b/lib/traceevent/event-plugin.c index bc10205..b2a30bb 100644 --- a/lib/traceevent/event-plugin.c +++ b/lib/traceevent/event-plugin.c @@ -599,6 +599,44 @@ tep_load_plugins(struct tep_handle *tep) return list; } +/** + * tep_load_plugins_dir - load traceevent plugins from a directory + * @tep: Trace event handler. + * @path: Path to a directory. All files with extension .so in that + * directory will be loaded as plugins. + * + * Returns a list of loaded plugins + */ +struct tep_plugin_list* +tep_load_plugins_dir(struct tep_handle *tep, char *path) +{ + struct tep_plugin_list *list = NULL; + + if (tep && tep->flags & TEP_DISABLE_PLUGINS) + return NULL; + + load_plugins_dir(tep, ".so", path, load_plugin, &list); + return list; +} + +/** + * tep_plugins_append - Concatenate two plugin lists. + * @list1: The first plugin list. + * @list2: The second plugin list. + * + * The second plugin list (list2) is appended to the first one (list1). + */ +void tep_plugins_append(struct tep_plugin_list *list1, + struct tep_plugin_list *list2) +{ + struct tep_plugin_list *list = list1; + + while (list && list->next) + list = list->next; + if (list) + list->next = list2; +} + void tep_unload_plugins(struct tep_plugin_list *plugin_list, struct tep_handle *tep) { diff --git a/tracecmd/trace-check-events.c b/tracecmd/trace-check-events.c index b09fcd0..eb840c6 100644 --- a/tracecmd/trace-check-events.c +++ b/tracecmd/trace-check-events.c @@ -43,12 +43,7 @@ void trace_check_events(int argc, char **argv) if (!pevent) exit(EINVAL); - if (tracecmd_disable_plugins) - tep_set_flag(pevent, TEP_DISABLE_PLUGINS); - if (tracecmd_disable_sys_plugins) - tep_set_flag(pevent, TEP_DISABLE_SYS_PLUGINS); - - list = tep_load_plugins(pevent); + list = trace_load_tep_plugins(pevent); ret = tracecmd_fill_local_events(tracing, pevent, &parsing_failures); if (ret || parsing_failures) ret = EINVAL; diff --git a/tracecmd/trace-list.c b/tracecmd/trace-list.c index 65099a5..840eeac 100644 --- a/tracecmd/trace-list.c +++ b/tracecmd/trace-list.c @@ -317,14 +317,9 @@ static void show_plugin_options(void) if (!pevent) die("Can not allocate pevent\n"); - if (tracecmd_disable_plugins) - tep_set_flag(pevent, TEP_DISABLE_PLUGINS); - if (tracecmd_disable_sys_plugins) - tep_set_flag(pevent, TEP_DISABLE_SYS_PLUGINS); - trace_seq_init(&s); - list = tep_load_plugins(pevent); + list = trace_load_tep_plugins(pevent); tep_plugin_print_options(&s); trace_seq_do_printf(&s); tep_unload_plugins(list, pevent); @@ -348,14 +343,9 @@ static void show_plugins(void) if (!pevent) die("Can not allocate pevent\n"); - if (tracecmd_disable_plugins) - tep_set_flag(pevent, TEP_DISABLE_PLUGINS); - if (tracecmd_disable_sys_plugins) - tep_set_flag(pevent, TEP_DISABLE_SYS_PLUGINS); - trace_seq_init(&s); - list = tep_load_plugins(pevent); + list = trace_load_tep_plugins(pevent); tep_print_plugins(&s, " ", "\n", list); trace_seq_do_printf(&s); From patchwork Fri Oct 4 13:36:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 11174521 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 279CF1709 for ; Fri, 4 Oct 2019 13:36:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 06141222C2 for ; Fri, 4 Oct 2019 13:36:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="durrgv4P" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388376AbfJDNg6 (ORCPT ); Fri, 4 Oct 2019 09:36:58 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:35824 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388197AbfJDNg6 (ORCPT ); Fri, 4 Oct 2019 09:36:58 -0400 Received: by mail-wr1-f66.google.com with SMTP id v8so7280329wrt.2 for ; Fri, 04 Oct 2019 06:36:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GFx24vPKmjI9q3Fl4A5Pvwia71Hjh1qC/tqQN7Bsp48=; b=durrgv4PyeVnhiagXpdyrPS7/a/Vu9RM0AvrDJbuUsFKrYv/FIPK/zwFfMF8Xfcpvk TfBwdli3nZEXzQnmbyF2wQCHShYWkfDKU/H4vHFnEKhF/7q/opBJ6+Igau3Q74ZbbRCn UTIHXatsIfx5nkkQDvPiTFP4XXrvxc9SuqQ9H2U6fdWoog36uJXI8nS9x4bydHxxwjuc ebv4CEsKAiTrLkYOm5Q4Xx+IwWBfw4OJg03cYzgZjbftiQ2Zud44Ro2aWb4JhloM+YVL yP2XYeiFcjnQe2qGn03ON9016AwU1q2w/2lhUcmUen3KZ+WPNMKBGx4cvPGAs/oVTeap c4hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GFx24vPKmjI9q3Fl4A5Pvwia71Hjh1qC/tqQN7Bsp48=; b=Qj4mFXEbmvtS/raR/WX/alIHMtl8Tgy9i+VX4F7fFpp+soFBe0rAiq7wpkwkPm/36e Rk1xt1kVVLOUalIFqfzhCI0pm4nD3Tb0lCqENQKFIzjq0uw6ASOV2200erKOD8bh0UV3 KHBY0qdDGiYxIwUf79CP75qD0CJHhl80My5dIX/WxtpnzfdpM6cpvGOY/7tmHuLYtGt1 JKkpbf+EULOPyzBo2qnn+/6MpOo+YQoaK+kM649BsYdzWWkN+eFdoHzg6yxUkzW2Zc1i zcQfYJVR7gZFa5ovkxIEOPi1rpoFwKkdJQIO+gPKwjOAdh5PE147WShYuGZFnuanW98j kTwg== X-Gm-Message-State: APjAAAVdubzKPnNAjlcTPy6+jYmC28JyWd3sbARX9++N93cxN65KMQb/ dsK3LqDr82pA3ulfc0ZNQBw= X-Google-Smtp-Source: APXvYqx7YlzHAeqDRZGWjroNpg/Py4C7siCq6rxEz1m6uU6FbPeIDSAJbJCVFdtzhUSfMS5tEfzwWQ== X-Received: by 2002:a5d:51c9:: with SMTP id n9mr6377016wrv.398.1570196215391; Fri, 04 Oct 2019 06:36:55 -0700 (PDT) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id a10sm7029988wrm.52.2019.10.04.06.36.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Oct 2019 06:36:54 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 4/5] trace-cmd: Change plugin install directories Date: Fri, 4 Oct 2019 16:36:46 +0300 Message-Id: <20191004133647.27759-5-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191004133647.27759-1-tz.stoyanov@gmail.com> References: <20191004133647.27759-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org From: Tzvetomir Stoyanov To be compliant with XDG user directory layout, the user's plugin directory is changed from ~/.traceevent/plugins to ~/.local/lib/traceevent/plugins/ Thanks to Patrick McLean: https://lore.kernel.org/linux-trace-devel/20190313144206.41e75cf8@patrickm/ The system plugin directory is changed from (install_prefix)/lib/trace-cmd/plugins to (install_prefix)/lib/traceevent/plugins This change paves the way for implementing trace-cmd specific plugins. Suggested-by: Patrick McLean Signed-off-by: Tzvetomir Stoyanov (VMware) --- Makefile | 16 ++++++++-------- lib/traceevent/event-plugin.c | 6 +++--- lib/traceevent/plugins/Makefile | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index e20eced..cb5b07b 100644 --- a/Makefile +++ b/Makefile @@ -56,15 +56,15 @@ export img_install img_install_SQ export DESTDIR DESTDIR_SQ ifeq ($(prefix),$(HOME)) -plugin_dir = $(HOME)/.trace-cmd/plugins +plugin_traceevent_dir = $(HOME)/.local/lib/traceevent/plugins python_dir = $(HOME)/.trace-cmd/python var_dir = $(HOME)/.trace-cmd/ else -plugin_dir = $(libdir)/trace-cmd/plugins +plugin_traceevent_dir = $(libdir)/traceevent/plugins python_dir ?= $(libdir)/trace-cmd/python -PLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)" +PLUGIN_DIR_TRACEEVENT = -DPLUGIN_TRACEEVENT_DIR="$(plugin_traceevent_dir)" PYTHON_DIR = -DPYTHON_DIR="$(python_dir)" -PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))' +PLUGIN_DIR_TRACEEVENT_SQ = '$(subst ','\'',$(PLUGIN_DIR_TRACEEVENT))' PYTHON_DIR_SQ = '$(subst ','\'',$(PYTHON_DIR))' var_dir = /var endif @@ -72,7 +72,7 @@ endif # Shell quotes bindir_SQ = $(subst ','\'',$(bindir)) bindir_relative_SQ = $(subst ','\'',$(bindir_relative)) -plugin_dir_SQ = $(subst ','\'',$(plugin_dir)) +plugin_traceevent_dir_SQ = $(subst ','\'',$(plugin_traceevent_dir)) python_dir_SQ = $(subst ','\'',$(python_dir)) VAR_DIR = -DVAR_DIR="$(var_dir)" @@ -85,10 +85,10 @@ HELP_DIR_SQ = '$(subst ','\'',$(HELP_DIR))' BASH_COMPLETE_DIR ?= /etc/bash_completion.d -export PLUGIN_DIR +export PLUGIN_DIR_TRACEEVENT export PYTHON_DIR export PYTHON_DIR_SQ -export plugin_dir_SQ +export plugin_traceevent_dir_SQ export python_dir_SQ export var_dir @@ -239,7 +239,7 @@ LIBS += -laudit endif # Append required CFLAGS -override CFLAGS += $(INCLUDES) $(PLUGIN_DIR_SQ) $(VAR_DIR) +override CFLAGS += $(INCLUDES) $(PLUGIN_DIR_TRACEEVENT_SQ) $(VAR_DIR) override CFLAGS += $(udis86-flags) $(blk-flags) override LDFLAGS += $(udis86-ldflags) diff --git a/lib/traceevent/event-plugin.c b/lib/traceevent/event-plugin.c index b2a30bb..ce9d53c 100644 --- a/lib/traceevent/event-plugin.c +++ b/lib/traceevent/event-plugin.c @@ -19,7 +19,7 @@ #include "event-utils.h" #include "trace-seq.h" -#define LOCAL_PLUGIN_DIR ".traceevent/plugins" +#define LOCAL_PLUGIN_DIR ".local/lib/traceevent/plugins/" static struct registered_plugin_options { struct registered_plugin_options *next; @@ -557,9 +557,9 @@ void tep_load_plugins_hook(struct tep_handle *tep, const char *suffix, * If a system plugin directory was defined, * check that first. */ -#ifdef PLUGIN_DIR +#ifdef PLUGIN_TRACEEVENT_DIR if (!tep || !(tep->flags & TEP_DISABLE_SYS_PLUGINS)) - load_plugins_dir(tep, suffix, PLUGIN_DIR, + load_plugins_dir(tep, suffix, PLUGIN_TRACEEVENT_DIR, load_plugin, data); #endif diff --git a/lib/traceevent/plugins/Makefile b/lib/traceevent/plugins/Makefile index 061d919..4050019 100644 --- a/lib/traceevent/plugins/Makefile +++ b/lib/traceevent/plugins/Makefile @@ -53,11 +53,11 @@ $(bdir)/plugin_python_loader.so: $(bdir)/%.so: $(bdir)/%.o PLUGINS_INSTALL = $(subst .so,.install,$(PLUGINS)) $(PLUGINS_INSTALL): $(bdir)/%.install : $(bdir)/%.so force - $(Q)$(call do_install_data,$<,$(plugin_dir_SQ)) + $(Q)$(call do_install_data,$<,$(plugin_traceevent_dir_SQ)) install_plugins: $(PLUGINS_INSTALL) -# The following targets are necessary to trigger a rebuild when $(PLUGIN_DIR) +# The following targets are necessary to trigger a rebuild when $(PLUGIN_DIR_TRACEEVENT) # and $(PYTHON_DIR) change. Without them, a full clean build would necessary # in order to get the binaries updated. From patchwork Fri Oct 4 13:36:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 11174523 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5542A16B1 for ; Fri, 4 Oct 2019 13:37:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1F7A1222C2 for ; Fri, 4 Oct 2019 13:37:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VsB6rL6G" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388197AbfJDNhC (ORCPT ); Fri, 4 Oct 2019 09:37:02 -0400 Received: from mail-wr1-f52.google.com ([209.85.221.52]:45568 "EHLO mail-wr1-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388333AbfJDNhB (ORCPT ); Fri, 4 Oct 2019 09:37:01 -0400 Received: by mail-wr1-f52.google.com with SMTP id r5so7196098wrm.12 for ; Fri, 04 Oct 2019 06:36:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QkfLSyXFPZJXluLNkve4m5RmMQ8kWYbgpv/uGqbviBU=; b=VsB6rL6GcldV2+9BXnNWthm1LzeKLsycWSs80J7cMB+EiKUB9VpepzHe3wiHzmF5ei 4osQrCSeE+kR3GcHaXjt7dlbkdxSWANd2/UIvTN+RRgFUULMqSIzfJHbCzorSNanJYPT xl6FOJg/daluuENwf7OW1g6Ph4DhQV/NbOzStnFj6uGosbHhg1h6Yxk3Xar26o+w3MxL 4ptJ+M7s0A7br/6Ude1xEtC+/IFzeLXGTy4DxwZoPcdWNjhtuESNq18KA+OWmHMsXLo/ ypRGwQ8Fh06GGdiHqY9MEO87aFAbxWaUiSnvO+NnipM6Vdzk6iApMmlGNGnuAj9aQq+4 9LYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QkfLSyXFPZJXluLNkve4m5RmMQ8kWYbgpv/uGqbviBU=; b=PaUZs/GhanAQPHEgMDFPJeSYCrcHa2XUUiWf0butMol+6+eh/jyYUS0wBP8tWNpyXM kTR4B2VgVJypR93qnI/ZB2ZNi+XVifgEi+iIGXB9mUHa67uB+MtI3pR2skMYFtSReX6J D3jxe8kFhzkLKK0WGWj+iVicNf4nDRW5atQ2vDbMioWe8XeNl+SUqnB9Dk5X9FxXSXzt +jOaWO9sq042s/gU9KG+aZN7x6JroNBNYT91ri5w0yw73jBwbWN+UoM2ByUoWvt0Z7ib vlS13nAypPqwQ1Jpu95V4CKl5H5GP8okux8HDXjY76O3SMbS/jW/xDN8xLpJQQs5YXe7 jmpg== X-Gm-Message-State: APjAAAX+eo1ZMWipDbeT6i92/IWkU9y0gCErSVVgHbEb1bUYelDv2GHW Ht+iA/NDmtUXuEoH/7Rn+J4= X-Google-Smtp-Source: APXvYqyIaARv/xblhhLkgMIezbBjqaxXKZhA06GUgC/ojonvAAAkbXUsorOdqIKGiWvZ98XoGMBq2w== X-Received: by 2002:adf:ea0d:: with SMTP id q13mr1395524wrm.111.1570196216653; Fri, 04 Oct 2019 06:36:56 -0700 (PDT) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id a10sm7029988wrm.52.2019.10.04.06.36.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Oct 2019 06:36:55 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 5/5] trace-cmd: Add initial infrastructure for trace-cmd specific plugins. Date: Fri, 4 Oct 2019 16:36:47 +0300 Message-Id: <20191004133647.27759-6-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191004133647.27759-1-tz.stoyanov@gmail.com> References: <20191004133647.27759-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Create a new directory lib/trace-cmd/plugins, where the libtracecmd plugins will be placed. Plugins compilation is integrated in the trace-cmd build process. New plugins are installed in $(HOME)/.local/lib/trace-cmd/plugins or $(libdir)/trace-cmd/plugins directories. Current python_plugin.so is part of libtraceevent plugins, so the python plugins path is changed from $(HOME)/.trace-cmd/python to $(HOME)/.local/lib/traceevent/python and $(libdir)/trace-cmd/python to $(libdir)/traceevent/python Added an initial set of APIs for working with trace-cmd plugins. Signed-off-by: Tzvetomir Stoyanov (VMware) --- .gitignore | 1 + Makefile | 43 ++++- include/trace-cmd/trace-cmd.h | 41 +++++ lib/trace-cmd/Makefile | 1 + lib/trace-cmd/plugins/Makefile | 58 ++++++ lib/trace-cmd/trace-plugin.c | 313 +++++++++++++++++++++++++++++++++ 6 files changed, 448 insertions(+), 9 deletions(-) create mode 100644 lib/trace-cmd/plugins/Makefile create mode 100644 lib/trace-cmd/trace-plugin.c diff --git a/.gitignore b/.gitignore index 20bb5a3..6759e51 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ TAGS cscope* traceevent_plugin_dir trace_python_dir +tracecmd_plugin_dir diff --git a/Makefile b/Makefile index cb5b07b..078b642 100644 --- a/Makefile +++ b/Makefile @@ -57,14 +57,18 @@ export DESTDIR DESTDIR_SQ ifeq ($(prefix),$(HOME)) plugin_traceevent_dir = $(HOME)/.local/lib/traceevent/plugins -python_dir = $(HOME)/.trace-cmd/python +plugin_tracecmd_dir = $(HOME)/.local/lib/trace-cmd/plugins +python_dir = $(HOME)/.local/lib/traceevent/python var_dir = $(HOME)/.trace-cmd/ else plugin_traceevent_dir = $(libdir)/traceevent/plugins -python_dir ?= $(libdir)/trace-cmd/python +plugin_tracecmd_dir = $(libdir)/trace-cmd/plugins +python_dir ?= $(libdir)/traceevent/python PLUGIN_DIR_TRACEEVENT = -DPLUGIN_TRACEEVENT_DIR="$(plugin_traceevent_dir)" +PLUGIN_DIR_TRACECMD = -DPLUGIN_TRACECMD_DIR="$(plugin_tracecmd_dir)" PYTHON_DIR = -DPYTHON_DIR="$(python_dir)" PLUGIN_DIR_TRACEEVENT_SQ = '$(subst ','\'',$(PLUGIN_DIR_TRACEEVENT))' +PLUGIN_DIR_TRACECMD_SQ = '$(subst ','\'',$(PLUGIN_DIR_TRACECMD))' PYTHON_DIR_SQ = '$(subst ','\'',$(PYTHON_DIR))' var_dir = /var endif @@ -73,6 +77,7 @@ endif bindir_SQ = $(subst ','\'',$(bindir)) bindir_relative_SQ = $(subst ','\'',$(bindir_relative)) plugin_traceevent_dir_SQ = $(subst ','\'',$(plugin_traceevent_dir)) +plugin_tracecmd_dir_SQ = $(subst ','\'',$(plugin_tracecmd_dir)) python_dir_SQ = $(subst ','\'',$(python_dir)) VAR_DIR = -DVAR_DIR="$(var_dir)" @@ -86,9 +91,11 @@ HELP_DIR_SQ = '$(subst ','\'',$(HELP_DIR))' BASH_COMPLETE_DIR ?= /etc/bash_completion.d export PLUGIN_DIR_TRACEEVENT +export PLUGIN_DIR_TRACECMD export PYTHON_DIR export PYTHON_DIR_SQ export plugin_traceevent_dir_SQ +export plugin_tracecmd_dir_SQ export python_dir_SQ export var_dir @@ -239,7 +246,8 @@ LIBS += -laudit endif # Append required CFLAGS -override CFLAGS += $(INCLUDES) $(PLUGIN_DIR_TRACEEVENT_SQ) $(VAR_DIR) +override CFLAGS += $(INCLUDES) $(VAR_DIR) +override CFLAGS += $(PLUGIN_DIR_TRACEEVENT_SQ) $(PLUGIN_DIR_TRACECMD_SQ) override CFLAGS += $(udis86-flags) $(blk-flags) override LDFLAGS += $(udis86-ldflags) @@ -268,13 +276,16 @@ gui: force $(CMD_TARGETS) $(kshark-dir)/build/Makefile @echo "gui build complete" @echo " kernelshark located at $(kshark-dir)/bin" -trace-cmd: force $(LIBTRACEEVENT_STATIC) $(LIBTRACECMD_STATIC) +trace-cmd: force $(LIBTRACEEVENT_STATIC) $(LIBTRACECMD_STATIC) \ + force $(obj)/lib/trace-cmd/plugins/tracecmd_plugin_dir $(Q)$(MAKE) -C $(src)/tracecmd $(obj)/tracecmd/$@ -$(LIBTRACEEVENT_SHARED): force $(obj)/lib/traceevent/plugins/traceevent_plugin_dir +$(LIBTRACEEVENT_SHARED): force $(obj)/lib/traceevent/plugins/trace_python_dir \ + $(obj)/lib/traceevent/plugins/traceevent_plugin_dir $(Q)$(MAKE) -C $(src)/lib/traceevent $@ -$(LIBTRACEEVENT_STATIC): force $(obj)/lib/traceevent/plugins/traceevent_plugin_dir +$(LIBTRACEEVENT_STATIC): force $(obj)/lib/traceevent/plugins/trace_python_dir \ + $(obj)/lib/traceevent/plugins/traceevent_plugin_dir $(Q)$(MAKE) -C $(src)/lib/traceevent $@ $(LIBTRACECMD_STATIC): force @@ -290,12 +301,21 @@ libtracecmd.so: $(LIBTRACECMD_SHARED) libs: $(LIBTRACECMD_SHARED) $(LIBTRACEEVENT_SHARED) -plugins: force $(obj)/lib/traceevent/plugins/traceevent_plugin_dir $(obj)/lib/traceevent/plugins/trace_python_dir +plugins_traceevent: force $(obj)/lib/traceevent/plugins/traceevent_plugin_dir \ + $(obj)/lib/traceevent/plugins/trace_python_dir $(Q)$(MAKE) -C $(src)/lib/traceevent/plugins +plugins_tracecmd: force $(obj)/lib/trace-cmd/plugins/tracecmd_plugin_dir + $(Q)$(MAKE) -C $(src)/lib/trace-cmd/plugins + +plugins: plugins_traceevent plugins_tracecmd + $(obj)/lib/traceevent/plugins/traceevent_plugin_dir: force $(Q)$(MAKE) -C $(src)/lib/traceevent/plugins $@ +$(obj)/lib/trace-cmd/plugins/tracecmd_plugin_dir: force + $(Q)$(MAKE) -C $(src)/lib/trace-cmd/plugins $@ + $(obj)/lib/traceevent/plugins/trace_python_dir: force $(Q)$(MAKE) -C $(src)/lib/traceevent/plugins $@ @@ -322,8 +342,12 @@ cscope: force $(RM) cscope* $(call find_tag_files) | cscope -b -q -install_plugins: force - $(Q)$(MAKE) -C $(src)/lib/traceevent/plugins $@ +install_plugins_traceevent: force + $(Q)$(MAKE) -C $(src)/lib/traceevent/plugins install_plugins +install_plugins_tracecmd: force + $(Q)$(MAKE) -C $(src)/lib/trace-cmd/plugins install_plugins + +install_plugins: install_plugins_traceevent install_plugins_tracecmd install_python: force $(Q)$(MAKE) -C $(src)/python $@ @@ -371,6 +395,7 @@ clean: $(MAKE) -C $(src)/lib/traceevent clean $(MAKE) -C $(src)/lib/trace-cmd clean $(MAKE) -C $(src)/lib/traceevent/plugins clean + $(MAKE) -C $(src)/lib/trace-cmd/plugins clean $(MAKE) -C $(src)/python clean $(MAKE) -C $(src)/tracecmd clean if [ -f $(kshark-dir)/build/Makefile ]; then $(MAKE) -C $(kshark-dir)/build clean; fi diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h index 0593463..f3d80ac 100644 --- a/include/trace-cmd/trace-cmd.h +++ b/include/trace-cmd/trace-cmd.h @@ -55,6 +55,47 @@ struct tracecmd_output; struct tracecmd_recorder; struct hook_list; +/* --- tracecmd plugins --- */ + +extern int tracecmd_disable_sys_plugins; +extern int tracecmd_disable_plugins; + +enum tracecmd_context { + TRACECMD_INPUT, + TRACECMD_OUTPUT, +}; + +enum tracecmd_plugin_flag { + TRACECMD_DISABLE_SYS_PLUGINS = 1, + TRACECMD_DISABLE_PLUGINS = 1 << 1, + +}; + +struct trace_plugin_context; + +struct trace_plugin_context * +tracecmd_plugin_context_create(enum tracecmd_context context, void *data); + +void tracecmd_plugin_set_flag(struct trace_plugin_context *context, + enum tracecmd_plugin_flag flag); + +#define TRACECMD_PLUGIN_LOADER tracecmd_plugin_loader +#define TRACECMD_PLUGIN_UNLOADER tracecmd_plugin_unloader +#define TRACECMD_PLUGIN_ALIAS tracecmd_plugin_alias +#define _MAKE_STR(x) #x +#define MAKE_STR(x) _MAKE_STR(x) +#define TRACECMD_PLUGIN_LOADER_NAME MAKE_STR(TRACECMD_PLUGIN_LOADER) +#define TRACECMD_PLUGIN_UNLOADER_NAME MAKE_STR(TRACECMD_PLUGIN_UNLOADER) +#define TRACECMD_PLUGIN_ALIAS_NAME MAKE_STR(TRACECMD_PLUGIN_ALIAS) + +typedef int (*tracecmd_plugin_load_func)(struct trace_plugin_context *trace); +typedef int (*tracecmd_plugin_unload_func)(struct trace_plugin_context *trace); + +struct tracecmd_input * +tracecmd_plugin_context_input(struct trace_plugin_context *trace_context); +struct tracecmd_output * +tracecmd_plugin_context_output(struct trace_plugin_context *trace_context); + static inline int tracecmd_host_bigendian(void) { unsigned char str[] = { 0x1, 0x2, 0x3, 0x4 }; diff --git a/lib/trace-cmd/Makefile b/lib/trace-cmd/Makefile index 3b4b5aa..6f3e6b1 100644 --- a/lib/trace-cmd/Makefile +++ b/lib/trace-cmd/Makefile @@ -15,6 +15,7 @@ OBJS += trace-recorder.o OBJS += trace-util.o OBJS += trace-filter-hash.o OBJS += trace-msg.o +OBJS += trace-plugin.o # Additional util objects OBJS += trace-blk-hack.o diff --git a/lib/trace-cmd/plugins/Makefile b/lib/trace-cmd/plugins/Makefile new file mode 100644 index 0000000..240e6be --- /dev/null +++ b/lib/trace-cmd/plugins/Makefile @@ -0,0 +1,58 @@ +include $(src)/scripts/utils.mk + +bdir:=$(obj)/lib/trace-cmd/plugins + +PLUGIN_OBJS = + +PLUGIN_OBJS := $(PLUGIN_OBJS:%.o=$(bdir)/%.o) +PLUGIN_BUILD := $(PLUGIN_OBJS:$(bdir)/%.o=$(bdir)/%.so) + +PLUGINS := $(PLUGIN_BUILD) + +DEPS := $(PLUGIN_OBJS:$(bdir)/%.o=$(bdir)/.%.d) + +all: $(PLUGINS) + +$(bdir): + @mkdir -p $(bdir) + +$(PLUGIN_OBJS): | $(bdir) +$(DEPS): | $(bdir) + +$(PLUGIN_OBJS): $(bdir)/%.o : %.c + $(Q)$(do_compile_plugin_obj) + +$(PLUGIN_BUILD): $(bdir)/%.so: $(bdir)/%.o + $(Q)$(do_plugin_build) + +$(DEPS): $(bdir)/.%.d: %.c + $(Q)$(CC) -M $(CPPFLAGS) $(CFLAGS) $< > $@ + +$(PLUGIN_OBJS): $(bdir)/%.o : $(bdir)/.%.d + +PLUGINS_INSTALL = $(subst .so,.install,$(PLUGINS)) + +$(PLUGINS_INSTALL): $(bdir)/%.install : $(bdir)/%.so force + $(Q)$(call do_install_data,$<,$(plugin_tracecmd_dir_SQ)) + +install_plugins: $(PLUGINS_INSTALL) + +# The following targets are necessary to trigger a rebuild when +# $(PLUGIN_DIR_TRACECMD) change. Without them, a full clean build would +# necessary in order to get the binaries updated. + +$(bdir)/tracecmd_plugin_dir: $(bdir) force + $(Q)$(N)$(call update_dir, 'PLUGIN_DIR_TRACECMD=$(PLUGIN_DIR_TRACECMD)') + +dep_includes := $(wildcard $(DEPS)) + +ifneq ($(dep_includes),) + include $(dep_includes) +endif + +clean: + $(RM) -f $(bdir)/*.a $(bdir)/*.so $(bdir)/*.o $(bdir)/.*.d\ + $(bdir)/tracecmd_plugin_dir + +force: +.PHONY: clean force diff --git a/lib/trace-cmd/trace-plugin.c b/lib/trace-cmd/trace-plugin.c new file mode 100644 index 0000000..6bec18b --- /dev/null +++ b/lib/trace-cmd/trace-plugin.c @@ -0,0 +1,313 @@ +// SPDX-License-Identifier: LGPL-2.1 +/* + * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt + * + */ +#include +#include +#include +#include +#include +#include "trace-cmd.h" +#include "trace-local.h" + +#define LOCAL_PLUGIN_DIR ".local/lib/trace-cmd/plugins/" + +struct trace_plugin_list { + struct trace_plugin_list *next; + char *name; + void *handle; +}; + +struct trace_plugin_context { + enum tracecmd_context context; + enum tracecmd_plugin_flag flags; + union { + void *data; + struct tracecmd_input *trace_input; + struct tracecmd_output *trace_output; + }; +}; + +/** + * tracecmd_plugin_context_create - Create and initialize tracecmd plugins context. + * @context: Context of the trace-cmd command. + * @data: Pointer to the context specific data, which will be passed to plugins. + * + * Returns a pointer to created tracecmd plugins context, or NULL in case memory + * allocation fails. The returned pointer should be freed by free (). + */ +struct trace_plugin_context * +tracecmd_plugin_context_create(enum tracecmd_context context, void *data) +{ + struct trace_plugin_context *trace; + + trace = calloc(1, sizeof(struct trace_plugin_context)); + if (!trace) + return NULL; + trace->context = context; + trace->data = data; + return trace; +} + +/** + * tracecmd_plugin_set_flag - Set a flag to tracecmd plugins context. + * @context: Context of the trace-cmd command. + * @flag: Flag, whil will be set. + * + */ +void tracecmd_plugin_set_flag(struct trace_plugin_context *context, + enum tracecmd_plugin_flag flag) +{ + if (context) + context->flags |= flag; +} + +/** + * tracecmd_plugin_context_input - Get a tracecmd_input plugin context. + * @context: Context of the trace-cmd command. + * + * Returns pointer to tracecmd_input, if such context is available or + * NULL otherwise. + */ +struct tracecmd_input * +tracecmd_plugin_context_input(struct trace_plugin_context *context) +{ + if (!context || context->context != TRACECMD_INPUT) + return NULL; + return context->trace_input; +} + +/** + * tracecmd_plugin_context_output - Get a tracecmd_output plugin context + * @context: Context of the trace-cmd command. + * + * Returns pointer to tracecmd_output, if such context is available or + * NULL otherwise. + */ +struct tracecmd_output * +tracecmd_plugin_context_output(struct trace_plugin_context *context) +{ + if (!context || context->context != TRACECMD_OUTPUT) + return NULL; + return context->trace_output; +} + +static void +load_plugin(struct trace_plugin_context *trace, const char *path, + const char *file, void *data) +{ + struct trace_plugin_list **plugin_list = data; + tracecmd_plugin_load_func func; + struct trace_plugin_list *list; + const char *alias; + char *plugin; + void *handle; + int ret; + + ret = asprintf(&plugin, "%s/%s", path, file); + if (ret < 0) { + warning("could not allocate plugin memory\n"); + return; + } + + handle = dlopen(plugin, RTLD_NOW | RTLD_GLOBAL); + if (!handle) { + warning("could not load plugin '%s'\n%s\n", + plugin, dlerror()); + goto out_free; + } + + alias = dlsym(handle, TRACECMD_PLUGIN_ALIAS_NAME); + if (!alias) + alias = file; + + func = dlsym(handle, TRACECMD_PLUGIN_LOADER_NAME); + if (!func) { + warning("could not find func '%s' in plugin '%s'\n%s\n", + TRACECMD_PLUGIN_LOADER_NAME, plugin, dlerror()); + goto out_free; + } + + list = malloc(sizeof(*list)); + if (!list) { + warning("could not allocate plugin memory\n"); + goto out_free; + } + + list->next = *plugin_list; + list->handle = handle; + list->name = plugin; + *plugin_list = list; + + pr_stat("registering plugin: %s", plugin); + func(trace); + return; + + out_free: + free(plugin); +} + +static void +load_plugins_dir(struct trace_plugin_context *trace, const char *suffix, + const char *path, + void (*load_plugin)(struct trace_plugin_context *trace, + const char *path, + const char *name, + void *data), + void *data) +{ + struct dirent *dent; + struct stat st; + DIR *dir; + int ret; + + ret = stat(path, &st); + if (ret < 0) + return; + + if (!S_ISDIR(st.st_mode)) + return; + + dir = opendir(path); + if (!dir) + return; + + while ((dent = readdir(dir))) { + const char *name = dent->d_name; + + if (strcmp(name, ".") == 0 || + strcmp(name, "..") == 0) + continue; + + /* Only load plugins that end in suffix */ + if (strcmp(name + (strlen(name) - strlen(suffix)), suffix) != 0) + continue; + + load_plugin(trace, path, name, data); + } + + closedir(dir); +} + +static char *get_source_plugins_dir(void) +{ + char *p, path[PATH_MAX+1]; + int ret; + + ret = readlink("/proc/self/exe", path, PATH_MAX); + if (ret > PATH_MAX || ret < 0) + return NULL; + + dirname(path); + p = strrchr(path, '/'); + if (!p) + return NULL; + /* Check if we are in the the source tree */ + if (strcmp(p, "/tracecmd") != 0) + return NULL; + + strcpy(p, "/lib/trace-cmd/plugins"); + return strdup(path); +} + +static void +load_plugins_hook(struct trace_plugin_context *trace, const char *suffix, + void (*load_plugin)(struct trace_plugin_context *trace, + const char *path, + const char *name, + void *data), + void *data) +{ + char *home; + char *path; + char *envdir; + int ret; + + if (trace && trace->flags & TRACECMD_DISABLE_PLUGINS) + return; + + /* + * If a system plugin directory was defined, + * check that first. + */ +#ifdef PLUGIN_TRACECMD_DIR + if (!trace || !(trace->flags & TRACECMD_DISABLE_SYS_PLUGINS)) + load_plugins_dir(trace, suffix, PLUGIN_TRACECMD_DIR, + load_plugin, data); +#endif + + /* + * Next let the environment-set plugin directory + * override the system defaults. + */ + envdir = getenv("TRACECMD_PLUGIN_DIR"); + if (envdir) + load_plugins_dir(trace, suffix, envdir, load_plugin, data); + + /* + * Now let the home directory override the environment + * or system defaults. + */ + home = getenv("HOME"); + if (!home) + return; + + ret = asprintf(&path, "%s/%s", home, LOCAL_PLUGIN_DIR); + if (ret < 0) { + warning("could not allocate plugin memory\n"); + return; + } + + load_plugins_dir(trace, suffix, path, load_plugin, data); + + free(path); + + path = get_source_plugins_dir(); + if (path) { + load_plugins_dir(trace, suffix, path, load_plugin, data); + free(path); + } +} + +/** + * tracecmd_load_plugins - Load trace-cmd specific plugins. + * @context: Context of the trace-cmd command, will be passed to the plugins + * at load time. + * + * Returns a list of loaded plugins + */ +struct trace_plugin_list* +tracecmd_load_plugins(struct trace_plugin_context *trace) +{ + struct trace_plugin_list *list = NULL; + + load_plugins_hook(trace, ".so", load_plugin, &list); + return list; +} + +/** + * tracecmd_unload_plugins - Unload trace-cmd specific plugins. + * @plugin_list - List of plugins, previously loaded with tracecmd_load_plugins. + * @context: Context of the trace-cmd command, will be passed to the plugins + * at unload time. + * + */ +void +tracecmd_unload_plugins(struct trace_plugin_list *plugin_list, + struct trace_plugin_context *trace) +{ + tracecmd_plugin_unload_func func; + struct trace_plugin_list *list; + + while (plugin_list) { + list = plugin_list; + plugin_list = list->next; + func = dlsym(list->handle, TRACECMD_PLUGIN_UNLOADER_NAME); + if (func) + func(trace); + dlclose(list->handle); + free(list->name); + free(list); + } +}