Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3885794pxt; Tue, 10 Aug 2021 13:50:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQn6375J3xEFyohUzSf4md1t2r/JEvedVPR2rKDK1DXFk+SWRCkBS/LwEUatNdHyZrNFsQ X-Received: by 2002:a6b:f919:: with SMTP id j25mr37746iog.2.1628628636699; Tue, 10 Aug 2021 13:50:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628628636; cv=none; d=google.com; s=arc-20160816; b=wIfmTGJmqY1u1jyV+RRlVA9Q63nqZgjZksj+AzPbRSPALiUgjrlgDHkK84/xj1oR0v f4z5aPV7wK18i1wHeQS0qgh9Nhh/N+iwfJapUDPgehrkyyii7sLwnF3yq3xpDvooYYYt oMGDZ7vLYvodJY/BYWWLjFZWC8Uc3F38ZOImEB7xwHnJpvwIbiwRwTa/Vs5fd9GMpVj+ URJmY8YK9unBKOtTnq8cuhVRfw3DFPGeD0XGGnoYDkJsaQlY5JGyapQ970baLUDOx12S KAryTDAfQyR+4kmYdoPVH8oUq2GR4ugXDPYHZrhURAFEN9Pu6N2XRsmZX5khKh1hMgFk 6deQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=JpfNTGLJ6Bul9MClfOdMlVAqOvrpMiWoONdwJ6SJX9Q=; b=YSpZsCPB+0R13AJHEnNicQ54aNNXn/r8E6ArZcwv3P6+4Pfe/ujeIj2zDcaT2yIVMf EU0AeZ4crs0AqMtXyb5Jois6TbEmPnwWajd2bLJLSW92PIS1eBwJmcAy9gTSlFMuKNzk 8HdoFN6picFoql3QNhQoRVrnhh+YKO49tkCpRYOKmAiS+PSwJpA6oEt8PWekw8XmvlmQ TSJSOF/pxii5qGB+Z7f6ba+dO5xreUkD/GEDMVkodPOmYu9qLoQLceduXIpA9RWP/PJd jjGdxs3r68r0Qp7OtAuw2njBtEoNcpD+PVlBhM81MM37quHWi4ikgvjszekn4YteTd7f hPBA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s12si23636100iog.99.2021.08.10.13.50.25; Tue, 10 Aug 2021 13:50:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233749AbhHJUtE (ORCPT + 99 others); Tue, 10 Aug 2021 16:49:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:44290 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232453AbhHJUss (ORCPT ); Tue, 10 Aug 2021 16:48:48 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5494161078; Tue, 10 Aug 2021 20:48:25 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.94.2) (envelope-from ) id 1mDYfg-003hAN-8L; Tue, 10 Aug 2021 16:48:24 -0400 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Tom Zanussi , Daniel Bristot de Oliveira , Masami Hiramatsu , Namhyung Kim , linux-rt-users , Clark Williams , "Steven Rostedt (VMware)" Subject: [PATCH 7/9] libtracefs: Add API tracefs_hist_data_keys/values() and next_bucket() Date: Tue, 10 Aug 2021 16:48:16 -0400 Message-Id: <20210810204818.880714-8-rostedt@goodmis.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210810204818.880714-1-rostedt@goodmis.org> References: <20210810204818.880714-1-rostedt@goodmis.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Steven Rostedt (VMware)" Add APIs: tracefs_hist_data_keys() tracefs_hist_data_values() tracefs_hist_data_next_bucket() tracefs_hist_data_first_bucket() Signed-off-by: Steven Rostedt (VMware) --- include/tracefs.h | 36 ++++++++++++++ src/tracefs-hist-data.c | 107 +++++++++++++++++++++++++++++----------- 2 files changed, 113 insertions(+), 30 deletions(-) diff --git a/include/tracefs.h b/include/tracefs.h index 7aa6a3e5673a..db0a1d73f091 100644 --- a/include/tracefs.h +++ b/include/tracefs.h @@ -431,6 +431,42 @@ void tracefs_hist_data_free_list(struct tracefs_hist_data **hdata_list); char **tracefs_hist_data_key_names(struct tracefs_hist_data *hdata); char **tracefs_hist_data_value_names(struct tracefs_hist_data *hdata); +enum tracefs_bucket_key_flags { + TRACEFS_BUCKET_KEY_FL_UNDEF = (1 << 29), + TRACEFS_BUCKET_KEY_FL_SINGLE = (1 << 30), + TRACEFS_BUCKET_KEY_FL_RANGE = (1 << 31), +}; + +struct tracefs_hist_bucket_key_single { + long long val; + char *sym; +}; + +struct tracefs_hist_bucket_key_range { + long long start; + long long end; +}; + +struct tracefs_hist_bucket_key { + struct tracefs_hist_bucket_key *next; + unsigned int flags; + union { + struct tracefs_hist_bucket_key_single single; + struct tracefs_hist_bucket_key_range range; + }; +}; + +struct tracefs_hist_bucket_val { + struct tracefs_hist_bucket_val *next; + long long val; +}; + +const struct tracefs_hist_bucket_key *tracefs_hist_data_keys(struct tracefs_hist_data *hdata); +const struct tracefs_hist_bucket_val *tracefs_hist_data_values(struct tracefs_hist_data *hdata); + +int tracefs_hist_data_next_bucket(struct tracefs_hist_data *hdata); +int tracefs_hist_data_first_bucket(struct tracefs_hist_data *hdata); + struct tracefs_synth; /* diff --git a/src/tracefs-hist-data.c b/src/tracefs-hist-data.c index c93c27453255..0f811d6e3154 100644 --- a/src/tracefs-hist-data.c +++ b/src/tracefs-hist-data.c @@ -113,36 +113,6 @@ static char *name_token(enum yytokentype type) return NULL; } -enum tracefs_bucket_key_flags { - TRACEFS_BUCKET_KEY_FL_UNDEF = (1 << 29), - TRACEFS_BUCKET_KEY_FL_SINGLE = (1 << 30), - TRACEFS_BUCKET_KEY_FL_RANGE = (1 << 31), -}; - -struct tracefs_hist_bucket_key_single { - long long val; - char *sym; -}; - -struct tracefs_hist_bucket_key_range { - long long start; - long long end; -}; - -struct tracefs_hist_bucket_key { - struct tracefs_hist_bucket_key *next; - unsigned int flags; - union { - struct tracefs_hist_bucket_key_single single; - struct tracefs_hist_bucket_key_range range; - }; -}; - -struct tracefs_hist_bucket_val { - struct tracefs_hist_bucket_val *next; - long long val; -}; - struct tracefs_hist_bucket { struct tracefs_hist_bucket *next; struct tracefs_hist_bucket_key *keys; @@ -165,6 +135,7 @@ struct tracefs_hist_data { struct key_types *current_key_type; struct tracefs_hist_bucket *buckets; struct tracefs_hist_bucket **next_bucket; + struct tracefs_hist_bucket *current_bucket; unsigned long long hits; unsigned long long entries; unsigned long long dropped; @@ -1029,6 +1000,9 @@ tracefs_hist_data_parse(const char *buffer, const char **next_buffer, char **err hist_lex_destroy(data.scanner); free(data.text); + /* Set to read the first bucket after creation */ + tracefs_hist_data_first_bucket(hdata); + return hdata; error: print_error(&data, err, state, type); @@ -1123,3 +1097,76 @@ char **tracefs_hist_data_value_names(struct tracefs_hist_data *hdata) return tracefs_list_dup(hdata->value_names); } +/** + * tracefs_hist_data_keys - Return the content of the keys + * @hdata: The hist data descriptor of the keys + * + * Returns the actual pointer to the key data list in the @hdata descriptor. + * It must not be modified or freed. + */ +const struct tracefs_hist_bucket_key * +tracefs_hist_data_keys(struct tracefs_hist_data *hdata) +{ + if (!hdata || !hdata->current_bucket) + return NULL; + + return hdata->current_bucket->keys; +} + +/** + * tracefs_hist_data_values - Return the content of the values + * @hdata: The hist data descriptor of the values + * + * Returns the actual pointer to the value data list in the @hdata descriptor. + * It must not be modified or freed. + */ +const struct tracefs_hist_bucket_val * +tracefs_hist_data_values(struct tracefs_hist_data *hdata) +{ + if (!hdata || !hdata->current_bucket) + return NULL; + + return hdata->current_bucket->vals; +} + +/** + * tracefs_hist_data_next_bucket - Move to the next bucket with content + * @hdata: The hist data desrciptor + * + * Move the "cursor" of the bucket that tracefs_hist_data_keys() + * and tracefs_hist_data_values() will return their data from. + * + * Returns -1 if @hdata is NULL or already hit the last bucket. + * Returns 0 if there's still data after going to the next bucket + * Returns 1 if there's no more data left. + */ +int tracefs_hist_data_next_bucket(struct tracefs_hist_data *hdata) +{ + if (!hdata || !hdata->current_bucket) + return -1; + + hdata->current_bucket = hdata->current_bucket->next; + + return !hdata->current_bucket; +} + +/** + * tracefs_hist_data_first_bucket - Reset to the first bucket + * @hdata: The hist data desrciptor + * + * Move the "cursor" of the bucket that tracefs_hist_data_keys() + * and tracefs_hist_data_values() will return their data from + * to the first bucket in the @hlist. + * + * Returns -1 if @hdata is NULL or already hit the last bucket. + * Returns 0 if there's still data after going to the next bucket + * Returns 1 if there's no more data left. + */ +int tracefs_hist_data_first_bucket(struct tracefs_hist_data *hdata) +{ + if (!hdata || !hdata->buckets) + return -1; + + hdata->current_bucket = hdata->buckets; + return !hdata->current_bucket; +} -- 2.30.2