Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2263066rbb; Tue, 27 Feb 2024 16:53:11 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUe4QsMJqIP9+vHaLaocswRp4qIMhLVTN3DQBFQpJG2YRUh20RUWn/sa85KC56APhV6qu2Ihh6HKQX7Wmelr/sg1zTVqZ9l/QIoR8YyOg== X-Google-Smtp-Source: AGHT+IFDBeg/8uWBDEjdqtWT60c8rdmbMKcmwz77IPe820in+geXFqZ0OBos6d6zLd+veqPuQwxK X-Received: by 2002:a17:902:c401:b0:1dc:51b5:f9b3 with SMTP id k1-20020a170902c40100b001dc51b5f9b3mr12901811plk.67.1709081590862; Tue, 27 Feb 2024 16:53:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709081590; cv=pass; d=google.com; s=arc-20160816; b=oIiqtqXljglU/a16KOcnZ4Lyc7aC8UNaTeXaq4aZwKO543F6ThZSVBbubmH3dtllFS ZwcBVLZcrXUYL9kWXvkvIymOk+rzanFwzHXq7lpygW/9tMxwmjodYZ/yasZDXOAPZ/Ca uv9k+RAv5kWaMxlmU7nUlYDrZ9UitfmGoSK2o2e2ANGuo7/Vgd8tsGh3tGULxkJr/m1i WVhcjXyZf6C6CGyxJx4tyuGnYPX+vdNEtsbL1BAKYcx2WbY6RNrFI2tIr1apdVRuT8T4 rGPCgPeYET3MsQFYzV0OPy2aMveAXppT4MellF0CgpNKkxZQahjVkwrg1dar9JDZ5gkT 8Oxg== 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=r1qzS73VIDdsqS6qRKKn/i40luj1kDA2ll9DZ6vwohc=; fh=s1fZEdGGHFKlkrF3njJuxobE+Xf6SbIV8h7pc+69Jsg=; b=urmg0+q0xL05LaQbr3qka69ZtFhiE/ye+26VVVWL6mvQSBdnefPuCI31BDHnpffo2S ZjQxtvo5yZf31rITAn0A/4OVyfaGnM5CAfq7BhOHbVXrb08sJ2A44JNOSNsXGzKG4pSH lU8Ikv/j8n1cLRSXOV7QsrQjzaCVPPOH89PSoyxTejhZeT8vP/DGQHtKmVp2HO8N8v5t nS7O8LjwkwfONal0hmuuM+YVP+dzeYul0mNqX+DVEgRF5YE0wDBO0nkkX6MJup+GQQCC jPbHPx7KpqKGgw6NY94j6tdJJV0BBnSxNugLbWICY7oFIlvL/T2RdIB0u8VfmYqqIxYQ 1lqA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FGKUgvTp; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-84290-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84290-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id s4-20020a170902ea0400b001dc38eaa5d6si2297286plg.531.2024.02.27.16.53.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 16:53:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84290-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FGKUgvTp; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-84290-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84290-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 905112835F1 for ; Wed, 28 Feb 2024 00:53:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F195CF4F1; Wed, 28 Feb 2024 00:52:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FGKUgvTp" 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 F1E513C3C; Wed, 28 Feb 2024 00:52:33 +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=1709081554; cv=none; b=mEbXJRHadWSxhh7etAhCOSLm9BkpcTMsNb3Qa04D71Q1LigYbyrB0bpkAsyKAk6NjK00tm2QI5ulLhvyAXwWRKtcFDDHrakZ+BWlU52LmhtVck9J8MZ+KM/bKun4vGwOV9wG5bYnNHIJaw+C1xbw5Tq4+iPw7YtasXH3CrGmp5s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709081554; c=relaxed/simple; bh=+IlYujNPWkLr0hPSR2olDKMPWbM11MBEXxrwzg1RtZE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gTDHMYHCTjxp30hJLzYsPXO9wTLdokYotrdI36YP31hEFIbr7Sk7GsgPISvUGsDuA1ONYzNhvx8h8cA8ba1pCC7pXM230q6w+BV3L5Bh+STIGDbijxYMfEi2I7CQ1Ij8KUADFHql66+CPlj/kGfluBZ/ChECvVmA3RybMLJJUPI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FGKUgvTp; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F4DEC43394; Wed, 28 Feb 2024 00:52:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709081553; bh=+IlYujNPWkLr0hPSR2olDKMPWbM11MBEXxrwzg1RtZE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FGKUgvTpckyQdW4eaNXoe9a8Sn14HMeP4Ll79sX7Je6DsZ1JrgvnbAqRW3R9OVtcb jsa/V4e5Pwp1iQ8HWIvvDkG9W5fPGaEbmkWHQ0ECg3an5LUanyg5fpJ0FRIoxfjsMG a5fVbEBWTzSHsRGMynujYn53u0KjgNKjibxAa/ym/es5SrqMz0VtSSEud+ltw5naUW GcCQxfGhT1fHB35BsvsaDJNc2N1NLmLJ8ZQa03ETethrrS2QfCYnNwk0m0wSTTCH09 vr7HrqzKbQpU/Rd/zDWav4hcqZ22RhHBKej9rvx/nS1yJ81pAnQp0PVERCBkDzZruE ZUsDBA+CmYZpw== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Andi Kleen Subject: [PATCH 4/4] perf annotate: Add comments in the data structures Date: Tue, 27 Feb 2024 16:52:30 -0800 Message-ID: <20240228005230.287113-5-namhyung@kernel.org> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog In-Reply-To: <20240228005230.287113-1-namhyung@kernel.org> References: <20240228005230.287113-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 Signed-off-by: Namhyung Kim --- tools/perf/util/annotate.h | 69 ++++++++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 4bdc70a9d376..13cc659e508c 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -239,11 +239,42 @@ int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool r size_t disasm__fprintf(struct list_head *head, FILE *fp); void symbol__calc_percent(struct symbol *sym, struct evsel *evsel); +/** + * struct sym_hist - symbol histogram information for an event + * + * @nr_samples: Total number of samples. + * @period: Sum of sample periods. + */ struct sym_hist { u64 nr_samples; u64 period; }; +/** + * struct cyc_hist - (CPU) cycle histogram for a basic block + * + * @start: Start address of current block (if known). + * @cycles: Sum of cycles for the longest basic block. + * @cycles_aggr: Total cycles for this address. + * @cycles_max: Max cycles for this address. + * @cycles_min: Min cycles for this address. + * @cycles_spark: History of cycles for the longest basic block. + * @num: Number of samples for the longest basic block. + * @num_aggr: Total number of samples for this address. + * @have_start: Whether the current branch info has a start address. + * @reset: Number of resets due to a different start address. + * + * If sample has branch_stack and cycles info, it can construct basic blocks + * between two adjacent branches. It'd have start and end addresses but + * sometimes the start address may not be available. So the cycles are + * accounted at the end address. If multiple basic blocks end at the same + * address, it will take the longest one. + * + * The @start, @cycles, @cycles_spark and @num fields are used for the longest + * block only. Other fields are used for all cases. + * + * See __symbol__account_cycles(). + */ struct cyc_hist { u64 start; u64 cycles; @@ -258,18 +289,24 @@ struct cyc_hist { u16 reset; }; -/** struct annotated_source - symbols with hits have this attached as in sannotation +/** + * struct annotated_source - symbols with hits have this attached as in annotation * - * @histograms: Array of addr hit histograms per event being monitored - * nr_histograms: This may not be the same as evsel->evlist->core.nr_entries if + * @source: List head for annotated_line (embeded in disasm_line). + * @histograms: Array of symbol histograms per event to maintain the total number + * of samples and period. + * @nr_histograms: This may not be the same as evsel->evlist->core.nr_entries if * we have more than a group in a evlist, where we will want * to see each group separately, that is why symbol__annotate2() * sets src->nr_histograms to evsel->nr_members. - * @lines: If 'print_lines' is specified, per source code line percentages - * @source: source parsed from a disassembler like objdump -dS - * @cyc_hist: Average cycles per basic block + * @offsets: Array of annotation_line to be accessed by offset. + * @samples: Hash map of sym_hist_entry. Keyed by event index and offset in symbol. + * @nr_entries: Number of annotated_line in the source list. + * @nr_asm_entries: Number of annotated_line with actual asm instruction in the + * source list. + * @max_line_len: Maximum length of objdump output in an annotated_line. * - * lines is allocated, percentages calculated and all sorted by percentage + * disasm_lines are allocated, percentages calculated and all sorted by percentage * when the annotation is about to be presented, so the percentages are for * one of the entries in the histogram array, i.e. for the event/counter being * presented. It is deallocated right after symbol__{tui,tty,etc}_annotate @@ -286,6 +323,24 @@ struct annotated_source { u16 max_line_len; }; +/** + * struct annotated_branch - basic block and IPC information for a symbol. + * + * @hit_cycles: Total executed cycles. + * @hit_insn: Total number of instructions executed. + * @total_insn: Number of instructions in the function. + * @cover_insn: Number of distinct, actually executed instructions. + * @cycles_hist: Array of cyc_hist for each instruction. + * @max_coverage: Maximum number of covered basic block (used for block-range). + * + * This struct is used by two different codes when the sample has branch stack + * and cycles information. annotation__compute_ipc() calculates average IPC + * using @hit_insn / @hit_cycles. The actual coverage can be calculated using + * @cover_insn / @total_insn. The @cycles_hist can give IPC for each (longest) + * basic block ends at the given address. + * process_basic_block() calculates coverage of instructions (or basic blocks) + * in the function. + */ struct annotated_branch { u64 hit_cycles; u64 hit_insn; -- 2.44.0.rc1.240.g4c46232300-goog