From patchwork Mon Jan 24 08:56:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12721684 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 37F1CC433F5 for ; Mon, 24 Jan 2022 08:56:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242515AbiAXI4u (ORCPT ); Mon, 24 Jan 2022 03:56:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242513AbiAXI4u (ORCPT ); Mon, 24 Jan 2022 03:56:50 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6330C06173B for ; Mon, 24 Jan 2022 00:56:49 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id k18so12151920wrg.11 for ; Mon, 24 Jan 2022 00:56:49 -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=wbSbY5kMvK/xAJ4X+/0ppCRwgiYfl9PVGzfAMmaqSGo=; b=my22ImAYUnL8nmy1BJ71o+y3PY5t0uIMkdSOqZOh8xvmt0ggkWbonsYqo6allzicoz gKagR06cc3k7uZIwMOUgqi8Wj09fNsXyYNMXS/PPgtvc5vqlfMBfekIJWfWFW/sbk9Y1 YbMTE4d3qrThhZnz4062/N2VgD+8mBpUQ4bZEp1F0QoaYt8kQQwSSVCjbEXu9RD114Oz VBx2v55GBImH50Rk+Kfu3MxVGKoEd2HhCNscRcxVaVlRLSkp4yR8rvU0Lz8f9QU6u0sO CGdE4O1Q3diH3T0Ms8DHO9+o3zVj7lf6Wc77ZFmkUWGHYWL11Uy5S9zbFolLxWUUVhTL 5pWw== 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=wbSbY5kMvK/xAJ4X+/0ppCRwgiYfl9PVGzfAMmaqSGo=; b=rf3qeuoC2o1iPkF5+K4Sva0fEIS9BmfrJPVHzbkLjqfNwpomCUDrjUhVdF0qmV4sCG Aa7sUSMI09QYGFt1iDTazTPP1rLgccR5OMEUWHHLImAVHG412RGcOwSX3J9/jDlP1fmE l+L+t5GtDvmsmOWhE2uY7ZNRdH7czc/+ZcGLlSDNHRVx+xc9U9mbO+LaABUYcSU6gH2L olJ+4/9GTM4D16jN69H+veZfYz6YOCu94KrojrE1livQgX+eSAfVwLGNGwrqP7aTZIcB oqHYhBscxvfxez91Lq2rY53vSSgaR/9FWFRqr2dX7j1ByMHHGHxrzMt9YeJYeP9vsasu /BVw== X-Gm-Message-State: AOAM530GxySaVMaVdEOeM30oAO/tIgznS4WdLS7mmo79DJIYxxfjFpoO yE8qQMagkRLnZVDg9VW/+yqklY5s8t8= X-Google-Smtp-Source: ABdhPJxp3k9NKAA+f5J/cTUtuHi47KJ4HC6hjFIKwfZ1KyT7SK6WDP2NAZWsztb6VYlih4FOKc/e/Q== X-Received: by 2002:adf:f083:: with SMTP id n3mr6865077wro.323.1643014607924; Mon, 24 Jan 2022 00:56:47 -0800 (PST) Received: from crow.eng.vmware.com ([146.247.46.134]) by smtp.gmail.com with ESMTPSA id f14sm14828091wri.44.2022.01.24.00.56.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 00:56:47 -0800 (PST) From: "Yordan Karadzhov (VMware)" To: linux-trace-devel@vger.kernel.org Cc: "Yordan Karadzhov (VMware)" Subject: [PATCH 01/10] trace-cruncher: Define Python type for synthetic events Date: Mon, 24 Jan 2022 10:56:16 +0200 Message-Id: <20220124085625.92297-2-y.karadz@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220124085625.92297-1-y.karadz@gmail.com> References: <20220124085625.92297-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Addind new Python type and constructor for it: synth() The new type 'PySynthEvent will be used to implement APIs for working with synthetic events. Signed-off-by: Yordan Karadzhov (VMware) --- src/ftracepy-utils.c | 58 ++++++++++++++++++++++++++++++++++++++++++++ src/ftracepy-utils.h | 5 ++++ src/ftracepy.c | 17 +++++++++++++ 3 files changed, 80 insertions(+) diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c index cecb180..1fcf2f8 100644 --- a/src/ftracepy-utils.c +++ b/src/ftracepy-utils.c @@ -2426,6 +2426,64 @@ PyObject *PyFtrace_hist(PyObject *self, PyObject *args, return NULL; } +PyObject *PyFtrace_synth(PyObject *self, PyObject *args, + PyObject *kwargs) +{ + const char *name, *start_match, *end_match, *match_name=NULL; + const char *start_sys, *start_evt, *end_sys, *end_evt; + static char *kwlist[] = {"name", + "start_sys", + "start_evt", + "end_sys", + "end_evt", + "start_match", + "end_match", + "match_name", + NULL}; + static struct tracefs_synth *synth; + struct tep_handle *tep; + PyObject *py_synth; + + if (!PyArg_ParseTupleAndKeywords(args, + kwargs, + "sssssss|s", + kwlist, + &name, + &start_sys, + &start_evt, + &end_sys, + &end_evt, + &start_match, + &end_match, + &match_name)) { + return NULL; + } + + tep = get_tep(NULL, NULL); + if (!tep) + return NULL; + + synth = tracefs_synth_alloc(tep, name, + start_sys, start_evt, + end_sys, end_evt, + start_match, end_match, + match_name); + tep_free(tep); + if (!synth) { + MEM_ERROR; + return NULL; + } + + py_synth = PySynthEvent_New(synth); + /* + * Here we only allocated and initializes a synthetic event object. + * However, no synthetic event is added to the system yet. Hence, + * there is no need to 'destroy' this event at exit. + */ + set_destroy_flag(py_synth, false); + return py_synth; +} + PyObject *PyFtrace_set_ftrace_loglevel(PyObject *self, PyObject *args, PyObject *kwargs) { diff --git a/src/ftracepy-utils.h b/src/ftracepy-utils.h index fc5016c..e8db811 100644 --- a/src/ftracepy-utils.h +++ b/src/ftracepy-utils.h @@ -30,6 +30,8 @@ C_OBJECT_WRAPPER_DECLARE(tracefs_dynevent, PyDynevent); C_OBJECT_WRAPPER_DECLARE(tracefs_hist, PyTraceHist) +C_OBJECT_WRAPPER_DECLARE(tracefs_synth, PySynthEvent) + PyObject *PyTepRecord_time(PyTepRecord* self); PyObject *PyTepRecord_cpu(PyTepRecord* self); @@ -210,6 +212,9 @@ PyObject *PyFtrace_register_kretprobe(PyObject *self, PyObject *args, PyObject *PyFtrace_hist(PyObject *self, PyObject *args, PyObject *kwargs); +PyObject *PyFtrace_synth(PyObject *self, PyObject *args, + PyObject *kwargs); + PyObject *PyFtrace_set_ftrace_loglevel(PyObject *self, PyObject *args, PyObject *kwargs); diff --git a/src/ftracepy.c b/src/ftracepy.c index f59bd4c..f8b8b36 100644 --- a/src/ftracepy.c +++ b/src/ftracepy.c @@ -221,6 +221,14 @@ C_OBJECT_WRAPPER(tracefs_hist, PyTraceHist, NO_DESTROY, tracefs_hist_free) +static PyMethodDef PySynthEvent_methods[] = { + {NULL, NULL, 0, NULL} +}; + +C_OBJECT_WRAPPER(tracefs_synth, PySynthEvent, + tracefs_synth_destroy, + tracefs_synth_free) + static PyMethodDef ftracepy_methods[] = { {"dir", (PyCFunction) PyFtrace_dir, @@ -382,6 +390,11 @@ static PyMethodDef ftracepy_methods[] = { METH_VARARGS | METH_KEYWORDS, "Define a histogram." }, + {"synth", + (PyCFunction) PyFtrace_synth, + METH_VARARGS | METH_KEYWORDS, + "Define a synthetic event." + }, {"set_ftrace_loglevel", (PyCFunction) PyFtrace_set_ftrace_loglevel, METH_VARARGS | METH_KEYWORDS, @@ -453,6 +466,9 @@ PyMODINIT_FUNC PyInit_ftracepy(void) if (!PyTraceHistTypeInit()) return NULL; + if (!PySynthEventTypeInit()) + return NULL; + TFS_ERROR = PyErr_NewException("tracecruncher.ftracepy.tfs_error", NULL, NULL); @@ -470,6 +486,7 @@ PyMODINIT_FUNC PyInit_ftracepy(void) PyModule_AddObject(module, "tracefs_instance", (PyObject *) &PyTfsInstanceType); PyModule_AddObject(module, "tracefs_dynevent", (PyObject *) &PyDyneventType); PyModule_AddObject(module, "tracefs_hist", (PyObject *) &PyTraceHistType); + PyModule_AddObject(module, "tracefs_synth", (PyObject *) &PySynthEventType); PyModule_AddObject(module, "tfs_error", TFS_ERROR); PyModule_AddObject(module, "tep_error", TEP_ERROR); From patchwork Mon Jan 24 08:56:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12721685 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 BE2FBC433EF for ; Mon, 24 Jan 2022 08:56:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242521AbiAXI4v (ORCPT ); Mon, 24 Jan 2022 03:56:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242513AbiAXI4u (ORCPT ); Mon, 24 Jan 2022 03:56:50 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74D24C06173B for ; Mon, 24 Jan 2022 00:56:50 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id r22so4530002wra.8 for ; Mon, 24 Jan 2022 00:56:50 -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=rajKJMk9i6OCX0+djnhFnxB55Z2bVgQHo2bOyQaRtxc=; b=FlQti5Y5s4Qg8j5jccKu2EJZk1cirGzco/JpeiA/hMOuGuQQu6p2x6HZNm3+bEyQBl YXrvddSA5LzLs/IJULGHMvAEUqPz5ASqZVmtHF78Phz6P3ZJ3zTiIrkhVe35L282LLJV eyGX2CDBQ0AJ5CdcPjya3/aTYHbrNtgMjSuG/8SEUo1UCGvpajXs15LCzHxPhnuo778n acnVUlpVc01fRXkx1B+u7UY95isubQgskg3DciUteslnpQjQjYbVaQRzh0nDUUznoKFE /LFTIzGjL8thVvMqugV4oNb1Jece0e8EI8b8fu8nuigG6hldpsIVrmjwBJjNFx36o2cU 1ubw== 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=rajKJMk9i6OCX0+djnhFnxB55Z2bVgQHo2bOyQaRtxc=; b=8L7VYiCO/oPaavFx4zWteckLhL8TCTmFqjIOLYULyOefH53ibbc51tvC9kAVP22Dj2 ezIRVPUgyseUMlumcFkNoXPuqERUEO7tEkZabjuf4AakT9YQ68naJibkAneXAoKjx96r 3N9nS8RgGa7FS+HjrzQHcC5RvciOsmnI+Blo/nF42Frx9JxIA3MioN/3pffLW8c/lpfD zCai+T4IwqiQTW4gvwYT0ufPCsCC3aIgatQkDipGGjldfDO1FNSOrxtMRT1HF743GECj E2TmJMWKpq7Ha9ZUnhBupXgVeoETd9rFvqZ1MjaVSrm0At7QGVetelY8UkgLLUqVUB5W VPCg== X-Gm-Message-State: AOAM532fdVFPGS5xiYxThFQIAFiuyivZjfReHGAkpdBRS3EyX14XgjDE IMuJfYiEoCl9PmR5nzwTAkrJqToMpeU= X-Google-Smtp-Source: ABdhPJzHJQIOE4h3RF1mEocR485L13Pd87Ry3yJzm1hGqS9VTLwdH/U9QPHYyHm77KrzXJ4rNv9awA== X-Received: by 2002:a05:6000:1846:: with SMTP id c6mr12114426wri.244.1643014608809; Mon, 24 Jan 2022 00:56:48 -0800 (PST) Received: from crow.eng.vmware.com ([146.247.46.134]) by smtp.gmail.com with ESMTPSA id f14sm14828091wri.44.2022.01.24.00.56.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 00:56:48 -0800 (PST) From: "Yordan Karadzhov (VMware)" To: linux-trace-devel@vger.kernel.org Cc: "Yordan Karadzhov (VMware)" Subject: [PATCH 02/10] trace-cruncher: APIs for adding start/end fields to synth. event Date: Mon, 24 Jan 2022 10:56:17 +0200 Message-Id: <20220124085625.92297-3-y.karadz@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220124085625.92297-1-y.karadz@gmail.com> References: <20220124085625.92297-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Here we add the following methods to the Python type for synthetic events: add_start_fields() add_end_fields() The new APIs allows for adding fields from the original 'start' and 'end' events to the new synthetic event. Signed-off-by: Yordan Karadzhov (VMware) --- src/ftracepy-utils.c | 64 ++++++++++++++++++++++++++++++++++++++++++++ src/ftracepy-utils.h | 6 +++++ src/ftracepy.c | 10 +++++++ 3 files changed, 80 insertions(+) diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c index 1fcf2f8..42bd9d0 100644 --- a/src/ftracepy-utils.c +++ b/src/ftracepy-utils.c @@ -1009,6 +1009,70 @@ PyObject *PyTraceHist_close(PyTraceHist *self, PyObject *args, Py_RETURN_NONE; } +typedef int (*add_field_ptr)(struct tracefs_synth *, + const char *, + const char *); + +PyObject *synth_add_fields(PySynthEvent *self, PyObject *args, + PyObject *kwargs, + bool to_start) +{ + static char *kwlist[] = {"fields", "names", NULL}; + PyObject *py_fields, *py_names = NULL; + PyObject *item_field, *item_name; + add_field_ptr add_field_func; + const char *field, *name; + int ret, n, i; + + if (!PyArg_ParseTupleAndKeywords(args, + kwargs, + "O|O", + kwlist, + &py_fields, + &py_names)) { + return NULL; + } + + add_field_func = to_start ? tracefs_synth_add_start_field: + tracefs_synth_add_end_field; + + n = PyList_Size(py_fields); + for (i = 0; i < n; ++i) { + item_field = PyList_GetItem(py_fields, i); + field = PyUnicode_DATA(item_field); + + name = NULL; + if (py_names) { + item_name = PyList_GetItem(py_names, i); + if (item_name && item_name != Py_None) + name = PyUnicode_DATA(item_name); + } + + ret = add_field_func(self->ptrObj, field, name); + if (ret < 0) { + TfsError_fmt(NULL, + "Failed to add %s field '%s' to synth. event %s", + to_start ? "start" : "end", field, + tracefs_synth_get_name(self->ptrObj)); + return NULL; + } + } + + Py_RETURN_NONE; +} + +PyObject *PySynthEvent_add_start_fields(PySynthEvent *self, PyObject *args, + PyObject *kwargs) +{ + return synth_add_fields(self, args, kwargs, true); +} + +PyObject *PySynthEvent_add_end_fields(PySynthEvent *self, PyObject *args, + PyObject *kwargs) +{ + return synth_add_fields(self, args, kwargs, false); +} + PyObject *PyFtrace_dir(PyObject *self) { return PyUnicode_FromString(tracefs_tracing_dir()); diff --git a/src/ftracepy-utils.h b/src/ftracepy-utils.h index e8db811..3c6c0f3 100644 --- a/src/ftracepy-utils.h +++ b/src/ftracepy-utils.h @@ -121,6 +121,12 @@ PyObject *PyTraceHist_read(PyTraceHist *self, PyObject *args, PyObject *PyTraceHist_close(PyTraceHist *self, PyObject *args, PyObject *kwargs); +PyObject *PySynthEvent_add_start_fields(PySynthEvent *self, PyObject *args, + PyObject *kwargs); + +PyObject *PySynthEvent_add_end_fields(PySynthEvent *self, PyObject *args, + PyObject *kwargs); + PyObject *PyFtrace_dir(PyObject *self); PyObject *PyFtrace_detach(PyObject *self, PyObject *args, PyObject *kwargs); diff --git a/src/ftracepy.c b/src/ftracepy.c index f8b8b36..44114f0 100644 --- a/src/ftracepy.c +++ b/src/ftracepy.c @@ -222,6 +222,16 @@ C_OBJECT_WRAPPER(tracefs_hist, PyTraceHist, tracefs_hist_free) static PyMethodDef PySynthEvent_methods[] = { + {"add_start_fields", + (PyCFunction) PySynthEvent_add_start_fields, + METH_VARARGS | METH_KEYWORDS, + "Add fields from the start event to save." + }, + {"add_end_fields", + (PyCFunction) PySynthEvent_add_end_fields, + METH_VARARGS | METH_KEYWORDS, + "Add fields from the end event to save." + }, {NULL, NULL, 0, NULL} }; From patchwork Mon Jan 24 08:56:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12721686 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 31B62C433FE for ; Mon, 24 Jan 2022 08:56:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242518AbiAXI4v (ORCPT ); Mon, 24 Jan 2022 03:56:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242522AbiAXI4v (ORCPT ); Mon, 24 Jan 2022 03:56:51 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B6D3C06173D for ; Mon, 24 Jan 2022 00:56:51 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id r14so1591956wrc.6 for ; Mon, 24 Jan 2022 00:56:51 -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=9tAHNhhRNdTYm1Qet3axot0lJ8+/Ofd4flCPsYy5/T4=; b=cmCrZJ6KRogXH8w8xF1cDodFs7KqvedxCPEPJ3MAs1+JkT57tDsblI5YPfhclxjq+g kI+uxO7cbSPxq3Xuo2f6tyxnn7EyrfgVB5PP13IihsioGsgC0PXOf5ky2vtdobf6taJz zTV3B+Mr2qKUAAjhOGRtAxLSEuMmeMF+YwwXZMVdh0f6joLyXAgTGzxsCwna6fAVlFJE HM8J5LYjooJuemdVt130xElP0oFowcs8ltJOHon9LMf2hsLhJ9Mjb1ihp1y3BEGcRBs+ PjzKFnEzcuMy4rh5vT/ug6soHrF/fXodr3ARPD7jbk8b979Bv6Xa3ZjQROvKYx4iMT+Z 2EAA== 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=9tAHNhhRNdTYm1Qet3axot0lJ8+/Ofd4flCPsYy5/T4=; b=LveJYrWWsXex2hW7P0UpefIVCeiiAnHafwa0sS8g06TGEGEZjJBcy9K7pIM924bUaa ZFX3S15XYPeOfyQK95SQyNpZhYlbfnjZ4lbV/eDx02uzC4PAPpvpPvisCjwfofF2F16P 7LfYVeVj3G9+DVd0ZA0kxnfB9XHuSBO5zclZwYvaapniNyHTIAt5Uiy+QpkD2J6dlKIW GMVkyxALuIitfVNqq5236U0p1/GREG4lkNjkHSpSK4xcRY+06lho//bzUk+QD8LdagD4 u3gNGhf1S+036ZlIWLuZFzhtFJ0bkZ4u07L+JYfxNW1zuCtC7nkypsnUObhxl2gvGA5Q fzFA== X-Gm-Message-State: AOAM530cT7LCQXXjvLCj3Oml4McBcV2KM1viqwjroCd2fYUAmyn2PvbU 23e3RqBmfwx/9YlpmmsK9qDYO40kIx8= X-Google-Smtp-Source: ABdhPJwDtUkUa3UYr348kcwF+K3i6gkRMIY6KBCVdwEZ1hNBz9b+5n9bPTryPSpeoyzfW5gJN7CZ7Q== X-Received: by 2002:a5d:6f17:: with SMTP id ay23mr13287362wrb.135.1643014609533; Mon, 24 Jan 2022 00:56:49 -0800 (PST) Received: from crow.eng.vmware.com ([146.247.46.134]) by smtp.gmail.com with ESMTPSA id f14sm14828091wri.44.2022.01.24.00.56.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 00:56:49 -0800 (PST) From: "Yordan Karadzhov (VMware)" To: linux-trace-devel@vger.kernel.org Cc: "Yordan Karadzhov (VMware)" Subject: [PATCH 03/10] trace-cruncher: APIs for adding arithmetic fields to synth. events Date: Mon, 24 Jan 2022 10:56:18 +0200 Message-Id: <20220124085625.92297-4-y.karadz@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220124085625.92297-1-y.karadz@gmail.com> References: <20220124085625.92297-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Here we add the following methods to the Python type for synthetic events: add_delta_start(), add_delta_end(), add_delta_T(), add_sum() The new APIs allows for adding to the new synthetic event, fields that are calculated from the fields of the original 'start' and 'end' events by using simple addition or subtraction. Signed-off-by: Yordan Karadzhov (VMware) --- src/ftracepy-utils.c | 81 ++++++++++++++++++++++++++++++++++++++++++++ src/ftracepy-utils.h | 12 +++++++ src/ftracepy.c | 20 +++++++++++ 3 files changed, 113 insertions(+) diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c index 42bd9d0..9245b07 100644 --- a/src/ftracepy-utils.c +++ b/src/ftracepy-utils.c @@ -1073,6 +1073,87 @@ PyObject *PySynthEvent_add_end_fields(PySynthEvent *self, PyObject *args, return synth_add_fields(self, args, kwargs, false); } +static inline void add_synth_field_err(const char *field, const char *event) +{ + TfsError_fmt(NULL, "Failed to add field '%s' to synth. event %s", + field, event); +} + +static inline PyObject * +add_synth_field(PySynthEvent *self, PyObject *args, PyObject *kwargs, + enum tracefs_synth_calc calc) +{ + static char *kwlist[] = {"name", "start_field", "end_field", NULL}; + const char *start_field, *end_field, *name; + int ret; + + if (!PyArg_ParseTupleAndKeywords(args, + kwargs, + "sss", + kwlist, + &name, + &start_field, + &end_field)) { + return NULL; + } + + ret = tracefs_synth_add_compare_field(self->ptrObj, + start_field, end_field, calc, + name); + if (ret < 0) { + add_synth_field_err(name, tracefs_synth_get_name(self->ptrObj)); + return NULL; + } + + Py_RETURN_NONE; +} + +PyObject *PySynthEvent_add_delta_start(PySynthEvent *self, PyObject *args, + PyObject *kwargs) +{ + return add_synth_field(self, args, kwargs, TRACEFS_SYNTH_DELTA_START); +} + +PyObject *PySynthEvent_add_delta_end(PySynthEvent *self, PyObject *args, + PyObject *kwargs) +{ + return add_synth_field(self, args, kwargs, TRACEFS_SYNTH_DELTA_END); +} + +PyObject *PySynthEvent_add_sum(PySynthEvent *self, PyObject *args, + PyObject *kwargs) +{ + return add_synth_field(self, args, kwargs, TRACEFS_SYNTH_ADD); +} + +PyObject *PySynthEvent_add_delta_T(PySynthEvent *self, PyObject *args, + PyObject *kwargs) +{ + static char *kwlist[] = {"name", "hd", NULL}; + const char *name = "delta_T"; + const char* time_rez; + int ret, hd = 0; + + if (!PyArg_ParseTupleAndKeywords(args, + kwargs, + "|sp", + kwlist, + &name, + &hd)) { + return NULL; + } + + time_rez = hd ? TRACEFS_TIMESTAMP : TRACEFS_TIMESTAMP_USECS; + ret = tracefs_synth_add_compare_field(self->ptrObj, time_rez, time_rez, + TRACEFS_SYNTH_DELTA_END, name); + if (ret < 0) { + add_synth_field_err(name, tracefs_synth_get_name(self->ptrObj)); + return NULL; + } + + Py_RETURN_NONE; +} + PyObject *PyFtrace_dir(PyObject *self) { return PyUnicode_FromString(tracefs_tracing_dir()); diff --git a/src/ftracepy-utils.h b/src/ftracepy-utils.h index 3c6c0f3..7b798fc 100644 --- a/src/ftracepy-utils.h +++ b/src/ftracepy-utils.h @@ -127,6 +127,18 @@ PyObject *PySynthEvent_add_start_fields(PySynthEvent *self, PyObject *args, PyObject *PySynthEvent_add_end_fields(PySynthEvent *self, PyObject *args, PyObject *kwargs); +PyObject *PySynthEvent_add_delta_start(PySynthEvent *self, PyObject *args, + PyObject *kwargs); + +PyObject *PySynthEvent_add_delta_end(PySynthEvent *self, PyObject *args, + PyObject *kwargs); + +PyObject *PySynthEvent_add_delta_T(PySynthEvent *self, PyObject *args, + PyObject *kwargs); + +PyObject *PySynthEvent_add_sum(PySynthEvent *self, PyObject *args, + PyObject *kwargs); + PyObject *PyFtrace_dir(PyObject *self); PyObject *PyFtrace_detach(PyObject *self, PyObject *args, PyObject *kwargs); diff --git a/src/ftracepy.c b/src/ftracepy.c index 44114f0..066fc65 100644 --- a/src/ftracepy.c +++ b/src/ftracepy.c @@ -232,6 +232,26 @@ static PyMethodDef PySynthEvent_methods[] = { METH_VARARGS | METH_KEYWORDS, "Add fields from the end event to save." }, + {"add_delta_start", + (PyCFunction) PySynthEvent_add_delta_start, + METH_VARARGS | METH_KEYWORDS, + "Add 'start - end' field." + }, + {"add_delta_end", + (PyCFunction) PySynthEvent_add_delta_end, + METH_VARARGS | METH_KEYWORDS, + "Add 'end - start' field." + }, + {"add_delta_T", + (PyCFunction) PySynthEvent_add_delta_T, + METH_VARARGS | METH_KEYWORDS, + "Add time-difference field." + }, + {"add_sum", + (PyCFunction) PySynthEvent_add_delta_T, + METH_VARARGS | METH_KEYWORDS, + "Add 'start + end' field." + }, {NULL, NULL, 0, NULL} }; From patchwork Mon Jan 24 08:56:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12721687 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 E7BDBC433F5 for ; Mon, 24 Jan 2022 08:56:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242520AbiAXI4y (ORCPT ); Mon, 24 Jan 2022 03:56:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242514AbiAXI4x (ORCPT ); Mon, 24 Jan 2022 03:56:53 -0500 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75782C061401 for ; Mon, 24 Jan 2022 00:56:53 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id n12-20020a05600c3b8c00b0034eb13edb8eso2064062wms.0 for ; Mon, 24 Jan 2022 00:56:53 -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=axfKaeOWgwNORJl845veEXj9grVMhyGAIBbWQqicf4A=; b=kyvESqjIlFeApV5OMXIYs3vEI+pVTo8DaTaKOukT5wtYIDVp/jaKQ7tnToDlBGh3xI 6gVyOpHf9Uo1zfOmpd/MZzqfw1Er9kg08F+VZ03i50pb+cXMvkmRVlSRnf7qwk/euway +m4YznD1i4aBpZ4FzcPzgIWCaCHvNebXlEiPcPjt1QNkKsO2OL6zeKpPa01YRbztMvZ+ vnZ9R/RSZW9KqBpWAJrz+rrCiGP+e6hB1aDp0c/KnBaDPizghirkWnDRzSnX0sCl5LI0 RNjIkcx3C91lvEBa3qxfiPq1nizgSF8A1y8GH3QhSjRogAq09KrQ2Rm2b0+2X2Gi1QKr cHCw== 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=axfKaeOWgwNORJl845veEXj9grVMhyGAIBbWQqicf4A=; b=BXASIpT6P65Q1phA6ldZm7GApP4UgmoHv56RYKIAVjHm1tFmKSWNA9uyTWaCSCFHO0 MIMWhNsDufAEmqyGsjglaxA+Ek399zllFMYlfqgbsKhVat013sGtTpjrF7KAgVyjd6iG FJKSmo8fSaUlpvTq3JQnoKx4pqYh7zz9SgkU8O0e00oQvVsx3AHChyY52f/3OrDn/vjB W18TOQeil9c0AX3EUVr1sM90SXbC8ZFJMrszeAp4StS92WphLufbM+HdcYrVTSMHmzlZ pPz3CFsxEbU8nrvIU6jT4cxc9tB0AkfCvE0tGZ2aisa0HtO3uZr3U6vQRaQAcybztZOm Px+Q== X-Gm-Message-State: AOAM532B/EZKvMIcy8Sbfba+OF+i5GocIb2TNDeIBZl8V9hN2uOXHli/ /I7H7zPd5X+K+DWU7A12EqJxSZ7GY/g= X-Google-Smtp-Source: ABdhPJyNSCuP41dXs/gm5TNg+0wx/6Y45zGE/MObq6o3zVPsADhPFSsR7XoHqvooJ4jt6+FWPEQgtA== X-Received: by 2002:a7b:c14b:: with SMTP id z11mr868319wmi.67.1643014611919; Mon, 24 Jan 2022 00:56:51 -0800 (PST) Received: from crow.eng.vmware.com ([146.247.46.134]) by smtp.gmail.com with ESMTPSA id f14sm14828091wri.44.2022.01.24.00.56.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 00:56:49 -0800 (PST) From: "Yordan Karadzhov (VMware)" To: linux-trace-devel@vger.kernel.org Cc: "Yordan Karadzhov (VMware)" Subject: [PATCH 04/10] trace-cruncher: APIs for registering/unregistering synth. events Date: Mon, 24 Jan 2022 10:56:19 +0200 Message-Id: <20220124085625.92297-5-y.karadz@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220124085625.92297-1-y.karadz@gmail.com> References: <20220124085625.92297-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Here we add the following methods to the Python type for synthetic events: register() unregister() The constructor only creates the objects that describe the new synthetic event. We need to use those new APIs in order to actually create/destroy the event into the system. Signed-off-by: Yordan Karadzhov (VMware) --- src/ftracepy-utils.c | 42 +++++++++++++++++++++++++++++++++++++----- src/ftracepy-utils.h | 4 ++++ src/ftracepy.c | 10 ++++++++++ 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c index 9245b07..244bff9 100644 --- a/src/ftracepy-utils.c +++ b/src/ftracepy-utils.c @@ -1154,17 +1154,49 @@ PyObject *PySynthEvent_add_delta_T(PySynthEvent *self, PyObject *args, Py_RETURN_NONE; } -PyObject *PyFtrace_dir(PyObject *self) -{ - return PyUnicode_FromString(tracefs_tracing_dir()); -} - static void set_destroy_flag(PyObject *py_obj, bool val) { PyFtrace_Object_HEAD *obj_head = (PyFtrace_Object_HEAD *)py_obj; obj_head->destroy = val; } +PyObject *PySynthEvent_register(PySynthEvent *self) +{ + if (tracefs_synth_create(self->ptrObj) < 0) { + TfsError_fmt(NULL, "Failed to register synth. event %s", + tracefs_synth_get_name(self->ptrObj)); + return NULL; + } + + /* + * Here the synthetic event gets added to the system. + * Hence we need to 'destroy' this event at exit. + */ + set_destroy_flag((PyObject *)self, true); + Py_RETURN_NONE; +} + +PyObject *PySynthEvent_unregister(PySynthEvent *self) +{ + if (tracefs_synth_destroy(self->ptrObj) < 0) { + TfsError_fmt(NULL, "Failed to unregister synth. event %s", + tracefs_synth_get_name(self->ptrObj)); + return NULL; + } + + /* + * Here the synthetic event gets removed from the system. + * Hence we no loger need to 'destroy' this event at exit. + */ + set_destroy_flag((PyObject *)self, false); + Py_RETURN_NONE; +} + +PyObject *PyFtrace_dir(PyObject *self) +{ + return PyUnicode_FromString(tracefs_tracing_dir()); +} + static PyObject *set_destroy(PyObject *args, PyObject *kwargs, bool destroy) { static char *kwlist[] = {"object", NULL}; diff --git a/src/ftracepy-utils.h b/src/ftracepy-utils.h index 7b798fc..40b41d8 100644 --- a/src/ftracepy-utils.h +++ b/src/ftracepy-utils.h @@ -139,6 +139,10 @@ PyObject *PySynthEvent_add_delta_T(PySynthEvent *self, PyObject *args, PyObject *PySynthEvent_add_sum(PySynthEvent *self, PyObject *args, PyObject *kwargs); +PyObject *PySynthEvent_register(PySynthEvent *self); + +PyObject *PySynthEvent_unregister(PySynthEvent *self); + PyObject *PyFtrace_dir(PyObject *self); PyObject *PyFtrace_detach(PyObject *self, PyObject *args, PyObject *kwargs); diff --git a/src/ftracepy.c b/src/ftracepy.c index 066fc65..0314aa1 100644 --- a/src/ftracepy.c +++ b/src/ftracepy.c @@ -252,6 +252,16 @@ static PyMethodDef PySynthEvent_methods[] = { METH_VARARGS | METH_KEYWORDS, "Add 'start + end' field." }, + {"register", + (PyCFunction) PySynthEvent_register, + METH_NOARGS, + "Register synth. event to a trace instance." + }, + {"unregister", + (PyCFunction) PySynthEvent_unregister, + METH_NOARGS, + "Unregister synth. event from a trace instance." + }, {NULL, NULL, 0, NULL} }; From patchwork Mon Jan 24 08:56:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12721688 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 39951C433EF for ; Mon, 24 Jan 2022 08:56:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242513AbiAXI4y (ORCPT ); Mon, 24 Jan 2022 03:56:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242517AbiAXI4y (ORCPT ); Mon, 24 Jan 2022 03:56:54 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4296AC06173B for ; Mon, 24 Jan 2022 00:56:54 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id s18so12165757wrv.7 for ; Mon, 24 Jan 2022 00:56:54 -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=CnLOh1CO/wK4ERt6Hj2WUyNRMmSpSpZ91QAySy6CmT4=; b=CqZQke8ihK8VCH+Znd1F3kC7T7/lOMnCNM5vUccwd/RQhey77PLk+aM27ucELpc8yc uo4BQAwF2it+cKuI/DVfkBvSbM8pJ29AtLuqRQeKT63VqfVycUzyTzIOXgQjWZ6PvSuc +1duoRpQdPP+BI9CN24yoJZCXg7SxYmf0oo3csGTYZ6N1MkLITR6rjaCbjBeL7/g1zzZ iDw9VOm1klhvabgXopsFY3cUscUN9MXSFKUXW0BWKxD2OZRaJNJ4ZRtsi73n+3P7Z2bb JfDXr7cZJa2Xx3q3Fnq6jrDTm6Dpugb55Tx+xIqCMR36gGT/tBANC2klH8ygTdFglYNq PuJQ== 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=CnLOh1CO/wK4ERt6Hj2WUyNRMmSpSpZ91QAySy6CmT4=; b=Gev0PApUQgkbdTDIgxse4mJ2Xq7fIHCbhITIGUMW5OcCaNRXVzrF2NGmv1iGthGVYU mibUEIK1f0uqy0S+tl/Ht7yikNHiwx28tBvCwRxqEw7B8s4EP7fkAZtqFTVUCiOPyxQV NmRtmVrnq+X3CWUxSwHx3jx9Io88AX+zN64vfTlZl/dmg+vBqXCCM6dLWAn0jPTDJ78F Gx17WsQjVM+u6XH/Jt1hRmAYwtiHN8Vy4BOcxVyLzIm6jTIjBQu9ZiARNzARFkvlbWco bRuTItsvBvlEQZ06KQ5i5Y1fTLfpzeT97ZzWogYsIwcZlrFMN9xokUqZuuRjDLEGamA5 LQDQ== X-Gm-Message-State: AOAM532ntF8AhT/R+w8svGdzKlCyr89iJEe8w4in4ZfRTnJYeTXg1lRD 0G6Ab47+2Tm7iavWc5ebNklGz9BL4po= X-Google-Smtp-Source: ABdhPJzbHcONK0RS9qvG1QJIgS45+JaOTGZUtsSWmnvDcj2i6NcOMxqB3JstpB4o9mTY68rmqSZzPA== X-Received: by 2002:adf:dec3:: with SMTP id i3mr6968376wrn.225.1643014612650; Mon, 24 Jan 2022 00:56:52 -0800 (PST) Received: from crow.eng.vmware.com ([146.247.46.134]) by smtp.gmail.com with ESMTPSA id f14sm14828091wri.44.2022.01.24.00.56.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 00:56:52 -0800 (PST) From: "Yordan Karadzhov (VMware)" To: linux-trace-devel@vger.kernel.org Cc: "Yordan Karadzhov (VMware)" Subject: [PATCH 05/10] trace-cruncher: APIs for enabling synth. events Date: Mon, 24 Jan 2022 10:56:20 +0200 Message-Id: <20220124085625.92297-6-y.karadz@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220124085625.92297-1-y.karadz@gmail.com> References: <20220124085625.92297-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Here we add the following methods to the Python type for synthetic events: enable() disable() is_enabled() The 3 new APIs replicate the APIs available for kpobes. Signed-off-by: Yordan Karadzhov (VMware) --- src/ftracepy-utils.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ src/ftracepy-utils.h | 9 +++++++++ src/ftracepy.c | 15 +++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c index 244bff9..8a0c3c3 100644 --- a/src/ftracepy-utils.c +++ b/src/ftracepy-utils.c @@ -2661,6 +2661,51 @@ PyObject *PyFtrace_synth(PyObject *self, PyObject *args, return py_synth; } +#define SYNTH_SYS "synthetic" + +static bool enable_synth(PySynthEvent *self, PyObject *args, PyObject *kwargs, + bool enable) +{ + struct tracefs_instance *instance; + + if (!get_instance_from_arg(args, kwargs, &instance)) + return NULL; + + return event_enable_disable(instance, SYNTH_SYS, + tracefs_synth_get_name(self->ptrObj), + enable); +} + +PyObject *PySynthEvent_enable(PySynthEvent *self, PyObject *args, + PyObject *kwargs) +{ + if (!enable_synth(self, args, kwargs, true)) + return NULL; + + Py_RETURN_NONE; +} + +PyObject *PySynthEvent_disable(PySynthEvent *self, PyObject *args, + PyObject *kwargs) +{ + if (!enable_synth(self, args, kwargs, false)) + return NULL; + + Py_RETURN_NONE; +} + +PyObject *PySynthEvent_is_enabled(PySynthEvent *self, PyObject *args, + PyObject *kwargs) +{ + struct tracefs_instance *instance; + + if (!get_instance_from_arg(args, kwargs, &instance)) + return NULL; + + return event_is_enabled(instance, SYNTH_SYS, + tracefs_synth_get_name(self->ptrObj)); +} + PyObject *PyFtrace_set_ftrace_loglevel(PyObject *self, PyObject *args, PyObject *kwargs) { diff --git a/src/ftracepy-utils.h b/src/ftracepy-utils.h index 40b41d8..daf1a19 100644 --- a/src/ftracepy-utils.h +++ b/src/ftracepy-utils.h @@ -143,6 +143,15 @@ PyObject *PySynthEvent_register(PySynthEvent *self); PyObject *PySynthEvent_unregister(PySynthEvent *self); +PyObject *PySynthEvent_enable(PySynthEvent *self, PyObject *args, + PyObject *kwargs); + +PyObject *PySynthEvent_disable(PySynthEvent *self, PyObject *args, + PyObject *kwargs); + +PyObject *PySynthEvent_is_enabled(PySynthEvent *self, PyObject *args, + PyObject *kwargs); + PyObject *PyFtrace_dir(PyObject *self); PyObject *PyFtrace_detach(PyObject *self, PyObject *args, PyObject *kwargs); diff --git a/src/ftracepy.c b/src/ftracepy.c index 0314aa1..62c6de0 100644 --- a/src/ftracepy.c +++ b/src/ftracepy.c @@ -262,6 +262,21 @@ static PyMethodDef PySynthEvent_methods[] = { METH_NOARGS, "Unregister synth. event from a trace instance." }, + {"enable", + (PyCFunction) PySynthEvent_enable, + METH_VARARGS | METH_KEYWORDS, + "Enable synth. event." + }, + {"disable", + (PyCFunction) PySynthEvent_disable, + METH_VARARGS | METH_KEYWORDS, + "Disable synth. event." + }, + {"is_enabled", + (PyCFunction) PySynthEvent_is_enabled, + METH_VARARGS | METH_KEYWORDS, + "Check if synth. event is enabled." + }, {NULL, NULL, 0, NULL} }; From patchwork Mon Jan 24 08:56:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12721689 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 7D3D4C4332F for ; Mon, 24 Jan 2022 08:56:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242519AbiAXI4z (ORCPT ); Mon, 24 Jan 2022 03:56:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242517AbiAXI4z (ORCPT ); Mon, 24 Jan 2022 03:56:55 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B4C4C06173B for ; Mon, 24 Jan 2022 00:56:55 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id h29so9520378wrb.5 for ; Mon, 24 Jan 2022 00:56:54 -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=fkg2Jb6D7BJON9PjzuIEQk5TeR5GDIvfZcXG48kLwWA=; b=e7S9scIMLvkA17dYsx7eCcWst88vOej/rkikeVnGf2NJA+xlVjatjPES+pLtjGj8gm vQQe/ROWoO6w+3R6hZJyRzrw6gvgZ5zse6yW7cn39p3VntFm9Z2MoigK5hQqD06dIgZI A4B7AYPzzJnwlM5LJo8vKz/prntW5iDPjM9R1vzBiTdiaU3zqQ7YnJ86S2Ut8GWW0PGF GhtL8kexL7B3XC3FWcaEmq9N7L0Wu7itYaKBqEz51/3esPAhBn4qc8mMu5xqv09wD/WG peQpxbNr51M/C1qZpUQFiMLY/mJYxRhxIktAcm/qbwJtSRQVyfxmY4ygmIuB8NudmuWq JPMQ== 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=fkg2Jb6D7BJON9PjzuIEQk5TeR5GDIvfZcXG48kLwWA=; b=Y8Nac2PPGfsJyVInhG+L0wqp82M89zOGfb5AGdbPudj6JYhyAQAcXHMddEud/PYmK4 xVOfyoJ1HQ+vncUtM+oI9LS87/L8aBkABD6bBVkspMpvVwYnuFy8P5i1xWPoag4iffHj oZYuCaISGOOHnvRatGlcyNviq2MmQCgrL8SzGXbRUxGLwvERXVgdxXLxTfDCdS9wH7te cElNzLMrSldNzaLz/SuLZrFiQUp2oL8s/HapRRz/y6zJihmyqbM9NWCDOk1aihWcNKq9 c1EYzyV13VzdpkyDiYPiZjy2AMCduAfj5V5ACVUmkbU/4wrixlDfFWkKBLUzaDDhZWLF OkXw== X-Gm-Message-State: AOAM531MKOAg/sP2zic+ovoKn/OpCIvdmsZYZFFwe2FpJuLbGtim256b k4axB4IQLn+/u7ABkRhQEtzLRDFbXTY= X-Google-Smtp-Source: ABdhPJxwgU/f04KT+zCYh+WXI4FR3aNpNNAlTsYE17OqdnodyO7fbN4duW/CbMxXd2CmMF9WG2nDqg== X-Received: by 2002:a5d:47cd:: with SMTP id o13mr13854123wrc.438.1643014613466; Mon, 24 Jan 2022 00:56:53 -0800 (PST) Received: from crow.eng.vmware.com ([146.247.46.134]) by smtp.gmail.com with ESMTPSA id f14sm14828091wri.44.2022.01.24.00.56.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 00:56:53 -0800 (PST) From: "Yordan Karadzhov (VMware)" To: linux-trace-devel@vger.kernel.org Cc: "Yordan Karadzhov (VMware)" Subject: [PATCH 06/10] trace-cryncher: Add static methods for manipulating filters Date: Mon, 24 Jan 2022 10:56:21 +0200 Message-Id: <20220124085625.92297-7-y.karadz@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220124085625.92297-1-y.karadz@gmail.com> References: <20220124085625.92297-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org All the code that can have a general use is extracted from the implementation of the APIs for dealing with filters of dynamic events and gets isolated in static methods. This is a preparation for the implementation of the APIs for dealing with filters of synthetic events. The new APIs for filtering synthetic events will be implemented in a following patch. Signed-off-by: Yordan Karadzhov (VMware) --- src/ftracepy-utils.c | 121 +++++++++++++++++++++++++++---------------- 1 file changed, 77 insertions(+), 44 deletions(-) diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c index 8a0c3c3..af73784 100644 --- a/src/ftracepy-utils.c +++ b/src/ftracepy-utils.c @@ -2241,13 +2241,34 @@ PyObject *PyFtrace_register_kretprobe(PyObject *self, PyObject *args, return PyDynevent_New(kprobe); } -PyObject *PyDynevent_set_filter(PyDynevent *self, PyObject *args, - PyObject *kwargs) +struct tep_event *dynevent_get_event(PyDynevent *event, + struct tep_handle **tep_ptr) +{ + struct tep_event *tep_evt; + struct tep_handle *tep; + + tep = get_tep(NULL, NULL); + if (!tep) + return NULL; + + tep_evt = tracefs_dynevent_get_event(tep, event->ptrObj); + if (!tep_evt) { + TfsError_setstr(NULL, "Failed to get dynevent."); + return NULL; + } + + if (tep_ptr) + *tep_ptr = tep; + + return tep_evt; +} + +static PyObject *set_filter(PyObject *args, PyObject *kwargs, + struct tep_handle *tep, + struct tep_event *event) { struct tracefs_instance *instance; PyObject *py_inst = NULL; - struct tep_handle * tep; - struct tep_event *event; const char *filter; static char *kwlist[] = {"filter", "instance", NULL}; @@ -2263,16 +2284,6 @@ PyObject *PyDynevent_set_filter(PyDynevent *self, PyObject *args, if (!get_optional_instance(py_inst, &instance)) return NULL; - tep = get_tep(NULL, NULL); - if (!tep) - return NULL; - - event = tracefs_dynevent_get_event(tep, self->ptrObj); - if (!event) { - TfsError_setstr(NULL, "Failed to get event."); - return NULL; - } - if (tracefs_event_filter_apply(instance, event, filter) < 0) { TfsError_fmt(NULL, "Failed to apply filter '%s' to event '%s'.", filter, event->name); @@ -2282,59 +2293,36 @@ PyObject *PyDynevent_set_filter(PyDynevent *self, PyObject *args, Py_RETURN_NONE; } -PyObject *PyDynevent_get_filter(PyDynevent *self, PyObject *args, - PyObject *kwargs) +static PyObject *get_filter(PyObject *args, PyObject *kwargs, + const char *system, const char* event ) { - char *evt_name, *evt_system, *filter = NULL; struct tracefs_instance *instance; PyObject *ret = NULL; + char *filter = NULL; char path[PATH_MAX]; - int type; if (!get_instance_from_arg(args, kwargs, &instance)) return NULL; - type = tracefs_dynevent_info(self->ptrObj, &evt_system, &evt_name, - NULL, NULL, NULL); - if (type == TRACEFS_DYNEVENT_UNKNOWN) { - PyErr_SetString(TFS_ERROR, "Failed to get dynevent info."); - return NULL; - } - - sprintf(path, "events/%s/%s/filter", evt_system, evt_name); + sprintf(path, "events/%s/%s/filter", system, event); if (read_from_file(instance, path, &filter) <= 0) - goto free; + return NULL; trim_new_line(filter); ret = PyUnicode_FromString(filter); - free: - free(evt_system); - free(evt_name); free(filter); return ret; } -PyObject *PyDynevent_clear_filter(PyDynevent *self, PyObject *args, - PyObject *kwargs) +static PyObject *clear_filter(PyObject *args, PyObject *kwargs, + struct tep_event *event) { struct tracefs_instance *instance; - struct tep_handle * tep; - struct tep_event *event; if (!get_instance_from_arg(args, kwargs, &instance)) return NULL; - tep = get_tep(NULL, NULL); - if (!tep) - return NULL; - - event = tracefs_dynevent_get_event(tep, self->ptrObj); - if (!event) { - TfsError_setstr(NULL, "Failed to get event."); - return NULL; - } - if (tracefs_event_filter_clear(instance, event) < 0) { TfsError_fmt(NULL, "Failed to clear filter for event '%s'.", event->name); @@ -2344,6 +2332,51 @@ PyObject *PyDynevent_clear_filter(PyDynevent *self, PyObject *args, Py_RETURN_NONE; } +PyObject *PyDynevent_set_filter(PyDynevent *self, PyObject *args, + PyObject *kwargs) +{ + struct tep_handle *tep; + struct tep_event *evt; + + evt = dynevent_get_event(self, &tep); + if (!evt) + return NULL; + + return set_filter(args, kwargs, tep, evt); +} + +PyObject *PyDynevent_get_filter(PyDynevent *self, PyObject *args, + PyObject *kwargs) +{ + struct tep_event *evt = dynevent_get_event(self, NULL); + char *evt_name, *evt_system; + int type; + + if (!evt) + return NULL; + + type = tracefs_dynevent_info(self->ptrObj, &evt_system, &evt_name, + NULL, NULL, NULL); + + if (type == TRACEFS_DYNEVENT_UNKNOWN) { + PyErr_SetString(TFS_ERROR, "Failed to get dynevent info."); + return NULL; + } + + return get_filter(args, kwargs, evt_system, evt_name); +} + +PyObject *PyDynevent_clear_filter(PyDynevent *self, PyObject *args, + PyObject *kwargs) +{ + struct tep_event *evt = dynevent_get_event(self, NULL); + + if (!evt) + return NULL; + + return clear_filter(args, kwargs, evt); +} + static bool enable_dynevent(PyDynevent *self, PyObject *args, PyObject *kwargs, bool enable) { From patchwork Mon Jan 24 08:56:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12721690 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 C0987C433F5 for ; Mon, 24 Jan 2022 08:56:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242524AbiAXI44 (ORCPT ); Mon, 24 Jan 2022 03:56:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242514AbiAXI44 (ORCPT ); Mon, 24 Jan 2022 03:56:56 -0500 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7C5CC06173B for ; Mon, 24 Jan 2022 00:56:55 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id r22so4530412wra.8 for ; Mon, 24 Jan 2022 00:56:55 -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=Xu6vBoYDdtUrdXK8a9RALrAK00fUiEeSHj6CTr9Bwjc=; b=ocs7/xs/GfUigL0HcLCINf3J4lN5dacSYCdXrOVI4/D0ZHgrsIEyuG8kBwSVQqdLZl SX4jEs/C2mlajg+VJMELCL4Ztz+Xt4S7pCUuICP5pgQy++KlodCytfsJQNF0X8pYTbT0 N4on2KR6sELHKlRF5Ry1LEbOcAhseUOopL/nKwOa9jQJJKDc6fmuta0OcTLz8XthaA+j 8iX1QkH37KgYgAxM0AFQxKb2qNDcm0BAKhDmFI5HIXjhgnrCy81l4GySlUz3fMfoj55+ oPcXYapM74XpsKDvV/gVYtnijrlU+f+aUrvwNH+jCornrMKgLvHHWKz0psHbRCq9+nlC CX2Q== 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=Xu6vBoYDdtUrdXK8a9RALrAK00fUiEeSHj6CTr9Bwjc=; b=puJ1oNGC+w0LhR2dKugvw8XvGt37ULVoblSBIT2/6c2JFarMjdLuiZRpBk1DpK0tJw BS0DnROWBFmQAf0unMsFlKFRTTC+sMfPw9wHXib26GzQ3KiF2eQnNIbcisT2KJ37xVeO uH37GD3nZONSxtBtaWdS91+JGUtddYdd/VB7kEuksQRRiWtXndkiD1zdoR0McfF5j/hx kAV32wpOTu7ZjdzV7RXLxCSUAC53mgynaBB2xy/CKEn+b0ECBbAf+r14xviWGI01EvjS V2hCNJvkRfFyLp2QkO6KwWRwAX5v7gnm6z8AG3HKJfsFwrL9AA8iAsQpNSlA5UMq+vU2 id5g== X-Gm-Message-State: AOAM5328VeTEyKA1fFU/TeNnMpdhWTgzY/HXq4oF1vX7ZlPfS/IPMKB/ 0fL/Nxb7v41puRwUZy/oGVLQw3dniyA= X-Google-Smtp-Source: ABdhPJwA9/L2G8WHX2OmQG+aXy4uaecdNc3c3oLFfS44SdlHZcXBJcTfEKdEZlVb/qcnDO4U42Fu4g== X-Received: by 2002:a5d:5846:: with SMTP id i6mr5028244wrf.4.1643014614186; Mon, 24 Jan 2022 00:56:54 -0800 (PST) Received: from crow.eng.vmware.com ([146.247.46.134]) by smtp.gmail.com with ESMTPSA id f14sm14828091wri.44.2022.01.24.00.56.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 00:56:53 -0800 (PST) From: "Yordan Karadzhov (VMware)" To: linux-trace-devel@vger.kernel.org Cc: "Yordan Karadzhov (VMware)" Subject: [PATCH 07/10] trace-cruncher: APIs for filtering synth. events Date: Mon, 24 Jan 2022 10:56:22 +0200 Message-Id: <20220124085625.92297-8-y.karadz@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220124085625.92297-1-y.karadz@gmail.com> References: <20220124085625.92297-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Here we add the following methods to the Python type for synthetic events: set_filter() get_filter() clear_filter() The new APIs allow for easy manipulation of the filters associated with a given synthetic event. Signed-off-by: Yordan Karadzhov (VMware) --- src/ftracepy-utils.c | 56 ++++++++++++++++++++++++++++++++++++++++++++ src/ftracepy-utils.h | 9 +++++++ src/ftracepy.c | 15 ++++++++++++ 3 files changed, 80 insertions(+) diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c index af73784..43c0f07 100644 --- a/src/ftracepy-utils.c +++ b/src/ftracepy-utils.c @@ -2739,6 +2739,62 @@ PyObject *PySynthEvent_is_enabled(PySynthEvent *self, PyObject *args, tracefs_synth_get_name(self->ptrObj)); } +struct tep_event *synth_get_event(PySynthEvent *event, struct tep_handle **tep_ptr) +{ + struct tep_event *tep_evt; + struct tep_handle *tep; + + tep = get_tep(NULL, NULL); + if (!tep) + return NULL; + + tep_evt = tracefs_synth_get_event(tep, event->ptrObj); + if (!tep_evt) { + TfsError_setstr(NULL, "Failed to get synth. event."); + return NULL; + } + + if (tep_ptr) + *tep_ptr = tep; + + return tep_evt; +} + +PyObject *PySynthEvent_set_filter(PySynthEvent *self, PyObject *args, + PyObject *kwargs) +{ + struct tep_handle *tep; + struct tep_event *evt; + + evt = synth_get_event(self, &tep); + if (!evt) + return NULL; + + return set_filter(args, kwargs, tep, evt); +} + +PyObject *PySynthEvent_get_filter(PySynthEvent *self, PyObject *args, + PyObject *kwargs) +{ + struct tep_event *evt = synth_get_event(self, NULL); + + if (!evt) + return NULL; + + return get_filter(args, kwargs, SYNTH_SYS, evt->name); +} + +PyObject *PySynthEvent_clear_filter(PySynthEvent *self, PyObject *args, + PyObject *kwargs) +{ + struct tep_event *evt = synth_get_event(self, NULL); + + if (!evt) + return NULL; + + return clear_filter(args, kwargs, evt); +} + PyObject *PyFtrace_set_ftrace_loglevel(PyObject *self, PyObject *args, PyObject *kwargs) { diff --git a/src/ftracepy-utils.h b/src/ftracepy-utils.h index daf1a19..f31b330 100644 --- a/src/ftracepy-utils.h +++ b/src/ftracepy-utils.h @@ -152,6 +152,15 @@ PyObject *PySynthEvent_disable(PySynthEvent *self, PyObject *args, PyObject *PySynthEvent_is_enabled(PySynthEvent *self, PyObject *args, PyObject *kwargs); +PyObject *PySynthEvent_set_filter(PySynthEvent *self, PyObject *args, + PyObject *kwargs); + +PyObject *PySynthEvent_get_filter(PySynthEvent *self, PyObject *args, + PyObject *kwargs); + +PyObject *PySynthEvent_clear_filter(PySynthEvent *self, PyObject *args, + PyObject *kwargs); + PyObject *PyFtrace_dir(PyObject *self); PyObject *PyFtrace_detach(PyObject *self, PyObject *args, PyObject *kwargs); diff --git a/src/ftracepy.c b/src/ftracepy.c index 62c6de0..50675c0 100644 --- a/src/ftracepy.c +++ b/src/ftracepy.c @@ -277,6 +277,21 @@ static PyMethodDef PySynthEvent_methods[] = { METH_VARARGS | METH_KEYWORDS, "Check if synth. event is enabled." }, + {"set_filter", + (PyCFunction) PySynthEvent_set_filter, + METH_VARARGS | METH_KEYWORDS, + "Define a filter for a synthetic event." + }, + {"get_filter", + (PyCFunction) PySynthEvent_get_filter, + METH_VARARGS | METH_KEYWORDS, + "Get the filter of a synthetic event." + }, + {"clear_filter", + (PyCFunction) PySynthEvent_clear_filter, + METH_VARARGS | METH_KEYWORDS, + "Clear the filter of a synthetic event." + }, {NULL, NULL, 0, NULL} }; From patchwork Mon Jan 24 08:56:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12721692 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 49072C433FE for ; Mon, 24 Jan 2022 08:56:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242522AbiAXI45 (ORCPT ); Mon, 24 Jan 2022 03:56:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242526AbiAXI45 (ORCPT ); Mon, 24 Jan 2022 03:56:57 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEFCBC06173B for ; Mon, 24 Jan 2022 00:56:56 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id f17so12167409wrx.1 for ; Mon, 24 Jan 2022 00:56:56 -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=m5I+tLN69QPUhS4jqG8C1Ixnhn1tRl62HglJZvcNlKY=; b=OLqUl8/M7vFoEXJWh1y2MLbBuvuiIwzezsd8baZrtxPkwVvuL6+RkBOCxmzE2Wsqdg rS9mkI/bt4plcBuVXlInsdUAwwvIP7fw333o+Bsru0RDRd8iQW8vwj2MAv5kSE34a0/0 kPSSfwF3gjCdztAWor+HdBS1q8jiwS8jvluZI9WenISjVff/735IyQj21SxAaRmZwPmm Kp3ExJwblyAogTGdT+lerAB6coLnKZNiDMODNi7SO4lzSKOpZ1LSw9+CMBVw9Lc70+K2 /71RQr4EbR/RkU/6MTMf1iJZNhvZpoHWMa+ZJFmfyD5K46HrsItOQkFMceTq24dKiYd3 T6Jg== 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=m5I+tLN69QPUhS4jqG8C1Ixnhn1tRl62HglJZvcNlKY=; b=3U68Bg5fi87yTb0VM+BDZeG68p8/pCL0tH87uGIQJ2B/Lsx57ZWqGxBCBm1syjQyi3 gX7g+/ugONZIO/cCRh2l7wspLlH0F0+fjNlcwnnho6npchmRY4l0OgHHz1EeXDV2ZKLK uNBMx59pKGYQsJEk1m5euxGq9y2kwwpA0zNeTRkkcD2Jn7T1lxyZCiPx5irPLYi+qFQ9 dri2WTbeXdZKHc9LWn2KX1Aa9KJ07zmGEAU2l18Czi/4WrnJpOJYF5epV524PB8VrYOG H8iNDJNBM3ZHvoJTbBKgg++2WPYrMo+qT33nVmtxVc69Op5FTH9FpKMLHn1Ki4kRIsVn f2/w== X-Gm-Message-State: AOAM533oQxys8COThx7+0g0Lt1D1INtCRvXBaFBeZpwGYFv1n/0zq90/ hm/lODX+FuWSnNQRz2PATzcrlfakhto= X-Google-Smtp-Source: ABdhPJzObpN3xXpoOpr1LV0VERLCtJ/vsuJiI2QJAcLzNn8uqjb0JiN9DQigJAlRNLUMwXTYB6sweA== X-Received: by 2002:a5d:6d45:: with SMTP id k5mr4195932wri.678.1643014615048; Mon, 24 Jan 2022 00:56:55 -0800 (PST) Received: from crow.eng.vmware.com ([146.247.46.134]) by smtp.gmail.com with ESMTPSA id f14sm14828091wri.44.2022.01.24.00.56.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 00:56:54 -0800 (PST) From: "Yordan Karadzhov (VMware)" To: linux-trace-devel@vger.kernel.org Cc: "Yordan Karadzhov (VMware)" Subject: [PATCH 08/10] trace-cruncher: API to show descriptor of the synth. event Date: Mon, 24 Jan 2022 10:56:23 +0200 Message-Id: <20220124085625.92297-9-y.karadz@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220124085625.92297-1-y.karadz@gmail.com> References: <20220124085625.92297-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Here we add the following method to the Python type for synthetic events: repr() The new APIs provides a representative descriptor of the synth. event, including the dynamic event and the two histograms. It can be useful in the case where the user wants to check what exactly gets passed to the kernel as definition of a synth event. Signed-off-by: Yordan Karadzhov (VMware) --- src/ftracepy-utils.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ src/ftracepy-utils.h | 2 ++ src/ftracepy.c | 5 +++++ 3 files changed, 59 insertions(+) diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c index 43c0f07..8c46590 100644 --- a/src/ftracepy-utils.c +++ b/src/ftracepy-utils.c @@ -1192,6 +1192,58 @@ PyObject *PySynthEvent_unregister(PySynthEvent *self) Py_RETURN_NONE; } +PyObject *PySynthEvent_repr(PySynthEvent *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = {"event", "hist_start", "hist_end", NULL}; + int event, hist_start, hist_end; + char buff[2048] = {0}; + bool new_line = false; + const char *str = NULL; + + event = hist_start = hist_end = true; + if (!PyArg_ParseTupleAndKeywords(args, + kwargs, + "|ppp", + kwlist, + &event, + &hist_start, + &hist_end)) { + return NULL; + } + + if (event) { + strcat(buff, "synth. event: "); + str = tracefs_synth_show_event(self->ptrObj); + if (str) + strcat(buff, str); + new_line = true; + } + + if (hist_start) { + if (new_line) + strcat(buff, "\n"); + else + new_line = true; + + strcat(buff, "hist. start: "); + str = tracefs_synth_show_start_hist(self->ptrObj); + if (str) + strcat(buff, str); + } + + if (hist_end) { + if (new_line) + strcat(buff, "\n"); + + strcat(buff, "hist. end: "); + str = tracefs_synth_show_end_hist(self->ptrObj); + if (str) + strcat(buff, str); + } + + return PyUnicode_FromString(strdup(buff)); +} + PyObject *PyFtrace_dir(PyObject *self) { return PyUnicode_FromString(tracefs_tracing_dir()); diff --git a/src/ftracepy-utils.h b/src/ftracepy-utils.h index f31b330..7612df6 100644 --- a/src/ftracepy-utils.h +++ b/src/ftracepy-utils.h @@ -161,6 +161,8 @@ PyObject *PySynthEvent_get_filter(PySynthEvent *self, PyObject *args, PyObject *PySynthEvent_clear_filter(PySynthEvent *self, PyObject *args, PyObject *kwargs); +PyObject *PySynthEvent_repr(PySynthEvent *self, PyObject *args, PyObject *kwargs); + PyObject *PyFtrace_dir(PyObject *self); PyObject *PyFtrace_detach(PyObject *self, PyObject *args, PyObject *kwargs); diff --git a/src/ftracepy.c b/src/ftracepy.c index 50675c0..3f71b5e 100644 --- a/src/ftracepy.c +++ b/src/ftracepy.c @@ -292,6 +292,11 @@ static PyMethodDef PySynthEvent_methods[] = { METH_VARARGS | METH_KEYWORDS, "Clear the filter of a synthetic event." }, + {"repr", + (PyCFunction) PySynthEvent_repr, + METH_VARARGS | METH_KEYWORDS, + "Show a representative descriptor of the synth. event." + }, {NULL, NULL, 0, NULL} }; From patchwork Mon Jan 24 08:56:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12721691 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 6CBC2C433EF for ; Mon, 24 Jan 2022 08:56:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242525AbiAXI46 (ORCPT ); Mon, 24 Jan 2022 03:56:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242514AbiAXI45 (ORCPT ); Mon, 24 Jan 2022 03:56:57 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E61DC061401 for ; Mon, 24 Jan 2022 00:56:57 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id r14so1592417wrc.6 for ; Mon, 24 Jan 2022 00:56:57 -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=IT9fnsBeCvct00PWZinRFT1MylwyyrFzOE1yTCdvq8Y=; b=mXRfYyiJmpf2XCW49h0PZrTrCGqO8dsdFJ1/3sKRpMysmjKGUQhxgI6gxrmLpYYFc9 MXO8C7RWdBquYHDiZX3BeIpnuf2o4ic+/hUMc3Lg5WygH7FSm3zoLpE313vxHWcBWwON ObNIc6R7tpoMNh8smbemVFkgz8yFuyGjFPw93PqPV35yEzZR+ua28FrpqQMrmZ0TDS4i p5gIJulccNHhczkVhiLlt4hNSamQYNcu7riKD7spqUte0QXIu+KNIYAT8gscvl/4pH4E quwhMy2UWNurd7YsFFYYRYm+Ip9PfNoU9vBALg0Z6UeB6Drx8uyjiaWFdPTqfkQwuuNn X12Q== 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=IT9fnsBeCvct00PWZinRFT1MylwyyrFzOE1yTCdvq8Y=; b=QCQb5/4sWjOcEkJ/dsfPRele0G2WrGU2waDIvQ69uaJSsWuP/6lhwtvlKKy8wcS6j6 QAnj41kRcuX7pi5eLSfL/4KUdynJyHy7KQO5LNTMKO/7sCvF7rFLEwxggqBFWBpRvPP+ O+hT78egvJIsxIf65LlILI6GNw5ZGM+ZS1kfeOwvlayOeT/3bEjdu13z4y3vfejyNQxh 7ox7Hi2QEnIJ9JasV8HHhK2aVd6i/ErVvJUgKmGe403VJ1QclYi6Vh5dsI3uLSimR2OW uSKeBt3vsmNl2v/ws5QhrqRlbNhGKicZ7iW49F3VY7BfSiHeZRs02cgG3FPVO+3W5ZlO MHfg== X-Gm-Message-State: AOAM531sV0/KTNL8CO0LyqpU6XrjkvW9JF0uliB5108GA0nJHViu+QjR y6krIPpRvRN59mnFvcbo5U0WsvMl5+A= X-Google-Smtp-Source: ABdhPJywsW/NUV8fYQhwUbMMYyZMUcU9PA2+Drax8VfPoK9QvCvrovVO8QV1XOk5EK9O937UsV7RpQ== X-Received: by 2002:a05:6000:1869:: with SMTP id d9mr3619160wri.432.1643014615721; Mon, 24 Jan 2022 00:56:55 -0800 (PST) Received: from crow.eng.vmware.com ([146.247.46.134]) by smtp.gmail.com with ESMTPSA id f14sm14828091wri.44.2022.01.24.00.56.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 00:56:55 -0800 (PST) From: "Yordan Karadzhov (VMware)" To: linux-trace-devel@vger.kernel.org Cc: "Yordan Karadzhov (VMware)" Subject: [PATCH 09/10] trace-cruncher: Add synthetic event example Date: Mon, 24 Jan 2022 10:56:24 +0200 Message-Id: <20220124085625.92297-10-y.karadz@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220124085625.92297-1-y.karadz@gmail.com> References: <20220124085625.92297-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org This is a very basic example, demonsting the usage of the new APIs for kernel synth. events. Signed-off-by: Yordan Karadzhov (VMware) --- examples/synth.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 examples/synth.py diff --git a/examples/synth.py b/examples/synth.py new file mode 100755 index 0000000..ec9427b --- /dev/null +++ b/examples/synth.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 + +""" +SPDX-License-Identifier: CC-BY-4.0 + +Copyright 2021 VMware Inc, Yordan Karadzhov (VMware) +""" + +import tracecruncher.ftracepy as ft + +# Define a synthetic event that combines 'sched_waking' and 'sched_switch'. +# A synth. event will be recorded every time a 'start' event (sched_waking) +# is followed by an 'end' event (sched_switch) and both events have the same +# value of the fields 'pid' and 'next_pid' (belong to the same process). +synth = ft.synth(name='synth_wakeup', + start_sys='sched', start_evt='sched_waking', + end_sys='sched', end_evt='sched_switch', + start_match='pid', end_match='next_pid', + match_name='pid') + +# Add to the synth. event two fields from the 'start' event. In the synth. event, +# the field 'target_cpu' will be renamed to 'cpu'. +synth.add_start_fields(fields=['target_cpu', 'prio'], + names=['cpu', None]) + +# Add to the synth. event one field from the 'end' event. +synth.add_end_fields(fields=['next_prio']) + +# Add to the synth. event a field that measures the time-difference between +# the 'start' and 'end' events. Use 'hd' time resolution (nanoseconds). +synth.add_delta_T(hd=True) + +# Register the synth. event on the system. +synth.register() + +inst = ft.create_instance() + +# Apply a filter and enable the synth. event. +synth.set_filter(instance=inst, filter='prio<100') +synth.enable(instance=inst) + +# Print the stream of trace events. "Ctrl+c" to stop tracing. +ft.read_trace(instance=inst) From patchwork Mon Jan 24 08:56:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12721693 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 B74B4C433F5 for ; Mon, 24 Jan 2022 08:56:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242517AbiAXI46 (ORCPT ); Mon, 24 Jan 2022 03:56:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242526AbiAXI46 (ORCPT ); Mon, 24 Jan 2022 03:56:58 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9AC1C06173B for ; Mon, 24 Jan 2022 00:56:57 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id k18so12152509wrg.11 for ; Mon, 24 Jan 2022 00:56:57 -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=4r5c1OhgDg4fVLQNXAQNqqUddRRCC9GVZ4qROs5kdnM=; b=jS+neGe3KibVbwZkw1DplVthoF2msb4vyxZ+JnsOo5Zo2AI7LU4TUaw/jsGNVfNEly m6P2i8FTTaL7VY2TiaC/lAvSV6567doWOoyeNmYMBE6TG/bSS6wfu1yoH5/12AMAgaBR RxNMRaCm8FSbOzJ975YJUd3L/JNrTQd0HU51rPAqwcxdUrLeFLpRSbuoJ08Od985HUGa RHAaXoAAnYGe3QYZd+JC+34/e0KylXKskXgles6eXHpBSazT5TlR2bIFocMKrenC3znQ FOaCc95jIvFMwRdGnAD2p6WiMYj2crVrA8rO3HmHBBRJ4AkjDrPEoLV2FN7XDRkyWasz 7Y1A== 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=4r5c1OhgDg4fVLQNXAQNqqUddRRCC9GVZ4qROs5kdnM=; b=2+E2WueVjoVRfjIbjzao3ckCOuxdH0G70MbffQOM0q6vBJ5V1ajrZi0ZmErCK4rRP6 EerfY86nFu+do7q99i47+8jYokf4yXWDOY8eRhncPWvX/1Y1tvvKyNRkTrIffwv80QAs H99KWHYnVrfAaQtVqDdblDTBgzUHpf2W30rOHT4f0JjCq52kkOpEf6tS8LMrKgKQT1Ba UN77XW0MTcZwiKlK1o/IwyaeYNT2S7BL/FO15cdpc6h7n+sC0qc826eWzEN06xAqrCUv BC2sH2HwxPzw7A/uqmFmx9UcNkh3YMqkeWxE4xPQ37EjwkhJII8mXIuXkNlL+WHiGeZq fyXA== X-Gm-Message-State: AOAM533twkI+efiF7eEP0Yhgs3WgXVAbRK2DmTAz+ezoAYyd6DUpK+9t qm43334QlyVLO1J7BmuFjWTC/i2vKw0= X-Google-Smtp-Source: ABdhPJz/lUrTi3aS/S1EMLU4rW7nKOm/3ge3ryHJ2eycGBFN2lwKg5/OjT56HYC+ynhCmDbuqW8NmQ== X-Received: by 2002:adf:d1c9:: with SMTP id b9mr13636458wrd.560.1643014616426; Mon, 24 Jan 2022 00:56:56 -0800 (PST) Received: from crow.eng.vmware.com ([146.247.46.134]) by smtp.gmail.com with ESMTPSA id f14sm14828091wri.44.2022.01.24.00.56.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 00:56:56 -0800 (PST) From: "Yordan Karadzhov (VMware)" To: linux-trace-devel@vger.kernel.org Cc: "Yordan Karadzhov (VMware)" Subject: [PATCH 10/10] trace-cruncher: Add synth. events tests Date: Mon, 24 Jan 2022 10:56:25 +0200 Message-Id: <20220124085625.92297-11-y.karadz@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220124085625.92297-1-y.karadz@gmail.com> References: <20220124085625.92297-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org APIs for kernel synthetic events have been added. Here we add the corresponding test cases. Signed-off-by: Yordan Karadzhov (VMware) --- .../tests/1_unit/test_01_ftracepy_unit.py | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/tracecruncher/tests/1_unit/test_01_ftracepy_unit.py b/tracecruncher/tests/1_unit/test_01_ftracepy_unit.py index 51970d3..2de3d89 100644 --- a/tracecruncher/tests/1_unit/test_01_ftracepy_unit.py +++ b/tracecruncher/tests/1_unit/test_01_ftracepy_unit.py @@ -691,5 +691,91 @@ class HistOopTestCase(unittest.TestCase): self.assertTrue(err in str(context.exception)) +class SyntTestCase(unittest.TestCase): + def test_synt_create(self): + synth = ft.synth(name='wakeup_lat', + start_sys='sched', start_evt='sched_waking', + end_sys='sched', end_evt='sched_switch', + start_match='pid', end_match='next_pid', + match_name='pid') + + synth.add_start_fields(fields=['target_cpu', 'prio'], + names=['cpu', None]) + synth.add_end_fields(fields=['prev_prio', 'next_prio'], + names=[None, 'nxt_p']) + synth.register() + + event = synth.repr(event=True, hist_start=False, hist_end=False) + hist_s = synth.repr(event=False, hist_start=True, hist_end=False) + hist_e = synth.repr(event=False, hist_start=False, hist_end=True) + + self.assertTrue('keys=pid'in hist_s) + self.assertTrue('keys=next_pid' in hist_e) + self.assertTrue('pid=next_pid' in hist_e) + self.assertTrue('onmatch(sched.sched_waking).trace(wakeup_lat,$pid' in hist_e) + + self.assertTrue('s32 cpu;' in event) + self.assertTrue('s32 prio;' in event) + hist_s = synth.repr(event=False, hist_start=True, hist_end=False) + split_1 = hist_s.split('__arg_') + arg1 = '__arg_' + split_1[1].split('=')[0] + arg2 = '__arg_' + split_1[2].split('=')[0] + self.assertTrue(arg1 + '=target_cpu' in hist_s) + self.assertTrue(arg2 + '=prio' in hist_s) + hist_e = synth.repr(event=False, hist_start=False, hist_end=True) + self.assertTrue('cpu=$' + arg1 in hist_e) + self.assertTrue('prio=$' + arg2 in hist_e) + split_2 = hist_e.split('trace(') + self.assertTrue('$pid' in split_2[1]) + self.assertTrue('$prio' in split_2[1]) + + event = synth.repr(event=True, hist_start=False, hist_end=False) + self.assertTrue('s32 prev_prio;' in event) + self.assertTrue('s32 nxt_p;' in event) + hist_e = synth.repr(event=False, hist_start=False, hist_end=True) + self.assertTrue('nxt_p=next_prio' in hist_e) + split_3 = hist_e.split('__arg_') + arg3 = '__arg_' + split_3[3].split('=')[0] + self.assertTrue(arg3 + '=prev_prio' in hist_e) + split_4 = hist_e.split('trace(') + self.assertTrue('$nxt_p' in split_4[1]) + self.assertTrue('$' + arg3 in split_4[1]) + + synth.unregister() + + def test_synt_enable(self): + synth = ft.synth(name='wakeup_lat', + start_sys='sched', start_evt='sched_waking', + end_sys='sched', end_evt='sched_switch', + start_match='pid', end_match='next_pid', + match_name='pid') + synth.register() + ret = synth.is_enabled() + self.assertEqual(ret, '0') + synth.enable() + ret = synth.is_enabled() + self.assertEqual(ret, '1') + synth.disable() + ret = synth.is_enabled() + self.assertEqual(ret, '0') + synth.unregister() + + def test_synt_enable(self): + evt_filter = 'prio<100' + synth = ft.synth(name='wakeup_lat', + start_sys='sched', start_evt='sched_waking', + end_sys='sched', end_evt='sched_switch', + start_match='pid', end_match='next_pid', + match_name='pid') + synth.add_start_fields(fields=['prio']) + synth.register() + self.assertEqual('none', synth.get_filter()) + synth.set_filter(filter=evt_filter) + self.assertEqual(evt_filter, synth.get_filter()) + synth.clear_filter() + self.assertEqual('none', synth.get_filter()) + synth.unregister() + + if __name__ == '__main__': unittest.main()