From patchwork Fri Sep 24 09:56:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12514873 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A0B8C433EF for ; Fri, 24 Sep 2021 09:57:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4A9CA610D1 for ; Fri, 24 Sep 2021 09:57:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245408AbhIXJ6t (ORCPT ); Fri, 24 Sep 2021 05:58:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245366AbhIXJ6t (ORCPT ); Fri, 24 Sep 2021 05:58:49 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25015C061574 for ; Fri, 24 Sep 2021 02:57:16 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id v22so33185911edd.11 for ; Fri, 24 Sep 2021 02:57:16 -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=Cs9pri9txCRkuN4l34KuLQVenfVooL4RZhs9R67bSBo=; b=MS3f5d6MHjPqFYuNMc6+UZ4ItONH7xdMureLS1dM52SB8SNx/BarmYBkHnDYq5rhzc I9mkuKRFAEGeBd+o97FGx0IVSgIvqKapiyaBSg6ZGaS/sbR+CdQevX2Njzz4F+4EQRud 9FBcVWcQ+7IjK2NDLIAChLyOu9Adjh2iUau1eVMI9zd2n0aWYt05m55mCGaHxH04shZJ jwMwbqIfPpods5o2vLTS1UYJ1fVnrwtn/Lg8adr/KE69OkWQotOE+QQrnGGoIciH05J6 W+eQGFZNq5UNsURl5g28YwtL24M2gZoAg7WrA57nMAvlNmK98oWADs8x4U3HO8HJ6S5R gBxQ== 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=Cs9pri9txCRkuN4l34KuLQVenfVooL4RZhs9R67bSBo=; b=0siufhkYBV9K5fGT0tU6BkhbwamgCVjNSAMCWmKL4H5jMVxxnrDhxJm7OEGFQRRojS pNDgiRPrN71moihHQOxV6jKqPR6kxiTU6YdoVzPgndP82ZFKEztzSf7Q9uE/buXOMFJp ihb/aSHknQ6RaZ9Vhe3tIhCui48B7iA6qOUGF7N1zvhBby/NlPaeOV+xTno4eTiMeW3u SxEMaZdKr1smEqxRznf1D93p+ym0p2u9QzvwqaOf4CJYykARwlLYafh5/NmaPOS8nuJ4 cYnLVH05lmFdcuhaqzovVA9AdQI9ipN9XrQxFdtBUxI7vbc2u1dhXLAfebFNIBKcug3f xGmA== X-Gm-Message-State: AOAM530v/Hl1ujqH+OyZjsZnGyDpUlNCAKCDIcSbWa16d8lMFMKgishB fZfJS3Alia5smopIV/XZ12bST6EvuG0= X-Google-Smtp-Source: ABdhPJzKDeRhodBYcfCogZfQUcdh5z9j/jUEwQx62qZ8fKpW9SUanJ0jEtWMOTClvoTDsQwTqMLa4A== X-Received: by 2002:a17:907:98e6:: with SMTP id ke6mr10693130ejc.63.1632477434608; Fri, 24 Sep 2021 02:57:14 -0700 (PDT) Received: from crow.. ([84.40.93.30]) by smtp.gmail.com with ESMTPSA id n13sm4635907ejk.97.2021.09.24.02.57.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 02:57:14 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [PATCH v2 1/4] libtracefs: Add new constructors for histograms Date: Fri, 24 Sep 2021 12:56:59 +0300 Message-Id: <20210924095702.151826-2-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210924095702.151826-1-y.karadz@gmail.com> References: <20210924095702.151826-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 | 19 +++++++++-- src/tracefs-hist.c | 84 ++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 87 insertions(+), 16 deletions(-) diff --git a/include/tracefs.h b/include/tracefs.h index 9d84777..5c4141e 100644 --- a/include/tracefs.h +++ b/include/tracefs.h @@ -310,10 +310,25 @@ enum tracefs_compare { }; void tracefs_hist_free(struct tracefs_hist *hist); +struct tracefs_hist * +tracefs_hist1d_alloc(struct tep_handle *tep, + const char *system, const char *event_name, + const char *key, enum tracefs_hist_key_type type); +struct tracefs_hist * +tracefs_hist2d_alloc(struct tep_handle *tep, + const char *system, const char *event_name, + 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 tep_handle *tep, - const char *system, const char *event, - const char *key, enum tracefs_hist_key_type type); + const char *system, const char *event_name, + 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 c112b68..ea12204 100644 --- a/src/tracefs-hist.c +++ b/src/tracefs-hist.c @@ -189,7 +189,7 @@ void tracefs_hist_free(struct tracefs_hist *hist) } /** - * tracefs_hist_alloc - Initialize a histogram + * tracefs_hist1d_alloc - Initialize one-dimensional histogram * @tep: The tep handle that has the @system and @event. * @system: The system the histogram event is in. * @event_name: The name of the event that the histogram will be attached to. @@ -205,15 +205,70 @@ void tracefs_hist_free(struct tracefs_hist *hist) * NULL on failure. */ struct tracefs_hist * +tracefs_hist1d_alloc(struct tep_handle *tep, + const char *system, const char *event_name, + const char *key, enum tracefs_hist_key_type type) +{ + struct tracefs_hist_axis axis[] = {{key, type}, {NULL, 0}}; + + return tracefs_hist_alloc(tep, system, event_name, axis); +} + +/** + * tracefs_hist2d_alloc - Initialize two-dimensional histogram + * @tep: The tep handle that has the @system and @event. + * @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 tep_handle *tep, + const char *system, const char *event_name, + 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(tep, system, event_name, axis); +} + +/** + * tracefs_hist_alloc - Initialize N-dimensional histogram + * @tep: The tep handle that has the @system and @event. + * @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 tep_handle *tep, const char *system, const char *event_name, - const char *key, enum tracefs_hist_key_type type) + struct tracefs_hist_axis *axes) { struct tep_event *event; struct tracefs_hist *hist; - int ret; - if (!system || !event_name || !key) + if (!system || !event_name) return NULL; event = tep_find_event_by_name(tep, system, event_name); @@ -226,20 +281,21 @@ tracefs_hist_alloc(struct tep_handle *tep, tep_ref(tep); hist->tep = tep; - hist->event = event; hist->system = strdup(system); hist->event_name = strdup(event_name); + if (!hist->system || !hist->event_name) + 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; } /** @@ -1768,8 +1824,8 @@ tracefs_synth_get_start_hist(struct tracefs_synth *synth) return NULL; } } else { - hist = tracefs_hist_alloc(tep, system, event, - key, type); + hist = tracefs_hist1d_alloc(tep, system, event, + key, type); if (!hist) return NULL; } From patchwork Fri Sep 24 09:57:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12514875 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D5A9C433FE for ; Fri, 24 Sep 2021 09:57:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 57F6760E54 for ; Fri, 24 Sep 2021 09:57:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245422AbhIXJ6u (ORCPT ); Fri, 24 Sep 2021 05:58:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245366AbhIXJ6t (ORCPT ); Fri, 24 Sep 2021 05:58:49 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB0C1C061574 for ; Fri, 24 Sep 2021 02:57:16 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id c21so33546837edj.0 for ; Fri, 24 Sep 2021 02:57:16 -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=WrqulUvtP74+nU2f2uM9SgxrL0TZt6t58MMlLBelMmM=; b=gBGH3tjssGoG4SetsguM56aBB195zgHfml9UPctX/Zodr9brL3v/uULXHOCILQAeNB gY0ukgZvH1fsVd4GZ9WVgGcylhX2tUneoTL3zoWMgOzj/i1x20/YXOi3/0K0R9UqKLvL JI5jHHKQApRRFKS1oCCqMhqfGkIQVhrLGx8fDpjJCEOdrIqCFuDkuQ+uPMnuqSYdvOsH gI7AERqFZ/K0ZETzd8RD62AWJuEBcPQhATOZF9XqhgL8TGp6zBwveUvF5Lj6zwGODx8W MRiP40DidbhV6Ze7fCrbgdbcvFguBcYKMMHgEbKj6TeJKeNK5Dzg23P3rsD01qmXIvz2 1blA== 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=WrqulUvtP74+nU2f2uM9SgxrL0TZt6t58MMlLBelMmM=; b=DF+RMI06BUWS2Opmegg6KwTgNu/iXikCgPDZ18c+LjiouXP8u7sYOk+i/OL6QG/gUf Yb6v0WCVC2mw/J0ZNHrNzSvjwViisNgeskDh5e9RS/YKlzFJIWjpNHe36pzFvt7brgT9 PyqdCiFryhiMDBs7SqptmD6p3371HQTgJ8IpRTH6oJzGRG1y40RTGtx5v7U7DF9D7lgI dKFyHI1JucCJqPf9uy2FvwqujGneaUDMKtaAI2P5oyKW07oY7tz4FRG2Xbt79+RNzhkw ineBN9cRZvpOFfk53PrigNqv4HYpMoFfVy7sWyywRRQMWuBpjK/8TkM9NNwHitjqfQFf 9gJA== X-Gm-Message-State: AOAM531mp/KMYbO699dlgWz+cG6P6H4lf39PLgOn2gQjoasrlzR8DtN1 zLLotMwUPGu2BgXh7CCJvuzsggSCIpQ= X-Google-Smtp-Source: ABdhPJy+ULjfyM6lRNkcxx/lj7LngUEsTVdjVb7TI+GvMDR2nTEzpzICCv2EbRKtYKSRm69afuJDTw== X-Received: by 2002:a17:906:1707:: with SMTP id c7mr9702417eje.377.1632477435492; Fri, 24 Sep 2021 02:57:15 -0700 (PDT) Received: from crow.. ([84.40.93.30]) by smtp.gmail.com with ESMTPSA id n13sm4635907ejk.97.2021.09.24.02.57.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 02:57:15 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [PATCH v2 2/4] libtracefs: Transform tracefs_hist_add_sort_key() Date: Fri, 24 Sep 2021 12:57:00 +0300 Message-Id: <20210924095702.151826-3-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210924095702.151826-1-y.karadz@gmail.com> References: <20210924095702.151826-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 has to know the number of sort keys at compile time, because the method overwrite all previously added keys. The problem is addressed by creating a tracefs_hist_add_sort_key() into two methods - one that overwrite and one that does not. The current version of 'tracefs_hist_add_sort_key()' gets renamed to 'tracefs_hist_set_sort_key()' without introducing any functional changes. In the same time a new 'tracefs_hist_add_sort_key()' function is defined. The new function can add one new sort key to the list of previously added sort keys. Signed-off-by: Yordan Karadzhov (VMware) --- include/tracefs.h | 4 +++- src/tracefs-hist.c | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/include/tracefs.h b/include/tracefs.h index 5c4141e..230bc41 100644 --- a/include/tracefs.h +++ b/include/tracefs.h @@ -333,7 +333,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, ...); + const char *sort_key); +int tracefs_hist_reset_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 ea12204..a7c20de 100644 --- a/src/tracefs-hist.c +++ b/src/tracefs-hist.c @@ -437,16 +437,43 @@ add_sort_key(struct tracefs_hist *hist, const char *sort_key, char **list) /** * tracefs_hist_add_sort_key - add a key for sorting the histogram * @hist: The histogram to add the sort key to + * @sort_key: The key to sort + * + * Call the function to add to the list of sort keys of the histohram in + * the order of priority that the keys would be sorted on output. + * + * Returns 0 on success, -1 on error. + */ +int tracefs_hist_add_sort_key(struct tracefs_hist *hist, + const 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_reset_sort_key - set a key for sorting the histogram + * @hist: The histogram to set the sort key to * @sort_key: The key to sort (and the strings after it) * Last one must be NULL. * - * Add a list of sort keys in the order of priority that the + * Set a list of sort keys in the order of priority that the * keys would be sorted on output. Keys must be added first. * * Returns 0 on success, -1 on error. */ -int tracefs_hist_add_sort_key(struct tracefs_hist *hist, - const char *sort_key, ...) +int tracefs_hist_reset_sort_key(struct tracefs_hist *hist, + const char *sort_key, ...) { char **list = NULL; char **tmp; From patchwork Fri Sep 24 09:57:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12514877 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E8E9C433EF for ; Fri, 24 Sep 2021 09:57:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4FB8C6103D for ; Fri, 24 Sep 2021 09:57:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245440AbhIXJ6v (ORCPT ); Fri, 24 Sep 2021 05:58:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245366AbhIXJ6u (ORCPT ); Fri, 24 Sep 2021 05:58:50 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AF5DC061574 for ; Fri, 24 Sep 2021 02:57:17 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id g8so33953997edt.7 for ; Fri, 24 Sep 2021 02:57:17 -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=4odmzpDi60uR+rmTTCdS/sgV65qAvxbWzIa/TiYa5NM=; b=qIYyvmHeNNnWJrz38CiIPL/0gJm8mdNT+wrmRHPsNNGLBcOa1IOOCmrLt9JmQUYm8B 9n/tlV+aao1bzDbIYcZyYOXY+eS9NR2Q0Wn2DpBa0UswhS4K0EMmnmtwiBWQCY0lt90H kS9Rzrh5twIynLq8qB+tavSmCaev1p1e3aEYsnumLbfadvesfRYOLI7VJD5TII4cy983 1Nm8T1za/fXEpgs4RPlhO/fcfqU6hdG0ArrHCOBpFiUsh4xK5UqVS7e2LlQ9Wdxz3V5T JvQKQFaI7Na3CEx1Pehs/S46aQaEdI+P8ak458L47Kr24hIcxgrob/JZtCUgz6YyV+A7 sP+A== 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=4odmzpDi60uR+rmTTCdS/sgV65qAvxbWzIa/TiYa5NM=; b=ZZcZzoUNrdRMABW70Vi/mQGNQOc1YitL/+eB0QRYlZPdrrl1SWjuL8AmuBmQIWOlD0 6p6M1sEVxiFIXeN6LioF4YS8LOQUdugFpjIxLHt0BcY1s5uz97cZirFnIfY0f89S/9bh F+MnZNRKPmSZmXkPoFWV1NlGUCFtXq4ZtSnUGKrPeFRNUx2BD+vLqmHgUegSUEpGFmp6 6ZsFq0GRsIwAtmWusn4DSrxVxCQGgCW1NTbaPUI29r7MfL85wLohwTZXDmiHm2OorM7f tVz8dtkKW3htopeNTddRf01D4E2xHszeqWzC0JxsjM9ALGcemYHoymwztngbdxyKeZaT Bkng== X-Gm-Message-State: AOAM530ehuzaH4wsPE5r7PuAf9EV2mdoIOu9H61GZXTBpPQOqgjESDIX j26iI4pKxObceGIDmTf6q4/lg/P7n9k= X-Google-Smtp-Source: ABdhPJxBsXlHDIlJ2jHRrmgBfsMxYl7Ylcmb7F/m+JdQhJO2+lYVw0Jxt5TWtLIZnBSDDbgoGtLEjA== X-Received: by 2002:a50:cfc3:: with SMTP id i3mr3843475edk.36.1632477436278; Fri, 24 Sep 2021 02:57:16 -0700 (PDT) Received: from crow.. ([84.40.93.30]) by smtp.gmail.com with ESMTPSA id n13sm4635907ejk.97.2021.09.24.02.57.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 02:57:16 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [PATCH v2 3/4] libtracefs: Add new 'hist' APIs Date: Fri, 24 Sep 2021 12:57:01 +0300 Message-Id: <20210924095702.151826-4-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210924095702.151826-1-y.karadz@gmail.com> References: <20210924095702.151826-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 | 3 +++ src/tracefs-hist.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/tracefs.h b/include/tracefs.h index 230bc41..ebe83fe 100644 --- a/include/tracefs.h +++ b/include/tracefs.h @@ -329,6 +329,9 @@ struct tracefs_hist * tracefs_hist_alloc(struct tep_handle *tep, const char *system, const char *event_name, 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); 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 a7c20de..27bab00 100644 --- a/src/tracefs-hist.c +++ b/src/tracefs-hist.c @@ -39,6 +39,21 @@ struct tracefs_hist { unsigned int filter_state; }; +const char *tracefs_get_hist_name(struct tracefs_hist *hist) +{ + return hist ? hist->name : NULL; +} + +const char *tracefs_get_hist_event(struct tracefs_hist *hist) +{ + return hist ? hist->event_name : NULL; +} + +const char *tracefs_get_hist_system(struct tracefs_hist *hist) +{ + return hist ? hist->system : NULL; +} + static void add_list(struct trace_seq *seq, const char *start, char **list) { From patchwork Fri Sep 24 09:57:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12514879 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3E8DC433EF for ; Fri, 24 Sep 2021 09:57:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AAA4260E54 for ; Fri, 24 Sep 2021 09:57:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245468AbhIXJ65 (ORCPT ); Fri, 24 Sep 2021 05:58:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245451AbhIXJ6v (ORCPT ); Fri, 24 Sep 2021 05:58:51 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69235C061574 for ; Fri, 24 Sep 2021 02:57:18 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id ee50so33993795edb.13 for ; Fri, 24 Sep 2021 02:57:18 -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=wBCqjXHWBmBSRhU1TRAUjG9WWuUPmGhegCeaVXbL/p0=; b=Fa0GfDBQhnp3doKLDhua1L4d5pKrQ+Mt7cI5N7gnXQf23UMfO5OfWonMby2O0yjy9E 12bIqYtrA4VdaZ8W4aLAGMU/PI9fqb6DdmEZUZTuvmtfFmzrhOhV6GbEI2BbHZ8CKCvf ugcjVB4InEqTXwBkU1Gmr9hGo7mvClziF3S1DbtRZ939X5bKyQTaN2lyd5UaupU/mQHx /cYWHAqQ3KCXGkowy71M5zriHaDIU/yQdX82IGTJysKkz8cOg8lBukENqm/TTqZzz4D1 3PESmM7WimGjKs1k2zpxph4vCofSMzwN5Z6qiST3IRCR5726DdPC9Qw3KODIijzuCj3b KZEA== 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=wBCqjXHWBmBSRhU1TRAUjG9WWuUPmGhegCeaVXbL/p0=; b=o4cS23Y6OCxhx/YGVRwToZ2cIQcm9+s6TKwY0jQc8DdRQlSVqhgmbWaZAR7WRpN43l 8DxxvlWHK0NaAse7Vr9dgCTrhmiCQor+fl6YoGLP51DwgedsJ9wiHKi2ZR7KEa4BOhi7 BMxb8d8fYJ/z/M5tL4i54cdTB4qOAo6JbpBm9jbA+C9p6sF1foINEmEzkuFO12vgaJSY s/HSW+RKmx1QDcHx53SSCb8sI1F/Lfc1F6SCMIFtst+1MwryZYH/kPdrRR9m2nXGmImn ed44nmjTkOCgvtn3TFYW3arQ+tG+o3URuPYblV2GzV6/RnHlExNrWEnL2v7yAbCD1ne8 6bSg== X-Gm-Message-State: AOAM533Ox8aASYoP+55vfUj2cv0V+QqtHIun4FkCKsX4JiZ8jidareUe shS3lg4xPntL5Up0gD/ophU= X-Google-Smtp-Source: ABdhPJyAEo/luze2dWY8yYfZZmvvNAbkFoi2dGmzx8489G23/ifgonOlDqtkCw7r0GkS5yLI/q6YTA== X-Received: by 2002:a50:e009:: with SMTP id e9mr3878222edl.254.1632477437014; Fri, 24 Sep 2021 02:57:17 -0700 (PDT) Received: from crow.. ([84.40.93.30]) by smtp.gmail.com with ESMTPSA id n13sm4635907ejk.97.2021.09.24.02.57.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 02:57:16 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [PATCH v2 4/4] libtracefs: Update 'hist' documentation Date: Fri, 24 Sep 2021 12:57:02 +0300 Message-Id: <20210924095702.151826-5-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210924095702.151826-1-y.karadz@gmail.com> References: <20210924095702.151826-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org New 'hist' APIs have been added and some existing APIs have been modified. Here we update the documentation accordingly. Signed-off-by: Yordan Karadzhov (VMware) --- Documentation/libtracefs-hist-cont.txt | 30 ++++++++-- Documentation/libtracefs-hist.txt | 80 +++++++++++++++----------- 2 files changed, 69 insertions(+), 41 deletions(-) diff --git a/Documentation/libtracefs-hist-cont.txt b/Documentation/libtracefs-hist-cont.txt index 1b0153c..2ee830d 100644 --- a/Documentation/libtracefs-hist-cont.txt +++ b/Documentation/libtracefs-hist-cont.txt @@ -11,18 +11,36 @@ SYNOPSIS -- *#include * -int tracefs_hist_pause(struct tracefs_hist pass:[*]hist); -int tracefs_hist_continue(struct tracefs_hist pass:[*]hist); -int tracefs_hist_reset(struct tracefs_hist pass:[*]hist); +int tracefs_hist_start(struct tracefs_instance pass:[*]instance, struct tracefs_hist pass:[*]hist); +int tracefs_hist_destory(struct tracefs_instance pass:[*]instance, struct tracefs_hist pass:[*]hist); +int tracefs_hist_pause(struct tracefs_instance pass:[*]instance, struct tracefs_hist pass:[*]hist); +int tracefs_hist_continue(struct tracefs_instance pass:[*]instance, struct tracefs_hist pass:[*]hist); +int tracefs_hist_reset(struct tracefs_instance pass:[*]instance, struct tracefs_hist pass:[*]hist); + -- DESCRIPTION ----------- + +*tracefs_hist_start* is called to actually start the histogram _hist_. +The _instance_ is the instance to start the histogram in, NULL if it +should start at the top level. + *tracefs_hist_pause* is called to pause the histogram _hist_. +The _instance_ is the instance to pause the histogram in, NULL if it +is in the top level. *tracefs_hist_continue* is called to continue a paused histogram _hist_. +The _instance_ is the instance to continue the histogram, NULL if it +is in the top level. *tracefs_hist_reset* is called to clear / reset the histogram _hist_. +The _instance_ is the instance to clear the histogram, NULL if it +is in the top level. + +*tracefs_hist_destory* is called to delete the histogram where it will no longer +exist. The _instance_ is the instance to delete the histogram from, NULL if it +is in the top level. RETURN VALUE ------------ @@ -83,14 +101,14 @@ int main (int argc, char **argv, char **env) } hist = tracefs_hist_alloc(instance, "kmem", "kmalloc", - "call_site", TRACEFS_HIST_KEY_SYM); + "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 03ac077..0139ba8 100644 --- a/Documentation/libtracefs-hist.txt +++ b/Documentation/libtracefs-hist.txt @@ -4,7 +4,7 @@ libtracefs(3) NAME ---- tracefs_hist_alloc, tracefs_hist_free, tracefs_hist_add_key, tracefs_hist_add_value, tracefs_hist_add_name, tracefs_hist_start, -tracefs_hist_destory, tracefs_hist_add_sort_key, tracefs_hist_sort_key_direction - Create and update event histograms +tracefs_hist_destory, tracefs_hist_add_sort_key, tracefs_hist_reset_sort_key,tracefs_hist_sort_key_direction - Create and update event histograms SYNOPSIS -------- @@ -12,15 +12,24 @@ SYNOPSIS -- *#include * -struct tracefs_hist pass:[*]tracefs_hist_alloc(struct tracefs_tep pass:[*] tep, +struct tracefs_hist pass:[*]tracefs_hist1d_alloc(struct tracefs_tep pass:[*] tep, const char pass:[*]system, const char pass:[*]event, const char pass:[*]key, enum tracefs_hist_key_type type); +struct tracefs_hist pass:[*]tracefs_hist2d_alloc(struct tracefs_tep pass:[*] tep, + const char pass:[*]system, const char pass:[*]event, + const char pass:[*]key1, enum tracefs_hist_key_type type1, + const char pass:[*]key2, enum tracefs_hist_key_type type2)); +struct tracefs_hist pass:[*]tracefs_hist_alloc(struct tracefs_tep pass:[*] tep, + const char pass:[*]system, const char pass:[*]event, + struct tracefs_hist_axis [*]axes); void tracefs_hist_free(struct tracefs_hist pass:[*]hist); int tracefs_hist_add_key(struct tracefs_hist pass:[*]hist, const char pass:[*]key, enum tracefs_hist_key_type type); int tracefs_hist_add_value(struct tracefs_hist pass:[*]hist, const char pass:[*]value); int tracefs_hist_add_sort_key(struct tracefs_hist pass:[*]hist, - const char pass:[*]sort_key, ...); + const char pass:[*]sort_key); +int tracefs_hist_reset_sort_key(struct tracefs_hist pass:[*]hist, + const char pass:[*]sort_key, ...); int tracefs_hist_sort_key_direction(struct tracefs_hist pass:[*]hist, const char pass:[*]sort_key, enum tracefs_hist_sort_direction dir); @@ -36,8 +45,7 @@ int tracefs_hist_show(struct trace_seq pass:[*]s, struct tracefs_instance pass:[ int tracefs_hist_command(struct tracefs_instance pass:[*]instance, struct tracefs_hist pass:[*]hist, enum tracefs_hist_command command); -int tracefs_hist_start(struct tracefs_instance pass:[*]instance, struct tracefs_hist pass:[*]hist); -int tracefs_hist_destory(struct tracefs_instance pass:[*]instance, struct tracefs_hist pass:[*]hist); + -- DESCRIPTION @@ -47,14 +55,31 @@ The syntax can be complex and difficult to get correct. This API handles the syntax, and facilitates the creation and interaction with the event histograms. See https://www.kernel.org/doc/html/latest/trace/histogram.html for more information. -*tracefs_hist_alloc*() allocates a "struct tracefs_hist" descriptor and returns -the address of it. This descriptor must be freed by *tracefs_hist_free*(). +*tracefs_hist1d_alloc*() allocates a "struct tracefs_hist" descriptor of a one-dimensional +histogram and returns the address of it. This descriptor must be freed by *tracefs_hist_free*(). The _tep_ is a trace event handle (see *tracefs_local_events*(3)), that holds the _system_ and _event_ that the histogram will be attached to. The _system_ is the system or group of the event. The _event_ is the event to attach the histogram to. -The _key_ is a field of the event that will be used as the key of the histogram. +The _key_ is a field of the event that will be used as the key(dimension) of the histogram. The _type_ is the type of the _key_. See KEY TYPES below. +*tracefs_hist2d_alloc*() allocates a "struct tracefs_hist" descriptor of a two-dimensional +histogram and returns the address of it. This descriptor must be freed by *tracefs_hist_free*(). +The _tep_ is a trace event handle (see *tracefs_local_events*(3)), that holds the +_system_ and _event_ that the histogram will be attached to. The _system_ is the +system or group of the event. The _event_ is the event to attach the histogram to. +The _key1_ is the first field of the event that will be used as the key(dimension) +of the histogram. The _type1_ is the type of the _key1_. See KEY TYPES below. +The _key2_ is the second field of the event that will be used as the key(dimension) +of the histogram. The _type2_ is the type of the _key2_. See KEY TYPES below. + +*tracefs_hist_alloc*() allocates a "struct tracefs_hist" descriptor of an N-dimensional +histogram and returns the address of it. This descriptor must be freed by *tracefs_hist_free*(). +The _tep_ is a trace event handle (see *tracefs_local_events*(3)), that holds the +_system_ and _event_ that the histogram will be attached to. The _system_ is the +system or group of the event. The _event_ is the event to attach the histogram to. +The _axes_ is an array of _key_ / _type_ pairs, defining the dimentions of the histogram. + *tracefs_hist_free*() frees the _tracefs_hist_ descriptor. Note, it does not stop or disable the running histogram if it was started. *tracefs_hist_destroy*() needs to be called to do so. @@ -73,8 +98,14 @@ key was hit. The _hist_ is the histogram descriptor to add the value to. The _value_ is a field in the histogram to add to when an instane of the key is hit. -*tracefs_hist_add_sort_key*() will add a key to sort on. Th _hist_ is the -the histrogram descriptor to add the sort key to. The _sort_key_ is a string +*tracefs_hist_add_sort_key*() will add a key to sort on. The _hist_ is the +histrogram descriptor to add the sort key to. The _sort_key_ is a string +that must match either an already defined key of the histogram, or an already +defined value. If _hist_ already has sorting keys (previously added) the new +_sort_key_ will have lower priority(be secondary or so on) when sorting. + +*tracefs_hist_reset_sort_key*() will reset the list of key to sort on. The _hist_ is +the histrogram descriptor to reset the sort key to. The _sort_key_ is a string that must match either an already defined key of the histogram, or an already defined value. Multiple sort keys may be added to denote a secondary, sort order and so on, but all sort keys must match an existing key or value, or be @@ -146,27 +177,6 @@ The _cmd_ can be one of: The below functions are wrappers to tracefs_hist_command() to make the calling conventions a bit easier to understand what is happening. -*tracefs_hist_start* is called to actually start the histogram _hist_. -The _instance_ is the instance to start the histogram in, NULL if it -should start at the top level. - -*tracefs_hist_pause* is called to pause the histogram _hist_. -The _instance_ is the instance to pause the histogram in, NULL if it -is in the top level. - -*tracefs_hist_continue* is called to continue a paused histogram _hist_. -The _instance_ is the instance to continue the histogram, NULL if it -is in the top level. - -*tracefs_hist_reset* is called to clear / reset the histogram _hist_. -The _instance_ is the instance to clear the histogram, NULL if it -is in the top level. - -*tracefs_hist_destory* is called to delete the histogram where it will no longer -exist. The _instance_ is the instance to delete the histogram from, NULL if it -is in the top level. - - KEY TYPES --------- @@ -263,15 +273,15 @@ int main (int argc, char **argv, char **env) } tep = tracefs_local_events(NULL); - hist = tracefs_hist_alloc(tep, "kmem", "kmalloc", - "call_site", TRACEFS_HIST_KEY_SYM); + hist = tracefs_hist2d_alloc(tep, "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",