Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1262700pxv; Fri, 25 Jun 2021 08:55:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZFrIJfnkzjVrhrSytT0Qkv25nyuQHWb+dUQUKEebO4lwwXF5VapICEyx5YX7NzjBRNF0I X-Received: by 2002:a17:906:86cc:: with SMTP id j12mr12020022ejy.548.1624636511348; Fri, 25 Jun 2021 08:55:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624636511; cv=none; d=google.com; s=arc-20160816; b=skkZiqd+uMFjjBJV0yhMX+RqA5gJPl+V7eAPZ8Ewyw4UvWUuB6h9MnsVvMOzSDAzmn hYkMnhT/IWp89GuR3j4PAWvXjsjIwJVI+vqGrKCy25l7PLS1kidsf1MgphcTraU/BjdT 2IVJOKWeWFC4RjiYMDF9uEWEpFTBv0elP6JBfO/P2RxdaTke1y/aiRYFm2gvHKr+Fhwt 6v2/YOyrNEC9nnrsEjko49uw1OsY4NnMg729ylO2CVGbFzu4gPV3ox2I//r5WS/CeilM m+ObWd2wJayfyF22paH9GRX8olc0IOshRcpakD6O6eKXSNyMl4nDApbI30xt8RSIiy78 3Pyg== 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 :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=op7/BKaoe3ba3IUt03EQ5cjTqeRTBFIYUGw/dUxAGL4=; b=TTBaif0zrEiUDIXsY9Xpz2+23J5cTfcaHT1wTcuqV1Gk9U7iYgQTXVaVPACtqKWDlp /RYwe2kAkcKWWzXlncKiQUJmGMOJkaJmGlIMyfUZRS1ZRaaleToPGNIPjgpYvcc+yKYL zjeurRCOm7Rm5BFHc5WL2Pzh9ItlH5xbtw+rIWr8koZK77hYBiIsgU45QawcRH9s9F9w KSujnluH/pslUux2vbUYigAH0Z1zAgMpt4jU5PzByAKGrA3MkLoijx9jzrLD1UKyJzBp GPvA1QJxTDGl3CjBfgFclL3BzlRwW7i9hUDexK+YB3WDBnyvrkq2fTGAvZxXD2J/ppBX K+eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=q0uUfUxC; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d19si6083454ejo.229.2021.06.25.08.54.47; Fri, 25 Jun 2021 08:55:11 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=q0uUfUxC; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229796AbhFYP4A (ORCPT + 99 others); Fri, 25 Jun 2021 11:56:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229738AbhFYPz7 (ORCPT ); Fri, 25 Jun 2021 11:55:59 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA70AC061574; Fri, 25 Jun 2021 08:53:38 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id l18-20020a1ced120000b029014c1adff1edso8764422wmh.4; Fri, 25 Jun 2021 08:53:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:cc:date:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=op7/BKaoe3ba3IUt03EQ5cjTqeRTBFIYUGw/dUxAGL4=; b=q0uUfUxC0KdzZbWw/l1Pcca3vOQ53lpCkqNkgcEQ6IP0Go2uEiAjho9E3h+BWZVpQ9 q7TW6ZTIQI0StuCgSYE09CtSXmy7T3JY+p+k9tw8+qggpBXD+dc+XQbvUIPq1hhu/8/a p0ctSkcdadFrp6UqmMJNEGOogr5Cjo0Gw/MfnSkPlOVLKuUENsJLyrWMU7K6fQxk5cKJ Fux1fu5KLsQu+9ysXUW8J0kkmzs3R0kwcrHxwvx2T9fzETAHopl64EeoT3j4WPHd6jvd Xo4uZ7tofjgH1XhASa14enA1xjTK0Jvsg7co7I0MQE1r68sloG/UyNycAHz2WeLSE/84 p/YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=op7/BKaoe3ba3IUt03EQ5cjTqeRTBFIYUGw/dUxAGL4=; b=XzUrFqwpDAHbNsiz9DSG0PQNNwQli2TlwoEUhTVKMKQw17lY9X4d5mYE1gsjyxaVwp St4/jP/OKo2OGE5cwwJQC/nWYu9tDM7+uEyvKHjlzMsY/ZlCJo7vVTued1WvWzjBiTVH M4EWwnvnAVcHjydUKiqdaLXeCcv9gUPA8/tSZvJcXGwD8yKKzruOMNlGODBpU2tB33OJ Vwdgra3ebC2pW02GXdtvtriy/vCAln7LVQIEMLD3DwmeapiK79a7vGtodWPWEvX2ZBAh OPIBm/dnhh44/IlKbXJ1hQ81gfIyYhm0KRGTftvsbmMWEHFDQcNczqytonazDfczzpfc uqsg== X-Gm-Message-State: AOAM532DnxUGZy53pmGU2u8ayUSslPRQn8i7FToLdchnEvD65ecHctRs qfqS4qx9iUva2S1pu5xFz70= X-Received: by 2002:a1c:2142:: with SMTP id h63mr11764885wmh.84.1624636417356; Fri, 25 Jun 2021 08:53:37 -0700 (PDT) Received: from [192.168.1.15] ([151.29.44.148]) by smtp.gmail.com with ESMTPSA id 4sm5786229wmf.34.2021.06.25.08.53.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Jun 2021 08:53:36 -0700 (PDT) Message-ID: Subject: Re: [PATCH v2] perf annotate: allow 's' on source code lines From: Riccardo Mancini To: Ian Rogers Cc: Arnaldo Carvalho de Melo , Namhyung Kim , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Martin Liska , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 25 Jun 2021 17:53:35 +0200 In-Reply-To: References: <20210624223423.189550-1-rickyman7@gmail.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.2 (3.40.2-1.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Ian, On Thu, 2021-06-24 at 22:37 -0700, Ian Rogers wrote: > On Thu, Jun 24, 2021 at 3:37 PM Riccardo Mancini wrote: > > > > In perf annotate, when 's' is pressed on a line containing > > source code, it shows the message "Only available for assembly > > lines". > > This patch gets rid of the error, moving the cursr to the next > > available asm line (or the closest previous one if no asm line > > is found moving forwards), before hiding source code lines. > > > > Changes in v2: > >  - handle case of no asm line found in > >    annotate_browser__find_next_asm_line by returning NULL and > >    handling error in caller. > > > > Signed-off-by: Riccardo Mancini > > Acked-by: Ian Rogers > > > --- > >  tools/perf/ui/browsers/annotate.c | 32 ++++++++++++++++++++++++++++--- > >  1 file changed, 29 insertions(+), 3 deletions(-) > > > > diff --git a/tools/perf/ui/browsers/annotate.c > > b/tools/perf/ui/browsers/annotate.c > > index ad0a70f0edaf..f5509a958e38 100644 > > --- a/tools/perf/ui/browsers/annotate.c > > +++ b/tools/perf/ui/browsers/annotate.c > > @@ -343,6 +343,29 @@ static void annotate_browser__calc_percent(struct > > annotate_browser *browser, > >         browser->curr_hot = rb_last(&browser->entries); > >  } > > > > +static struct annotation_line *annotate_browser__find_next_asm_line( > > +                                       struct annotate_browser *browser, > > +                                       struct annotation_line *al) > > +{ > > +       struct annotation_line *it = al; > > + > > +       /* find next asm line */ > > +       list_for_each_entry_continue(it, browser->b.top, node) { > > +               if (it->idx_asm >= 0) > > +                       return it; > > +       } > > + > > +       /* no asm line found forwards, try backwards */ > > +       it = al; > > +       list_for_each_entry_continue_reverse(it, browser->b.top, node) { > > +               if (it->idx_asm >= 0) > > +                       return it; > > +       } > > + > > +       /* There are no asm lines */ > > +       return NULL; > > +} > > + > >  static bool annotate_browser__toggle_source(struct annotate_browser > > *browser) > >  { > >         struct annotation *notes = browser__annotation(&browser->b); > > @@ -363,9 +386,12 @@ static bool annotate_browser__toggle_source(struct > > annotate_browser *browser) > >                 browser->b.index = al->idx; > >         } else { > >                 if (al->idx_asm < 0) { > > -                       ui_helpline__puts("Only available for assembly > > lines."); > > -                       browser->b.seek(&browser->b, -offset, SEEK_CUR); > > -                       return false; > > +                       /* move cursor to next asm line */ > > comment nit, perhaps prefer "closest" rather than "next" due to > searching backward. The backward search is just a fallback in case the forward one finds no asm line, which I believe is unlikely. Maybe it's also impossible, but I don't really know how those lines are generated, so I put a fallback in place. Furthermore, "closest" would imply that a previous asm line could be chosen over a subsequent one if closer, even if the latter is present. Thanks, Riccardo > > Thanks, > Ian > > > +                       al = annotate_browser__find_next_asm_line(browser, > > al); > > +                       if (!al) { > > +                               browser->b.seek(&browser->b, -offset, > > SEEK_CUR); > > +                               return false; > > +                       } > >                 } > > > >                 if (al->idx_asm < offset) > > -- > > 2.31.1 > >