Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1448327lqp; Fri, 22 Mar 2024 15:43:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXwr4HWqxBkkyoXXEZ2u28O889da9DHZgBi6h+sTIsWRlAsZbXYGQGiEtrRyRz7QMGoFBsVXOl2FTQCuOQQh3LIqxOXUNJJtU6aH5VcSg== X-Google-Smtp-Source: AGHT+IHpXwj9i+KAtH2yma67Qnd0+CASSQPgY3ykPYicHnxOBU+Ad65uXwB9ASgsunmWjdpUEWSZ X-Received: by 2002:a17:902:ecd1:b0:1e0:9a0a:7cd with SMTP id a17-20020a170902ecd100b001e09a0a07cdmr1411033plh.37.1711147412143; Fri, 22 Mar 2024 15:43:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711147412; cv=pass; d=google.com; s=arc-20160816; b=ysBKRhmtR7Vcdpx7aVX9lVW/0l+xfGyj4jzjzYs8lD71S4OciCrjWGemy4vXbl6tJ9 Qb+ewFENVqMaY4VryBG2vm9BYrs9wU3xCYnBxttNoA3i/AVbDql3O3sGCVYaLQ25sR4S KHjzTCMqASpGrV9Ye69QdHB/fhCJBWd0BnM4nROhCrjGwS+MRlrugMGE6Lm1CFH0wzNl EGHz2snFsOoAm4FEpyYzre8TnlSfjj+WeiZGrUk3DV3HU/RWHBSJW7WL9bjnwxSnU1fX R7kc3vIOl9k7gV+pT5PxNMgGax9Sc0Y9krNFjKAVAGVQABeYLN/OVl5fQRyA3zxbaU1Y /xLQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=V25y7agglUXj8oAstCJjWDQUDbi2r2TGH+pKBn8spC0=; fh=fHhbvXgCev/wpffLVpfaAi8pPyv7hrTyhVPgsZ7HNrs=; b=P5vTQ8zys8tmOxEk5YB3N1JIBwRHNWmOpTIolFbahgBXKqcJEojNRTYe+T/4FGwOrX AG2OF9OJh+cDYZfJgUAaVz6FyrforcXi+du3LAjK+lExTv0+NwZghttR6TPCcHL0UbrG X3r9D6h5FfvTkOalX1oVQ6ObWd6NtCnMDZT7oZJWMi1+OcjGrcI66Jv5sEyNqLhZEGuT pl/rnyEA85FD0Q25Mcjyc69uRq/l/+jwKDrGQz8qDTo+Q8K++BnQbRX5X4jxYrGupLr+ mCGsgcmuNHfGTeV3eGj/+7x/dmYk3ZcEd9vsMaHOOBi3J3xVS6T89gn/sbdJ6cEU76YP jgyw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=O4bmu+WR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112075-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112075-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id b5-20020a170902650500b001dddcbe0aacsi406384plk.188.2024.03.22.15.43.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 15:43:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112075-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=O4bmu+WR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112075-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112075-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id CCABC28317D for ; Fri, 22 Mar 2024 22:43:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6A38B82C60; Fri, 22 Mar 2024 22:43:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="O4bmu+WR" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C2C582885; Fri, 22 Mar 2024 22:43:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711147395; cv=none; b=q5uTvKcgcFOoTEBhEkHkcnrUJxA4O09faEXHkNfYQzZ35SWtVlUB2YvSBu40mBIHrpPwFkx8BMLPnJoGlEpmgdSRW+/CDYIx4HFJVGUT9OzW+Tqe/DoxpDggNnmKVqYJBiW1na6QSriNVICU7DwPOeYPCs2Q64MTVk9UxsndeNU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711147395; c=relaxed/simple; bh=94c3ApKhfdXXy5yXArKe+AKXVzYjtIcn0YWblDXG74s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JFoMgcZCJTRSTpQlEGq90SdXJKnmoJjd13tWZAdSe8yAKGxcaffKsgta/R+7mzw2/uUmJvzBeQ9fH++SXSpJ9fsADLNnd/ltRthtJAsfJeCAIbWad+QiEnMJA1IVGWEyG/gZJORZ82NHdNYe/R8I4WkLcfEdhekvQgI46G8xTBo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=O4bmu+WR; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91720C433A6; Fri, 22 Mar 2024 22:43:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711147394; bh=94c3ApKhfdXXy5yXArKe+AKXVzYjtIcn0YWblDXG74s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O4bmu+WRE+FtSbvM59nlmr+1cOJLgo+cGiAaGLLr+8H1TT4eOp3M56KF+HRLfIbwK IHsI1g3iU+xAjN/Jo/7fvIZEAYledthK7TBwz23Vr8ijqKpn05luIWUCHRBCpRiZK+ CNcMYR8OvkjIAGvAyLGHwcf0ZI1ywcjqxnkgA2nSvHmlfSZyxvd6MQMGqfMAbUEmCM tbKobMpEnfhHA6Dc0X8ZdWqUm1ghPto70eRVnpikOwuhqTj9lsDIC0NbyF1GgmmwqZ EioGwoobomG3EwOC48nJMbTLgGqcRwI3JMCjgvAQ/ZQTh9GPhEpLhdVcCRGavvdCZY 0IDm/bVWXN6xg== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 2/2] perf annotate: Honor output options with --data-type Date: Fri, 22 Mar 2024 15:43:13 -0700 Message-ID: <20240322224313.423181-2-namhyung@kernel.org> X-Mailer: git-send-email 2.44.0.396.g6e790dbe36-goog In-Reply-To: <20240322224313.423181-1-namhyung@kernel.org> References: <20240322224313.423181-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit For data type profiling output, it should be in sync with normal output so make it display percentage for each field. Also use coloring scheme for users to identify fields with big overhead easily. Users can use --show-total-period or --show-nr-samples to change the output style like in the normal perf annotate output. Before: $ perf annotate --data-type Annotate type: 'struct task_struct' in [kernel.kallsyms] (34 samples): ============================================================================ samples offset size field 34 0 9792 struct task_struct { 2 0 24 struct thread_info thread_info { 0 0 8 long unsigned int flags; 1 8 8 long unsigned int syscall_work; 0 16 4 u32 status; 1 20 4 u32 cpu; }; After: $ perf annotate --data-type Annotate type: 'struct task_struct' in [kernel.kallsyms] (34 samples): ============================================================================ Percent offset size field 100.00 0 9792 struct task_struct { 3.55 0 24 struct thread_info thread_info { 0.00 0 8 long unsigned int flags; 1.63 8 8 long unsigned int syscall_work; 0.00 16 4 u32 status; 1.91 20 4 u32 cpu; }; Signed-off-by: Namhyung Kim --- tools/perf/builtin-annotate.c | 44 ++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 3e9f7e0596e8..16e1581207c9 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -42,6 +42,7 @@ #include #include #include +#include struct perf_annotate { struct perf_tool tool; @@ -332,6 +333,8 @@ static void print_annotated_data_header(struct hist_entry *he, struct evsel *evs struct dso *dso = map__dso(he->ms.map); int nr_members = 1; int nr_samples = he->stat.nr_events; + int width = 7; + const char *val_hdr = "Percent"; if (evsel__is_group_event(evsel)) { struct hist_entry *pair; @@ -353,8 +356,30 @@ static void print_annotated_data_header(struct hist_entry *he, struct evsel *evs nr_members = evsel->core.nr_members; } + if (symbol_conf.show_total_period) { + width = 11; + val_hdr = "Period"; + } else if (symbol_conf.show_nr_samples) { + width = 7; + val_hdr = "Samples"; + } + printf("============================================================================\n"); - printf("%*s %10s %10s %s\n", 11 * nr_members, "samples", "offset", "size", "field"); + printf("%*s %10s %10s %s\n", (width + 1) * nr_members, val_hdr, + "offset", "size", "field"); +} + +static void print_annotated_data_value(struct type_hist *h, u64 period, int nr_samples) +{ + double percent = h->period ? (100.0 * period / h->period) : 0; + const char *color = get_percent_color(percent); + + if (symbol_conf.show_total_period) + color_fprintf(stdout, color, " %11" PRIu64, period); + else if (symbol_conf.show_nr_samples) + color_fprintf(stdout, color, " %7d", nr_samples); + else + color_fprintf(stdout, color, " %7.2f", percent); } static void print_annotated_data_type(struct annotated_data_type *mem_type, @@ -364,10 +389,14 @@ static void print_annotated_data_type(struct annotated_data_type *mem_type, struct annotated_member *child; struct type_hist *h = mem_type->histograms[evsel->core.idx]; int i, nr_events = 1, samples = 0; + u64 period = 0; + int width = symbol_conf.show_total_period ? 11 : 7; - for (i = 0; i < member->size; i++) + for (i = 0; i < member->size; i++) { samples += h->addr[member->offset + i].nr_samples; - printf(" %10d", samples); + period += h->addr[member->offset + i].period; + } + print_annotated_data_value(h, period, samples); if (evsel__is_group_event(evsel)) { struct evsel *pos; @@ -376,9 +405,12 @@ static void print_annotated_data_type(struct annotated_data_type *mem_type, h = mem_type->histograms[pos->core.idx]; samples = 0; - for (i = 0; i < member->size; i++) + period = 0; + for (i = 0; i < member->size; i++) { samples += h->addr[member->offset + i].nr_samples; - printf(" %10d", samples); + period += h->addr[member->offset + i].period; + } + print_annotated_data_value(h, period, samples); } nr_events = evsel->core.nr_members; } @@ -394,7 +426,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}", 11 * nr_events + 24 + indent, ""); + printf("%*s}", (width + 1) * nr_events + 24 + indent, ""); printf(";\n"); } -- 2.44.0.396.g6e790dbe36-goog