Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1357395pxf; Fri, 19 Mar 2021 05:37:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw053WTpyn0U1jVf/WSXkoun+Wo/OdKMbKVwxJ6dlatDAJTxTY2OIV8ZKmWpsgvjnkE370H X-Received: by 2002:a17:906:2dc1:: with SMTP id h1mr4144763eji.460.1616157457733; Fri, 19 Mar 2021 05:37:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616157457; cv=none; d=google.com; s=arc-20160816; b=w7RfHqvqFYSCngdIiEMmOCr+uq0tHSFYUulfBalFH7IIM+8kQ4A55bXzq5ay2WM5Pl H0qd7BcENf3TPai/YaRzTTDkvy4JUp2Tmv+ExLuEzN66cpIvE1GHDHPkNhJN20afzeaU FqGaZ5jrEvSyImR8klmujgJIt/7FFnKJsaT84/sUbxffsMoq1AqgElb/pkQbxx9A24ug ncTPMji7lnyr5go+54BmV40ICZFTUV5RU0rcwPtljzbL2B2b7lKBH7EUvo7c/Pwe2YET QLwH32Pd+ozdKTP/eHw6F6XufkwNDMCgWqYbeQQRtc0X/JVlVyZlZc5mM6SWx3RhXUTy f1Wg== 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 :message-id:date:subject:cc:to:from; bh=d4a6mmE+ifcPxsYINB54Sx1DShvJ6/mfFh1CLvUpffM=; b=J0NUS3eI7UcH0FYu9M9vsC5jpsFgABzKEJWTJUg9e4LKxN+2vfpjQ9bYyuGG0BtV4O 0ZLfuJlgEY2z5sDuw3GZgS+HJffmBMjo//e3mjwH2lJNLvA2e7RZBHXFAZdzUIZzrZ+x OO9Gx9jKA4svPNwH/f+SMQet88BDA46+bMi4vGrVkM6ccdyBPeXH7pRrXR8y+evngs9P YvJxzH1sWxf5lx8vQdNDyodf5w7EpgBLAeHUq8zFTFNtJeccoAq/kvlayYLaaUeefABY 7X7aQqTGX/iv0Ina0pwC0omwYe6wcEkdo+lJYLcXX5BE+BEEZdnCWW+oO1FGq67kNhRr n+Qg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dk21si4208169ejb.324.2021.03.19.05.37.14; Fri, 19 Mar 2021 05:37:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229941AbhCSMgS (ORCPT + 99 others); Fri, 19 Mar 2021 08:36:18 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:14101 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229634AbhCSMfq (ORCPT ); Fri, 19 Mar 2021 08:35:46 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4F23Gh44r7z19GgM; Fri, 19 Mar 2021 20:33:48 +0800 (CST) Received: from ubuntu1804.huawei.com (10.67.174.61) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.498.0; Fri, 19 Mar 2021 20:35:36 +0800 From: Yang Jihong To: , , , , , , , , , , CC: , Subject: [PATCH v7] perf annotate: Fix sample events lost in stdio mode Date: Fri, 19 Mar 2021 20:35:27 +0800 Message-ID: <20210319123527.173883-1-yangjihong1@huawei.com> X-Mailer: git-send-email 2.30.GIT MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.174.61] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In hist__find_annotations function, since different hist_entry may point to same symbol, we free notes->src to signal already processed this symbol in stdio mode; when annotate, entry will skipped if notes->src is NULL to avoid repeated output. However, there is a problem, for example, run the following command: # perf record -e branch-misses -e branch-instructions -a sleep 1 perf.data file contains different types of sample event. If the same IP sample event exists in branch-misses and branch-instructions, this event uses the same symbol. When annotate branch-misses events, notes->src corresponding to this event is set to null, as a result, when annotate branch-instructions events, this event is skipped and no annotate is output. Solution of this patch is to remove zfree in hists__find_annotations and change sort order to "dso,symbol" to avoid duplicate output when different processes correspond to the same symbol. Signed-off-by: Yang Jihong --- Changes since v6: - Remove separate setup_sorting() for branch mode. Changes since v5: - Add Signed-off-by tag. Changes since v4: - Use the same sort key "dso,symbol" in branch stack mode. Changes since v3: - Modify the first line of comments. Changes since v2: - Remove zfree in hists__find_annotations. - Change sort order to avoid duplicate output. Changes since v1: - Change processed flag variable from u8 to bool. tools/perf/builtin-annotate.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index a23ba6bb99b6..795c2ac7fcd1 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -374,13 +374,6 @@ static void hists__find_annotations(struct hists *hists, } else { hist_entry__tty_annotate(he, evsel, ann); nd = rb_next(nd); - /* - * Since we have a hist_entry per IP for the same - * symbol, free he->ms.sym->src to signal we already - * processed this symbol. - */ - zfree(¬es->src->cycles_hist); - zfree(¬es->src); } } } @@ -619,14 +612,22 @@ int cmd_annotate(int argc, const char **argv) setup_browser(true); - if ((use_browser == 1 || annotate.use_stdio2) && annotate.has_br_stack) { + /* + * Events of different processes may correspond to the same + * symbol, we do not care about the processes in annotate, + * set sort order to avoid repeated output. + */ + sort_order = "dso,symbol"; + + /* + * Set SORT_MODE__BRANCH so that annotate display IPC/Cycle + * if branch info is in perf data in TUI mode. + */ + if ((use_browser == 1 || annotate.use_stdio2) && annotate.has_br_stack) sort__mode = SORT_MODE__BRANCH; - if (setup_sorting(annotate.session->evlist) < 0) - usage_with_options(annotate_usage, options); - } else { - if (setup_sorting(NULL) < 0) - usage_with_options(annotate_usage, options); - } + + if (setup_sorting(NULL) < 0) + usage_with_options(annotate_usage, options); ret = __cmd_annotate(&annotate); -- 2.30.GIT