From patchwork Thu Jan 27 07:01:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12726338 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E239CC433EF for ; Thu, 27 Jan 2022 07:01:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229565AbiA0HBR (ORCPT ); Thu, 27 Jan 2022 02:01:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237028AbiA0HBQ (ORCPT ); Thu, 27 Jan 2022 02:01:16 -0500 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D834C061714 for ; Wed, 26 Jan 2022 23:01:16 -0800 (PST) Received: by mail-ed1-x535.google.com with SMTP id p12so2258074edq.9 for ; Wed, 26 Jan 2022 23:01:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gvUm1vMVMOle4NmzvmM/AB+u9q/Lv/ZKTMKXzLSz9zI=; b=EfLaTJzoUvmYpZBiJIfjcyOiRjel9vYu0mHiGWypIGrg2nYMw1Dv6kTzTzsxDWE1Sw ncdzpfOqNPQFxIAjhsrJvy9tBye3rdRnUmuEvnWnepknig5zmKJn8KMjwkk4cX9SXvrW Mn2Luk74Styn75WDgGF9ZTjjQ37zJ5s4z+OejPOi0Loghjif+kTxEGLjhTt89dbsTIcf sEEzLfxDkDPqRTHjXZBbCskbCHvdm3x8xyLcsQjNkU2Ap2q2OZf4qBzfQczNrmv5lP64 HE6mWPik+3O9dUWC4CalLdAq823ShkOHVC2LBUCfzQ/lZgAKBi7F3c/uveb9vwv4le25 2o3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gvUm1vMVMOle4NmzvmM/AB+u9q/Lv/ZKTMKXzLSz9zI=; b=wW+aTefA1u0CJcLPq/3PC4l1Jncl87kc1t4dhQmNoxuEhZQ7TimAg6Jwbr9fjo6+wV Kj+nJ3sXZOHJsWMGSTGF7x9Z6ahmlGzpdj13HfTfSdUXgwLfiytL7ct3baBEMCfzlVzl 2/ssAM/sWKfWCAHleuyRgGTllS6LJf5pl6C+vZtqOBm1B4KOHbIp3DyYHXNB6P8tWAR6 pAGgv9eAGl3rdcLztoAMuM6uQl6dQvONFE7iedoV+tfgfszRLigHMj3hGWtS1RRmNqbW 7N9fA1QZieOfRl0PsPI3pzRqS4UdPPS7HZyMLGTngRa7uT6nr3cTnDJgjBu29Q1YqJR+ Kqfw== X-Gm-Message-State: AOAM5337+bpFvt835AFcocYdvcLE5MnIM1YFnX4Sx3QqbfqXxkOuqSdN H8PWT2KLFyih1okaUtbBpEpS2HLxk+k= X-Google-Smtp-Source: ABdhPJyv5LCDPWHBRX6mKphzxr1cNx4L4WFnLpBkOsSDAqY8AR24bcbEoqeiA642RrIX7Bg4MOYyaA== X-Received: by 2002:a05:6402:5248:: with SMTP id t8mr2402688edd.14.1643266874604; Wed, 26 Jan 2022 23:01:14 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id i17sm8317079ejp.60.2022.01.26.23.01.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 23:01:14 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: y.karadz@gmail.com Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 1/3] trace-cruncher: Add support for event probes Date: Thu, 27 Jan 2022 09:01:09 +0200 Message-Id: <20220127070111.27529-2-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220127070111.27529-1-tz.stoyanov@gmail.com> References: <20220127070111.27529-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Event probe (eprobe) is a new type of ftrace dynamic events, introduced in the Linux kernel 5.15 version. It is useful to have support for it in trace-cruncher, as it allows more flexibility when printing event's data. Signed-off-by: Tzvetomir Stoyanov (VMware) --- src/ftracepy-utils.c | 32 ++++++++++++++++++++++++++++++++ src/ftracepy-utils.h | 2 ++ src/ftracepy.c | 5 +++++ 3 files changed, 39 insertions(+) diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c index 8c46590..053b659 100644 --- a/src/ftracepy-utils.c +++ b/src/ftracepy-utils.c @@ -2315,6 +2315,38 @@ struct tep_event *dynevent_get_event(PyDynevent *event, return tep_evt; } +PyObject *PyFtrace_eprobe(PyObject *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = {"event", "target_system", "target_event", "fetchargs", NULL}; + const char *event, *target_system, *target_event, *fetchargs; + struct tracefs_dynevent *eprobe; + + if (!PyArg_ParseTupleAndKeywords(args, + kwargs, + "ssss", + kwlist, + &event, + &target_system, + &target_event, + &fetchargs)) { + return NULL; + } + + eprobe = tracefs_eprobe_alloc(TC_SYS, event, target_system, target_event, fetchargs); + if (!eprobe) { + MEM_ERROR; + return NULL; + } + + if (tracefs_dynevent_create(eprobe) < 0) { + TfsError_fmt(NULL, "Failed to create eprobe '%s'", event); + tracefs_dynevent_free(eprobe); + return NULL; + } + + return PyDynevent_New(eprobe); +} + static PyObject *set_filter(PyObject *args, PyObject *kwargs, struct tep_handle *tep, struct tep_event *event) diff --git a/src/ftracepy-utils.h b/src/ftracepy-utils.h index 7612df6..c96fd85 100644 --- a/src/ftracepy-utils.h +++ b/src/ftracepy-utils.h @@ -251,6 +251,8 @@ PyObject *PyFtrace_register_kprobe(PyObject *self, PyObject *args, PyObject *PyFtrace_register_kretprobe(PyObject *self, PyObject *args, PyObject *kwargs); +PyObject *PyFtrace_eprobe(PyObject *self, PyObject *args, PyObject *kwargs); + PyObject *PyFtrace_hist(PyObject *self, PyObject *args, PyObject *kwargs); diff --git a/src/ftracepy.c b/src/ftracepy.c index 3f71b5e..464e8d3 100644 --- a/src/ftracepy.c +++ b/src/ftracepy.c @@ -460,6 +460,11 @@ static PyMethodDef ftracepy_methods[] = { METH_VARARGS | METH_KEYWORDS, "Define a kretprobe." }, + {"eprobe", + (PyCFunction) PyFtrace_eprobe, + METH_VARARGS | METH_KEYWORDS, + "Define an eprobe." + }, {"hist", (PyCFunction) PyFtrace_hist, METH_VARARGS | METH_KEYWORDS, From patchwork Thu Jan 27 07:01:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12726339 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49C5BC433F5 for ; Thu, 27 Jan 2022 07:01:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237031AbiA0HBT (ORCPT ); Thu, 27 Jan 2022 02:01:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237028AbiA0HBS (ORCPT ); Thu, 27 Jan 2022 02:01:18 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 500C4C061714 for ; Wed, 26 Jan 2022 23:01:17 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id w14so2258341edd.10 for ; Wed, 26 Jan 2022 23:01:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2HnGuIneRynFxENKuxdJLTxuibLizoDMquQzVbAiiJU=; b=ZWJUxnHxz7wXlbNtV1F3tRIA17ZoclOVIuNRCHGokpKjEAB3Ykh2AERbfWGhnwRWzc diY4ua4+fdpgtdfzjAIVcSSZhK83R13Pdt6O98f5tXqnJ31Byn0snmBQm3UWez388/54 +Bi92XplpZdMdzs1Y3mvmJGmpzP0Kx9WFNUf+Qly5lqsIWvptt54YTM5Rbfk0myDR1Dm 0zXqWKFk2Jpkr5DW8rXwHyXUIMoIFMkjx3XRovo5SUELeNW/0Mw8uLGdDy5LkaIKz7BN KSkgi8HxtBm8l75Dqx8iKebc/ftpuGfdd3jGOorZ27DliN1Bo43PLfy1waLyAf0jZGRK pX9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2HnGuIneRynFxENKuxdJLTxuibLizoDMquQzVbAiiJU=; b=5sqrapHo3Urp98yBdQFBu80r1KO0TMySrMPSqcpS7gJBwsjO0e633qPvYbh2qoIMAg +L+1PilvgDOmVWdlcaQglvspbj14sljILfE5Uwn1E2+XcDvbLPz5oy24HIqN/cfqLrBO RpTrFWrmHOeQjEnocEzImwmWWiqKBzCI8y4I1W1bFTiiUCOQW9fkZIMV91s36wELvxfP MOumyCN9qgjacQ4HYMhB9CKUyYycBcOz7L87wF+x0vRfXEAv8MrnNWL/N1OeQBvDrbuN kOiSCMw7UR3bZgqC1+HYmk+opKaZ0jpanBlmpK8iWi7WkjNFhDynJpHDViOkTRkGQim7 AtEA== X-Gm-Message-State: AOAM532iBorV/0aTO1Il7/TF4HKEAdtT9Sh7Wc+Zfy9/4BTujg9zqvmO /4TxwQQ4MKyAQbl5ADLShuWbKm75sdk= X-Google-Smtp-Source: ABdhPJyWjSnel/ZfFs/F1rM9cIgDGemVZz3BKYW7gSiIHu6tBc159CiXrX6oosnL0xcvhZPS6el0fA== X-Received: by 2002:a05:6402:2052:: with SMTP id bc18mr2317410edb.63.1643266875787; Wed, 26 Jan 2022 23:01:15 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id i17sm8317079ejp.60.2022.01.26.23.01.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 23:01:15 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: y.karadz@gmail.com Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 2/3] trace-cruncher: Unit test for event probes API Date: Thu, 27 Jan 2022 09:01:10 +0200 Message-Id: <20220127070111.27529-3-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220127070111.27529-1-tz.stoyanov@gmail.com> References: <20220127070111.27529-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org All trace-cruncher APIs should be covered by unit tests. Added a test for newly introduced event probes API. Signed-off-by: Tzvetomir Stoyanov (VMware) --- .../tests/1_unit/test_01_ftracepy_unit.py | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tracecruncher/tests/1_unit/test_01_ftracepy_unit.py b/tracecruncher/tests/1_unit/test_01_ftracepy_unit.py index 2de3d89..d773acc 100644 --- a/tracecruncher/tests/1_unit/test_01_ftracepy_unit.py +++ b/tracecruncher/tests/1_unit/test_01_ftracepy_unit.py @@ -14,6 +14,7 @@ import tracecruncher.ft_utils as tc instance_name = 'test_instance1' another_instance_name = 'test_instance2' +kernel_version = tuple(map(int, (os.uname()[2].split('.')[:2]))) class InstanceTestCase(unittest.TestCase): def test_dir(self): @@ -457,6 +458,55 @@ class KprobeTestCase(unittest.TestCase): ret = kp1.is_enabled(instance=inst) self.assertEqual(ret, '0') +class EprobeTestCase(unittest.TestCase): + def test_eprobe(self): + """ Event probes are introduced in Linux kernel 5.15 + """ + if kernel_version < (5, 15): + return + + evt1 = 'sopen_in' + evt1_tsys = 'syscalls' + evt1_tevent = 'sys_enter_openat' + evt1_args = 'file=+0($filename):ustring' + evt2 = 'sopen_out' + evt2_tsys = 'syscalls' + evt2_tevent = 'sys_exit_openat' + evt2_args = 'res=$ret:u64' + + ep1 = ft.eprobe(event=evt1, target_system=evt1_tsys, target_event=evt1_tevent, + fetchargs=evt1_args) + self.assertEqual(evt1, ep1.event()) + self.assertEqual("{}.{}".format(evt1_tsys, evt1_tevent), ep1.address()) + self.assertEqual(evt1_args, ep1.probe()) + + ep2 = ft.eprobe(event=evt2, target_system=evt2_tsys, target_event=evt2_tevent, + fetchargs=evt2_args) + self.assertEqual(evt2, ep2.event()) + self.assertEqual("{}.{}".format(evt2_tsys, evt2_tevent), ep2.address()) + self.assertEqual(evt2_args, ep2.probe()) + + def test_enable_eprobe(self): + """ Event probes are introduced in Linux kernel 5.15 + """ + if kernel_version < (5, 15): + return + + evt1 = 'sopen_out' + evt1_tsys = 'syscalls' + evt1_tevent = 'sys_exit_openat' + evt1_args = 'res=$ret:u64' + + ep1 = ft.eprobe(event=evt1, target_system=evt1_tsys, target_event=evt1_tevent, + fetchargs=evt1_args) + inst = ft.create_instance(instance_name) + ep1.enable(instance=inst) + ret = ep1.is_enabled(instance=inst) + self.assertEqual(ret, '1') + + ep1.disable(instance=inst) + ret = ep1.is_enabled(instance=inst) + self.assertEqual(ret, '0') class TracingOnTestCase(unittest.TestCase): def test_ON_OF(self): From patchwork Thu Jan 27 07:01:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12726340 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0550BC433FE for ; Thu, 27 Jan 2022 07:01:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237028AbiA0HBT (ORCPT ); Thu, 27 Jan 2022 02:01:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237030AbiA0HBS (ORCPT ); Thu, 27 Jan 2022 02:01:18 -0500 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F053C06173B for ; Wed, 26 Jan 2022 23:01:18 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id b13so2362114edn.0 for ; Wed, 26 Jan 2022 23:01:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FL5QkgZS1Ox/933zA1U8FsAUnggCkt58Ers1x/2y+WI=; b=DSZ4P6hoiZC9tLqiFSEZdN/m/7t5lxV+OI6SOZL03xbv74FBsZjVLEHTNOvOrlP/vY btPLA7+Wo6uB9bXdeRAij0HfkznmlUCuA7cDs+7Zv3efYkTGG+M8RBJGEaeWaiZ6e/az xId6ixkXnXpa2hzg0AImt26o78ZheYXiw+HivjDCBmPrG3u+xsumhnBQYh6nvcg82EpC 1avX78XTfqoz6yF2ev+cVvMw7L3jV9TbBKqVJMnG90+YQ8kh7/Odr4px7AZCBC25XwIa NgJfow3L4kzaOuVsiI1d20RbrVVVcWbcY0+XJ2Cf3IjYE8vHd6MuPzxdfFrwJ+lf4O5m Eykw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FL5QkgZS1Ox/933zA1U8FsAUnggCkt58Ers1x/2y+WI=; b=JsesVLZbADWfm2yunn76Xm0K6KIy2WHx2JMGK3K6lOPC35vltWxOeKf788bEmo5KyA YuJYB5ZbF8NFUeZnQmaWqITdR2+c903H1sELqSOBi6josHP2lTrS2sirVrfIfp+uTe79 k3B75pGUcwliumzxRn/sW4bNqr2l5acuHWuXvTqJQx5CiwwHd4WsN+zAJTbby3murnKb jHiapbo8tvmru5hFcIaVVRq5fgRwyuKhO5NKYCTossxwnvx5VnDhaXtqGYQ5SvGi5Qjf gNRkBtx5f4VRMIguMHwCYb9CDIOB6kqjzYiFQtcENK6O69GUqn20Q3m8p7lNGoaZLM4V iEbQ== X-Gm-Message-State: AOAM5329y/8YELbRsTHsWd+t3QPt6tgn0gjMfGYrNPwOboEcu0xV3UTH EUSuTZzzA/tXNfja0jF5PoamImySUGc= X-Google-Smtp-Source: ABdhPJw9XBCKzsqDSeDPDzOyzTZVe3ML93uC9NOTqFHH2P+u3bZid/hwk6hiu1jO78YWuQ/r6Dm36w== X-Received: by 2002:a50:ef05:: with SMTP id m5mr2343338eds.47.1643266876974; Wed, 26 Jan 2022 23:01:16 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id i17sm8317079ejp.60.2022.01.26.23.01.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 23:01:16 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: y.karadz@gmail.com Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 3/3] trace-cruncher: Example for event probes API Date: Thu, 27 Jan 2022 09:01:11 +0200 Message-Id: <20220127070111.27529-4-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220127070111.27529-1-tz.stoyanov@gmail.com> References: <20220127070111.27529-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org trace-cruncher APIs should have examples, to demonstrate their usage in a real use case. Added an example for newly introduced event probes API. Signed-off-by: Tzvetomir Stoyanov (VMware) --- examples/eprobe.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 examples/eprobe.py diff --git a/examples/eprobe.py b/examples/eprobe.py new file mode 100755 index 0000000..85b0685 --- /dev/null +++ b/examples/eprobe.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 + +""" +SPDX-License-Identifier: CC-BY-4.0 + +Copyright 2022 VMware Inc, Tzvetomir Stoyanov (VMware) +""" + +import sys + +import tracecruncher.ftracepy as ft +import tracecruncher.ft_utils as tc + +open_probe = ft.eprobe(event='sopen_in', target_system='syscalls', + target_event='sys_enter_openat', fetchargs='file=+0($filename):ustring') + +tep = tc.local_tep() + +def callback(event, record): + print(tep.info(event, record)) + +if __name__ == "__main__": + if len(sys.argv) < 2: + print('Usage: ', sys.argv[0], ' [PROCESS]') + sys.exit(1) + + inst = ft.create_instance(tracing_on=False) + open_probe.enable(instance=inst) + ft.trace_process(instance=inst, argv=sys.argv[1:])