Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp31926pxh; Thu, 7 Apr 2022 13:05:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLl+Oyqtnt7no1IeHw1vvnvaYbdzfuHFjEeGrZQ35YoQS3vB4YFv5iirRiDxJVYSRfgHLu X-Received: by 2002:a65:5605:0:b0:399:4e2f:413d with SMTP id l5-20020a655605000000b003994e2f413dmr12333754pgs.504.1649361922372; Thu, 07 Apr 2022 13:05:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649361922; cv=none; d=google.com; s=arc-20160816; b=aCK7nD0FYatuHiHM00ZloaAwYwTGuQ7Ldja6rhXVN3Q1SE28i43ObPZac1Cjm72lmC 5ppiUyD+VFWd01SuZW7HZqoITBOMRxzLwWxK1GLDDLfOrnhoH+o+gRX8mmAf2+VoL0E5 iqqDEE1l75u6mdxXPD9+P0tzO2yO0Mhc9mQ1xwyHMIIlQwJoM8O0yC76Fw1Nt+EGk0BB sdRxItSP4BBkVrwDC6ZmH5YdyF5hcxMUJdhZ1Rb761gF0zlgRqLdCLqcRPvJb4p/DAGf IW5FtkFA8ULkVlstVqVV0Me6YtvtaF3NKYpuzpqsmiPshG57F6xrMIqr85U+7wfNFOLb tEcQ== 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=YgX/Ch4snq3lUonCDtFA06PwMEiptVBAMG3kQ3+CiFE=; b=vy87MzAvdzJ5sbbPskrm557jH24kVBqkJTMcP1rfl2TiS79a59mLxFpxNTIzefdKRS EMDnaH/qD+oW+zdqzJ3i+V8CwU546k9cuUywfruYXB5rl7x9y286XMo7gFNL3j7/gcTR KDApVl7pJZ5BVMB3Fu86F3vA6fiBzg0o8QTCAScffgbQbjZ+Wvq8pkqP0pD1MDaffgDU lrPmAV5t7utYvG9xedj8o1nawqGZB27uYxa36r2rQwu3hP467fOfSGaaTwW/YgAjADEK t2KVrE2J7TmAKUaqB3eqEH4UmnrtF7Au0XU0RD9+Pi9BOF0jmzClEQkM0mh2PmZ//s9b l9+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id k17-20020a63f011000000b003816043ef29si19951407pgh.286.2022.04.07.13.05.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 13:05:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 631202A1E83; Thu, 7 Apr 2022 12:29:28 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243457AbiDGJA1 (ORCPT + 99 others); Thu, 7 Apr 2022 05:00:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235118AbiDGJAZ (ORCPT ); Thu, 7 Apr 2022 05:00:25 -0400 Received: from euporie.uberspace.de (euporie.uberspace.de [185.26.156.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 487492229E for ; Thu, 7 Apr 2022 01:58:21 -0700 (PDT) Received: (qmail 17897 invoked by uid 989); 7 Apr 2022 08:58:19 -0000 Authentication-Results: euporie.uberspace.de; auth=pass (plain) From: Florian Fischer To: Xing Zhengjun Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Florian Schmaus , Florian Fischer Subject: [PATCH v3 1/3] perf stat: introduce stats for the user and system rusage times Date: Thu, 7 Apr 2022 10:57:19 +0200 Message-Id: <20220407085721.3289414-2-florian.fischer@muhq.space> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407085721.3289414-1-florian.fischer@muhq.space> References: <69656438-8b9a-000b-0702-02dc480639f9@linux.intel.com> <20220407085721.3289414-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; Thu, 07 Apr 2022 10:58: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 nanoseconds to be consistent with 'duration_time', although the finest resolution the struct timeval data in rusage provides are microseconds. Signed-off-by: Florian Fischer --- tools/perf/builtin-stat.c | 5 ++++- tools/perf/util/stat-shadow.c | 2 ++ tools/perf/util/stat.h | 21 +++++++++++++++++++++ 3 files changed, 27 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..e31c94d952e9 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,20 @@ 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) { + const u64 us_to_ns = 1000; + const u64 s_to_ns = 1000000000; + update_stats(&ru_stats->ru_utime_usec_stat, + (rusage->ru_utime.tv_usec * us_to_ns + rusage->ru_utime.tv_sec * s_to_ns)); + update_stats(&ru_stats->ru_stime_usec_stat, + (rusage->ru_stime.tv_usec * us_to_ns + rusage->ru_stime.tv_sec * s_to_ns)); +} + struct evsel; struct evlist; @@ -196,6 +216,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