Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5000717rdb; Tue, 12 Dec 2023 16:16:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IHDzCck1yPTLXBO1j0AHCVUNMPmMMI94Ho8EVg3R4/ndv1zk6/h5Ey0Bfj09+YbzcpOwuE6 X-Received: by 2002:a17:90b:1bc3:b0:286:4579:a67c with SMTP id oa3-20020a17090b1bc300b002864579a67cmr3549613pjb.15.1702426571072; Tue, 12 Dec 2023 16:16:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702426571; cv=none; d=google.com; s=arc-20160816; b=JfO1cqDbESOhFxQnXWl35jGmM6imQnb/YSlL6GZN4yM93bcCWHxzYOM9IDBUVZgXCX OeZZmT8e4itth/heMi31BVjQfTGcvULKBMaAxgABl70y25VuOo4iuAr+FwXEJwKSd8YY +2raxaIVJcYyc8V86eqvMtZHryfhKQ7SI+CW4fBkH+z1Fhzppq/7w+Kxx1+R/rJIOqKR ktn6MS1kXYJPt8UdN1rl1oR6A589fI7J9I6OcFh+6TjYqYJtt8RcsaOjeloF1jULiLbg uvrntf4e1paCph5ialAz0VmZ5ZNhJq+Hzozd3driL2+VkCcMut6/Y37yTBrzYh2cTPhM /J2A== 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=pfai8ZdPoFkOghSjq9znXjq6BNqecnfi+Uhs1ECso1A=; fh=7Id7wL2M+oCJXD4imOzx4OKioxBXSOZqypDprm7aO4E=; b=Mv12RYu4ThE+0J/nKEcKV16L91TVFS0+pKQWUfuhiPKdiX5EO5RXZU4sdF1a5KtHhQ zytSQn5Xfu3GEgg27dIE0FaxLUBruQbcPbtCVP68JqMlGE/TAcDCSkTl5wOci8pdOapt BfKzEgdloA3m0fASi7kBzxwY6iOy2+0Bc1rYfBvFnXfcHomBHVos2Z19Zrlr44CrLl/Q Jca6K6o2nXrar96+QmZO+h0rkH3jlJLwG9V9380EbStHvF+w3PQU+ntb8RqrS3JXi4NN QscvSSPxW1kXWcRx4lK//UCBXnnn9XRXzRx9pXC71UDVN5gZwnfyKnMcfSilqrUmXukm PqcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=D5DrRpXu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id v7-20020a17090a6b0700b0028ad8255f28si675262pjj.31.2023.12.12.16.16.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 16:16:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=D5DrRpXu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 96C8C801B41A; Tue, 12 Dec 2023 16:16:01 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377920AbjLMAO0 (ORCPT + 99 others); Tue, 12 Dec 2023 19:14:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378076AbjLMAOK (ORCPT ); Tue, 12 Dec 2023 19:14:10 -0500 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB15119E; Tue, 12 Dec 2023 16:13:48 -0800 (PST) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1d0c4d84bf6so38279105ad.1; Tue, 12 Dec 2023 16:13:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702426427; x=1703031227; 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=pfai8ZdPoFkOghSjq9znXjq6BNqecnfi+Uhs1ECso1A=; b=D5DrRpXu+zfsX4V3yLUVs3Kul6DMLqDVJEtiqcXuhfTcLYEV+kaUlp/TX2Yh8Pv2wv SeV9Ah1Iy5sNPj6zKTkwb2ZYiBidtG5ySzegpSRiR16AkduK0P0D0qOcDCxOd/slBxEK vhkEixmWWmGiOWosX6dkbklRkikRrBg9HH7MaaECBCRcK0yB65xI7SfwrTsc7EDbCfei qNZ2XWAmUy0d0kFY8t51OR8AP/XwD1ibiwR9cIzB1dZiRpN7c67PsHsS/IdZeaHWeKb1 7Fwy1q/YfQANMREGQBW80mkzzZolAjzxt8whZn7MTaqaj6prmPSaK0Kw1aBYRoYnok+c SEQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702426427; x=1703031227; 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=pfai8ZdPoFkOghSjq9znXjq6BNqecnfi+Uhs1ECso1A=; b=n5QGPf58e0PZmaiuDbOgWvuUxsmNqNbYttEdP4nca8ce1okW01snUHjnykU56kXbYU zL6cpbGbHl/3o8yV6UzUAGebbDrssb3O07afIHiH2kxgbVWE8FCYA90dWsM2nP2xd+IH E0h/AUJLHgZhNzJTtVThZMGKN6xAswxeciZi/JzYfyO/laB2f3joAZwYVhUPZqter0Ap 4QVFc+hFv/Jmz3QnBt9in2OwMvQsI0OqXG/6VDBfIKCnCZoW3FmGD38E2mHZErPRwsAO glNFo8wgh2Jhr5hdMj8LZpC7mwzxhSan8cRQFYFzz9K1Q020x5eNtx8LpXVciSZPHzoU iRWQ== X-Gm-Message-State: AOJu0Yy+V4N/JMbqwJm6hrx11Lky5nfsInmPJaBF0HSw83j2E8i99yMj 8YJLYbFHxbPNxHwZ3BVZx/0= X-Received: by 2002:a17:903:11cd:b0:1d3:2e0e:c889 with SMTP id q13-20020a17090311cd00b001d32e0ec889mr2318864plh.62.1702426427405; Tue, 12 Dec 2023 16:13:47 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 16:13:46 -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 12/17] perf report: Add 'typeoff' sort key Date: Tue, 12 Dec 2023 16:13:18 -0800 Message-ID: <20231213001323.718046-13-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 howler.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 (howler.vger.email [0.0.0.0]); Tue, 12 Dec 2023 16:16:01 -0800 (PST) The typeoff sort key shows the data type name, offset and the name of the field. This is useful to see which field in the struct is accessed most frequently. $ perf report -s type,typeoff --hierarchy --stdio ... # Overhead Data Type / Data Type Offset # ............ ............................ # ... 1.23% struct cfs_rq 0.19% struct cfs_rq +404 (throttle_count) 0.19% struct cfs_rq +0 (load.weight) 0.19% struct cfs_rq +336 (leaf_cfs_rq_list.next) 0.09% struct cfs_rq +272 (propagate) 0.09% struct cfs_rq +196 (removed.nr) 0.09% struct cfs_rq +80 (curr) 0.09% struct cfs_rq +544 (lt_b_children_throttled) 0.06% struct cfs_rq +320 (rq) Signed-off-by: Namhyung Kim --- tools/perf/Documentation/perf-report.txt | 1 + tools/perf/util/annotate.c | 1 + tools/perf/util/hist.h | 1 + tools/perf/util/sort.c | 83 +++++++++++++++++++++++- tools/perf/util/sort.h | 2 + 5 files changed, 87 insertions(+), 1 deletion(-) diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt index aec34417090b..b57eb51b47aa 100644 --- a/tools/perf/Documentation/perf-report.txt +++ b/tools/perf/Documentation/perf-report.txt @@ -119,6 +119,7 @@ OPTIONS to the previous instruction in cycles. And currently supported only on X86 - simd: Flags describing a SIMD operation. "e" for empty Arm SVE predicate. "p" for partial Arm SVE predicate - type: Data type of sample memory access. + - typeoff: Offset in the data type of sample memory access. By default, comm, dso and symbol keys are used. (i.e. --sort comm,dso,symbol) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 6747779ecef8..f966e8f83c5e 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -3716,6 +3716,7 @@ struct annotated_data_type *hist_entry__get_data_type(struct hist_entry *he) op_loc->offset, he->stat.nr_events, he->stat.period); + he->mem_type_off = op_loc->offset; return mem_type; } return NULL; diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 7ebbf427b1ea..18128a49309e 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -83,6 +83,7 @@ enum hist_column { HISTC_ADDR, HISTC_SIMD, HISTC_TYPE, + HISTC_TYPE_OFFSET, HISTC_NR_COLS, /* Last entry */ }; diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index a41209e242ae..d78e680d3988 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -2153,8 +2153,10 @@ static void sort__type_init(struct hist_entry *he) return; he->mem_type = hist_entry__get_data_type(he); - if (he->mem_type == NULL) + if (he->mem_type == NULL) { he->mem_type = &unknown_type; + he->mem_type_off = 0; + } } static int64_t @@ -2198,6 +2200,84 @@ struct sort_entry sort_type = { .se_width_idx = HISTC_TYPE, }; +/* --sort typeoff */ + +static int64_t +sort__typeoff_sort(struct hist_entry *left, struct hist_entry *right) +{ + struct annotated_data_type *left_type = left->mem_type; + struct annotated_data_type *right_type = right->mem_type; + int64_t ret; + + if (!left_type) { + sort__type_init(left); + left_type = left->mem_type; + } + + if (!right_type) { + sort__type_init(right); + right_type = right->mem_type; + } + + ret = strcmp(left_type->self.type_name, right_type->self.type_name); + if (ret) + return ret; + return left->mem_type_off - right->mem_type_off; +} + +static void fill_member_name(char *buf, size_t sz, struct annotated_member *m, + int offset, bool first) +{ + struct annotated_member *child; + + if (list_empty(&m->children)) + return; + + list_for_each_entry(child, &m->children, node) { + if (child->offset <= offset && offset < child->offset + child->size) { + int len = 0; + + /* It can have anonymous struct/union members */ + if (child->var_name) { + len = scnprintf(buf, sz, "%s%s", + first ? "" : ".", child->var_name); + first = false; + } + + fill_member_name(buf + len, sz - len, child, offset, first); + return; + } + } +} + +static int hist_entry__typeoff_snprintf(struct hist_entry *he, char *bf, + size_t size, unsigned int width __maybe_unused) +{ + struct annotated_data_type *he_type = he->mem_type; + char buf[4096]; + + buf[0] = '\0'; + if (list_empty(&he_type->self.children)) + snprintf(buf, sizeof(buf), "no field"); + else + fill_member_name(buf, sizeof(buf), &he_type->self, + he->mem_type_off, true); + buf[4095] = '\0'; + + return repsep_snprintf(bf, size, "%s %+d (%s)", he_type->self.type_name, + he->mem_type_off, buf); +} + +struct sort_entry sort_type_offset = { + .se_header = "Data Type Offset", + .se_cmp = sort__type_cmp, + .se_collapse = sort__typeoff_sort, + .se_sort = sort__typeoff_sort, + .se_init = sort__type_init, + .se_snprintf = hist_entry__typeoff_snprintf, + .se_width_idx = HISTC_TYPE_OFFSET, +}; + struct sort_dimension { const char *name; @@ -2254,6 +2334,7 @@ static struct sort_dimension common_sort_dimensions[] = { DIM(SORT_GLOBAL_RETIRE_LAT, "retire_lat", sort_global_p_stage_cyc), DIM(SORT_SIMD, "simd", sort_simd), DIM(SORT_ANNOTATE_DATA_TYPE, "type", sort_type), + DIM(SORT_ANNOTATE_DATA_TYPE_OFFSET, "typeoff", sort_type_offset), }; #undef DIM diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h index aabf0b8331a3..d806adcc1e1e 100644 --- a/tools/perf/util/sort.h +++ b/tools/perf/util/sort.h @@ -113,6 +113,7 @@ struct hist_entry { u64 p_stage_cyc; u8 cpumode; u8 depth; + int mem_type_off; struct simd_flags simd_flags; /* We are added by hists__add_dummy_entry. */ @@ -247,6 +248,7 @@ enum sort_type { SORT_GLOBAL_RETIRE_LAT, SORT_SIMD, SORT_ANNOTATE_DATA_TYPE, + SORT_ANNOTATE_DATA_TYPE_OFFSET, /* branch stack specific sort keys */ __SORT_BRANCH_STACK, -- 2.43.0.472.g3155946c3a-goog