Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp244566rbb; Fri, 23 Feb 2024 21:10:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXlN5Yyiu+timzm6zCFsV4J/ww3NXqwcJBxMtF0secfDW0T22smx+Qb61wkglfOQBpbY4AxzUcUBOm5nX9Nzox8nZnTxwThxr6phoS+AQ== X-Google-Smtp-Source: AGHT+IHSKjho9hyvAl25p6oBH5gVlRMVq7TLSWv1FiXxb6j0GibRMT8xZDr4j41lSYu7E/5aLwDd X-Received: by 2002:a05:6a20:dc98:b0:19e:ce71:bb4d with SMTP id ky24-20020a056a20dc9800b0019ece71bb4dmr1543849pzb.38.1708751456302; Fri, 23 Feb 2024 21:10:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708751456; cv=pass; d=google.com; s=arc-20160816; b=hNw+E8PXVK0W63HMicm1lXvzOuovQMVGaFbQgSodAMJ3DK8WMHtwNEDFzkiQb2PIBi N9S3DpFxmkvLyp7hR8APXUOi7f7yRO1KlvrsK/DiM0LpPhEjmjx93kTYMrDLRJ7CutwB SlCPqE1PdxrrSpI28VcR1vV2rysKI5/y4ZOrG/6n2vdG9PFKH6UvJAR5tN7CTtl4w+7Q e+DcNgtUoCXNEYo91BSh6zqsmdjj0YggDux8917W8cbOq87i9Qkf/HylfGgtpw5O7eCH B3cR8jiRnFijlKbrCVWSvXkLGjyhWE/yokT1bzkRzjF3XAdMajDRFRWRPfdmYfN9bhI1 VXvQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:dkim-signature:date; bh=FwT1c3JSEQOWuaUP6z8lJns3QADyY2PvY4E2x0VTTzo=; fh=wDOAr5fOeQrn9bSrzJ7ni89qq/+loG6kf/+P6aQ17G0=; b=Pt+xrY6N2yRnLo2YSNFNTCusoqurHsrSkNVK4rf4roIZzxKFqf7Fcapbp3qa/6/UC8 yPIXpeJelTg4yvXymFK+RMoWfjefM40f+pT7NZPndd79sseWugtzuD2d0mkEwi3qDiio lbBCCf3RN0mb5VEwl3cklQBdINPfEtgKRslRCHA559R/e0Ndb3NAvwVZW0LrGf3UXVFP BKhapj7Lrqx328wdA8lBBz1mwedLlgK24f8eVwVqH1DeeVoRfbhsvM2GKs3Sguedf4eA f+sok1I5zMfVQ5gHNFCiFEJTkQZRiGnwVhps0G2J8JJqB3t8mzndlQyBPbj7C/4SPZoQ iviw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=tuLBCVtc; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79471-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79471-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id g11-20020a056a0023cb00b006e465f8059bsi389310pfc.278.2024.02.23.21.10.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 21:10:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79471-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=tuLBCVtc; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79471-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79471-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id EF13C2842E4 for ; Sat, 24 Feb 2024 05:10:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B502F171B0; Sat, 24 Feb 2024 05:10:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="tuLBCVtc" Received: from out-182.mta1.migadu.com (out-182.mta1.migadu.com [95.215.58.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B47D125A7 for ; Sat, 24 Feb 2024 05:10:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708751446; cv=none; b=HPrMGkPvvUk3FpZn9hgPn2xxKd4n3YZXXKPofXg2E2wTx0gIMStu4ccTKrrvkBalRUwIm+MhQDs1XutMUHtLoYmyLIUohr5GhzV4S5dmW4SZ2xOI6WCwP/CO1luejTuSd3SQvuMnx5YaNmisToIvUsk8Q+rsM0GZAjp3gm2osjc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708751446; c=relaxed/simple; bh=2vD98sT+UQ2yQWG56xKXb7srFiVLS6GuDr6TzcoR/go=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rR8IwU2oYBv6ICfNOxyjFn/z5Cu8rVqoIlEWfOqM6Dkjik6l3pCYkVr/nyjqwMaT/cK1jXOpOtIpdm6CVQIML3OQQM98X5JF90YSPRGzvEim7g0bASi9kWDRz6FkRnxtsl9hklQdYv3ORmNPa0A+2W+weg00nt5TR9SIQ2zsVfM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=tuLBCVtc; arc=none smtp.client-ip=95.215.58.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Date: Sat, 24 Feb 2024 00:10:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708751442; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=FwT1c3JSEQOWuaUP6z8lJns3QADyY2PvY4E2x0VTTzo=; b=tuLBCVtcSGFdCEuUEohXMOUMjK2i0SyBEYFVNe7wS9cDQFafwoEAjsHjrtrJOxQJ6zczNt hLWfzOtaJNUqZBVW4n5k1n4eQR4pZP9Itj9v8X+H52cDa0lE8hMKkjFzbcxbpBVlmV6eYQ 2somZ+jRP1ysbvaY5H7LitwK2/1xoUM= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: "Darrick J. Wong" Cc: akpm@linux-foundation.org, daniel@gluo.nz, linux-xfs@vger.kernel.org, linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 09/10] time_stats: report information in json format Message-ID: References: <170873667916.1860949.11027844260383646446.stgit@frogsfrogsfrogs> <170873668085.1860949.11659237532415596101.stgit@frogsfrogsfrogs> <20240224041545.GC616564@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240224041545.GC616564@frogsfrogsfrogs> X-Migadu-Flow: FLOW_OUT On Fri, Feb 23, 2024 at 08:15:45PM -0800, Darrick J. Wong wrote: > On Fri, Feb 23, 2024 at 05:12:26PM -0800, Darrick J. Wong wrote: > > From: Darrick J. Wong > > > > Export json versions of time statistics information. Given the tabular > > nature of the numbers exposed, this will make it a lot easier for higher > > (than C) level languages (e.g. python) to import information without > > needing to write yet another clumsy string parser. > > > > Signed-off-by: Darrick J. Wong > > Signed-off-by: Kent Overstreet > > --- > > include/linux/time_stats.h | 2 + > > lib/time_stats.c | 87 ++++++++++++++++++++++++++++++++++++++++++++ > > 2 files changed, 89 insertions(+) > > > > > > diff --git a/include/linux/time_stats.h b/include/linux/time_stats.h > > index b3c810fff963a..4e1f5485ed039 100644 > > --- a/include/linux/time_stats.h > > +++ b/include/linux/time_stats.h > > @@ -156,6 +156,8 @@ static inline bool track_event_change(struct time_stats *stats, bool v) > > struct seq_buf; > > void time_stats_to_seq_buf(struct seq_buf *, struct time_stats *, > > const char *epoch_name, unsigned int flags); > > +void time_stats_to_json(struct seq_buf *, struct time_stats *, > > + const char *epoch_name, unsigned int flags); > > > > void time_stats_exit(struct time_stats *); > > void time_stats_init(struct time_stats *); > > diff --git a/lib/time_stats.c b/lib/time_stats.c > > index 0fb3d854e503b..c0f209dd9f6dd 100644 > > --- a/lib/time_stats.c > > +++ b/lib/time_stats.c > > @@ -266,6 +266,93 @@ void time_stats_to_seq_buf(struct seq_buf *out, struct time_stats *stats, > > } > > EXPORT_SYMBOL_GPL(time_stats_to_seq_buf); > > > > +void time_stats_to_json(struct seq_buf *out, struct time_stats *stats, > > + const char *epoch_name, unsigned int flags) > > +{ > > + struct quantiles *quantiles = time_stats_to_quantiles(stats); > > + s64 f_mean = 0, d_mean = 0; > > + u64 f_stddev = 0, d_stddev = 0; > > + > > + if (stats->buffer) { > > + int cpu; > > + > > + spin_lock_irq(&stats->lock); > > + for_each_possible_cpu(cpu) > > + __time_stats_clear_buffer(stats, per_cpu_ptr(stats->buffer, cpu)); > > + spin_unlock_irq(&stats->lock); > > + } > > + > > + if (stats->freq_stats.n) { > > + /* avoid divide by zero */ > > + f_mean = mean_and_variance_get_mean(stats->freq_stats); > > + f_stddev = mean_and_variance_get_stddev(stats->freq_stats); > > + d_mean = mean_and_variance_get_mean(stats->duration_stats); > > + d_stddev = mean_and_variance_get_stddev(stats->duration_stats); > > + } else if (flags & TIME_STATS_PRINT_NO_ZEROES) { > > + /* unless we didn't want zeroes anyway */ > > + return; > > + } > > + > > + seq_buf_printf(out, "{\n"); > > + seq_buf_printf(out, " \"epoch\": \"%s\",\n", epoch_name); > > + seq_buf_printf(out, " \"count\": %llu,\n", stats->duration_stats.n); > > + > > + seq_buf_printf(out, " \"duration_ns\": {\n"); > > + seq_buf_printf(out, " \"min\": %llu,\n", stats->min_duration); > > + seq_buf_printf(out, " \"max\": %llu,\n", stats->max_duration); > > + seq_buf_printf(out, " \"total\": %llu,\n", stats->total_duration); > > + seq_buf_printf(out, " \"mean\": %llu,\n", d_mean); > > + seq_buf_printf(out, " \"stddev\": %llu\n", d_stddev); > > + seq_buf_printf(out, " },\n"); > > + > > + d_mean = mean_and_variance_weighted_get_mean(stats->duration_stats_weighted, TIME_STATS_MV_WEIGHT); > > + d_stddev = mean_and_variance_weighted_get_stddev(stats->duration_stats_weighted, TIME_STATS_MV_WEIGHT); > > + > > + seq_buf_printf(out, " \"duration_ewma_ns\": {\n"); > > + seq_buf_printf(out, " \"mean\": %llu,\n", d_mean); > > + seq_buf_printf(out, " \"stddev\": %llu\n", d_stddev); > > + seq_buf_printf(out, " },\n"); > > + > > + seq_buf_printf(out, " \"frequency_ns\": {\n"); > > I took the variable names too literally here; these labels really ought > to be "between_ns" and "between_ewma_ns" to maintain consistency with > the labels in the table format. > > > + seq_buf_printf(out, " \"min\": %llu,\n", stats->min_freq); > > + seq_buf_printf(out, " \"max\": %llu,\n", stats->max_freq); > > + seq_buf_printf(out, " \"mean\": %llu,\n", f_mean); > > + seq_buf_printf(out, " \"stddev\": %llu\n", f_stddev); > > + seq_buf_printf(out, " },\n"); > > + > > + f_mean = mean_and_variance_weighted_get_mean(stats->freq_stats_weighted, TIME_STATS_MV_WEIGHT); > > + f_stddev = mean_and_variance_weighted_get_stddev(stats->freq_stats_weighted, TIME_STATS_MV_WEIGHT); > > + > > + seq_buf_printf(out, " \"frequency_ewma_ns\": {\n"); > > + seq_buf_printf(out, " \"mean\": %llu,\n", f_mean); > > + seq_buf_printf(out, " \"stddev\": %llu\n", f_stddev); > > + > > + if (quantiles) { > > + u64 last_q = 0; > > + > > + /* close frequency_ewma_ns but signal more items */ > > (also this comment) > > > + seq_buf_printf(out, " },\n"); > > + > > + seq_buf_printf(out, " \"quantiles_ns\": [\n"); > > + eytzinger0_for_each(i, NR_QUANTILES) { > > + bool is_last = eytzinger0_next(i, NR_QUANTILES) == -1; > > + > > + u64 q = max(quantiles->entries[i].m, last_q); > > + seq_buf_printf(out, " %llu", q); > > + if (!is_last) > > + seq_buf_printf(out, ", "); > > + last_q = q; > > + } > > + seq_buf_printf(out, " ]\n"); > > + } else { > > + /* close frequency_ewma_ns without dumping further */ > > (this one too) > > Kent, would you mind making that edit the next time you reflow your > branch? > > --D > > > + seq_buf_printf(out, " }\n"); > > + } > > + > > + seq_buf_printf(out, "}\n"); > > +} > > +EXPORT_SYMBOL_GPL(time_stats_to_json); > > + > > void time_stats_exit(struct time_stats *stats) > > { > > free_percpu(stats->buffer); > > > > From 5885a65fa5a0aace7bdf1a8fa58ac2bca3b15900 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Sat, 24 Feb 2024 00:10:06 -0500 Subject: [PATCH] fixup! time_stats: report information in json format diff --git a/lib/time_stats.c b/lib/time_stats.c index 0b90c80cba9f..d7dd64baebb8 100644 --- a/lib/time_stats.c +++ b/lib/time_stats.c @@ -313,7 +313,7 @@ void time_stats_to_json(struct seq_buf *out, struct time_stats *stats, seq_buf_printf(out, " \"stddev\": %llu\n", d_stddev); seq_buf_printf(out, " },\n"); - seq_buf_printf(out, " \"frequency_ns\": {\n"); + seq_buf_printf(out, " \"between_ns\": {\n"); seq_buf_printf(out, " \"min\": %llu,\n", stats->min_freq); seq_buf_printf(out, " \"max\": %llu,\n", stats->max_freq); seq_buf_printf(out, " \"mean\": %llu,\n", f_mean); @@ -323,14 +323,14 @@ void time_stats_to_json(struct seq_buf *out, struct time_stats *stats, f_mean = mean_and_variance_weighted_get_mean(stats->freq_stats_weighted, TIME_STATS_MV_WEIGHT); f_stddev = mean_and_variance_weighted_get_stddev(stats->freq_stats_weighted, TIME_STATS_MV_WEIGHT); - seq_buf_printf(out, " \"frequency_ewma_ns\": {\n"); + seq_buf_printf(out, " \"between_ewma_ns\": {\n"); seq_buf_printf(out, " \"mean\": %llu,\n", f_mean); seq_buf_printf(out, " \"stddev\": %llu\n", f_stddev); if (quantiles) { u64 last_q = 0; - /* close frequency_ewma_ns but signal more items */ + /* close between_ewma_ns but signal more items */ seq_buf_printf(out, " },\n"); seq_buf_printf(out, " \"quantiles_ns\": [\n"); @@ -345,7 +345,7 @@ void time_stats_to_json(struct seq_buf *out, struct time_stats *stats, } seq_buf_printf(out, " ]\n"); } else { - /* close frequency_ewma_ns without dumping further */ + /* close between_ewma_ns without dumping further */ seq_buf_printf(out, " }\n"); }