From patchwork Fri Sep 10 16:38:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12485617 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,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 3980BC4332F for ; Fri, 10 Sep 2021 16:39:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 21B7B61208 for ; Fri, 10 Sep 2021 16:39:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229944AbhIJQkZ (ORCPT ); Fri, 10 Sep 2021 12:40:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230146AbhIJQkT (ORCPT ); Fri, 10 Sep 2021 12:40:19 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 918D4C06175F for ; Fri, 10 Sep 2021 09:39:08 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id t19so5417871ejr.8 for ; Fri, 10 Sep 2021 09:39:08 -0700 (PDT) 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=f/b6pGCLNFVwuIGlaak6s3O+ozWULqNfRRPxAC7QgTE=; b=LxVjiyOowRgcNTsBiUuecSRugEE8+a/fzEbV3nuE9GTrWxP63P7NBeIPnmuk36H17k 5WX/3HHuPOEsk+W50bKVxoXu2hYNeyk3A6MrzN8jssdsnYCk/cjhGwzizvxxtDzHmpuA Z/M7sK90gbrk2EI1DlM1/u+F9W2YKeZA7hGNLrt7e64VJRkjgzp278NGYNFLTgoUe/qS Wmtl9+auKb1QskqhcaCGaVe8h/tcuJSCRPgFatTps0lcivq5NG0QxdIZGAYPZutp1mwe fAQZsNxcuM5CT0cYiJyZoqdu9iWCqRfoGrsaXfaaB1kEXh2bxYnFx8WvTKtef2GUaqVH eOOg== 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=f/b6pGCLNFVwuIGlaak6s3O+ozWULqNfRRPxAC7QgTE=; b=jhKCa9DHVh0b8NMvRp0GI56vdYsYnCHw0q0NkQoGdu+omqobuUpLNZXAqDmgsPyVBm bT9gGbYH8zlkhyXQ6z9f5EUZRnlB8HCuV9g1GUMVXjGvdH2YTnY+HzmGx9G7f2BLjE/d xvmXPDDfOdfkTxFv8hP+Xj8jJp0cbIIDc5aKEdZLtEsuri7Ad0XoG38hPM9oDMZ7UkeX RvNrW7Pm0pzEkw6PtfYQ/EaGaRKqEl9Ij+3R4BB9zvJ5zqp/JCd4N+RvB0wS2GjNtFgj D66O8gX6e9VY2uGo40hrh/UPeAGtJiiIkpqEbDnZCOzshnyf0zaC+YqOu9mYTXpYSx6Y 6Kmw== X-Gm-Message-State: AOAM532cf2wHWovPFo3ZleGz/+5tShZw4Wf3iPCws6LtNH3/BKhFuazk iodV/Rw4v8oUe36kC+Y/+SiR01FHJys= X-Google-Smtp-Source: ABdhPJwloF8OUqinJJWc/WPYuNdoS0q6K9AAU+fxtotlQK29WaE9Ip57YVIUTQUTWHQhGL0wHLmaZA== X-Received: by 2002:a17:906:686:: with SMTP id u6mr9968653ejb.569.1631291947157; Fri, 10 Sep 2021 09:39:07 -0700 (PDT) Received: from crow.. ([95.87.199.93]) by smtp.gmail.com with ESMTPSA id g9sm3095290edk.54.2021.09.10.09.39.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 09:39:06 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [RFC PATCH 1/4] libtracefs: Add new constructors for histograms Date: Fri, 10 Sep 2021 19:38:54 +0300 Message-Id: <20210910163857.324696-2-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210910163857.324696-1-y.karadz@gmail.com> References: <20210910163857.324696-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The current way to create an N-dimensional histogram is bit counterintuitive. We first have to call tracefs_hist_alloc() which is essentially a constructor of 1d histogram. Then we have to call tracefs_hist_add_key() N-1 times in order to increase the dimentions of the histogram. Here we transform tracefs_hist_alloc() into a constructor of N-dimensional histogram and we also add 2 helper constructors for 1d and 2d histograms. Signed-off-by: Yordan Karadzhov (VMware) --- include/tracefs.h | 17 +++++++++- src/tracefs-hist.c | 82 ++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 85 insertions(+), 14 deletions(-) diff --git a/include/tracefs.h b/include/tracefs.h index b4aa75d..64fbb3f 100644 --- a/include/tracefs.h +++ b/include/tracefs.h @@ -280,10 +280,25 @@ enum tracefs_hist_sort_direction { struct tracefs_hist; void tracefs_hist_free(struct tracefs_hist *hist); +struct tracefs_hist * +tracefs_hist1d_alloc(struct tracefs_instance * instance, + const char *system, const char *event, + const char *key, enum tracefs_hist_key_type type); +struct tracefs_hist * +tracefs_hist2d_alloc(struct tracefs_instance * instance, + const char *system, const char *event, + const char *key1, enum tracefs_hist_key_type type1, + const char *key2, enum tracefs_hist_key_type type2); + +struct tracefs_hist_axis { + const char *key; + enum tracefs_hist_key_type type; +}; + struct tracefs_hist * tracefs_hist_alloc(struct tracefs_instance * instance, const char *system, const char *event, - const char *key, enum tracefs_hist_key_type type); + struct tracefs_hist_axis *axes); int tracefs_hist_add_key(struct tracefs_hist *hist, const char *key, enum tracefs_hist_key_type type); int tracefs_hist_add_value(struct tracefs_hist *hist, const char *value); diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c index 6519f7e..8501d64 100644 --- a/src/tracefs-hist.c +++ b/src/tracefs-hist.c @@ -141,7 +141,7 @@ void tracefs_hist_free(struct tracefs_hist *hist) } /** - * tracefs_hist_alloc - Initialize a histogram + * tracefs_hist1d_alloc - Initialize one-dimensional histogram * @instance: The instance the histogram will be in (NULL for toplevel) * @system: The system the histogram event is in. * @event: The event that the histogram will be attached to. @@ -157,14 +157,69 @@ void tracefs_hist_free(struct tracefs_hist *hist) * NULL on failure. */ struct tracefs_hist * +tracefs_hist1d_alloc(struct tracefs_instance * instance, + const char *system, const char *event, + const char *key, enum tracefs_hist_key_type type) +{ + struct tracefs_hist_axis axis[] = {{key, type}, {NULL, 0}}; + + return tracefs_hist_alloc(instance, system, event, axis); +} + +/** + * tracefs_hist2d_alloc - Initialize two-dimensional histogram + * @instance: The instance the histogram will be in (NULL for toplevel) + * @system: The system the histogram event is in. + * @event: The event that the histogram will be attached to. + * @key1: The first primary key the histogram will use + * @type1: The format type of the first key. + * @key2: The second primary key the histogram will use + * @type2: The format type of the second key. + * + * Will initialize a histogram descriptor that will be attached to + * the @system/@event with the given @key1 and @key2 as the primaries. + * This only initializes the descriptor, it does not start the histogram + * in the kernel. + * + * Returns an initialized histogram on success. + * NULL on failure. + */ +struct tracefs_hist * +tracefs_hist2d_alloc(struct tracefs_instance * instance, + const char *system, const char *event, + const char *key1, enum tracefs_hist_key_type type1, + const char *key2, enum tracefs_hist_key_type type2) +{ + struct tracefs_hist_axis axis[] = {{key1, type1}, + {key2, type2}, + {NULL, 0}}; + + return tracefs_hist_alloc(instance, system, event, axis); +} + +/** + * tracefs_hist_alloc - Initialize N-dimensional histogram + * @instance: The instance the histogram will be in (NULL for toplevel) + * @system: The system the histogram event is in + * @event: The event that the histogram will be attached to + * @axes: An array of histogram axes, terminated by a {NULL, 0} entry + * + * Will initialize a histogram descriptor that will be attached to + * the @system/@event. This only initializes the descriptor with the given + * @axes keys as primaries. This only initializes the descriptor, it does + * not start the histogram in the kernel. + * + * Returns an initialized histogram on success. + * NULL on failure. + */ +struct tracefs_hist * tracefs_hist_alloc(struct tracefs_instance * instance, const char *system, const char *event, - const char *key, enum tracefs_hist_key_type type) + struct tracefs_hist_axis *axes) { struct tracefs_hist *hist; - int ret; - if (!system || !event || !key) + if (!system || !event) return NULL; if (!tracefs_event_file_exists(instance, system, event, HIST_FILE)) @@ -174,8 +229,7 @@ tracefs_hist_alloc(struct tracefs_instance * instance, if (!hist) return NULL; - ret = trace_get_instance(instance); - if (ret < 0) { + if (trace_get_instance(instance) < 0) { free(hist); return NULL; } @@ -184,16 +238,18 @@ tracefs_hist_alloc(struct tracefs_instance * instance, hist->system = strdup(system); hist->event = strdup(event); + if (!hist->system || !hist->event) + goto fail; - ret = tracefs_hist_add_key(hist, key, type); - - if (!hist->system || !hist->event || ret < 0) { - tracefs_hist_free(hist); - return NULL; - } - + for (; axes && axes->key; axes++) + if (tracefs_hist_add_key(hist, axes->key, axes->type) < 0) + goto fail; return hist; + + fail: + tracefs_hist_free(hist); + return NULL; } /** From patchwork Fri Sep 10 16:38:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12485611 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,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 E6536C43217 for ; Fri, 10 Sep 2021 16:39:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D064E611CC for ; Fri, 10 Sep 2021 16:39:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230243AbhIJQkX (ORCPT ); Fri, 10 Sep 2021 12:40:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230203AbhIJQkU (ORCPT ); Fri, 10 Sep 2021 12:40:20 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 841CEC061764 for ; Fri, 10 Sep 2021 09:39:09 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id dc3so5416330ejb.10 for ; Fri, 10 Sep 2021 09:39:09 -0700 (PDT) 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=XmA317lK1vX1gIDGP8ql5chCEV7TO4+vs27Aepi/bQ0=; b=JQuPPn+AeTz0IgkdBkAwv3egTw3+ctd/UV4nOXoR3S6yb4LJNzJ8/DUNc+IMClzAwb 6Y3+C5ol1Zh1LFusZohq9QMKNM70utmPWfTeoWlnshl2MJ2Uxj1LI7fPa6B3My+FVJlw vDYp9kkF+8Di4EArZQ887UfWBanpi+b3vjqMDrOEkGXuSf/7JwZfoUG98Cmt2zVAHco+ b/vLJCqnGmnh8z9MeFOJ1qn31rJIwUzMqClFmnw2rz6cxfNTJet6t1/nPes0NZOz+Oh7 c115hcwPSfsAi15x8Qux2OsEcbIC6X62pmmsjxAqW3xuZMudAaOlB6WMTSxORVdV4ntW tdsQ== 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=XmA317lK1vX1gIDGP8ql5chCEV7TO4+vs27Aepi/bQ0=; b=4OljLJpS4ReN4VKG2GBPFyBoU4yfUgaAze0a7Iq/lGHpMD8KvIGiNGqLCdXgtapKhA zFa5Y5NZa9AD9tV+N6XvDjMUHJacsY0Us8Jo5nmBRTGzdBk2J/Lf4LIfA9L3X4roCDDG AWgXgG1rphkabn9GcRjnvLBht8aXhNMHuiYOJmndclNUIeKg9meLPbywRkWMNiQe+RoZ 8TgHyAnIefZ8inUgw80gPVGreApuvIamRAaMCmgdMSwG19iBjTpWJ0f/2WesGDbSLfkm IMaNWR6yq+d+wRNAV8rX0YhOc5htviPeqzgV5Xx1xXsHHYBn8bntBs5mUsYqwElBJ0cR NxPQ== X-Gm-Message-State: AOAM530PeY7YK9gbD6YOTjZyIgV+O83zodjhn6B9r5v8RQhBk4mPmtTW wPtoxDxSGZlm+0yACegqGUKC69nZedE= X-Google-Smtp-Source: ABdhPJyMhMEeq7LGNDvg4l8omZyU29Aw+gvhcLlb4DCFUuN+NRocFzm+SgoeAqsdlLgaEXfwSjz7vQ== X-Received: by 2002:a17:907:98ce:: with SMTP id kd14mr10452363ejc.440.1631291948034; Fri, 10 Sep 2021 09:39:08 -0700 (PDT) Received: from crow.. ([95.87.199.93]) by smtp.gmail.com with ESMTPSA id g9sm3095290edk.54.2021.09.10.09.39.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 09:39:07 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [RFC PATCH 2/4] libtracefs: Transform tracefs_hist_add_sort_key() Date: Fri, 10 Sep 2021 19:38:55 +0300 Message-Id: <20210910163857.324696-3-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210910163857.324696-1-y.karadz@gmail.com> References: <20210910163857.324696-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The current version of the API makes it hard to add multiple sort keys to a histogram. The only way to do this is to use the variadic arguments, however in order to do this the caller have to know the number of sort keys at compile time, because the method overwrite all previously added keys. The problem is addressed by splitting tracefs_hist_add_sort_key() into two methods - one that overwrite and one that does not. Signed-off-by: Yordan Karadzhov (VMware) --- include/tracefs.h | 4 +++- src/tracefs-hist.c | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/include/tracefs.h b/include/tracefs.h index 64fbb3f..c3fa1d6 100644 --- a/include/tracefs.h +++ b/include/tracefs.h @@ -303,7 +303,9 @@ int tracefs_hist_add_key(struct tracefs_hist *hist, const char *key, enum tracefs_hist_key_type type); int tracefs_hist_add_value(struct tracefs_hist *hist, const char *value); int tracefs_hist_add_sort_key(struct tracefs_hist *hist, - const char *sort_key, ...); + char *sort_key); +int tracefs_hist_sort_key(struct tracefs_hist *hist, + const char *sort_key, ...); int tracefs_hist_sort_key_direction(struct tracefs_hist *hist, const char *sort_key, enum tracefs_hist_sort_direction dir); diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c index 8501d64..2ea90d9 100644 --- a/src/tracefs-hist.c +++ b/src/tracefs-hist.c @@ -453,6 +453,23 @@ add_sort_key(struct tracefs_hist *hist, const char *sort_key, char **list) return tracefs_list_add(list, sort_key); } +int tracefs_hist_add_sort_key(struct tracefs_hist *hist, + char *sort_key) +{ + char **list = hist->sort; + + if (!hist || !sort_key) + return -1; + + list = add_sort_key(hist, sort_key, hist->sort); + if (!list) + return -1; + + hist->sort = list; + + return 0; +} + /** * tracefs_hist_add_sort_key - add a key for sorting the histogram * @hist: The histogram to add the sort key to @@ -464,8 +481,8 @@ add_sort_key(struct tracefs_hist *hist, const char *sort_key, char **list) * * Returns 0 on success, -1 on error. */ -int tracefs_hist_add_sort_key(struct tracefs_hist *hist, - const char *sort_key, ...) +int tracefs_hist_sort_key(struct tracefs_hist *hist, + const char *sort_key, ...) { char **list = NULL; char **tmp; From patchwork Fri Sep 10 16:38:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12485613 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,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 5280FC4332F for ; Fri, 10 Sep 2021 16:39:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3237161208 for ; Fri, 10 Sep 2021 16:39:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230114AbhIJQkX (ORCPT ); Fri, 10 Sep 2021 12:40:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230258AbhIJQkV (ORCPT ); Fri, 10 Sep 2021 12:40:21 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 471B3C061574 for ; Fri, 10 Sep 2021 09:39:10 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id a25so5442812ejv.6 for ; Fri, 10 Sep 2021 09:39:10 -0700 (PDT) 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=6Ztix/mSisIcNTomnFYxEhhxtgmrLBPkGI5Fz5tlIKo=; b=HTBzJ6RTnI3fx1wL3lG2ldhPcTsrAHWfoVucIxwV7aDw2rfvlqY+2NjgmoKpOfY3xJ jzRsEtVKaITy6itMN6ouzA2MDYkBrHiGDvqDVppBLr1wvzXURJhLsFnxl3oQeLjDkeaH FIzxYJx26Ft78Q15l9WRNKsMf1RFIi33iUajk+F6hZxX7zS6n9sUEOykF/cDGlA0agBj MzCPwK4OgtCh0s/dezgOJug+tkK/BSmNuaSCpU82umOFRGUOUqDxLLaIxbOUcJFaO39g ah+PFobL1w5px3cIPBuk29zC0qOnrNxq+Ae4onAzO+QSlDe091rTwizRySjXFnidWAK1 m/6g== 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=6Ztix/mSisIcNTomnFYxEhhxtgmrLBPkGI5Fz5tlIKo=; b=TZTYHNHUER9v6cq6C5GjVZWPzfVxdxQ/dTjlqTgLNEU87vIfljfnXDvCnETB9kxrtt ETDE6L9KP51nSA4I+h4aPbo12DAD7u8tV+O20Kew9CtpB3+CL10fPcLjdKWB8HDQBO3Q zj4JCXjpx9xkx4uOLuEloxC9vsxnZljf7nzK5vwn6P8aFTKFhZKSkc7TRKUTKeeHrY7J W7jyJwZFgBc88HZGk0DX/4HYFEx68X2URpEaggyDKjs8CJg2DJ3++5foFNfKR7QjJZxj +xcgztAZKiwNkGAHgbqyYrSJ9Kd6OrfJ/loEX5P/hflt/8G6XA/DtbdlGHi7+PE2zvzm vBVA== X-Gm-Message-State: AOAM531r3gzGWfIQiy7bzu6KjtyzCk5nNDX6AaUItt0j/hUk+FzcrRTc 5o3p0bx/aQ7SDJ+iMpFit6s= X-Google-Smtp-Source: ABdhPJyYAor1u1mZqGpplZawmp1BO8pbWtMC4u0HXEQ0YAdkb1O76o8dfO5gKxyhxIJCCVD5HnvCwg== X-Received: by 2002:a17:906:9241:: with SMTP id c1mr10375347ejx.125.1631291948838; Fri, 10 Sep 2021 09:39:08 -0700 (PDT) Received: from crow.. ([95.87.199.93]) by smtp.gmail.com with ESMTPSA id g9sm3095290edk.54.2021.09.10.09.39.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 09:39:08 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [RFC PATCH 3/4] libtracefs: Add new 'hist' APIs Date: Fri, 10 Sep 2021 19:38:56 +0300 Message-Id: <20210910163857.324696-4-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210910163857.324696-1-y.karadz@gmail.com> References: <20210910163857.324696-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The new APIs will be valuable in a number of different scenarios. For example if the user wants to implement a function that does the readout of a histogram, the only argument that will have to be passed to this function is the histogram descriptor. The same applies for the case when the user wants to print an adequate error message in a case of a failure. Signed-off-by: Yordan Karadzhov (VMware) --- include/tracefs.h | 4 ++++ src/tracefs-hist.c | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/tracefs.h b/include/tracefs.h index c3fa1d6..255be9b 100644 --- a/include/tracefs.h +++ b/include/tracefs.h @@ -299,6 +299,10 @@ struct tracefs_hist * tracefs_hist_alloc(struct tracefs_instance * instance, const char *system, const char *event, struct tracefs_hist_axis *axes); +const char *tracefs_get_hist_name(struct tracefs_hist *hist); +const char *tracefs_get_hist_event(struct tracefs_hist *hist); +const char *tracefs_get_hist_system(struct tracefs_hist *hist); +struct tracefs_instance *tracefs_get_hist_instance(struct tracefs_hist *hist); int tracefs_hist_add_key(struct tracefs_hist *hist, const char *key, enum tracefs_hist_key_type type); int tracefs_hist_add_value(struct tracefs_hist *hist, const char *value); diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c index 2ea90d9..175b627 100644 --- a/src/tracefs-hist.c +++ b/src/tracefs-hist.c @@ -34,6 +34,26 @@ struct tracefs_hist { int size; }; +const char *tracefs_get_hist_name(struct tracefs_hist *hist) +{ + return hist ? hist->name : NULL; +} + +struct tracefs_instance *tracefs_get_hist_instance(struct tracefs_hist *hist) +{ + return hist ? hist->instance : NULL; +} + +const char *tracefs_get_hist_event(struct tracefs_hist *hist) +{ + return hist ? hist->event : NULL; +} + +const char *tracefs_get_hist_system(struct tracefs_hist *hist) +{ + return hist ? hist->system : NULL; +} + enum tracefs_hist_command { HIST_CMD_NONE = 0, HIST_CMD_PAUSE, From patchwork Fri Sep 10 16:38:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12485615 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,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 4EED6C433F5 for ; Fri, 10 Sep 2021 16:39:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3848C611CC for ; Fri, 10 Sep 2021 16:39:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230154AbhIJQkY (ORCPT ); Fri, 10 Sep 2021 12:40:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230272AbhIJQkW (ORCPT ); Fri, 10 Sep 2021 12:40:22 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AD9AC061766 for ; Fri, 10 Sep 2021 09:39:11 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id a25so5442892ejv.6 for ; Fri, 10 Sep 2021 09:39:11 -0700 (PDT) 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=iFxkFKimb4SYn9oH9t3gLTUmDTFC+h81zIObZUcChf4=; b=U+uHDJP8dKe+8rm1gSxYu8Xf+Qf813L2EGy8Tzkan+KDL5MqkrNO36z9AUCcz0pLrd x75nC9S0uneo37ytEchonDlAe/bxMm2rJU5IGPcw5Pur7vvfVe+ahFmXBF6Tw02izUNp STbJPDl/Xl2UFHQnpsZBQ2/rrerem37GtYjQdUgLi4iqGJhjffTL51AFE2ChDx4h2J6o eYcitIGgp4aiwYeClEpNrZJdNZCQtPRiAFgD2v3pBVceHuL5rXXVNdtklQV5w3DttQjE HyMaro82nsI345mNeeMn6mTQhI/P18KfG/pLbdB3GWiZqHJeAaKfWSqUtdsQVjuuM1G1 Oyyg== 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=iFxkFKimb4SYn9oH9t3gLTUmDTFC+h81zIObZUcChf4=; b=ik/cZpoknBzOPMp2uhT+36SjxJFKU5cbEuyHP7Y7Sq9MBP6lWUv+kJY9dN+zALB1Wq LynZhJ6QA0kRZaUdpMBn3SJUIWl1i/7NCROy3UZN1lsPcEDpMvN07bdV5FwHiClPxrjr j6YBifd26gm/VpZMx3TeH81lJ4xPF4w8KDrDAl5dJm1Ev7ys4VjPHY1RUfGJh7LGJ68Q LrsXDDDhdvrNFt9soiOeXDEJQoOUM7NGFFqQEXfY5s+Q9dsnoRFFGpPdn1MgDmUA1qoq V9/gvhOjhnbTmy3ewBeSW90/MqFOo3vG5dGle74b9+WLKRT04zlqn0wUQTY5SG5eJWTf zRqw== X-Gm-Message-State: AOAM533D3qzrFusxtr8pCs5+qad/q30Yt9HTrilOyBccHPuxRSt7ufFZ WMWXUmXuWu1CxPKiq8W8qsw= X-Google-Smtp-Source: ABdhPJw/q0Wtv6OHoc6C+egXPa7VMW0NBXot/doSPAned3Y4jzcCxQZJC1iv/dcCzcJDnunNN0G7Hg== X-Received: by 2002:a17:906:9747:: with SMTP id o7mr10267400ejy.486.1631291949663; Fri, 10 Sep 2021 09:39:09 -0700 (PDT) Received: from crow.. ([95.87.199.93]) by smtp.gmail.com with ESMTPSA id g9sm3095290edk.54.2021.09.10.09.39.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 09:39:09 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [RFC PATCH 4/4] libtracefs: Remove tracefs_hist_add_key() Date: Fri, 10 Sep 2021 19:38:57 +0300 Message-Id: <20210910163857.324696-5-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210910163857.324696-1-y.karadz@gmail.com> References: <20210910163857.324696-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Since we have appropriate constructor for N-dimensional histograms, this method is no longer needed. Signed-off-by: Yordan Karadzhov (VMware) --- Documentation/libtracefs-hist-cont.txt | 8 +- Documentation/libtracefs-hist.txt | 8 +- include/tracefs.h | 2 - src/tracefs-hist.c | 110 +++++++++++-------------- 4 files changed, 58 insertions(+), 70 deletions(-) diff --git a/Documentation/libtracefs-hist-cont.txt b/Documentation/libtracefs-hist-cont.txt index 1b0153c..d584b46 100644 --- a/Documentation/libtracefs-hist-cont.txt +++ b/Documentation/libtracefs-hist-cont.txt @@ -82,15 +82,15 @@ int main (int argc, char **argv, char **env) exit(-1); } - hist = tracefs_hist_alloc(instance, "kmem", "kmalloc", - "call_site", TRACEFS_HIST_KEY_SYM); + hist = tracefs_hist2d_alloc(instance, "kmem", "kmalloc", + "call_site", TRACEFS_HIST_KEY_SYM, + "bytes_req", 0); if (!hist) { fprintf(stderr, "Failed hist create\n"); exit(-1); } - ret = tracefs_hist_add_key(hist, "bytes_req", 0); - ret |= tracefs_hist_add_value(hist, "bytes_alloc"); + ret = tracefs_hist_add_value(hist, "bytes_alloc"); ret |= tracefs_hist_add_sort_key(hist, "bytes_req", "bytes_alloc", NULL); ret |= tracefs_hist_sort_key_direction(hist, "bytes_alloc", diff --git a/Documentation/libtracefs-hist.txt b/Documentation/libtracefs-hist.txt index 0254c5f..692f488 100644 --- a/Documentation/libtracefs-hist.txt +++ b/Documentation/libtracefs-hist.txt @@ -186,15 +186,15 @@ int main (int argc, char **argv, char **env) exit(-1); } - hist = tracefs_hist_alloc(instance, "kmem", "kmalloc", - "call_site", TRACEFS_HIST_KEY_SYM); + hist = tracefs_hist2d_alloc(instance, "kmem", "kmalloc", + "call_site", TRACEFS_HIST_KEY_SYM, + "bytes_req", 0); if (!hist) { fprintf(stderr, "Failed hist create\n"); exit(-1); } - ret = tracefs_hist_add_key(hist, "bytes_req", 0); - ret |= tracefs_hist_add_value(hist, "bytes_alloc"); + ret = tracefs_hist_add_value(hist, "bytes_alloc"); ret |= tracefs_hist_add_sort_key(hist, "bytes_req", "bytes_alloc", NULL); ret |= tracefs_hist_sort_key_direction(hist, "bytes_alloc", diff --git a/include/tracefs.h b/include/tracefs.h index 255be9b..5c193a2 100644 --- a/include/tracefs.h +++ b/include/tracefs.h @@ -303,8 +303,6 @@ const char *tracefs_get_hist_name(struct tracefs_hist *hist); const char *tracefs_get_hist_event(struct tracefs_hist *hist); const char *tracefs_get_hist_system(struct tracefs_hist *hist); struct tracefs_instance *tracefs_get_hist_instance(struct tracefs_hist *hist); -int tracefs_hist_add_key(struct tracefs_hist *hist, const char *key, - enum tracefs_hist_key_type type); int tracefs_hist_add_value(struct tracefs_hist *hist, const char *value); int tracefs_hist_add_sort_key(struct tracefs_hist *hist, char *sort_key); diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c index 175b627..b71b0e3 100644 --- a/src/tracefs-hist.c +++ b/src/tracefs-hist.c @@ -217,6 +217,55 @@ tracefs_hist2d_alloc(struct tracefs_instance * instance, return tracefs_hist_alloc(instance, system, event, axis); } +static int add_hist_key(struct tracefs_hist *hist, const char *key, + enum tracefs_hist_key_type type) +{ + bool use_key = false; + char *key_type = NULL; + char **new_list; + int ret; + + switch (type) { + case TRACEFS_HIST_KEY_NORMAL: + use_key = true; + ret = 0; + break; + case TRACEFS_HIST_KEY_HEX: + ret = asprintf(&key_type, "%s.hex", key); + break; + case TRACEFS_HIST_KEY_SYM: + ret = asprintf(&key_type, "%s.sym", key); + break; + case TRACEFS_HIST_KEY_SYM_OFFSET: + ret = asprintf(&key_type, "%s.sym-offset", key); + break; + case TRACEFS_HIST_KEY_SYSCALL: + ret = asprintf(&key_type, "%s.syscall", key); + break; + case TRACEFS_HIST_KEY_EXECNAME: + ret = asprintf(&key_type, "%s.execname", key); + break; + case TRACEFS_HIST_KEY_LOG: + ret = asprintf(&key_type, "%s.log2", key); + break; + case TRACEFS_HIST_KEY_USECS: + ret = asprintf(&key_type, "%s.usecs", key); + break; + } + + if (ret < 0) + return -1; + + new_list = tracefs_list_add(hist->keys, use_key ? key : key_type); + free(key_type); + if (!new_list) + return -1; + + hist->keys = new_list; + + return 0; +} + /** * tracefs_hist_alloc - Initialize N-dimensional histogram * @instance: The instance the histogram will be in (NULL for toplevel) @@ -262,7 +311,7 @@ tracefs_hist_alloc(struct tracefs_instance * instance, goto fail; for (; axes && axes->key; axes++) - if (tracefs_hist_add_key(hist, axes->key, axes->type) < 0) + if (add_hist_key(hist, axes->key, axes->type) < 0) goto fail; return hist; @@ -272,65 +321,6 @@ tracefs_hist_alloc(struct tracefs_instance * instance, return NULL; } -/** - * tracefs_hist_add_key - add to a key to a histogram - * @hist: The histogram to add the key to. - * @key: The name of the key field. - * @type: The type of the key format. - * - * This adds a secondary or tertiary key to the histogram. - * - * Returns 0 on success, -1 on error. - */ -int tracefs_hist_add_key(struct tracefs_hist *hist, const char *key, - enum tracefs_hist_key_type type) -{ - bool use_key = false; - char *key_type = NULL; - char **new_list; - int ret; - - switch (type) { - case TRACEFS_HIST_KEY_NORMAL: - use_key = true; - ret = 0; - break; - case TRACEFS_HIST_KEY_HEX: - ret = asprintf(&key_type, "%s.hex", key); - break; - case TRACEFS_HIST_KEY_SYM: - ret = asprintf(&key_type, "%s.sym", key); - break; - case TRACEFS_HIST_KEY_SYM_OFFSET: - ret = asprintf(&key_type, "%s.sym-offset", key); - break; - case TRACEFS_HIST_KEY_SYSCALL: - ret = asprintf(&key_type, "%s.syscall", key); - break; - case TRACEFS_HIST_KEY_EXECNAME: - ret = asprintf(&key_type, "%s.execname", key); - break; - case TRACEFS_HIST_KEY_LOG: - ret = asprintf(&key_type, "%s.log2", key); - break; - case TRACEFS_HIST_KEY_USECS: - ret = asprintf(&key_type, "%s.usecs", key); - break; - } - - if (ret < 0) - return -1; - - new_list = tracefs_list_add(hist->keys, use_key ? key : key_type); - free(key_type); - if (!new_list) - return -1; - - hist->keys = new_list; - - return 0; -} - /** * tracefs_hist_add_value - add to a value to a histogram * @hist: The histogram to add the value to.