Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5000652rdb; Tue, 12 Dec 2023 16:16:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IFbKRpI5oK+WROquDwoUYpH27UaTEtwcKC2wRYJZaeS3WNdzvOXt91oa4DALFBlgu90/TWt X-Received: by 2002:a05:6e02:1bce:b0:35d:6ee2:17fd with SMTP id x14-20020a056e021bce00b0035d6ee217fdmr10248821ilv.30.1702426562783; Tue, 12 Dec 2023 16:16:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702426562; cv=none; d=google.com; s=arc-20160816; b=mlkUAzZYKGbftp1Iyn+10d+VXc2jgcrETZvYDxJ9zC0dbWzhmfkU0MP6oTliIDMbCY zpFn73pgPGATcO7tFv+yrsgiZEVizymSvyRh76qSJnKYv+NZkbuKuuThr49+y3cJgREW tytHKBjdqM4XWMk9icQ1v+bWUgmGPkjjO+vnuTdHHQEh6zlure6ejuIlkriyRKtwF9Uk BOEwbt5c6+TgVGCdlQV6tOhdBwZAi9aLbNJ2UVQwOn9OafqUjSFfFKhYJ8aUt0576T2r IFaDVocuItgzc4n+esIhLhEAoRzcdzejNxXICYua7+S5fzrzu9A7gtQCOy0rQxAtmZN+ 9d+g== 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:sender :dkim-signature; bh=VxLAF5RjXuu8mgch2ETJfxdZfj9JgVVMGl5qHF6yEa4=; fh=7Id7wL2M+oCJXD4imOzx4OKioxBXSOZqypDprm7aO4E=; b=OBkNifkuBBRtBcgqmS+R/uhyzqnCf1cY+8BVwctl+AlVEKWxwi4r9JiPjDu5FIWoUo lDgw5CTnTvxzu+8zo0cMKmfoKqSoKhW9YYqmt1pu3RPw071HYwv2RuiJkkjkb4okMnMn 1jOEC1AJTdt3VD/4HBenlfq4EhmgivErifzD7SQ48hXAcXqxKxcDX5TOkFnhL3h1zEu2 XERIZCVUM9dYkAVaiIZIRFyi+yG2PHB0xIPUR9wsy6StTjsTo0Bxzx2Sda2P7nNa0EJG fozSGBDTZW214d1ie0IuArixi48Hfm0J79wf3oS39yk+HLqVf9dd9S7Sx5Xd878OFhQa 0oqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Lof7l3mS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id bq6-20020a056a02044600b005b928c7b284si8976241pgb.587.2023.12.12.16.16.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 16:16:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Lof7l3mS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 9291D807BED4; Tue, 12 Dec 2023 16:15:17 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378064AbjLMAOw (ORCPT + 99 others); Tue, 12 Dec 2023 19:14:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378140AbjLMAOW (ORCPT ); Tue, 12 Dec 2023 19:14:22 -0500 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F41DED54; Tue, 12 Dec 2023 16:13:54 -0800 (PST) Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1d06819a9cbso38208615ad.1; Tue, 12 Dec 2023 16:13:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702426433; x=1703031233; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=VxLAF5RjXuu8mgch2ETJfxdZfj9JgVVMGl5qHF6yEa4=; b=Lof7l3mSxSFZZktBxx/wmeIf5p7QoPcHcEhSEq2/k7hzIwb8hqBUm2WT7JmvJwZjl0 tXpagBxvR4Sv5efpIbw8AIDQZ8jPSzQhGsIIBB9OsucpsPA+HJc2E8/OmRUdDp3TE3Vf 0DfKsqeo0cGxCVQcWEeC+GKfzomXDUH++tTgHWuz4Na7HiMeSUBJvkf061sqluZz8pN+ 8O/8hJ4igbw6bkuKW4iLxR56V6FQW/4oCwhiereE/gz8fAELa+y8LVv8h56+SwTkSmWj 94Ec5nvp3jeTSbjbeZpkPyWXftPNpNP+9ptgSojKJdMclqXsrPGM6VC0wgG1MOEaTxEo Ef2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702426433; x=1703031233; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=VxLAF5RjXuu8mgch2ETJfxdZfj9JgVVMGl5qHF6yEa4=; b=vGoyUPDq7QZr/TqQ45L1Pd29xxn0am2LCzNYe0y6Y7N1XhsPBZIDoqN8etmAxm//p8 MXSZQZH4yIzKqde9Rb/MlkGWxYc/QRrAx8dt5yalCkAeYF0eluQP9jLTzPssrxaUjfJE 4h/2x6stsydXeTtpLkbmXWayuvz8gFRJ50um0Y/D/R2Fa08wuxE+lUW7YtKZHfsXb2ne BnuAXLg/7KaTtrWsuM1YhnnF1gK2Jau3V9iBO611fWuMrTpVGm30N7xV6ccf6jKa9gOY l6YsQxBOJVi+WOKpUTHzbF/OkTz0V3crcNZ8yTOb+Y+lGDRHglfcqfbL4/aPncSohjJg e05Q== X-Gm-Message-State: AOJu0YxgAY8R6I1w1/JXkVAQ7dV3ZQY6tqtSC8HmLC97Sax1CfmiGBz/ L8JF0tGdaCLXxw7tYTH0RUY= X-Received: by 2002:a17:903:1c3:b0:1d3:4783:ce7 with SMTP id e3-20020a17090301c300b001d347830ce7mr860001plh.103.1702426432635; Tue, 12 Dec 2023 16:13:52 -0800 (PST) Received: from bangji.corp.google.com ([2620:15c:2c0:5:8251:f360:4316:214e]) by smtp.gmail.com with ESMTPSA id i11-20020a17090332cb00b001d0ab572458sm9136398plr.121.2023.12.12.16.13.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 16:13:51 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa , Peter Zijlstra Cc: Ian Rogers , Adrian Hunter , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Linus Torvalds , Stephane Eranian , Masami Hiramatsu , linux-toolchains@vger.kernel.org, linux-trace-devel@vger.kernel.org Subject: [PATCH 15/17] perf annotate: Support event group display Date: Tue, 12 Dec 2023 16:13:21 -0800 Message-ID: <20231213001323.718046-16-namhyung@kernel.org> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog In-Reply-To: <20231213001323.718046-1-namhyung@kernel.org> References: <20231213001323.718046-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 12 Dec 2023 16:15:17 -0800 (PST) When events are grouped together, it'd be natural to show them at once like in other mode. Handle group leaders with members to collect the number of samples together and display like below: $ perf annotate --data-type --group ... Annotate type: 'struct page' in vmlinux (1 samples): event[0] = cpu/mem-loads,ldlat=30/P event[1] = cpu/mem-stores/P event[2] = dummy:u ============================================================================ samples offset size field 1 0 0 0 64 struct page { 0 0 0 0 8 long unsigned int flags; 0 0 0 8 40 union { 0 0 0 8 40 struct { 0 0 0 8 16 union { 0 0 0 8 16 struct list_head lru { 0 0 0 8 8 struct list_head* next; 0 0 0 16 8 struct list_head* prev; }; 0 0 0 8 16 struct { 0 0 0 8 8 void* __filler; 0 0 0 16 4 unsigned int mlock_count; }; 0 0 0 8 16 struct list_head buddy_list { 0 0 0 8 8 struct list_head* next; 0 0 0 16 8 struct list_head* prev; }; Signed-off-by: Namhyung Kim --- tools/perf/builtin-annotate.c | 89 ++++++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 12 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 8acfbbc1b9c2..3956ea1334cc 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -325,19 +325,64 @@ static int hist_entry__tty_annotate(struct hist_entry *he, return symbol__tty_annotate2(&he->ms, evsel); } +static void print_annotated_data_header(struct hist_entry *he, struct evsel *evsel) +{ + struct dso *dso = map__dso(he->ms.map); + int nr_members = 1; + int nr_samples = he->stat.nr_events; + + if (evsel__is_group_event(evsel)) { + struct hist_entry *pair; + + list_for_each_entry(pair, &he->pairs.head, pairs.node) + nr_samples += pair->stat.nr_events; + } + + printf("Annotate type: '%s' in %s (%d samples):\n", + he->mem_type->self.type_name, dso->name, nr_samples); + + if (evsel__is_group_event(evsel)) { + struct evsel *pos; + int i = 0; + + for_each_group_evsel(pos, evsel) + printf(" event[%d] = %s\n", i++, pos->name); + + nr_members = evsel->core.nr_members; + } + + printf("============================================================================\n"); + printf("%*s %10s %10s %s\n", 11 * nr_members, "samples", "offset", "size", "field"); +} + static void print_annotated_data_type(struct annotated_data_type *mem_type, struct annotated_member *member, struct evsel *evsel, int indent) { struct annotated_member *child; struct type_hist *h = mem_type->histograms[evsel->core.idx]; - int i, samples = 0; + int i, nr_events = 1, samples = 0; for (i = 0; i < member->size; i++) samples += h->addr[member->offset + i].nr_samples; + printf(" %10d", samples); + + if (evsel__is_group_event(evsel)) { + struct evsel *pos; + + for_each_group_member(pos, evsel) { + h = mem_type->histograms[pos->core.idx]; + + samples = 0; + for (i = 0; i < member->size; i++) + samples += h->addr[member->offset + i].nr_samples; + printf(" %10d", samples); + } + nr_events = evsel->core.nr_members; + } - printf(" %10d %10d %10d %*s%s\t%s", - samples, member->offset, member->size, indent, "", member->type_name, + printf(" %10d %10d %*s%s\t%s", + member->offset, member->size, indent, "", member->type_name, member->var_name ?: ""); if (!list_empty(&member->children)) @@ -347,7 +392,7 @@ static void print_annotated_data_type(struct annotated_data_type *mem_type, print_annotated_data_type(mem_type, child, evsel, indent + 4); if (!list_empty(&member->children)) - printf("%*s}", 35 + indent, ""); + printf("%*s}", 11 * nr_events + 24 + indent, ""); printf(";\n"); } @@ -391,8 +436,6 @@ static void hists__find_annotations(struct hists *hists, } if (ann->data_type) { - struct dso *dso = map__dso(he->ms.map); - /* skip unknown type */ if (he->mem_type->histograms == NULL) goto find_next; @@ -414,11 +457,7 @@ static void hists__find_annotations(struct hists *hists, goto find_next; } - printf("Annotate type: '%s' in %s (%d samples):\n", - he->mem_type->self.type_name, dso->name, he->stat.nr_events); - printf("============================================================================\n"); - printf(" %10s %10s %10s %s\n", "samples", "offset", "size", "field"); - + print_annotated_data_header(he, evsel); print_annotated_data_type(he->mem_type, &he->mem_type->self, evsel, 0); printf("\n"); goto find_next; @@ -521,8 +560,20 @@ static int __cmd_annotate(struct perf_annotate *ann) evsel__reset_sample_bit(pos, CALLCHAIN); evsel__output_resort(pos, NULL); - if (symbol_conf.event_group && !evsel__is_group_leader(pos)) + /* + * An event group needs to display other events too. + * Let's delay printing until other events are processed. + */ + if (symbol_conf.event_group) { + if (!evsel__is_group_leader(pos)) { + struct hists *leader_hists; + + leader_hists = evsel__hists(evsel__leader(pos)); + hists__match(leader_hists, hists); + hists__link(leader_hists, hists); + } continue; + } hists__find_annotations(hists, pos, ann); } @@ -533,6 +584,20 @@ static int __cmd_annotate(struct perf_annotate *ann) goto out; } + /* Display group events together */ + evlist__for_each_entry(session->evlist, pos) { + struct hists *hists = evsel__hists(pos); + u32 nr_samples = hists->stats.nr_samples; + + if (nr_samples == 0) + continue; + + if (!symbol_conf.event_group || !evsel__is_group_leader(pos)) + continue; + + hists__find_annotations(hists, pos, ann); + } + if (use_browser == 2) { void (*show_annotations)(void); -- 2.43.0.472.g3155946c3a-goog