From patchwork Tue Aug 17 16:41:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12441757 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 190B2C4338F for ; Tue, 17 Aug 2021 16:41:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E5A7960FE6 for ; Tue, 17 Aug 2021 16:41:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230420AbhHQQmU (ORCPT ); Tue, 17 Aug 2021 12:42:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229920AbhHQQmS (ORCPT ); Tue, 17 Aug 2021 12:42:18 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAD01C061764 for ; Tue, 17 Aug 2021 09:41:43 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id r19so29079838eds.13 for ; Tue, 17 Aug 2021 09:41:43 -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=dvQOYcdkaA9RAlrwEppLpq09VEggm5oXxIPlxlY+fqE=; b=kOOPzfL6a8NkkmAcyjSBT75BggTu9qVl3MPqhtH1BxVyp3+u/Hyx11jhW4pRWh3SwF HRfF71E9JQhTyE6lfvn4WCiPutWGYD1MMWULAGd55sRVJZOWbYrQ45OrmvOTo5/su9JW HSp4DHEgesaAxKpRgipf86iwMF31/wLPRG5wzyFBPflE3RL4Bromm6ShoNlycYZkDupq VaCrtkMHYCZyBkhoQUOhUEAlhwXJ0f27DrgqNUEP4d4hvcfhmdEovagNqjnn1SdpDm0+ f7Y7vPGJD2GdCCHWYA81xGBuVmBs1kZYTBroIEHMs5CXveLyvIt0rPN+l+1CVCXKkkD9 xYvA== 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=dvQOYcdkaA9RAlrwEppLpq09VEggm5oXxIPlxlY+fqE=; b=VSmOMxI4g4C4Q2DrTd7FbiyQEf9u0E9eO193gRuzR3rxzL4I87dTkeWRNzb1vY7x6C lM7nzDTENBdlz2IWV37nvl24P7pk9MgACBfCiRayZ1VAn0KHH4qgt+7ET27VV2XM3WO2 AHgiYDAPiB9Tvkkr97TVoXTfljEUJVk14Cc/EwxIJwHjUXV9eMu6v0i2A2xdzjfmi5re CctM8btNPBOSbStpDrg1mp3O/zbAiyYBAmY98Qp/scExVWe6QLRg0ifCLrX6dNC3HUDv v3vH0vbuwPGIA2M3JsCsyyuz1dLTyYdsC3KIhe94y5LzZ8LwH5ZatBFyt2uM2U4n21Zv uHZw== X-Gm-Message-State: AOAM530kAPg9gjg6nxEAZG1RtLkvy7/LGZpR4L2FUaD0X+ac968q4nnC lJp++9ZMisTCXP88/G+pAwUvRR4JqkE= X-Google-Smtp-Source: ABdhPJy/5fhUx74q4fkqh6S/8Acwhjx2dD+OI8+WzB1wYuA0TYRxY5zZfvdVQug1cKmiwuMB+bSfBA== X-Received: by 2002:a50:998f:: with SMTP id m15mr4983190edb.193.1629218502371; Tue, 17 Aug 2021 09:41:42 -0700 (PDT) Received: from crow.. ([95.87.199.109]) by smtp.gmail.com with ESMTPSA id i16sm968283ejx.78.2021.08.17.09.41.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 09:41:41 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: linux-trace-devel@vger.kernel.org Cc: "Yordan Karadzhov (VMware)" Subject: [PATCH 1/4] trace-cruncher: Use proper naming in common.h Date: Tue, 17 Aug 2021 19:41:07 +0300 Message-Id: <20210817164110.152016-1-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org PyTepEvent was the first Python type defined in the C extension module. A legacy from this first implementation can be found in the naming of some variables used by the type definition macros. Signed-off-by: Yordan Karadzhov (VMware) --- src/common.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common.h b/src/common.h index 9985328..6046c0f 100644 --- a/src/common.h +++ b/src/common.h @@ -54,27 +54,27 @@ static inline void no_free() #define STR(x) #x -#define MAKE_TYPE_STR(x) STR(traceevent.x) +#define MAKE_TYPE_STR(x) STR(trace.x) -#define MAKE_DIC_STR(x) STR(libtraceevent x object) +#define MAKE_DIC_STR(x) STR(libtrace x object) #define C_OBJECT_WRAPPER_DECLARE(c_type, py_type) \ typedef struct { \ PyObject_HEAD \ struct c_type *ptrObj; \ } py_type; \ -PyObject *py_type##_New(struct c_type *evt_ptr); \ +PyObject *py_type##_New(struct c_type *c_ptr); \ bool py_type##TypeInit(); \ #define C_OBJECT_WRAPPER(c_type, py_type, ptr_free) \ static PyTypeObject py_type##Type = { \ PyVarObject_HEAD_INIT(NULL, 0) MAKE_TYPE_STR(c_type) \ }; \ -PyObject *py_type##_New(struct c_type *evt_ptr) \ +PyObject *py_type##_New(struct c_type *c_ptr) \ { \ py_type *newObject; \ newObject = PyObject_New(py_type, &py_type##Type); \ - newObject->ptrObj = evt_ptr; \ + newObject->ptrObj = c_ptr; \ return (PyObject *) newObject; \ } \ static int py_type##_init(py_type *self, PyObject *args, PyObject *kwargs) \ From patchwork Tue Aug 17 16:41:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12441759 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 1C94EC4320A for ; Tue, 17 Aug 2021 16:41:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F2D746102A for ; Tue, 17 Aug 2021 16:41:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229920AbhHQQmV (ORCPT ); Tue, 17 Aug 2021 12:42:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229991AbhHQQmS (ORCPT ); Tue, 17 Aug 2021 12:42:18 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E45C6C0613C1 for ; Tue, 17 Aug 2021 09:41:44 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id u3so39920279ejz.1 for ; Tue, 17 Aug 2021 09:41:44 -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=fTA18C1juGWZITUqmZQxJSRUfIcz4vFTw5d47852z3k=; b=UjvyVxCOJXL47+osyQGqTC/pXWlph+uNR4kwo0RRtDy1q7ieLazXkseSr4e65TJyq9 t5T6OsdL1V908tBrh5nHMMg8zToPO3WW/rfCn2WdTD7jXnvX3wxem2+uf9c2p5Kajeua modp0DfusfPIbJNNw7DDu/XkvzsnpYo00Ae+9jLwQoAPRpB852ZgiolgX+hK7cZ//Y3I zwqAaNyi2TTN7VqtXzh1JJP4Qa6Lt9W4DJ59kMYe61r14HeaktCuQchHRrYe7H1VTzXm hN5zejCBmw2EiepYNBetTe7X4j5N1UnkNMzvpZD1gxACfHpEks9g683TC/P5NYtPyivm TImg== 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=fTA18C1juGWZITUqmZQxJSRUfIcz4vFTw5d47852z3k=; b=fRfooxXknWBfztPPX0YvqJ+PsOsw4G4UFYC6Rxx6+ZnXCBylckdsmIwMxrxt3KElbn BWV4hqyGqg+LbQ2SONMQqx6y1iT2jsIJ/GJqDyjTwoWQcNjRFC+XzwRKfmXOPtPcGPv8 gRlmr/hqehsm5fjttrf8F4O5Nwht30AXH4rHJerZck6iH5JkvwkpW7nuIG3q2/YKLpGU OQfiWavcDmT2cnamwE2pTSrOmlMNHZl+PRrm5uDw271X+fYsFptWmga0SLJccPz8JGen qDw0DugDH25f6w5GmiRNdmQ5qf4c54/H+tXnaPU05MEmQ3BcKaKwlvlxGjYZfTDudFLv ED0g== X-Gm-Message-State: AOAM5316+R4YxIwgvcalfroQA/xSFq6s1E3S75NubJkQnSpIO3hOO9ep 4vZUejIYtBPiMHJfR2ki+RYDKQQfIRw= X-Google-Smtp-Source: ABdhPJxJZZPcYYj78gNLDzLokTcgv0QZAwScuHVuwtRQq/Ko+0+aMYLxtNyK7RGiIIpm3ZO7UaFr1A== X-Received: by 2002:a17:907:1199:: with SMTP id uz25mr4981442ejb.448.1629218503233; Tue, 17 Aug 2021 09:41:43 -0700 (PDT) Received: from crow.. ([95.87.199.109]) by smtp.gmail.com with ESMTPSA id i16sm968283ejx.78.2021.08.17.09.41.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 09:41:42 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: linux-trace-devel@vger.kernel.org Cc: "Yordan Karadzhov (VMware)" Subject: [PATCH 2/4] trace-cruncher: Add type checking for the custom Python types Date: Tue, 17 Aug 2021 19:41:08 +0300 Message-Id: <20210817164110.152016-2-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210817164110.152016-1-y.karadz@gmail.com> References: <20210817164110.152016-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The new method checks if an object has a Python type that matches the type defined in the C extension module. Signed-off-by: Yordan Karadzhov (VMware) --- src/common.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/common.h b/src/common.h index 6046c0f..fa64696 100644 --- a/src/common.h +++ b/src/common.h @@ -65,6 +65,7 @@ static inline void no_free() } py_type; \ PyObject *py_type##_New(struct c_type *c_ptr); \ bool py_type##TypeInit(); \ +bool py_type##_Check(PyObject *obj); \ #define C_OBJECT_WRAPPER(c_type, py_type, ptr_free) \ static PyTypeObject py_type##Type = { \ @@ -101,5 +102,9 @@ bool py_type##TypeInit() \ Py_INCREF(&py_type##Type); \ return true; \ } \ +bool py_type##_Check(PyObject *obj) \ +{ \ + return (obj->ob_type == &py_type##Type) ? true : false; \ +} \ #endif From patchwork Tue Aug 17 16:41:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12441761 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 49827C432BE for ; Tue, 17 Aug 2021 16:41:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2CF0B60FD9 for ; Tue, 17 Aug 2021 16:41:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230192AbhHQQmV (ORCPT ); Tue, 17 Aug 2021 12:42:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230108AbhHQQmT (ORCPT ); Tue, 17 Aug 2021 12:42:19 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 958D0C0613CF for ; Tue, 17 Aug 2021 09:41:45 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id qk33so39791153ejc.12 for ; Tue, 17 Aug 2021 09:41:45 -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=cUXOAd3UwL3ba5bajTmLLYoNhzK48AfPGaXJbynwjvs=; b=MibvHmPw0oew2AOZyHdeix9jyH2SODQXzkBg/UKV9Ol8w/Nl9mryupiCtsYlA+tZJm +nNM1/ef3ij2Gi1Oscta4JAa1z1IK2Tv9QpMY1fMG5bhmpge42cUCR2/EUoPd+HdxBSQ 2WwaDXiEUffAgSzmXebOvJnX7lcEBFjFKcNYYuwWsO9q7B317sEJGA/8H8tLGGcj6V0k uW/RnaenP/+0iF76qrpxEgjO96S+BP5C1xqna7QwVGEtVfixxhyhyKCvtFg1H8C85kSE kQ978H23hVlGLnjEOGxbpnnaOggWuo+O3FsHCOy/cjZxqLtNRD/pBfuK689T7c3DHb/k p/9Q== 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=cUXOAd3UwL3ba5bajTmLLYoNhzK48AfPGaXJbynwjvs=; b=L44txU2eq49IeXyRh24y5zioqlmLjBJ+EIlTbLs4Gs7RkJMNi9sr6pS2Mvr1+dEITg wFx7ktD6o5VJCnzTv0lfE03fYh/lUiFD8i9SeOSHZiW7ykTyiDqdEHqR0sc8o0pKhTef dB39hpSExk45UY7j8J3PevL5O7l7LXSuHVyA0b69G511oLUvHKjYSVegoecsimMO56M2 Z+TKYOJ/C6ZIOtKnWk/ho62Z3wVIXO729MHbrYNudZA9oEMxMarb0bVlQqD0JBGYvxvJ oQB36naIw1VWlT2I6sA4y5w4WtF9Rx8QGglqDbhxeZ43epTdj2wUIt20ZV8aORhJH9dy aBvA== X-Gm-Message-State: AOAM533+m54kwXuR557bxe8wXFTcD16ItfEQfCtAnFkxWEMksZua7+0I x7UONj/ZzGYxexoMAT6syaXPBbdEd1g= X-Google-Smtp-Source: ABdhPJx0kZQYxkEwuoBBX2pqRJjcl6HKX8H6AvOvozwPTttrxELcrUrWaBWTECxZYhl08PDmUbBp5Q== X-Received: by 2002:a17:907:7615:: with SMTP id jx21mr4834114ejc.505.1629218503954; Tue, 17 Aug 2021 09:41:43 -0700 (PDT) Received: from crow.. ([95.87.199.109]) by smtp.gmail.com with ESMTPSA id i16sm968283ejx.78.2021.08.17.09.41.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 09:41:43 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: linux-trace-devel@vger.kernel.org Cc: "Yordan Karadzhov (VMware)" Subject: [PATCH 3/4] trace-cruncher: Define Python type for instances Date: Tue, 17 Aug 2021 19:41:09 +0300 Message-Id: <20210817164110.152016-3-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210817164110.152016-1-y.karadz@gmail.com> References: <20210817164110.152016-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org We add a custom Python type that wraps the 'tracefs_instance' object, defined in libtracefs. This is a preparation for a general refactorung of the way libtracefs instances are handled by trace-cruncher. Signed-off-by: Yordan Karadzhov (VMware) --- src/ftracepy-utils.c | 5 +++++ src/ftracepy-utils.h | 4 ++++ src/ftracepy.c | 15 +++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c index 6739db7..6b2f879 100644 --- a/src/ftracepy-utils.c +++ b/src/ftracepy-utils.c @@ -531,6 +531,11 @@ bool get_instance_from_arg(PyObject *args, PyObject *kwargs, return true; } +PyObject *PyTfsInstance_dir(PyTfsInstance *self) +{ + return PyUnicode_FromString(tracefs_instance_get_dir(self->ptrObj)); +} + PyObject *PyFtrace_dir(PyObject *self) { return PyUnicode_FromString(tracefs_tracing_dir()); diff --git a/src/ftracepy-utils.h b/src/ftracepy-utils.h index 5d7c19c..cf75e0b 100644 --- a/src/ftracepy-utils.h +++ b/src/ftracepy-utils.h @@ -22,6 +22,8 @@ C_OBJECT_WRAPPER_DECLARE(tep_event, PyTepEvent) C_OBJECT_WRAPPER_DECLARE(tep_handle, PyTep) +C_OBJECT_WRAPPER_DECLARE(tracefs_instance, PyTfsInstance) + PyObject *PyTepRecord_time(PyTepRecord* self); PyObject *PyTepRecord_cpu(PyTepRecord* self); @@ -44,6 +46,8 @@ PyObject *PyTep_init_local(PyTep *self, PyObject *args, PyObject *PyTep_get_event(PyTep *self, PyObject *args, PyObject *kwargs); +PyObject *PyTfsInstance_dir(PyTfsInstance *self); + PyObject *PyFtrace_dir(PyObject *self); PyObject *PyFtrace_create_instance(PyObject *self, PyObject *args, diff --git a/src/ftracepy.c b/src/ftracepy.c index e3fec7b..628a53a 100644 --- a/src/ftracepy.c +++ b/src/ftracepy.c @@ -73,6 +73,17 @@ static PyMethodDef PyTep_methods[] = { C_OBJECT_WRAPPER(tep_handle, PyTep, tep_free) +static PyMethodDef PyTfsInstance_methods[] = { + {"dir", + (PyCFunction) PyTfsInstance_dir, + METH_NOARGS, + "Get the absolute path to the instance directory." + }, + {NULL, NULL, 0, NULL} +}; + +C_OBJECT_WRAPPER(tracefs_instance, PyTfsInstance, tracefs_instance_destroy) + static PyMethodDef ftracepy_methods[] = { {"dir", (PyCFunction) PyFtrace_dir, @@ -321,6 +332,9 @@ PyMODINIT_FUNC PyInit_ftracepy(void) if (!PyTepRecordTypeInit()) return NULL; + if (!PyTfsInstanceTypeInit()) + return NULL; + TFS_ERROR = PyErr_NewException("tracecruncher.ftracepy.tfs_error", NULL, NULL); @@ -335,6 +349,7 @@ PyMODINIT_FUNC PyInit_ftracepy(void) PyModule_AddObject(module, "tep_handle", (PyObject *) &PyTepType); PyModule_AddObject(module, "tep_event", (PyObject *) &PyTepEventType); PyModule_AddObject(module, "tep_record", (PyObject *) &PyTepRecordType); + PyModule_AddObject(module, "tracefs_instance", (PyObject *) &PyTfsInstanceType); PyModule_AddObject(module, "tfs_error", TFS_ERROR); PyModule_AddObject(module, "tep_error", TEP_ERROR); From patchwork Tue Aug 17 16:41:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12441763 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.7 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 8D3CCC43216 for ; Tue, 17 Aug 2021 16:41:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6F7A760FDA for ; Tue, 17 Aug 2021 16:41:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229477AbhHQQmW (ORCPT ); Tue, 17 Aug 2021 12:42:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230204AbhHQQmU (ORCPT ); Tue, 17 Aug 2021 12:42:20 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B24CBC061764 for ; Tue, 17 Aug 2021 09:41:46 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id gr13so10790104ejb.6 for ; Tue, 17 Aug 2021 09:41:46 -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=tg2A9mIinXCz5V4K17rvL64pY7aWeLbwIPbDOJmY1+g=; b=oScuUzxiYCgRBZ+nh5YChP1BcmbsbBpVT4usE8gZDKXf0DtX95+XDUEKhUhh8XeOl5 B3nCjlW41xdiLx2iLyN8QHqbwK3da2qIPASiMz2GICZHnjXgBTffQLh3wYjLK7SzPTY1 +RzKjJSkq4zbxLM7GwjyNK481cdgl3XBpH55HquObUgNcSKdkwEzrK8PGlh86I3BBFrS VB8Ddrz7vzGm6ITsF92jrtHEYghIxLqn/u1rcUdV05m0JqjVtrK1tw8JQmTL7RkRBoDE 7LPUGhxeP5Kxg3DTmnE2d8G7oZDE88Na8qXXwsox/4RueFZEpxpnadQS+ODXtxQzkHd1 xUXw== 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=tg2A9mIinXCz5V4K17rvL64pY7aWeLbwIPbDOJmY1+g=; b=Z/vnixzFJQ7z2ZuG5dxbxbDc8FqW+/qdK++gMN+I07Im+b58JS/QM5JUDSzOiLQqX+ VobH77S+Zn+YJ3FE6K91XbdXCLxGp1FVMVs1I+kHrBIpevyYWd+hMCUJExstY1VQdS09 V7nqK4ck8cgnZ5k5qRcdDB5tNxLEpUyIAveM2022Z4ORtH258TPzpVI5UcAVanIcSpw3 D1WFjkksfepn29+yx3pGEMfeunXNFerWbwWstNFFgXz/WJwEv/QVV7ry+tH9rJW8Gl0C PcCpBc5akHNGmiLPgWE93cDctjpte0fSKHWI9DtNEvt0Ye8GAv0UEAAcpLMjXWGjpBLc L8Hg== X-Gm-Message-State: AOAM532dWCTIJrqwVz1NLEog9rfYIqNepTfXqiOhaERZ39xW+fwDa9tW NBUWNrDvDD+OnLTnB6LXMzVPONfhCeU= X-Google-Smtp-Source: ABdhPJxcITNl6zozH2oZ3qn8cG/2wiug5etXfQf9QT0O42VFrkSrKVZng+XwzpiByLcEnJyJ8JxC2w== X-Received: by 2002:a17:906:3b53:: with SMTP id h19mr4948703ejf.431.1629218504827; Tue, 17 Aug 2021 09:41:44 -0700 (PDT) Received: from crow.. ([95.87.199.109]) by smtp.gmail.com with ESMTPSA id i16sm968283ejx.78.2021.08.17.09.41.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 09:41:44 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: linux-trace-devel@vger.kernel.org Cc: "Yordan Karadzhov (VMware)" Subject: [PATCH 4/4] trace-cruncher: Refactor the way libtracefs instances are handled Date: Tue, 17 Aug 2021 19:41:10 +0300 Message-Id: <20210817164110.152016-4-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210817164110.152016-1-y.karadz@gmail.com> References: <20210817164110.152016-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Currently all libtracefs instances created by trace-cruncher are wrapped by a dedicated C structure and stored in a binary search tree. The ordering in the tree is based on a string comparison. The tree is used for accessing the created instances and for cleanup when the module exits (garbage collection). In this refactoring we eliminate the need of the tree by switching to using the custom Python type for libtracefs instances. The new type is defined in the C extension of the module. Signed-off-by: Yordan Karadzhov (VMware) --- src/ftracepy-utils.c | 412 +++++------------- src/ftracepy-utils.h | 10 - src/ftracepy.c | 20 - tests/1_unit/test_01_ftracepy_unit.py | 245 +++++------ .../test_01_ftracepy_integration.py | 56 +-- 5 files changed, 242 insertions(+), 501 deletions(-) diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c index 6b2f879..9333a3b 100644 --- a/src/ftracepy-utils.c +++ b/src/ftracepy-utils.c @@ -19,7 +19,6 @@ // trace-cruncher #include "ftracepy-utils.h" -static void *instance_root; PyObject *TFS_ERROR; PyObject *TEP_ERROR; PyObject *TRACECRUNCHER_ERROR; @@ -419,118 +418,6 @@ static PyObject *tfs_list2py_list(char **list) return py_list; } -struct instance_wrapper { - struct tracefs_instance *ptr; - const char *name; -}; - -const char *instance_wrapper_get_name(const struct instance_wrapper *iw) -{ - if (!iw->ptr) - return iw->name; - - return tracefs_instance_get_name(iw->ptr); -} - -static int instance_compare(const void *a, const void *b) -{ - const struct instance_wrapper *iwa, *iwb; - - iwa = (const struct instance_wrapper *) a; - iwb = (const struct instance_wrapper *) b; - - return strcmp(instance_wrapper_get_name(iwa), - instance_wrapper_get_name(iwb)); -} - -void instance_wrapper_free(void *ptr) -{ - struct instance_wrapper *iw; - if (!ptr) - return; - - 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)); - - free(iw->ptr); - } - - free(ptr); -} - -static void destroy_all_instances(void) -{ - tdestroy(instance_root, instance_wrapper_free); - instance_root = NULL; -} - -static struct tracefs_instance *find_instance(const char *name) -{ - struct instance_wrapper iw, **iw_ptr; - if (!is_set(name)) - return NULL; - - if (!tracefs_instance_exists(name)) { - PyErr_Format(TFS_ERROR, "Trace instance \'%s\' does not exist.", - name); - return NULL; - } - - iw.ptr = NULL; - iw.name = name; - iw_ptr = tfind(&iw, &instance_root, instance_compare); - if (!iw_ptr || !(*iw_ptr) || !(*iw_ptr)->ptr || - strcmp(tracefs_instance_get_name((*iw_ptr)->ptr), name) != 0) { - PyErr_Format(TFS_ERROR, "Unable to find trace instances \'%s\'.", - name); - return NULL; - } - - return (*iw_ptr)->ptr; -} - -bool get_optional_instance(const char *instance_name, - struct tracefs_instance **instance) -{ - *instance = NULL; - if (is_set(instance_name)) { - *instance = find_instance(instance_name); - if (!instance) { - PyErr_Format(TFS_ERROR, - "Failed to find instance \'%s\'.", - instance_name); - return false; - } - } - - return true; -} - -bool get_instance_from_arg(PyObject *args, PyObject *kwargs, - struct tracefs_instance **instance) -{ - const char *instance_name; - - static char *kwlist[] = {"instance", NULL}; - instance_name = NO_ARG; - if (!PyArg_ParseTupleAndKeywords(args, - kwargs, - "|s", - kwlist, - &instance_name)) { - return false; - } - - if (!get_optional_instance(instance_name, instance)) - return false; - - return true; -} - PyObject *PyTfsInstance_dir(PyTfsInstance *self) { return PyUnicode_FromString(tracefs_instance_get_dir(self->ptrObj)); @@ -570,7 +457,6 @@ static bool tracing_OFF(struct tracefs_instance *instance); PyObject *PyFtrace_create_instance(PyObject *self, PyObject *args, PyObject *kwargs) { - struct instance_wrapper *iw, **iw_ptr; struct tracefs_instance *instance; const char *name = NO_ARG; int tracing_on = true; @@ -598,115 +484,53 @@ PyObject *PyFtrace_create_instance(PyObject *self, PyObject *args, return NULL; } - iw = calloc(1, sizeof(*iw)); - if (!iw) { - MEM_ERROR - return NULL; - } - - iw->ptr = instance; - 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) { - PyErr_Format(TFS_ERROR, - "Failed to store new trace instance \'%s\'.", - name); - tracefs_instance_destroy(instance); - tracefs_instance_free(instance); - free(iw); - - return NULL; - } - if (!tracing_on) tracing_OFF(instance); - return PyUnicode_FromString(name); + return PyTfsInstance_New(instance); } -PyObject *PyFtrace_destroy_instance(PyObject *self, PyObject *args, - PyObject *kwargs) +static bool get_optional_instance(PyObject *py_obj, + struct tracefs_instance **instance) { - struct tracefs_instance *instance; - struct instance_wrapper iw; - char *name; + PyTfsInstance *py_inst; - static char *kwlist[] = {"name", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, - kwargs, - "s", - kwlist, - &name)) { - return NULL; - } - - if (is_all(name)) { - destroy_all_instances(); - Py_RETURN_NONE; + if (!py_obj) { + *instance = NULL; + return true; } - instance = find_instance(name); - if (!instance) { - PyErr_Format(TFS_ERROR, - "Unable to destroy trace instances \'%s\'.", - name); - return NULL; + if (!PyTfsInstance_Check(py_obj)) { + PyErr_SetString(TRACECRUNCHER_ERROR, + "Passing argument \'instance\' with incompatible type."); + return false; } - iw.ptr = NULL; - iw.name = name; - tdelete(&iw, &instance_root, instance_compare); - - tracefs_instance_destroy(instance); - tracefs_instance_free(instance); + py_inst = (PyTfsInstance *)py_obj; + *instance = py_inst->ptrObj; - Py_RETURN_NONE; + return true; } -PyObject *instance_list; - -static void instance_action(const void *nodep, VISIT which, int depth) +bool get_instance_from_arg(PyObject *args, PyObject *kwargs, + struct tracefs_instance **instance) { - struct instance_wrapper *iw = *( struct instance_wrapper **) nodep; - const char *name; - - switch(which) { - case preorder: - case endorder: - break; + static char *kwlist[] = {"instance", NULL}; + PyObject *py_inst = NULL; + *instance = NULL; - case postorder: - case leaf: - name = tracefs_instance_get_name(iw->ptr); - PyList_Append(instance_list, PyUnicode_FromString(name)); - break; + if (!PyArg_ParseTupleAndKeywords(args, + kwargs, + "|O", + kwlist, + &py_inst)) { + return false; } -} - -PyObject *PyFtrace_get_all_instances(PyObject *self) -{ - instance_list = PyList_New(0); - twalk(instance_root, instance_action); - - return instance_list; -} - -PyObject *PyFtrace_destroy_all_instances(PyObject *self) -{ - destroy_all_instances(); - - Py_RETURN_NONE; -} - -PyObject *PyFtrace_instance_dir(PyObject *self, PyObject *args, - PyObject *kwargs) -{ - struct tracefs_instance *instance; - if (!get_instance_from_arg(args, kwargs, &instance)) + if (!get_optional_instance(py_inst, instance)) return NULL; - return PyUnicode_FromString(tracefs_instance_get_dir(instance)); + return true; } PyObject *PyFtrace_available_tracers(PyObject *self, PyObject *args, @@ -728,21 +552,22 @@ PyObject *PyFtrace_available_tracers(PyObject *self, PyObject *args, PyObject *PyFtrace_set_current_tracer(PyObject *self, PyObject *args, PyObject *kwargs) { - const char *file = "current_tracer", *tracer, *instance_name; + static char *kwlist[] = {"tracer", "instance", NULL}; + const char *file = "current_tracer", *tracer; struct tracefs_instance *instance; + PyObject *py_inst = NULL; - static char *kwlist[] = {"tracer", "instance", NULL}; - tracer = instance_name = NO_ARG; + tracer = NO_ARG; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|ss", + "|sO", kwlist, &tracer, - &instance_name)) { + &py_inst)) { return NULL; } - if (!get_optional_instance(instance_name, &instance)) + if (!get_optional_instance(py_inst, &instance)) return NULL; if (is_set(tracer) && @@ -816,20 +641,21 @@ PyObject *PyFtrace_available_system_events(PyObject *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = {"system", "instance", NULL}; - const char *instance_name = NO_ARG, *system; struct tracefs_instance *instance; + PyObject *py_inst = NULL; + const char *system; char **list; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "s|s", + "s|O", kwlist, &system, - &instance_name)) { + &py_inst)) { return NULL; } - if (!get_optional_instance(instance_name, &instance)) + if (!get_optional_instance(py_inst, &instance)) return NULL; list = tracefs_system_events(tracefs_instance_get_dir(instance), @@ -927,21 +753,22 @@ static bool set_enable_event(PyObject *self, bool enable) { static char *kwlist[] = {"instance", "system", "event", NULL}; - const char *instance_name, *system, *event; struct tracefs_instance *instance; + PyObject *py_inst = NULL; + const char *system, *event; - instance_name = system = event = NO_ARG; + system = event = NO_ARG; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|sss", + "|Oss", kwlist, - &instance_name, + &py_inst, &system, &event)) { return false; } - if (!get_optional_instance(instance_name, &instance)) + if (!get_optional_instance(py_inst, &instance)) return false; return event_enable_disable(instance, system, event, enable); @@ -975,22 +802,21 @@ static bool set_enable_events(PyObject *self, PyObject *args, PyObject *kwargs, PyObject *system_list = NULL, *event_list = NULL, *system_event_list; const char **systems = NULL, **events = NULL; struct tracefs_instance *instance; - const char *instance_name; + PyObject *py_inst = NULL; char *file = NULL; int ret, s, e; - instance_name = NO_ARG; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|sOO", + "|OOO", kwlist, - &instance_name, + &py_inst, &system_list, &event_list)) { return false; } - if (!get_optional_instance(instance_name, &instance)) + if (!get_optional_instance(py_inst, &instance)) return false; if (!system_list && !event_list) @@ -1102,21 +928,22 @@ PyObject *PyFtrace_event_is_enabled(PyObject *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = {"instance", "system", "event", NULL}; - const char *instance_name, *system, *event; struct tracefs_instance *instance; + PyObject *py_inst = NULL; + const char *system, *event; - instance_name = system = event = NO_ARG; + system = event = NO_ARG; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|sss", + "|Oss", kwlist, - &instance_name, + &py_inst, &system, &event)) { return false; } - if (!get_optional_instance(instance_name, &instance)) + if (!get_optional_instance(py_inst, &instance)) return false; return event_is_enabled(instance, system, event); @@ -1125,23 +952,24 @@ PyObject *PyFtrace_event_is_enabled(PyObject *self, PyObject *args, PyObject *PyFtrace_set_event_filter(PyObject *self, PyObject *args, PyObject *kwargs) { - const char *instance_name = NO_ARG, *system, *event, *filter; + const char *system, *event, *filter; struct tracefs_instance *instance; + PyObject *py_inst = NULL; char path[PATH_MAX]; static char *kwlist[] = {"system", "event", "filter", "instance", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "sss|s", + "ssO|)", kwlist, &system, &event, &filter, - &instance_name)) { + &py_inst)) { return NULL; } - if (!get_optional_instance(instance_name, &instance)) + if (!get_optional_instance(py_inst, &instance)) return NULL; sprintf(path, "events/%s/%s/filter", system, event); @@ -1156,22 +984,23 @@ PyObject *PyFtrace_set_event_filter(PyObject *self, PyObject *args, PyObject *PyFtrace_clear_event_filter(PyObject *self, PyObject *args, PyObject *kwargs) { - const char *instance_name = NO_ARG, *system, *event; struct tracefs_instance *instance; + PyObject *py_inst = NULL; + const char *system, *event; char path[PATH_MAX]; static char *kwlist[] = {"system", "event", "instance", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "ss|s", + "ss|O", kwlist, &system, &event, - &instance_name)) { + &py_inst)) { return NULL; } - if (!get_optional_instance(instance_name, &instance)) + if (!get_optional_instance(py_inst, &instance)) return NULL; sprintf(path, "events/%s/%s/filter", system, event); @@ -1330,21 +1159,21 @@ static bool set_pid(struct tracefs_instance *instance, PyObject *PyFtrace_set_event_pid(PyObject *self, PyObject *args, PyObject *kwargs) { - const char *instance_name = NO_ARG; struct tracefs_instance *instance; + PyObject *py_inst = NULL; PyObject *pid_val; static char *kwlist[] = {"pid", "instance", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O|s", + "O|O", kwlist, &pid_val, - &instance_name)) { + &py_inst)) { return NULL; } - if (!get_optional_instance(instance_name, &instance)) + if (!get_optional_instance(py_inst, &instance)) return NULL; if (!set_pid(instance, "set_event_pid", pid_val)) @@ -1356,21 +1185,21 @@ PyObject *PyFtrace_set_event_pid(PyObject *self, PyObject *args, PyObject *PyFtrace_set_ftrace_pid(PyObject *self, PyObject *args, PyObject *kwargs) { - const char *instance_name = NO_ARG; struct tracefs_instance *instance; + PyObject *py_inst = NULL; PyObject *pid_val; static char *kwlist[] = {"pid", "instance", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O|s", + "O|O", kwlist, &pid_val, - &instance_name)) { + &py_inst)) { return NULL; } - if (!get_optional_instance(instance_name, &instance)) + if (!get_optional_instance(py_inst, &instance)) return NULL; if (!set_pid(instance, "set_ftrace_pid", pid_val)) @@ -1396,20 +1225,21 @@ static bool set_opt(struct tracefs_instance *instance, static PyObject *set_option_py_args(PyObject *args, PyObject *kwargs, const char *val) { - const char *instance_name = NO_ARG, *opt; struct tracefs_instance *instance; + PyObject *py_inst = NULL; + const char *opt; static char *kwlist[] = {"option", "instance", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "s|s", + "s|O", kwlist, &opt, - &instance_name)) { + &py_inst)) { return NULL; } - if (!get_optional_instance(instance_name, &instance)) + if (!get_optional_instance(py_inst, &instance)) return NULL; if (!set_opt(instance, opt, val)) @@ -1433,21 +1263,22 @@ PyObject *PyFtrace_disable_option(PyObject *self, PyObject *args, PyObject *PyFtrace_option_is_set(PyObject *self, PyObject *args, PyObject *kwargs) { - const char *instance_name = NO_ARG, *opt; struct tracefs_instance *instance; + PyObject *py_inst = NULL; enum tracefs_option_id opt_id; + const char *opt; static char *kwlist[] = {"option", "instance", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "s|s", + "s|O", kwlist, &opt, - &instance_name)) { + &py_inst)) { return NULL; } - if (!get_optional_instance(instance_name, &instance)) + if (!get_optional_instance(py_inst, &instance)) return NULL; opt_id = tracefs_option_id(opt); @@ -1686,22 +1517,23 @@ PyObject *PyFtrace_registered_kprobes(PyObject *self) PyObject *PyFtrace_set_kprobe_filter(PyObject *self, PyObject *args, PyObject *kwargs) { - const char *instance_name = NO_ARG, *event, *filter; struct tracefs_instance *instance; + PyObject *py_inst = NULL; + const char *event, *filter; char path[PATH_MAX]; static char *kwlist[] = {"event", "filter", "instance", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "ss|s", + "ss|O", kwlist, &event, &filter, - &instance_name)) { + &py_inst)) { return NULL; } - if (!get_optional_instance(instance_name, &instance)) + if (!get_optional_instance(py_inst, &instance)) return NULL; sprintf(path, "events/%s/%s/filter", TC_SYS, event); @@ -1716,21 +1548,22 @@ PyObject *PyFtrace_set_kprobe_filter(PyObject *self, PyObject *args, PyObject *PyFtrace_clear_kprobe_filter(PyObject *self, PyObject *args, PyObject *kwargs) { - const char *instance_name = NO_ARG, *event; struct tracefs_instance *instance; + PyObject *py_inst = NULL; char path[PATH_MAX]; + const char *event; static char *kwlist[] = {"event", "instance", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "s|s", + "s|O", kwlist, &event, - &instance_name)) { + &py_inst)) { return NULL; } - if (!get_optional_instance(instance_name, &instance)) + if (!get_optional_instance(py_inst, &instance)) return NULL; sprintf(path, "events/%s/%s/filter", TC_SYS, event); @@ -1747,19 +1580,19 @@ static bool enable_kprobe(PyObject *self, PyObject *args, PyObject *kwargs, { static char *kwlist[] = {"event", "instance", NULL}; struct tracefs_instance *instance; - const char *instance_name, *event; + PyObject *py_inst = NULL; + const char *event = NO_ARG; - instance_name = event = NO_ARG; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "s|s", + "s|O", kwlist, &event, - &instance_name)) { + &py_inst)) { return false; } - if (!get_optional_instance(instance_name, &instance)) + if (!get_optional_instance(py_inst, &instance)) return false; return event_enable_disable(instance, TC_SYS, event, enable); @@ -1788,19 +1621,19 @@ PyObject *PyFtrace_kprobe_is_enabled(PyObject *self, PyObject *args, { static char *kwlist[] = {"event", "instance", NULL}; struct tracefs_instance *instance; - const char *instance_name, *event; + PyObject *py_inst = NULL; + const char *event = NO_ARG; - instance_name = event = NO_ARG; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "s|s", + "s|O", kwlist, &event, - &instance_name)) { + &py_inst)) { return NULL; } - if (!get_optional_instance(instance_name, &instance)) + if (!get_optional_instance(py_inst, &instance)) return NULL; return event_is_enabled(instance, TC_SYS, event); @@ -2003,27 +1836,27 @@ static bool init_callback_tep(struct tracefs_instance *instance, PyObject *PyFtrace_trace_shell_process(PyObject *self, PyObject *args, PyObject *kwargs) { - const char *plugin = "__main__", *py_callback = "callback", *instance_name; + const char *plugin = "__main__", *py_callback = "callback"; static char *kwlist[] = {"process", "plugin", "callback", "instance", NULL}; struct tracefs_instance *instance; + PyObject *py_inst = NULL; struct tep_handle *tep; PyObject *py_func; char *process; pid_t pid; - instance_name = NO_ARG; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "s|sss", + "s|ssO", kwlist, &process, &plugin, &py_callback, - &instance_name)) { + &py_inst)) { return NULL; } - if (!get_optional_instance(instance_name, &instance)) + if (!get_optional_instance(py_inst, &instance)) return NULL; if (!init_callback_tep(instance, plugin, py_callback, &tep, &py_func)) @@ -2050,27 +1883,27 @@ PyObject *PyFtrace_trace_shell_process(PyObject *self, PyObject *args, PyObject *PyFtrace_trace_process(PyObject *self, PyObject *args, PyObject *kwargs) { - const char *plugin = "__main__", *py_callback = "callback", *instance_name; + const char *plugin = "__main__", *py_callback = "callback"; static char *kwlist[] = {"argv", "plugin", "callback", "instance", NULL}; struct tracefs_instance *instance; + PyObject *py_inst = NULL; struct tep_handle *tep; PyObject *py_func, *py_argv, *py_arg; pid_t pid; int i, argc; - instance_name = NO_ARG; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O|sss", + "O|ssO", kwlist, &py_argv, &plugin, &py_callback, - &instance_name)) { + &py_inst)) { return NULL; } - if (!get_optional_instance(instance_name, &instance)) + if (!get_optional_instance(py_inst, &instance)) return NULL; if (!init_callback_tep(instance, plugin, py_callback, &tep, &py_func)) @@ -2153,8 +1986,7 @@ PyObject *PyFtrace_iterate_trace(PyObject *self, PyObject *args, const char *plugin = "__main__", *py_callback = "callback"; bool *callback_status = &callback_ctx.status; bool *keep_going = &iterate_keep_going; - - const char *instance_name; + PyObject *py_inst = NULL; struct tep_handle *tep; PyObject *py_func; int ret; @@ -2162,20 +1994,19 @@ PyObject *PyFtrace_iterate_trace(PyObject *self, PyObject *args, (*(volatile bool *)keep_going) = true; signal(SIGINT, iterate_stop); - instance_name = NO_ARG; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|sss", + "|ssO", kwlist, &plugin, &py_callback, - &instance_name)) { + &py_inst)) { return NULL; } py_func = get_callback_func(plugin, py_callback); if (!py_func || - !get_optional_instance(instance_name, &itr_instance) || + !get_optional_instance(py_inst, &itr_instance) || !notrace_this_pid(itr_instance)) return NULL; @@ -2199,22 +2030,22 @@ PyObject *PyFtrace_iterate_trace(PyObject *self, PyObject *args, PyObject *PyFtrace_hook2pid(PyObject *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = {"pid", "fork", "instance", NULL}; - const char *instance_name = NO_ARG; struct tracefs_instance *instance; + PyObject *py_inst = NULL; PyObject *pid_val; int fork = -1; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O|ps", + "O|pO", kwlist, &pid_val, &fork, - &instance_name)) { + &py_inst)) { return NULL; } - if (!get_optional_instance(instance_name, &instance)) + if (!get_optional_instance(py_inst, &instance)) return NULL; if (!hook2pid(instance, pid_val, fork)) @@ -2226,5 +2057,4 @@ PyObject *PyFtrace_hook2pid(PyObject *self, PyObject *args, PyObject *kwargs) void PyFtrace_at_exit(void) { destroy_all_kprobes(); - destroy_all_instances(); } diff --git a/src/ftracepy-utils.h b/src/ftracepy-utils.h index cf75e0b..a3be385 100644 --- a/src/ftracepy-utils.h +++ b/src/ftracepy-utils.h @@ -53,16 +53,6 @@ PyObject *PyFtrace_dir(PyObject *self); PyObject *PyFtrace_create_instance(PyObject *self, PyObject *args, PyObject *kwargs); -PyObject *PyFtrace_destroy_instance(PyObject *self, PyObject *args, - PyObject *kwargs); - -PyObject *PyFtrace_get_all_instances(PyObject *self); - -PyObject *PyFtrace_destroy_all_instances(PyObject *self); - -PyObject *PyFtrace_instance_dir(PyObject *self, PyObject *args, - PyObject *kwargs); - PyObject *PyFtrace_available_tracers(PyObject *self, PyObject *args, PyObject *kwargs); diff --git a/src/ftracepy.c b/src/ftracepy.c index 628a53a..ca358ce 100644 --- a/src/ftracepy.c +++ b/src/ftracepy.c @@ -95,26 +95,6 @@ static PyMethodDef ftracepy_methods[] = { METH_VARARGS | METH_KEYWORDS, "Create new tracefs instance." }, - {"get_all_instances", - (PyCFunction) PyFtrace_get_all_instances, - METH_NOARGS, - "Get all existing tracefs instances." - }, - {"destroy_instance", - (PyCFunction) PyFtrace_destroy_instance, - METH_VARARGS | METH_KEYWORDS, - "Destroy existing tracefs instance." - }, - {"destroy_all_instances", - (PyCFunction) PyFtrace_destroy_all_instances, - METH_NOARGS, - "Destroy all existing tracefs instances." - }, - {"instance_dir", - (PyCFunction) PyFtrace_instance_dir, - METH_VARARGS | METH_KEYWORDS, - "Get the absolute path to the instance directory." - }, {"available_tracers", (PyCFunction) PyFtrace_available_tracers, METH_VARARGS | METH_KEYWORDS, diff --git a/tests/1_unit/test_01_ftracepy_unit.py b/tests/1_unit/test_01_ftracepy_unit.py index 0d62da2..57db0ad 100644 --- a/tests/1_unit/test_01_ftracepy_unit.py +++ b/tests/1_unit/test_01_ftracepy_unit.py @@ -22,48 +22,20 @@ class InstanceTestCase(unittest.TestCase): self.assertTrue(os.path.isdir(instances_dir)) def test_create_instance(self): - ft.create_instance(instance_name) - self.assertTrue(ft.is_tracing_ON(instance_name)) + inst = ft.create_instance(instance_name) + self.assertTrue(ft.is_tracing_ON(inst)) instances_dir = ft.dir() + '/instances/' self.assertTrue(os.path.isdir(instances_dir + instance_name)) auto_inst = ft.create_instance(tracing_on=False) self.assertFalse(ft.is_tracing_ON(auto_inst)) - ft.destroy_instance(auto_inst) - - def test_destroy_instance(self): - ft.destroy_instance(instance_name) - instances_dir = ft.dir() + '/instances/' - self.assertFalse(os.path.isdir(instances_dir + instance_name)) - - err = 'Unable to destroy trace instances' - with self.assertRaises(Exception) as context: - ft.destroy_instance(instance_name) - self.assertTrue(err in str(context.exception)) - - ft.create_instance(instance_name) - ft.create_instance(another_instance_name) - ft.destroy_all_instances() - self.assertFalse(os.path.isdir(instances_dir + instance_name)) - - ft.create_instance(instance_name) - ft.create_instance(another_instance_name) - ft.destroy_instance('all') - self.assertFalse(os.path.isdir(instances_dir + instance_name)) - - def test_get_all(self): - ft.create_instance(instance_name) - ft.create_instance(another_instance_name) - self.assertEqual(ft.get_all_instances(), - [instance_name, another_instance_name]) - ft.destroy_all_instances() def test_instance_dir(self): - ft.create_instance(instance_name) + inst = ft.create_instance(instance_name) tracefs_dir = ft.dir(); instance_dir = tracefs_dir + '/instances/' + instance_name - self.assertEqual(instance_dir, ft.instance_dir(instance_name)) - ft.destroy_all_instances() + self.assertEqual(instance_dir, inst.dir()) + class PyTepTestCase(unittest.TestCase): def test_init_local(self): @@ -73,8 +45,8 @@ class PyTepTestCase(unittest.TestCase): tep.init_local(dir=tracefs_dir, systems=['sched', 'irq']); - ft.create_instance(instance_name) - tracefs_dir = ft.instance_dir(instance_name) + inst = ft.create_instance(instance_name) + tracefs_dir = inst.dir() tep.init_local(dir=tracefs_dir, systems=['sched', 'irq']); err='function missing required argument \'dir\'' @@ -86,7 +58,6 @@ class PyTepTestCase(unittest.TestCase): with self.assertRaises(Exception) as context: tep.init_local(dir='no_dir', systems=['sched', 'irq']); self.assertTrue(err in str(context.exception)) - ft.destroy_all_instances() def test_get_event(self): tracefs_dir = ft.dir() @@ -144,302 +115,284 @@ class EventsTestCase(unittest.TestCase): self.assertTrue(len(systems) > 1) self.assertTrue('sched' in systems) - ft.create_instance(instance_name) - systems = ft.available_event_systems(instance_name) + inst = ft.create_instance(instance_name) + systems = ft.available_event_systems(inst) self.assertTrue(len(systems) > 1) self.assertTrue('sched' in systems) - ft.destroy_all_instances() - def test_available_system_events(self): events = ft.available_system_events(system='sched') self.assertTrue(len(events) > 1) self.assertTrue('sched_switch' in events) - ft.create_instance(instance_name) - events = ft.available_system_events(instance=instance_name, - system='sched') + inst = ft.create_instance(instance_name) + events = ft.available_system_events(instance=inst, + system='sched') self.assertTrue(len(events) > 1) self.assertTrue('sched_switch' in events) err = 'function missing required argument' with self.assertRaises(Exception) as context: - ft.available_system_events(instance=instance_name) + ft.available_system_events(instance=inst) self.assertTrue(err in str(context.exception)) - ft.destroy_all_instances() - def test_enable_event(self): - ft.create_instance(instance_name) - - ret = ft.event_is_enabled(instance=instance_name, system='all') + inst = ft.create_instance(instance_name) + ret = ft.event_is_enabled(instance=inst, system='all') self.assertEqual(ret, '0') - ft.enable_event(instance=instance_name, system='all') - ret = ft.event_is_enabled(instance=instance_name, system='all') + ft.enable_event(instance=inst, system='all') + ret = ft.event_is_enabled(instance=inst, system='all') self.assertEqual(ret, '1') - ft.disable_event(instance=instance_name, system='all') - ret = ft.event_is_enabled(instance=instance_name, system='all') + ft.disable_event(instance=inst, system='all') + ret = ft.event_is_enabled(instance=inst, system='all') self.assertEqual(ret, '0') - ret = ft.event_is_enabled(instance=instance_name, event='all') + ret = ft.event_is_enabled(instance=inst, event='all') self.assertEqual(ret, '0') - ft.enable_event(instance=instance_name, event='all') - ret = ft.event_is_enabled(instance=instance_name, event='all') + ft.enable_event(instance=inst, event='all') + ret = ft.event_is_enabled(instance=inst, event='all') self.assertEqual(ret, '1') - ft.disable_event(instance=instance_name, event='all') - ret = ft.event_is_enabled(instance=instance_name, event='all') + ft.disable_event(instance=inst, event='all') + ret = ft.event_is_enabled(instance=inst, event='all') self.assertEqual(ret, '0') - ret = ft.event_is_enabled(instance=instance_name, system='sched') + ret = ft.event_is_enabled(instance=inst, system='sched') self.assertEqual(ret, '0') - ft.enable_event(instance=instance_name, system='sched') - ret = ft.event_is_enabled(instance=instance_name, system='sched') + ft.enable_event(instance=inst, system='sched') + ret = ft.event_is_enabled(instance=inst, system='sched') self.assertEqual(ret, '1') - ft.disable_event(instance=instance_name, system='sched') - ret = ft.event_is_enabled(instance=instance_name, system='sched') + ft.disable_event(instance=inst, system='sched') + ret = ft.event_is_enabled(instance=inst, system='sched') self.assertEqual(ret, '0') - ft.enable_event(instance=instance_name, + ft.enable_event(instance=inst, system='sched', event='sched_switch') - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system='sched', event='sched_switch') self.assertEqual(ret, '1') - ft.disable_event(instance=instance_name, + ft.disable_event(instance=inst, system='sched', event='sched_switch') - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system='sched', event='sched_switch') self.assertEqual(ret, '0') - ft.enable_event(instance=instance_name, + ft.enable_event(instance=inst, system='sched', event='all') - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system='sched', event='all') self.assertEqual(ret, '1') - ft.disable_event(instance=instance_name, + ft.disable_event(instance=inst, system='sched', event='all') - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system='sched', event='all') self.assertEqual(ret, '0') - ft.enable_event(instance=instance_name, + ft.enable_event(instance=inst, event='sched_switch') - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system='sched', event='sched_switch') self.assertEqual(ret, '1') - ft.disable_event(instance=instance_name, + ft.disable_event(instance=inst, event='sched_switch') - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system='sched', event='sched_switch') self.assertEqual(ret, '0') - ft.enable_event(instance=instance_name, + ft.enable_event(instance=inst, system='all', event='sched_switch') - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system='sched', event='sched_switch') self.assertEqual(ret, '1') - ft.disable_event(instance=instance_name, + ft.disable_event(instance=inst, system='all', event='sched_switch') - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system='sched', event='sched_switch') self.assertEqual(ret, '0') - ft.destroy_all_instances() - def test_enable_event_err(self): - ft.create_instance(instance_name) + inst = ft.create_instance(instance_name) err = 'Failed to enable/disable event' with self.assertRaises(Exception) as context: - ft.enable_event(instance=instance_name, + ft.enable_event(instance=inst, system='zero') self.assertTrue(err in str(context.exception)) with self.assertRaises(Exception) as context: - ft.enable_event(instance=instance_name, + ft.enable_event(instance=inst, system='sched', event='zero') self.assertTrue(err in str(context.exception)) - ft.destroy_all_instances() - def test_enable_events(self): - ft.create_instance(instance_name) - ft.enable_events(instance=instance_name, + inst = ft.create_instance(instance_name) + ft.enable_events(instance=inst, events='all') - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, event='all') self.assertEqual(ret, '1') - ft.disable_events(instance=instance_name, + ft.disable_events(instance=inst, events='all') - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, event='all') self.assertEqual(ret, '0') - ft.enable_events(instance=instance_name, + ft.enable_events(instance=inst, systems=['sched', 'irq']) - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system='sched', event='all') self.assertEqual(ret, '1') - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system='irq', event='all') self.assertEqual(ret, '1') - ft.disable_events(instance=instance_name, + ft.disable_events(instance=inst, systems=['sched', 'irq']) - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system='sched', event='all') self.assertEqual(ret, '0') - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system='irq', event='all') self.assertEqual(ret, '0') - ft.enable_events(instance=instance_name, + ft.enable_events(instance=inst, systems=['sched', 'irq'], events=[['sched_switch', 'sched_waking'], ['all']]) - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system='sched', event='sched_switch') self.assertEqual(ret, '1') - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system='sched', event='sched_waking') self.assertEqual(ret, '1') - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system='sched', event='sched_wakeup') self.assertEqual(ret, '0') - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system='irq', event='all') self.assertEqual(ret, '1') - ft.disable_events(instance=instance_name, + ft.disable_events(instance=inst, systems=['sched', 'irq'], events=[['sched_switch', 'sched_waking'], ['all']]) - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system='sched', event='sched_switch') self.assertEqual(ret, '0') - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system='sched', event='sched_waking') self.assertEqual(ret, '0') - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system='irq', event='all') self.assertEqual(ret, '0') - ft.destroy_all_instances() - def test_enable_events_err(self): - ft.create_instance(instance_name) + inst = ft.create_instance(instance_name) err = 'Inconsistent \"events\" argument' with self.assertRaises(Exception) as context: - ft.enable_events(instance=instance_name, + ft.enable_events(instance=inst, systems=['sched'], events=['all']) self.assertTrue(err in str(context.exception)) err = 'Failed to enable events for unspecified system' with self.assertRaises(Exception) as context: - ft.enable_events(instance=instance_name, + ft.enable_events(instance=inst, events=['sched_switch', 'sched_wakeup']) self.assertTrue(err in str(context.exception)) err = 'Failed to enable/disable event' with self.assertRaises(Exception) as context: - ft.enable_events(instance=instance_name, + ft.enable_events(instance=inst, systems=['sched'], events=[['no_event']]) self.assertTrue(err in str(context.exception)) - ft.destroy_all_instances() - class OptionsTestCase(unittest.TestCase): def test_enable_option(self): - ft.create_instance(instance_name) + inst = ft.create_instance(instance_name) opt = 'event-fork' - ret = ft.option_is_set(instance=instance_name, - option=opt) + ret = ft.option_is_set(instance=inst, + option=opt) self.assertFalse(ret) - ft.enable_option(instance=instance_name, + ft.enable_option(instance=inst, option=opt) - ret = ft.option_is_set(instance=instance_name, + ret = ft.option_is_set(instance=inst, option=opt) self.assertTrue(ret) - ft.disable_option(instance=instance_name, + ft.disable_option(instance=inst, option=opt) - ret = ft.option_is_set(instance=instance_name, + ret = ft.option_is_set(instance=inst, option=opt) self.assertFalse(ret) opt = 'no-opt' err = 'Failed to set option \"no-opt\"' with self.assertRaises(Exception) as context: - ft.enable_option(instance=instance_name, + ft.enable_option(instance=inst, option=opt) self.assertTrue(err in str(context.exception)) - ft.destroy_all_instances() - def test_supported_options(self): - ft.create_instance(instance_name) - opts = ft.supported_options(instance_name) + inst = ft.create_instance(instance_name) + opts = ft.supported_options(inst) self.assertTrue(len(opts) > 20) self.assertTrue('event-fork' in opts) - ft.destroy_all_instances() - def test_enabled_options(self): - ft.create_instance(instance_name) - opts = ft.enabled_options(instance_name) + inst = ft.create_instance(instance_name) + opts = ft.enabled_options(inst) n = len(opts) - ft.enable_option(instance=instance_name, option='function-fork') - ft.enable_option(instance=instance_name, option='event-fork') - opts = ft.enabled_options(instance_name) + ft.enable_option(instance=inst, option='function-fork') + ft.enable_option(instance=inst, option='event-fork') + opts = ft.enabled_options(inst) self.assertEqual(len(opts), n + 2) self.assertTrue('event-fork' in opts) self.assertTrue('function-fork' in opts) - ft.destroy_all_instances() class KprobeTestCase(unittest.TestCase): def test_register_kprobe(self): @@ -487,17 +440,17 @@ class KprobeTestCase(unittest.TestCase): ft.register_kprobe(event=evt1, function=evt1_func, probe=evt1_prove) - ft.create_instance(instance_name) - ft.enable_kprobe(instance=instance_name, event=evt1) - ret = ft.kprobe_is_enabled(instance=instance_name, event=evt1) + inst = ft.create_instance(instance_name) + ft.enable_kprobe(instance=inst, event=evt1) + ret = ft.kprobe_is_enabled(instance=inst, event=evt1) self.assertEqual(ret, '1') - ft.disable_kprobe(instance=instance_name, event=evt1) - ret = ft.kprobe_is_enabled(instance=instance_name, event=evt1) + ft.disable_kprobe(instance=inst, event=evt1) + ret = ft.kprobe_is_enabled(instance=inst, event=evt1) self.assertEqual(ret, '0') ft.unregister_kprobe(event='ALL') - ft.destroy_all_instances() + class TracingOnTestCase(unittest.TestCase): def test_ON_OF(self): @@ -505,16 +458,14 @@ class TracingOnTestCase(unittest.TestCase): self.assertTrue(ft.is_tracing_ON()) ft.tracing_OFF() - ft.create_instance(instance_name) - ft.tracing_ON(instance=instance_name) - self.assertTrue(ft.is_tracing_ON(instance=instance_name)) + inst = ft.create_instance(instance_name) + ft.tracing_ON(instance=inst) + self.assertTrue(ft.is_tracing_ON(instance=inst)) self.assertFalse(ft.is_tracing_ON()) - ft.tracing_OFF(instance=instance_name) - - ft.destroy_all_instances() + ft.tracing_OFF(instance=inst) def test_err(self): - err = 'returned a result with an error set' + err = 'incompatible type' with self.assertRaises(Exception) as context: ft.tracing_ON('zero') self.assertTrue(err in str(context.exception)) diff --git a/tests/2_integration/test_01_ftracepy_integration.py b/tests/2_integration/test_01_ftracepy_integration.py index d3b2c6b..824decd 100755 --- a/tests/2_integration/test_01_ftracepy_integration.py +++ b/tests/2_integration/test_01_ftracepy_integration.py @@ -19,18 +19,9 @@ class InstanceTestCase(unittest.TestCase): for i in range(25) : instance_name = 'test_instance_%s' % i - ft.create_instance(instance_name) + inst = ft.create_instance(instance_name) self.assertTrue(os.path.isdir(instances_dir + instance_name)) - for i in range(15) : - instance_name = 'test_instance_%s' % i - ft.destroy_instance(instance_name) - self.assertFalse(os.path.isdir(instances_dir + instance_name)) - - self.assertEqual(len(os.listdir(instances_dir)), 10) - ft.destroy_instance('all') - self.assertEqual(len(os.listdir(instances_dir)), 0) - def test_current_tracer(self): current = ft.get_current_tracer() self.assertEqual(current, 'nop') @@ -42,68 +33,67 @@ class InstanceTestCase(unittest.TestCase): ft.set_current_tracer() instance_name = 'test_instance' - ft.create_instance(instance_name) - current = ft.get_current_tracer(instance=instance_name) + inst = ft.create_instance(instance_name) + current = ft.get_current_tracer(instance=inst) self.assertEqual(current, 'nop') - ft.tracing_OFF(instance=instance_name) - ft.set_current_tracer(instance=instance_name, tracer=name) - current = ft.get_current_tracer(instance=instance_name) + ft.tracing_OFF(instance=inst) + ft.set_current_tracer(instance=inst, tracer=name) + current = ft.get_current_tracer(instance=inst) self.assertEqual(current, name) - ft.destroy_instance('all') def test_enable_events(self): instance_name = 'test_instance' - ft.create_instance(instance_name) - systems = ft.available_event_systems(instance=instance_name) + inst = ft.create_instance(instance_name) + systems = ft.available_event_systems(instance=inst) systems.remove('ftrace') for s in systems: - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system=s) self.assertEqual(ret, '0') - ft.enable_event(instance=instance_name, + ft.enable_event(instance=inst, system=s) - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system=s) self.assertEqual(ret, '1') - ft.disable_event(instance=instance_name, + ft.disable_event(instance=inst, system=s) - events = ft.available_system_events(instance=instance_name, + events = ft.available_system_events(instance=inst, system=s) for e in events: - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system=s, event=e) self.assertEqual(ret, '0') - ft.enable_event(instance=instance_name, + ft.enable_event(instance=inst, system=s, event=e) - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system=s, event=e) self.assertEqual(ret, '1') - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system=s) if e != events[-1]: self.assertEqual(ret, 'X') - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system=s) self.assertEqual(ret, '1') - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system=s) self.assertEqual(ret, '1') - ft.disable_event(instance=instance_name, event='all') + ft.disable_event(instance=inst, event='all') for s in systems: - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system=s) self.assertEqual(ret, '0') - events = ft.available_system_events(instance=instance_name, + events = ft.available_system_events(instance=inst, system=s) for e in events: - ret = ft.event_is_enabled(instance=instance_name, + ret = ft.event_is_enabled(instance=inst, system=s, event=e) self.assertEqual(ret, '0')