Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1044379pxb; Wed, 6 Apr 2022 07:24:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMcCgAsYGbEHBN5W8eX1A8o7xgqxNL9QYWfX5CRUBfZ9XR5cPn5BbTrNrTESYGI/dKT1pW X-Received: by 2002:a17:902:f78d:b0:14d:522e:deb3 with SMTP id q13-20020a170902f78d00b0014d522edeb3mr8897710pln.173.1649255084730; Wed, 06 Apr 2022 07:24:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649255084; cv=none; d=google.com; s=arc-20160816; b=efpRiqj0Lesd+pcjfoKKfgtU121xBEneRxt2wIlyCoO2HdxZF8MWq90MBd3qCl/kZK lKvIk3b7NU85OJpeGgDB9JrCwDsFR9Rfi6lGhha8/j/F/FMuV8w9iFkLe+9Y9z/WCoRk u+Hu+HKdpquy+87oZxoFs3zVWZxykV2mLYcCouAWH7Tq3B2Oe6AjNbuTYfmKcEu0Ugrm OODivQTL3KHS/IiEb3mXgsdWOXbhUctMpHVx3vLLutPNvmJzcMfoxCVzKtZXcOd2J17O fsEQnjQWdHcmOd2DvuGTJa6WVqOVKZSnp2sxtAfSAy985fYhscgeyb4Tpc060skniNhC 1MhQ== 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=gweypQo5NXWkUL/rax6awQTUpVtxzPnP88T323F6OA8=; b=wZ4rWTgiq2Dhh/nCH+65w3Ro+uy3Crjd9HB4lLkCGgpjyK6QQ8OTWnUbleH0E4waUT 9hYT+2UXnhND9vM+Sctm8yUPs2CYs5G9cTjIxfa+Fhey3dte5BDZPjuFM8ZnZ++mbZSK 3ci3xz3dUSdvJle/bmWm1IF86gQM+re9OgJoKOz+nrl2BeNy09pLTrTrGxvo4ufzMHbI RQN39hN4ykMO2rzVzLMdZKMEBB7Fby7k5mKVPbX9Lish3y0zuWCxvgvhbcUUGZdv9FqU COQygoyhesvOWV4mZVtIA38gfVXrSZHP0ybEt8WUlHkThHrfXIOsv5qttPke8HiOsd9N /onw== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id p15-20020a1709028a8f00b001560318de2csi14270637plo.318.2022.04.06.07.24.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 07:24:44 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B90FE4F940B; Wed, 6 Apr 2022 05:08:44 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232137AbiDFL7u (ORCPT + 99 others); Wed, 6 Apr 2022 07:59:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232882AbiDFL6U (ORCPT ); Wed, 6 Apr 2022 07:58:20 -0400 Received: from euporie.uberspace.de (euporie.uberspace.de [185.26.156.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 374775282E5 for ; Wed, 6 Apr 2022 00:29:20 -0700 (PDT) Received: (qmail 8294 invoked by uid 989); 6 Apr 2022 07:29:19 -0000 Authentication-Results: euporie.uberspace.de; auth=pass (plain) From: Florian Fischer To: Arnaldo Carvalho de Melo Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Florian Schmaus , Florian Fischer Subject: [PATCH v2 1/4] perf stat: introduce stats for the user and system rusage times Date: Wed, 6 Apr 2022 09:28:36 +0200 Message-Id: <20220406072839.107519-2-florian.fischer@muhq.space> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220406072839.107519-1-florian.fischer@muhq.space> References: <20220406072839.107519-1-florian.fischer@muhq.space> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Bar: ----- X-Rspamd-Report: R_MISSING_CHARSET(0.5) MIME_GOOD(-0.1) REPLY(-4) MID_CONTAINS_FROM(1) BAYES_HAM(-2.999999) X-Rspamd-Score: -5.599999 Received: from unknown (HELO unkown) (::1) by euporie.uberspace.de (Haraka/2.8.28) with ESMTPSA; Wed, 06 Apr 2022 09:29:19 +0200 X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,FROM_SUSPICIOUS_NTLD, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is preparation for exporting rusage values as tool events. Add new global stats tracking the values obtained via rusage. For now only ru_utime and ru_stime are part of the tracked stats. Both are stored as micro seconds because thats the finest resolution the struct timeval data in rusage provides. --- tools/perf/builtin-stat.c | 5 ++++- tools/perf/util/stat-shadow.c | 2 ++ tools/perf/util/stat.h | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index a96f106dc93a..61faffb535f5 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -216,6 +216,7 @@ static struct perf_stat_config stat_config = { .run_count = 1, .metric_only_len = METRIC_ONLY_LEN, .walltime_nsecs_stats = &walltime_nsecs_stats, + .ru_stats = &ru_stats, .big_num = true, .ctl_fd = -1, .ctl_fd_ack = -1, @@ -1010,8 +1011,10 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) evlist__reset_prev_raw_counts(evsel_list); runtime_stat_reset(&stat_config); perf_stat__reset_shadow_per_stat(&rt_stat); - } else + } else { update_stats(&walltime_nsecs_stats, t1 - t0); + update_rusage_stats(&ru_stats, &stat_config.ru_data); + } /* * Closing a group leader splits the group, and as we only disable diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index 10af7804e482..ea4c35e4f1da 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -26,6 +26,7 @@ struct runtime_stat rt_stat; struct stats walltime_nsecs_stats; +struct rusage_stats ru_stats; struct saved_value { struct rb_node rb_node; @@ -199,6 +200,7 @@ void perf_stat__reset_shadow_stats(void) { reset_stat(&rt_stat); memset(&walltime_nsecs_stats, 0, sizeof(walltime_nsecs_stats)); + memset(&ru_stats, 0, sizeof(ru_stats)); } void perf_stat__reset_shadow_per_stat(struct runtime_stat *st) diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 335d19cc3063..b14a45d8af63 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -108,6 +108,11 @@ struct runtime_stat { struct rblist value_list; }; +struct rusage_stats { + struct stats ru_utime_usec_stat; + struct stats ru_stime_usec_stat; +}; + typedef struct aggr_cpu_id (*aggr_get_id_t)(struct perf_stat_config *config, struct perf_cpu cpu); struct perf_stat_config { @@ -148,6 +153,7 @@ struct perf_stat_config { const char *csv_sep; struct stats *walltime_nsecs_stats; struct rusage ru_data; + struct rusage_stats *ru_stats; struct cpu_aggr_map *aggr_map; aggr_get_id_t aggr_get_id; struct cpu_aggr_map *cpus_aggr_map; @@ -177,6 +183,18 @@ static inline void init_stats(struct stats *stats) stats->max = 0; } +static inline void init_rusage_stats(struct rusage_stats *ru_stats) { + init_stats(&ru_stats->ru_utime_usec_stat); + init_stats(&ru_stats->ru_stime_usec_stat); +} + +static inline void update_rusage_stats(struct rusage_stats *ru_stats, struct rusage* rusage) { + update_stats(&ru_stats->ru_utime_usec_stat, + (rusage->ru_utime.tv_usec + rusage->ru_utime.tv_sec * 1000000ULL)); + update_stats(&ru_stats->ru_stime_usec_stat, + (rusage->ru_stime.tv_usec + rusage->ru_stime.tv_sec * 1000000ULL)); +} + struct evsel; struct evlist; @@ -196,6 +214,7 @@ bool __perf_stat_evsel__is(struct evsel *evsel, enum perf_stat_evsel_id id); extern struct runtime_stat rt_stat; extern struct stats walltime_nsecs_stats; +extern struct rusage_stats ru_stats; typedef void (*print_metric_t)(struct perf_stat_config *config, void *ctx, const char *color, const char *unit, -- 2.35.1