Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4462819ioa; Wed, 27 Apr 2022 04:32:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxclHTDFHeMXKnxhz8GhVsL/qPIxeh/lAOM1KM/R6dSzIyFvBjsiMtFqCjVKSf71VTdUAkc X-Received: by 2002:a63:80c8:0:b0:3c1:5213:acb5 with SMTP id j191-20020a6380c8000000b003c15213acb5mr1192695pgd.557.1651059167572; Wed, 27 Apr 2022 04:32:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651059167; cv=none; d=google.com; s=arc-20160816; b=kOsFhf9h2ue3Ldjz9F4yTUR5aVF+l6mxMMb/Cu2skbOYg4GicGOGLFHxrwCAb2bXP0 HR85l+JqEpGUAmLp+mTn5qFbxdtI0WPIeUgeBkE62m6JG8SyjjI+6z6d028uODgLjpDl 1ztNkvj0wNetqvT1Db5hzrX9bKUyTeZb9Yjt6m0+GtCu+hy8f0KZdOvlfKIpnxfK2xjr LV6ZfHnT98R0zcCKNxqwAcOPbIpLrAicrySYBuys9ZAtytoPw4ifo9qkrx5TOAKOTbwd TzbbRZhNW34CeRu4B+NoF767P2Fgak3lhqpvQYwEzlTpDOdA/xYIZZFXhgM9X5+HbxSf 4xMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=LEw35Gp3O6jItGy5TeIREN+UddKvpiKz43OtX2JxC44=; b=OtjSd8pBhttSdBwWnmjhwp/lUK+e0OhqFfGuTU8tfG/bPpMJsy202SUdojmRxPGNXg 9J89ckLiN0wTi6zwiLBgLeZ9+DTOzsTyMyt+inJ0VB7eDTMTD5FsGRJQulr41vQfKMoQ 8teG9ygT71j2KzaboWue7c5kDPdojv8h+/ZPW2MUm2sEsbRubYr2CkUqsbRMN2vcZKnk z90DkDhJeHzmYqAnjkiGh/3HzL3p5NiDNxV8nfgJqTaaJUsFzrtqv/5a7xpC6XHaR1t1 BYplGa/5/8HjJ5hjXvFPxvO3/Y2vae+5X8RsKsKAULunqdIOucjdUcyxdUGGW4u6rHsO wIsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=gwADGskl; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id w4-20020a170902e88400b00153b2d165f5si1539851plg.509.2022.04.27.04.32.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 04:32:47 -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; dkim=pass header.i=@google.com header.s=20210112 header.b=gwADGskl; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8E5E6C848C; Wed, 27 Apr 2022 03:20:17 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352341AbiD0Bqk (ORCPT + 99 others); Tue, 26 Apr 2022 21:46:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236081AbiD0Bqj (ORCPT ); Tue, 26 Apr 2022 21:46:39 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2182B33EBF for ; Tue, 26 Apr 2022 18:43:30 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id v12so440157wrv.10 for ; Tue, 26 Apr 2022 18:43:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LEw35Gp3O6jItGy5TeIREN+UddKvpiKz43OtX2JxC44=; b=gwADGsklxjgdgANW7WaTe0AWCSx6+zME7mNBDa+HZoyoqD892mcONC4xTne87haJmd akJpYS2M2erRLSTrWOiywXtw/wJBv5jx6SncUA+XVb5KDp0am6DsBiHmNLkI9GKAu9hl M2fzvTlkxCQTcpxyxQz5l+1ymJUB/FkEQgKK9amNt5kcJddywFnqnS/ghVzOBAX2qn8/ 2U3VflbOA01kMtN82G3GoesgogAlSh07G9/XZAIl/NxKIdu8s+cOGvXGABReWw9TWkWI vs/lc9zkJPihvbQOJX0g4vRLyZtHKIbNmpnMv6OEd5lu7bcoV3LfaKdlUzFF6UARS7kh D4wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LEw35Gp3O6jItGy5TeIREN+UddKvpiKz43OtX2JxC44=; b=ULmIWZ1+9iN8iFGIlBwgJy85L53/vW9dyAMU9xVOpR1hHFHaFBe3/US9MQoaZM6Fdy QYx+nRJ2kwflgEI7RnSUhqvj0HhXEtUXse1Mc1fre166arERQ6kAPLKVY+qwneKtTz4b tbjrw5HiLVivgCEJEoFOAHdhgVPnMHX88jdIOwIlYSsuC3lDRgF7rAw7J9YSdZlp45Zx enn+JOw0JuEzDSwYU+1RZOlTh6wGwiWIiufCj1sogh6HGaG8PIDdO+mA+z87k8JIM0uA kXUi8lcbJbiZt7NjoXEBY53/YW7tHvKgt4KHUNC3RYDFVtJj4xsQ3etKTv3dBKCW272u dIqQ== X-Gm-Message-State: AOAM531os1GMA7NBwB8tehN74JkeAJsF7W94WXzzSVqPcVkA11tZ8oV9 XKU4rERRn1JYer09gBjP4StndB+QOXKWG+MFFcmUyw== X-Received: by 2002:adf:eb09:0:b0:207:bb77:9abb with SMTP id s9-20020adfeb09000000b00207bb779abbmr20421879wrn.375.1651023808407; Tue, 26 Apr 2022 18:43:28 -0700 (PDT) MIME-Version: 1.0 References: <20220420102354.468173-1-florian.fischer@muhq.space> <20220420102354.468173-2-florian.fischer@muhq.space> In-Reply-To: <20220420102354.468173-2-florian.fischer@muhq.space> From: Ian Rogers Date: Tue, 26 Apr 2022 18:43:16 -0700 Message-ID: Subject: Re: [PATCH v4 1/3] perf stat: introduce stats for the user and system rusage times To: Florian Fischer Cc: linux-perf-users@vger.kernel.org, Xing Zhengjun , linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,USER_IN_DEF_DKIM_WL 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 On Wed, Apr 20, 2022 at 3:24 AM Florian Fischer wrote: > > 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); > +} Is there a missing call to this function? Thanks, Ian > +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.36.0 >