From patchwork Mon Jul 12 12:32:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12370969 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F329C07E9A for ; Mon, 12 Jul 2021 12:32:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 307AE60FF2 for ; Mon, 12 Jul 2021 12:32:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232627AbhGLMfp (ORCPT ); Mon, 12 Jul 2021 08:35:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229950AbhGLMfo (ORCPT ); Mon, 12 Jul 2021 08:35:44 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D98CDC0613DD for ; Mon, 12 Jul 2021 05:32:54 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id t3so27700958edt.12 for ; Mon, 12 Jul 2021 05:32: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:mime-version :content-transfer-encoding; bh=59a+wgtio3H2Yl9QvOAwrecUPo0WRNpBELA/KD4uJVU=; b=qm41ipiARgtsvXlDN/E/9LFZDnAVzFktkzJXU/wS83souu+Xtkyc/OsDyAkFEipazo sLtpZncWoTNnzqoD5HYcqycBpIjp+h59HhDpEzWitoRfJRkMfig11kC1tjOWoZI8XjPh b2urA2rNclujGRN1YVMtkh3TmZVTdfgHZywHfhZiI5vE2FJ4Q0uHROxuowlLlC8v/QT4 CXHeVX/zRsYDeG1rHdQlAlE6Q3nIhw/2ggifizn7CuVQMujKOg1DLdJMhdZXlOJeenLq opFY1RkaA21DHYY5R7Ygl67fh/LqH+F2LvVK8ElA4nWMC6vOg88v1SIolV9rxH78SVpJ So3g== 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:mime-version :content-transfer-encoding; bh=59a+wgtio3H2Yl9QvOAwrecUPo0WRNpBELA/KD4uJVU=; b=OjynsGU0v7caNM6UXKI6/CjQplZA9TPUtzLD+cur2lEfYBjt/jvnVC5zT/Q6xKtjT1 UhtePsRwfleUJfpGF+fsmNUiqd34NoQLnfR/vuKo8Y2igK6vVJ15ECAVq+OJAIXFRRXx O6FYeNRuVART9BU5j30Lt5dzB4BfMWzE7iJdApZrFkycxyjJcxjsfvvvO5gz2+yjonVK 3vmFhD47oUpaZEXblZLlpTdnCfYBR6FoWGpyYbVbWl4ddyLwy7cBiX/bECbJ2QGKY87o HcC9qaHoWOKo5tcsclfIZEfexpcuySl4kGsi2Dc2zJvVRLc046z/ks2m1mTVdLY4drnB pOGQ== X-Gm-Message-State: AOAM5313P1bKoAX9JeVN8k5zmeBkdH75ncPbTWeyd3Qv+47H4M6iZNI4 luk4ywda5XZlkJ4HteuKn+AsDXrOoh0= X-Google-Smtp-Source: ABdhPJxpLfwM4z1xfoF07sqfvvsUbrdFX63XFA+rTdHz1dHcU5+VTIWCDdmXttNrDBPuIp6FKA2rIw== X-Received: by 2002:a05:6402:42d2:: with SMTP id i18mr64432223edc.168.1626093172698; Mon, 12 Jul 2021 05:32:52 -0700 (PDT) Received: from localhost.localdomain ([95.87.199.98]) by smtp.gmail.com with ESMTPSA id z5sm6477473ejn.65.2021.07.12.05.32.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jul 2021 05:32:52 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: linux-trace-devel@vger.kernel.org Cc: "Yordan Karadzhov (VMware)" Subject: [PATCH 1/4] trace-cruncher: Add set_ftrace_loglevel() Date: Mon, 12 Jul 2021 15:32:39 +0300 Message-Id: <20210712123242.223500-1-y.karadz@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Signed-off-by: Yordan Karadzhov (VMware) --- src/ftracepy-utils.c | 23 +++++++++++++++++++++++ src/ftracepy-utils.h | 3 +++ src/ftracepy.c | 5 +++++ 3 files changed, 31 insertions(+) diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c index dfb0669..8f4b50c 100644 --- a/src/ftracepy-utils.c +++ b/src/ftracepy-utils.c @@ -1801,6 +1801,29 @@ PyObject *PyFtrace_kprobe_is_enabled(PyObject *self, PyObject *args, return event_is_enabled(instance, TC_SYS, event); } +PyObject *PyFtrace_set_ftrace_loglevel(PyObject *self, PyObject *args, + PyObject *kwargs) +{ + static char *kwlist[] = {"level", NULL}; + int level; + + if (!PyArg_ParseTupleAndKeywords(args, + kwargs, + "i", + kwlist, + &level)) { + return NULL; + } + + if (level < 0) + level = 0; + + tracefs_set_loglevel(level); + tep_set_loglevel(level); + + Py_RETURN_NONE; +} + static bool set_fork_options(struct tracefs_instance *instance, bool enable) { if (enable) { diff --git a/src/ftracepy-utils.h b/src/ftracepy-utils.h index d826427..5d7c19c 100644 --- a/src/ftracepy-utils.h +++ b/src/ftracepy-utils.h @@ -155,6 +155,9 @@ PyObject *PyFtrace_disable_kprobe(PyObject *self, PyObject *args, PyObject *PyFtrace_kprobe_is_enabled(PyObject *self, PyObject *args, PyObject *kwargs); +PyObject *PyFtrace_set_ftrace_loglevel(PyObject *self, PyObject *args, + PyObject *kwargs); + PyObject *PyFtrace_trace_process(PyObject *self, PyObject *args, PyObject *kwargs); diff --git a/src/ftracepy.c b/src/ftracepy.c index e5fcd54..e3fec7b 100644 --- a/src/ftracepy.c +++ b/src/ftracepy.c @@ -269,6 +269,11 @@ static PyMethodDef ftracepy_methods[] = { METH_VARARGS | METH_KEYWORDS, "Check if kprobe event is enabled." }, + {"set_ftrace_loglevel", + (PyCFunction) PyFtrace_set_ftrace_loglevel, + METH_VARARGS | METH_KEYWORDS, + "Set the verbose level of the ftrace libraries." + }, {"trace_process", (PyCFunction) PyFtrace_trace_process, METH_VARARGS | METH_KEYWORDS, From patchwork Mon Jul 12 12:32:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12370967 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01052C07E99 for ; Mon, 12 Jul 2021 12:32:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DAC7D60FF3 for ; Mon, 12 Jul 2021 12:32:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232731AbhGLMfp (ORCPT ); Mon, 12 Jul 2021 08:35:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232627AbhGLMfo (ORCPT ); Mon, 12 Jul 2021 08:35:44 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58AA4C0613E5 for ; Mon, 12 Jul 2021 05:32:55 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id o5so34290260ejy.7 for ; Mon, 12 Jul 2021 05:32:55 -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=20o7DKK/6J3aD1OcuBjqhh3bybqLXvXGgkH4+mDh/R4=; b=hE8gECMCvXi7Tqt2+jILfBuJ1jYHAbjX6/zFyq6WCMXyG4KBs/u0E87do2IKrv4K5X W0LjG7dVG32JTz36CnGsMEKWt/WuaZ2NGzfJNzPWnnJrsdsUQVb65k7uOXes1FLx3vtm HG2uDc/+m0MXzS9ASxlJHyq0YcO+cqxJccFHymmz7FouagRtJSgGsrdaXcPsKfvJXuCS kWomBjA0YwLGh97Cdr5hUCb3BAE7Vg1FsyV7CM9hhohpC3BhnsxsOXy1HQ0HV9VashvX CJvn2eLNix27fwHk9+DEn9Ko8tlVa4IfRs6pFNjDtMOJL6ZHlVgIjpnJvAydU1vM9pXk 8KMQ== 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=20o7DKK/6J3aD1OcuBjqhh3bybqLXvXGgkH4+mDh/R4=; b=YzAZEXtbxctL96tib0yiFpjeqrrH50hea3HSURu54dUXtg+VqmC5WUyG74Y/Uy2Ac8 i635WXQ6DJ3PmgdEJ5DJZ4fWXurqUGz9Ob8KHPnqfdSU6uLk89yc9+kBuN9VnDLKXJlP 9xy5Ni0HlIdOGdYWshAnveSCcEqGkb9XWat6ZdsLUjRS693o9rY8VUwS9DEBiAYEk+Eh xWCTSlNO12p4uAgFqc61izKlzB/vky7tN7BbwvbH4M9kM9sw0/eQxe9pH1GNgEZz9k38 aGa5HmS2ew9RmAJCOqxTrIOmEJbVJAyUf4slvdwCRSQF1P2Fh9tdTR5LEhQ6ZyP3HIxg Ri2Q== X-Gm-Message-State: AOAM5308j7E5lqGxWa1/aVvGUNv8sJSevzSf3wxU44N9awLstQJ3lzRH Uci+Y7O8eJ9derteiNtxNuDqZJBMeP4= X-Google-Smtp-Source: ABdhPJzTz8DuZgS9ggHmAtErt3mmAJ+KUHuOt3YJTYhaHFfLyLaTBkpzBm5bBkkfXLa3gXRJoDYdUA== X-Received: by 2002:a17:906:fad5:: with SMTP id lu21mr53369759ejb.469.1626093173794; Mon, 12 Jul 2021 05:32:53 -0700 (PDT) Received: from localhost.localdomain ([95.87.199.98]) by smtp.gmail.com with ESMTPSA id z5sm6477473ejn.65.2021.07.12.05.32.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jul 2021 05:32:53 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: linux-trace-devel@vger.kernel.org Cc: "Yordan Karadzhov (VMware)" Subject: [PATCH 2/4] trace-cruncher: Add local_tep() to utils Date: Mon, 12 Jul 2021 15:32:40 +0300 Message-Id: <20210712123242.223500-2-y.karadz@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210712123242.223500-1-y.karadz@gmail.com> References: <20210712123242.223500-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The function can be used to retrieve the "tep" event of the current (local) system. Signed-off-by: Yordan Karadzhov (VMware) --- tracecruncher/ft_utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tracecruncher/ft_utils.py b/tracecruncher/ft_utils.py index 5b4f2f2..8c245b1 100644 --- a/tracecruncher/ft_utils.py +++ b/tracecruncher/ft_utils.py @@ -11,6 +11,15 @@ import ctypes from . import ftracepy as ft +def local_tep(): + """ Get the "tep" event of the current system (local). + """ + tep = ft.tep_handle(); + tep.init_local(dir=ft.dir()); + + return tep + + def find_event_id(system, event): """ Get the unique identifier of a trace event. """ From patchwork Mon Jul 12 12:32:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12370971 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8BE6C07E9C for ; Mon, 12 Jul 2021 12:32:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 894586023F for ; Mon, 12 Jul 2021 12:32:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233100AbhGLMfq (ORCPT ); Mon, 12 Jul 2021 08:35:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229950AbhGLMfp (ORCPT ); Mon, 12 Jul 2021 08:35:45 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E605C0613E8 for ; Mon, 12 Jul 2021 05:32:56 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id ca14so10846478edb.2 for ; Mon, 12 Jul 2021 05:32: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=rSz6mrPqwJsEnJmiYaSEC1iXC3vlmtFLYEes6zINfZU=; b=gVa3c+06fkxNfmprF9br2mBScfnbY1s3KnYzGJdg2h68/J0nrh0h9JL+4/pyvBdqB8 4xvFeKdDF0MuMeghuFZQZY2IUXlNUaTQWe/F8kufzg5Df6CgqM6L0qS4mh4GZOSIfFV4 MZAFUZ+HBgSxvvnnk+QmesingsDix6/vCwGMWWZ0oNy4tvYZfJf9q9mbpk7uPoU1No67 yKtbqbQPns13LLOGMBdT2QUuuxYQ4dJRZse6M7PhvjEaMvA20yb9C4mxoAOVq+oxj1h8 ohrUYFwrKwcHytOpsbb6TQQtD9h8zw8hvROo16x1/yTBqL1g5Yy+FVR4ZpZOb4l88BGw jeVQ== 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=rSz6mrPqwJsEnJmiYaSEC1iXC3vlmtFLYEes6zINfZU=; b=kknFimeOtC3siGIUCPfChwG8PFCWP8m2Mq9QJfCEfH/rTZwYWRa0BcDBq0+9vWtLht HpqiJ2TU0SYJ6lfkp93qLjIRd3hcAWJAOeCWCP6FZ03v8LOxgmHGrBdYhh1liqbuJ0hO J57B/MZhu8DOn0eMSjJuS2XZtudaiJRIRLnThtbNW8d8qdc2SELhEWLxOsy8HfiICiL/ QCM92Jex1hncQqCyWcZEgGmwbvFN8m2p0VQ53Em1s1qMKlr0ywsmdvYYXYUTvdc8iRUl pKJvJES0du3g36UDwzUsdZO/JbmozlP4dJuFFgAgAjuHpL+I05z6e7BM35e0LoAU+lzA 7gQw== X-Gm-Message-State: AOAM533o91u+MOAy+0t6X+o9vchO2W1nVqFrrqCceZzWnvFnUyFVV2+2 eGsxiNsuYc0qew8Iw+f1WWuWN1waCRE= X-Google-Smtp-Source: ABdhPJz92rFXZ8uEglA50I3FC6zCNeuLbCI0nvi5z6LF6JFb0GHql0vz+SJRieM5ox2PbrQfG9js6g== X-Received: by 2002:a05:6402:33a:: with SMTP id q26mr12453592edw.369.1626093175060; Mon, 12 Jul 2021 05:32:55 -0700 (PDT) Received: from localhost.localdomain ([95.87.199.98]) by smtp.gmail.com with ESMTPSA id z5sm6477473ejn.65.2021.07.12.05.32.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jul 2021 05:32:54 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: linux-trace-devel@vger.kernel.org Cc: "Yordan Karadzhov (VMware)" Subject: [PATCH 3/4] trace-cruncher: Allow for detachable instances Date: Mon, 12 Jul 2021 15:32:41 +0300 Message-Id: <20210712123242.223500-3-y.karadz@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210712123242.223500-1-y.karadz@gmail.com> References: <20210712123242.223500-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org If the instance is created with "detached=True", the Python module is no longer responsible for destroying it when exiting. It is therefore up to the user free it explicitly, or to keep it active. Signed-off-by: Yordan Karadzhov (VMware) --- src/ftracepy-utils.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c index 8f4b50c..d061817 100644 --- a/src/ftracepy-utils.c +++ b/src/ftracepy-utils.c @@ -421,6 +421,12 @@ static PyObject *tfs_list2py_list(char **list) struct instance_wrapper { struct tracefs_instance *ptr; + bool detached; + + /* + * This name will be used only for searching. The actual name of + * the instance is owned by the "tracefs_instance" object. + */ const char *name; }; @@ -451,10 +457,12 @@ void instance_wrapper_free(void *ptr) iw = ptr; if (iw->ptr) { - if (tracefs_instance_destroy(iw->ptr) < 0) - fprintf(stderr, - "\ntfs_error: Failed to destroy instance '%s'.\n", - get_instance_name(iw->ptr)); + if (!iw->detached) { + if (tracefs_instance_destroy(iw->ptr) < 0) + fprintf(stderr, + "\ntfs_error: Failed to destroy instance '%s'.\n", + get_instance_name(iw->ptr)); + } free(iw->ptr); } @@ -569,14 +577,16 @@ PyObject *PyFtrace_create_instance(PyObject *self, PyObject *args, struct tracefs_instance *instance; const char *name = NO_ARG; int tracing_on = true; + int detached = false; + static char *kwlist[] = {"name", "tracing_on", "detached", NULL}; - static char *kwlist[] = {"name", "tracing_on", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|sp", + "|spp", kwlist, &name, - &tracing_on)) { + &tracing_on, + &detached)) { return NULL; } @@ -600,6 +610,11 @@ PyObject *PyFtrace_create_instance(PyObject *self, PyObject *args, } iw->ptr = instance; + if (detached) { + printf("detached instance: %s\n", name); + iw->detached = detached; + } + iw_ptr = tsearch(iw, &instance_root, instance_compare); if (!iw_ptr || !(*iw_ptr) || !(*iw_ptr)->ptr || strcmp(tracefs_instance_get_name((*iw_ptr)->ptr), name) != 0) { From patchwork Mon Jul 12 12:32:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12370973 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E004C07E99 for ; Mon, 12 Jul 2021 12:33:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0719B61003 for ; Mon, 12 Jul 2021 12:33:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233067AbhGLMfr (ORCPT ); Mon, 12 Jul 2021 08:35:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229950AbhGLMfr (ORCPT ); Mon, 12 Jul 2021 08:35:47 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4D76C0613DD for ; Mon, 12 Jul 2021 05:32:57 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id v20so34243444eji.10 for ; Mon, 12 Jul 2021 05:32: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=eceWyTFNnPBQfYSkYX5yOi4Zdou57BzvQlADbNIRtMU=; b=gp/q7P9vKIedm0T8yJwV51lamAY91AsATsKCyjgKBV99wNdC/9QN/2zXG1tBTvjk2w UGkYZV/MoEtf304bxyN4nqXQz8zBYOV7oLmUa60ARNAOb2+kNQ3WhVguO3HebUVRNwZz KJjxeRIy4OMrdqd6WSAqHRMkR/wrNJugduR7hlz0TU4vkwB2cO/3oxl9vv+WsHHel6oj GnnZkUcigyrw7BlAq+YU/rfimoVFNTLll8ULaZUg/pUknSoqyd4r3MLwMG2d+C/UrPum u6SnFVaHVt+qess0Hbug//FG7e6taTQt9rVDfM0OE15xTC17MwN4CEb9VJ2Zk9selbLm 8Fqw== 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=eceWyTFNnPBQfYSkYX5yOi4Zdou57BzvQlADbNIRtMU=; b=B/E2s0Tl5y8QvANmcgQ/F0A6a5WCe/0GThfdZ9i5ajA+q5Na+8rCAaaQr5NYHYuDFr /talK+6bQlgaGvUdSZSs8pFW5tUv1/sgniVR6J7UcDN2zXD4X237KW8wPV0gVHF8v+UO FIwrRqOPT7IW6iD2JtWWQfCvQJXqwmJz74n8rIchFJkwA/nKU7I+UuwlpCswqSMI5tvH 8/cjFJ6YhcSRYSkREfxXyIhcTsAUgX+MU4f8DktBGM/fnn9euPavo6xBdrF0ttrBMvYC rg8z5EFgX8cfl5tU7bvKmKyiX8Sud/nmIgPFGdoXDJh81Zhrc5reHrpJGvcXCHyr29XU HYHg== X-Gm-Message-State: AOAM533VE5lr9VMoj6iwBJUnwNmk8T+1uOq9pab9l19r8jVN9kVDgyPO d2nSlU48OnQ0jd49ybQDCJ42rwHihkA= X-Google-Smtp-Source: ABdhPJxV8NsXv/jRvPgPtuYDUkZRKjOjUDJF2TGEp9QEkS+hFz78XTv6iEpHgri/rmaDsNZJ0H2Nag== X-Received: by 2002:a17:906:7111:: with SMTP id x17mr6897308ejj.294.1626093176321; Mon, 12 Jul 2021 05:32:56 -0700 (PDT) Received: from localhost.localdomain ([95.87.199.98]) by smtp.gmail.com with ESMTPSA id z5sm6477473ejn.65.2021.07.12.05.32.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jul 2021 05:32:56 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: linux-trace-devel@vger.kernel.org Cc: "Yordan Karadzhov (VMware)" Subject: [PATCH 4/4] trace-cruncher: Allow for detachable kprobes Date: Mon, 12 Jul 2021 15:32:42 +0300 Message-Id: <20210712123242.223500-4-y.karadz@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210712123242.223500-1-y.karadz@gmail.com> References: <20210712123242.223500-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org If a kprobe or kretprobe is created with "detached=True", the Python module is no longer responsible for destroying it when exiting. It is therefore up to the user free it explicitly, or to keep it active. Signed-off-by: Yordan Karadzhov (VMware) --- src/ftracepy-utils.c | 26 ++++++++++++++++---------- tests/1_unit/test_01_ftracepy_unit.py | 9 +++++++++ tracecruncher/ft_utils.py | 8 ++++---- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c index d061817..605f7eb 100644 --- a/src/ftracepy-utils.c +++ b/src/ftracepy-utils.c @@ -1570,16 +1570,18 @@ bool store_new_kprobe(const char *event) PyObject *PyFtrace_register_kprobe(PyObject *self, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"event", "function", "probe", NULL}; + static char *kwlist[] = {"event", "function", "probe", "detached", NULL}; const char *event, *function, *probe; + int detached = false; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "sss", + "sss|p", kwlist, &event, &function, - &probe)) { + &probe, + &detached)) { return NULL; } @@ -1589,8 +1591,9 @@ PyObject *PyFtrace_register_kprobe(PyObject *self, PyObject *args, return NULL; } - if (!store_new_kprobe(event)) - return NULL; + if (!detached) + if (!store_new_kprobe(event)) + return NULL; Py_RETURN_NONE; } @@ -1598,16 +1601,18 @@ PyObject *PyFtrace_register_kprobe(PyObject *self, PyObject *args, PyObject *PyFtrace_register_kretprobe(PyObject *self, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"event", "function", "probe", NULL}; + static char *kwlist[] = {"event", "function", "probe", "detached", NULL}; const char *event, *function, *probe = "$retval"; + int detached = false; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "ss|s", + "ss|sp", kwlist, &event, &function, - &probe)) { + &probe, + &detached)) { return NULL; } @@ -1617,8 +1622,9 @@ PyObject *PyFtrace_register_kretprobe(PyObject *self, PyObject *args, return NULL; } - if (!store_new_kprobe(event)) - return NULL; + if (!detached) + if (!store_new_kprobe(event)) + return NULL; Py_RETURN_NONE; } diff --git a/tests/1_unit/test_01_ftracepy_unit.py b/tests/1_unit/test_01_ftracepy_unit.py index 0d62da2..a7a6dec 100644 --- a/tests/1_unit/test_01_ftracepy_unit.py +++ b/tests/1_unit/test_01_ftracepy_unit.py @@ -479,6 +479,15 @@ class KprobeTestCase(unittest.TestCase): all_kprobes = ft.registered_kprobes() self.assertEqual(len(all_kprobes), 0) + ft.register_kprobe(event=evt1, function=evt1_func, + probe=evt1_prove, detached=True) + ft.unregister_kprobe(event='ALL') + all_kprobes = ft.registered_kprobes() + self.assertEqual(len(all_kprobes), 1) + ft.unregister_kprobe(event='ALL', force=True) + all_kprobes = ft.registered_kprobes() + self.assertEqual(len(all_kprobes), 0) + def test_enable_kprobe(self): evt1 = 'mkdir' diff --git a/tracecruncher/ft_utils.py b/tracecruncher/ft_utils.py index 8c245b1..a976885 100644 --- a/tracecruncher/ft_utils.py +++ b/tracecruncher/ft_utils.py @@ -171,12 +171,12 @@ class kprobe(kprobe_base): offset=offset, size=size) - def register(self): + def register(self, detached=False): """ Register this probe to Ftrace. """ probe = ' '.join('{!s}={!s}'.format(key,val) for (key, val) in self.fields.items()) - ft.register_kprobe(event=self.name, function=self.func, probe=probe); + ft.register_kprobe(event=self.name, function=self.func, probe=probe, detached=detached); self.evt_id = find_event_id(system=ft.tc_event_system(), event=self.name) @@ -203,8 +203,8 @@ class kretval_probe(kprobe_base): """ super().__init__(name, func) - def register(self): + def register(self, detached=False): """ Register this probe to Ftrace. """ - ft.register_kprobe(event=self.name, function=self.func); + ft.register_kprobe(event=self.name, function=self.func, detached=detached); self.evt_id = find_event_id(system=ft.tc_event_system(), event=self.name)