From patchwork Thu Nov 9 23:59:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 163667 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b129:0:b0:403:3b70:6f57 with SMTP id q9csp787363vqs; Thu, 9 Nov 2023 16:04:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IEZx9xBI5jHcUgyjzOIHKI/BOFvdhDrdz/xB9fjQkWZm6A+YGZp3mit2WWxYoTlG2e6arKl X-Received: by 2002:a17:90a:1a04:b0:281:61c:1399 with SMTP id 4-20020a17090a1a0400b00281061c1399mr3243446pjk.3.1699574652787; Thu, 09 Nov 2023 16:04:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699574652; cv=none; d=google.com; s=arc-20160816; b=lt64WZD+fAM41evK4Q4HiXllhvw++dcAS4T1OCdwW0cZtyJ+g9EpFpi70DonOcSlj9 geRTTJARhyNRCWPnCptEoCrb2arBdWbkM41dt5YgWYCgCARtrlrVJHu0b5Ym7Hcu6UX+ oV9J4Jg2/PkGfdjQoaOoKzcZzj1vCCO2B/dM/0IT/eVCL2/LMXtfjSfyilv4bh6WTaO7 ufd9Q4pbJ/794DBSFvHtrldQu/WAAS+FgGC/87oNdUbcl1rYEC/W5KhU6Zju6dOFeZoN 12bwwvYOAI7U3Q2fWpfpuGUW51dIYVClI97hY0o4FsQDluK+48E9ZtOi/bUIYyFB7ZAf xaug== 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=0IiGmHiFZ7D8eBmQHmks1FISgbWWSEVYxrId79vUA9A=; fh=K//si1Hi/RYC7s39rVvmvh0YbZGmBrdWWHQg3cPF7Xc=; b=uZOEYnGJDktgdFLDD5gqey61MssN5gY7sEbdCCGLdondT3ifgFhNLphf1DLhfdLYZp sCBbsgk4ZgRRYn/pbpCvGrn4TGfyk5f5VAkNLqiFeINU4+B6nKy05r1PLhb+Fz5LnSBU sC5efuGJNk5ThrYitTPdC9N5BS6HRNqKLOVdY7GYsBof3tVxqafe5/HrWZtnkJ3jrKhS fLc3usgqGV9HawCqJzktBiI8XCzML3iyLCGASlcl19GQupKRoPl7R9gbHJwiG13bOLxe nwB0Uqhi3i2dhYwbJhiQnpTlwgd5/Z8jPoF6geQGeetGZx7P1p+U1f9uHAkEKbhZHsOZ 9BQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Eq0rnRph; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id lk11-20020a17090b33cb00b002806cdeecc6si3178317pjb.35.2023.11.09.16.04.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 16:04:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Eq0rnRph; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id F03E88362DA2; Thu, 9 Nov 2023 16:03:45 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345675AbjKJACi (ORCPT + 30 others); Thu, 9 Nov 2023 19:02:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345550AbjKJABp (ORCPT ); Thu, 9 Nov 2023 19:01:45 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17CB8479C; Thu, 9 Nov 2023 16:00:57 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-280260db156so1276059a91.2; Thu, 09 Nov 2023 16:00:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699574456; x=1700179256; 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=0IiGmHiFZ7D8eBmQHmks1FISgbWWSEVYxrId79vUA9A=; b=Eq0rnRphh4YG20cPFNmkcSzETaKJt8nd1qDchWfJkuOKY1lxl7LPLrdDPykuWpVVp2 /IFc4KxpsdYlMok88fTnJL4Kr0Abtvr6AyKpdPHnTXTG+KDgg6B1O0J8AdwhaR1uiicE 2X0WdbZTMjRCZLtbX0t5VU6NpoECsLZaEec9zVmDeg+Z9ineF/r6g88Z5iVhefitxWvP phUj0/mH1SUlNVFM0zxTsXB5qEnXnVHKsbRt62332NuvVMG/GTYinEC2qRugk/ayCOVI 6FtE0JKbzBjKl32y52UF2nWeJxqUOw219jINWiV1S9dJ4I9qlbCuU20XpCdIbab4GAsD mpQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699574456; x=1700179256; 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=0IiGmHiFZ7D8eBmQHmks1FISgbWWSEVYxrId79vUA9A=; b=cmM9sqsRONLFZEhj2n745mYwc5HUltQiM4jCDK2AudVBas8vQb9Hv6hCGq2Pq6i+EA hrj33m8+XeUbmfsVNrFkUGoAZfjX0YLVKoWnF5ulOzvWjeBo8lfnc0C8kbzRm7ozJ6Od 92Ozuyyq9z9uf9tUFcEoE5F3FjBnHKEH5fDa8DzvdlNbA9KleHU8p4nOmQjJ0YQ8Hjzi Cg/IDQGSmxEa/snwZe1ZUGRdA/AmtI63gDL5hSvNG9OS+OXfH+/fAz/ws0F4ME1NlHFk LCJgvZE7ZKo1ajEd7IaF2mcp2soyB7csI3PaCSPKzgBh9AONCCdsCBUjo3u5HwSI0yzU 4bbA== X-Gm-Message-State: AOJu0YyUzgNNZZgW+jXavps+P8Ewt+UYNEtTSISKjfFqkSOtWUvOSBVC t3HGGvUXlwOqRtvzh56uafs= X-Received: by 2002:a17:90b:4d0f:b0:281:a69:4430 with SMTP id mw15-20020a17090b4d0f00b002810a694430mr3219663pjb.42.1699574456512; Thu, 09 Nov 2023 16:00:56 -0800 (PST) Received: from bangji.corp.google.com ([2620:15c:2c0:5:d45c:ae16:d959:a5f1]) by smtp.gmail.com with ESMTPSA id k32-20020a17090a4ca300b002635db431a0sm371312pjh.45.2023.11.09.16.00.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 16:00:56 -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 , Andi Kleen , linux-trace-devel@vger.kernel.org, linux-toolchains@vger.kernel.org Subject: [PATCH 27/52] perf annotate: Add --insn-stat option for debugging Date: Thu, 9 Nov 2023 15:59:46 -0800 Message-ID: <20231110000012.3538610-28-namhyung@kernel.org> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog In-Reply-To: <20231110000012.3538610-1-namhyung@kernel.org> References: <20231110000012.3538610-1-namhyung@kernel.org> MIME-Version: 1.0 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 (groat.vger.email [0.0.0.0]); Thu, 09 Nov 2023 16:03:46 -0800 (PST) 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 groat.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782133191127729903 X-GMAIL-MSGID: 1782133191127729903 This is for a debugging purpose. It'd be useful to see per-instrucion level success/failure stats. $ perf annotate --data-type --insn-stat Annotate Instruction stats total 264, ok 143 (54.2%), bad 121 (45.8%) Name : Good Bad ----------------------------------------------------------- movq : 45 31 movl : 22 11 popq : 0 19 cmpl : 16 3 addq : 8 7 cmpq : 11 3 cmpxchgl : 3 7 cmpxchgq : 8 0 incl : 3 3 movzbl : 4 2 incq : 4 2 decl : 6 0 ... Signed-off-by: Namhyung Kim --- tools/perf/builtin-annotate.c | 41 +++++++++++++++++++++++++++++++++++ tools/perf/util/annotate.c | 38 ++++++++++++++++++++++++++++++++ tools/perf/util/annotate.h | 8 +++++++ 3 files changed, 87 insertions(+) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index e4fc00bc8fdf..9516d2dbc488 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -59,6 +59,7 @@ struct perf_annotate { bool group_set; bool data_type; bool type_stat; + bool insn_stat; float min_percent; const char *sym_hist_filter; const char *cpu_list; @@ -439,6 +440,42 @@ static void print_annotate_data_stat(struct annotated_data_stat *s) #undef PRINT_STAT } +static void print_annotate_item_stat(struct list_head *head, const char *title) +{ + struct annotated_item_stat *istat, *pos, *iter; + int total_good, total_bad, total; + int sum1, sum2; + LIST_HEAD(tmp); + + /* sort the list by count */ + list_splice_init(head, &tmp); + total_good = total_bad = 0; + + list_for_each_entry_safe(istat, pos, &tmp, list) { + total_good += istat->good; + total_bad += istat->bad; + sum1 = istat->good + istat->bad; + + list_for_each_entry(iter, head, list) { + sum2 = iter->good + iter->bad; + if (sum1 > sum2) + break; + } + list_move_tail(&istat->list, &iter->list); + } + total = total_good + total_bad; + + printf("Annotate %s stats\n", title); + printf("total %d, ok %d (%.1f%%), bad %d (%.1f%%)\n\n", total, + total_good, 100.0 * total_good / (total ?: 1), + total_bad, 100.0 * total_bad / (total ?: 1)); + printf(" %-10s: %5s %5s\n", "Name", "Good", "Bad"); + printf("-----------------------------------------------------------\n"); + list_for_each_entry(istat, head, list) + printf(" %-10s: %5d %5d\n", istat->name, istat->good, istat->bad); + printf("\n"); +} + static void hists__find_annotations(struct hists *hists, struct evsel *evsel, struct perf_annotate *ann) @@ -448,6 +485,8 @@ static void hists__find_annotations(struct hists *hists, if (ann->type_stat) print_annotate_data_stat(&ann_data_stat); + if (ann->insn_stat) + print_annotate_item_stat(&ann_insn_stat, "Instruction"); while (nd) { struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); @@ -798,6 +837,8 @@ int cmd_annotate(int argc, const char **argv) parse_data_type), OPT_BOOLEAN(0, "type-stat", &annotate.type_stat, "Show stats for the data type annotation"), + OPT_BOOLEAN(0, "insn-stat", &annotate.insn_stat, + "Show instruction stats for the data type annotation"), OPT_END() }; int ret; diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index c284a29979d6..3ac601d70f61 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -102,6 +102,7 @@ static struct ins_ops ret_ops; /* Data type collection debug statistics */ struct annotated_data_stat ann_data_stat; +LIST_HEAD(ann_insn_stat); static int arch__grow_instructions(struct arch *arch) { @@ -3669,6 +3670,30 @@ static struct disasm_line *find_disasm_line(struct symbol *sym, u64 ip) return NULL; } +static struct annotated_item_stat *annotate_data_stat(struct list_head *head, + const char *name) +{ + struct annotated_item_stat *istat; + + list_for_each_entry(istat, head, list) { + if (!strcmp(istat->name, name)) + return istat; + } + + istat = zalloc(sizeof(*istat)); + if (istat == NULL) + return NULL; + + istat->name = strdup(name); + if (istat->name == NULL) { + free(istat); + return NULL; + } + + list_add_tail(&istat->list, head); + return istat; +} + /** * hist_entry__get_data_type - find data type for given hist entry * @he: hist entry @@ -3687,6 +3712,7 @@ struct annotated_data_type *hist_entry__get_data_type(struct hist_entry *he) struct annotated_insn_loc loc; struct annotated_op_loc *op_loc; struct annotated_data_type *mem_type; + struct annotated_item_stat *istat; u64 ip = he->ip; int i; @@ -3715,8 +3741,15 @@ struct annotated_data_type *hist_entry__get_data_type(struct hist_entry *he) return NULL; } + istat = annotate_data_stat(&ann_insn_stat, dl->ins.name); + if (istat == NULL) { + ann_data_stat.no_insn++; + return NULL; + } + if (annotate_get_insn_location(arch, dl, &loc) < 0) { ann_data_stat.no_insn_ops++; + istat->bad++; return NULL; } @@ -3725,6 +3758,10 @@ struct annotated_data_type *hist_entry__get_data_type(struct hist_entry *he) continue; mem_type = find_data_type(ms, ip, op_loc->reg, op_loc->offset); + if (mem_type) + istat->good++; + else + istat->bad++; if (symbol_conf.annotate_data_sample) { annotated_data_type__update_samples(mem_type, evsel, @@ -3737,5 +3774,6 @@ struct annotated_data_type *hist_entry__get_data_type(struct hist_entry *he) } ann_data_stat.no_mem_ops++; + istat->bad++; return NULL; } diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 06281a50ecf6..2cef96859e45 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -485,4 +485,12 @@ int annotate_get_insn_location(struct arch *arch, struct disasm_line *dl, /* Returns a data type from the sample instruction (if any) */ struct annotated_data_type *hist_entry__get_data_type(struct hist_entry *he); +struct annotated_item_stat { + struct list_head list; + char *name; + int good; + int bad; +}; +extern struct list_head ann_insn_stat; + #endif /* __PERF_ANNOTATE_H */