Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1861114rwe; Fri, 2 Sep 2022 05:10:29 -0700 (PDT) X-Google-Smtp-Source: AA6agR62Jrb6Q/WpcQvvRWZN7TB/YhpfZV2O+owsQqhW0cqi7vcZc5P7pZZSWbmR2sC/6H8UCBju X-Received: by 2002:a17:90b:388e:b0:1f5:40d4:828d with SMTP id mu14-20020a17090b388e00b001f540d4828dmr4642152pjb.31.1662120628838; Fri, 02 Sep 2022 05:10:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662120628; cv=none; d=google.com; s=arc-20160816; b=oTXtng8b0+o0+c1xZTgdlyuqtgmsEvPyoCDBOj8GDs47r6GAs/OCIyQFEmvr/ub1dz 3C0+0AP6TlpP3tfVJgYpLKzbZPk2fgFoo9ALeyroLIPOiaZjyIJ20+qbWVmRejwxwer/ lxB16md6TQ9rwp8okg1I8LaCWyxWhYo+i2lBAPLYm2HKaNrucJ0+O0/+WASYVPv2tjvl k04N4Kbp2DWu8jyNO8FqXW65XPaQrVWqUa5SYxqJhcujuBRomSjJZLLcUPro1tl8nV6H bOMKESfZbp2MgHWn+qMRrvw0UCIxAifgumWfoKY12vJl45tTt4d60SBGhnm9lY/v3ISh 36hA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=uenkkKZHfYzMxc7TZxzbQhYOg0hlKnb0UD3b8lcY4Dk=; b=oz+bn9RBRhFTsA6oOyGL1D1e0iQ+0NHbYNF6+TAtYGttpbg4ComqSB8e4z+8rdvPvW yioiAAAygFlIMuPpDTSZPVN8OJxct40dhLKR6uXhy+mr3x7NITb7yzmsizfnl9OcIi+s l1jCvk/vMwLzNrzSiK5mWK6pCPCHymGgG91D8+DqxX2Auun7gAy8+krJbD/stPj/yA2W gN58ZgPw2yxx+SRSnyQfUMfwAT2b0bXWMWRt5+CKAXVyCMFu+2O/JL4Xl0LiX2MgVUae KzHbWKNWmTUqQwt9KAGgdAVh+YbZLZdw8xl5xZmw8fzd6US+MpqHLtPWzJIS9LySPHTm EaPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dmbTOAVN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a2-20020a170902ecc200b00175105a3083si1996708plh.406.2022.09.02.05.10.12; Fri, 02 Sep 2022 05:10:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dmbTOAVN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235619AbiIBMBQ (ORCPT + 99 others); Fri, 2 Sep 2022 08:01:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235686AbiIBMBL (ORCPT ); Fri, 2 Sep 2022 08:01:11 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4889552451 for ; Fri, 2 Sep 2022 05:01:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662120069; x=1693656069; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=MA2F1NX+R2+2eM0M3J1/D21ak0GR9GaYbn0h6g67VsY=; b=dmbTOAVNneYdqKg0xmaODbEskgagSBypDTIn/2G/xCBFp+fmdmlvcI4a 6LV6DEwr+DMCqhDE+uT82D6Pq/hZixWzxdK2gz3mEmAnfwMW46P5AElwt tS+OnnVcxPfwffpu9C3ustZovx4vprLeWtVyabtDHR1H9bxXRj8KSQU0L H0p6nyucX1lifnMvbR/+rZxuFZGQt4TYVqH1EIbB9bHBpMzTFtwyPeqrM k7Xwyqy2RwBHYjOcwOqOXzBvFWaWfAJ6dFLM1ArTRwOYMXKV2etcVva/t U4Y/z3/xpFvgfb/gnp+MzXnhU8OVuMN9yw1zIlOUbpZsaWWiNJ9lLWD76 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10457"; a="295971295" X-IronPort-AV: E=Sophos;i="5.93,283,1654585200"; d="scan'208";a="295971295" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2022 05:01:07 -0700 X-IronPort-AV: E=Sophos;i="5.93,283,1654585200"; d="scan'208";a="674331452" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO [10.0.2.15]) ([10.252.42.34]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2022 05:01:05 -0700 Message-ID: Date: Fri, 2 Sep 2022 15:01:01 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0 Thunderbird/91.11.0 Subject: Re: [PATCH 5/5] perf intel-pt: Support itrace option flag d+e to log on error Content-Language: en-US To: Namhyung Kim Cc: Andi Kleen , Arnaldo Carvalho de Melo , Jiri Olsa , Ian Rogers , linux-kernel References: <20220901110032.9226-1-adrian.hunter@intel.com> <20220901110032.9226-6-adrian.hunter@intel.com> <1a7aaa51-1858-bb59-834c-7e8f6a58bc39@intel.com> From: Adrian Hunter Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/09/22 04:34, Namhyung Kim wrote: > On Thu, Sep 1, 2022 at 9:29 AM Adrian Hunter wrote: >> >> On 1/09/22 17:31, Andi Kleen wrote: >>> >>> On 9/1/2022 4:00 AM, Adrian Hunter wrote: > > [SNIP] >>>> + >>>> +static void log_buf__dump(struct log_buf *b) >>>> +{ >>>> + if (!b->buf) >>>> + return; >>>> + >>>> + fflush(f); >>>> + fprintf(b->backend, "Dumping debug log buffer (first line may be sliced)\n"); >>> >>> >>> Should be easy to skip the first line, no? >> >> Not as easy as typing " (first line may be sliced)" ;-) >> >> Still not sure it is worth having the extra complication, but here >> is the change as a separate patch: >> >> From: Adrian Hunter >> Date: Thu, 1 Sep 2022 19:01:33 +0300 >> Subject: [PATCH] perf intel-pt: Remove first line of log dumped on error >> >> Instead of printing "(first line may be sliced)", always remove the >> first line of the debug log when dumping on error. >> >> Signed-off-by: Adrian Hunter >> --- >> .../perf/util/intel-pt-decoder/intel-pt-log.c | 27 ++++++++++++++++--- >> 1 file changed, 24 insertions(+), 3 deletions(-) >> >> diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-log.c b/tools/perf/util/intel-pt-decoder/intel-pt-log.c >> index ea96dcae187a7..6cc465d1f7a9e 100644 >> --- a/tools/perf/util/intel-pt-decoder/intel-pt-log.c >> +++ b/tools/perf/util/intel-pt-decoder/intel-pt-log.c >> @@ -143,16 +143,37 @@ static FILE *log_buf__open(struct log_buf *b, FILE *backend, unsigned int sz) >> return file; >> } >> >> +static bool remove_first_line(const char **p, size_t *n) >> +{ >> + for (; *n && **p != '\n'; ++*p, --*n) >> + ; >> + if (*n) { >> + *p += 1; >> + *n -= 1; >> + return true; >> + } >> + return false; >> +} >> + >> +static void write_lines(const char *p, size_t n, FILE *fp, bool *remove_first) >> +{ >> + if (*remove_first) >> + *remove_first = !remove_first_line(&p, &n); >> + fwrite(p, n, 1, fp); >> +} >> + >> static void log_buf__dump(struct log_buf *b) >> { >> + bool remove_first = true; > > Isn't it only required when the buf is wrapped? Very true! Thanks for spotting that! I will send a new version. > > Thanks, > Namhyung > > >> + >> if (!b->buf) >> return; >> >> fflush(f); >> - fprintf(b->backend, "Dumping debug log buffer (first line may be sliced)\n"); >> + fprintf(b->backend, "Dumping debug log buffer\n"); >> if (b->wrapped) >> - fwrite(b->buf + b->head, b->buf_sz - b->head, 1, b->backend); >> - fwrite(b->buf, b->head, 1, b->backend); >> + write_lines(b->buf + b->head, b->buf_sz - b->head, b->backend, &remove_first); >> + write_lines(b->buf, b->head, b->backend, &remove_first); >> fprintf(b->backend, "End of debug log buffer dump\n"); >> >> b->head = 0; >> -- >> 2.34.1 >>