Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3431416rdh; Mon, 27 Nov 2023 14:17:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IHxl4gjBDR5Ily2nXKyj8Va23qC45qZkL06Dq4lbaRgsHREvqZLYfU1lTCyBiJNLz/uaR9O X-Received: by 2002:a05:6808:6543:b0:3b8:3986:be5d with SMTP id fn3-20020a056808654300b003b83986be5dmr19271159oib.42.1701123459310; Mon, 27 Nov 2023 14:17:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701123459; cv=none; d=google.com; s=arc-20160816; b=Ldg2Pye5WR3O7zlSaCBPLJBa9ILxOUiJFMXp5fLgTAZTvrZS57xuCBpNucY8HfP35H dLuOKmfa8akTO1yXZX4VFETCddSq5/uEdfYBgarJXPIGCLTr2og+lMc2P+VZ8zxwj1BX gbYOuJs7vHaJC2NHm7eb/faBWE47+Vqq/kWHBSNSP0AHkQyaN+4wsediNMXq+gVFuDSe Y86DAP58NfSHR0k2aT1Ii+aOeGpnErfPkNjKSFSANBk6Fs7W4ltXXy8YfH28RySyEYYi g4HlBfUDkZi9eK2KjH3qbXkqXXRMjTjgfVEe2WcRF6ZfqgCdM5I3sIFMAgfJzbvUZjaP jq3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=74QLH4lft9zfzlsPq86t9Qk+/WjoI7cS4MoOjhAmrDw=; fh=Io7x3OacpefNRRNKoYAzVE0aWTDwD7FRzyCdD1e3AN4=; b=uVnsjsCG4+LVnFk+bDJkgixJCRlBkilXNDpQj+PW5/9e4lcQi+++3lNsgYVo/+h6tU Ih4/CynfuPjA57X8iM8cY+Rc/hQ5Smyw4wdKRQ7QWzH/W+QoyPbYjX5nKSRpkMTvNquy V2zGKuDPwBImpdDMiXs3rPXqQL0AzV0nqFJH94d1TjQsaERFMEGLCB5F8knhYPohDYhO r5y7wflFobCbeLmL8SchO0zJb9BvttxkzAgovP5Uv4TSSKXzPAYf+IZLWv0EaBgSOMA9 5CVzHoH+mHDMcYWdkDmYeK+huFYbamSt+/gwXxKcSdfYAGMaqoLOoFt5+QPQRWUNZVlw akhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="Y/oR5VbW"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id 34-20020a630d62000000b005bddca8236dsi10685474pgn.699.2023.11.27.14.17.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 14:17:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="Y/oR5VbW"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 0E6A3818D514; Mon, 27 Nov 2023 14:17:35 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233482AbjK0WQt (ORCPT + 99 others); Mon, 27 Nov 2023 17:16:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233697AbjK0WKQ (ORCPT ); Mon, 27 Nov 2023 17:10:16 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1805C10F6 for ; Mon, 27 Nov 2023 14:10:04 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5cd2100f467so60730377b3.1 for ; Mon, 27 Nov 2023 14:10:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701123003; x=1701727803; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=74QLH4lft9zfzlsPq86t9Qk+/WjoI7cS4MoOjhAmrDw=; b=Y/oR5VbWO0lojZUT3goA1EGmqSRbmbnvRdC5dRR4fA2LIeuTr8KZovchCmi8HCXIJG p0hOJ4sAmT86IMx0Wh6/nqK0NpjLnSsaqeZ7tEjEuv8CzDkqY7L0wDqgQQfRQ4MDFOlh jaVN8i7tqYQ0N5NsPdptlwxzllWDeGAr/Z9d69MoEDAjOs7dW42UahVF/nAKmWKpFEdC V7ltwXQQRwlRFGVrzM3rrmk2atXiYJa/xvsOTbnhlPr94u5MmfvXVdQIQMQ1YXvGOrQc YmS5nP9DLTwx8VyIKuGQ5xjMq/IQLAVvJNRAgQKM43jPo4EqRAl5ZauN/HgrBpHoWWZg +/iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701123003; x=1701727803; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=74QLH4lft9zfzlsPq86t9Qk+/WjoI7cS4MoOjhAmrDw=; b=hHWwOmCcclyTYKpTVH1tme+emujQq8tfdUF1AHRwBS533chsk9AV5HtveveB0pxBts KcdrGwTkoiLQXl+IcEor28IVyiXw4dsLG7WcDT9q4sWNZNpEBWIKqQlxRezpzOPqlu2P nYiV6bELkIKW8CMt9d9zOGlLZWgCTyessGcQdUbSvyI6kNlk8GYFN5vIDFjdbnPykjgs Ff6FHsu7YkzquLQMcIkzafJeZN54ZUB+AXZM7PCPP67dLUhAklR5i4DTXZDHCWvL/N+i vlAKFdmEMWTyl2tIr6QrAwdqK+FckWD9PICSu4m0ezA1IHtcUoxoGCPoy9RK6SEc+IhP XbZA== X-Gm-Message-State: AOJu0YxUVIr8gU5HHmwaT0K+IFJjm68IphMadLVL75PxfQX7izP60xAP zkDFNMZarifVADqEx+B5+oILfbcnvha8 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:829:6e77:9093:f39b]) (user=irogers job=sendgmr) by 2002:a05:690c:fcd:b0:5ca:fef:82a4 with SMTP id dg13-20020a05690c0fcd00b005ca0fef82a4mr492696ywb.4.1701123003294; Mon, 27 Nov 2023 14:10:03 -0800 (PST) Date: Mon, 27 Nov 2023 14:08:29 -0800 In-Reply-To: <20231127220902.1315692-1-irogers@google.com> Message-Id: <20231127220902.1315692-18-irogers@google.com> Mime-Version: 1.0 References: <20231127220902.1315692-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Subject: [PATCH v5 17/50] perf debug: Expose debug file From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Nick Terrell , Kan Liang , Andi Kleen , Kajol Jain , Athira Rajeev , Huacai Chen , Masami Hiramatsu , Vincent Whitchurch , "Steinar H. Gunderson" , Liam Howlett , Miguel Ojeda , Colin Ian King , Dmitrii Dolgov <9erthalion6@gmail.com>, Yang Jihong , Ming Wang , James Clark , K Prateek Nayak , Sean Christopherson , Leo Yan , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Li Dong , Sandipan Das , liuwenyu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Guilherme Amadio Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email 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 (pete.vger.email [0.0.0.0]); Mon, 27 Nov 2023 14:17:35 -0800 (PST) Some dumping call backs need to be passed a FILE*. Expose debug file via an accessor API for a consistent way to do this. Catch the unlikely failure of it not being set. Switch two cases where stderr was being used instead of debug_file. Signed-off-by: Ian Rogers --- tools/perf/util/debug.c | 22 +++++++++++++++------- tools/perf/util/debug.h | 1 + 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c index 88378c4c5dd9..e282b4ceb4d2 100644 --- a/tools/perf/util/debug.c +++ b/tools/perf/util/debug.c @@ -38,12 +38,21 @@ bool dump_trace = false, quiet = false; int debug_ordered_events; static int redirect_to_stderr; int debug_data_convert; -static FILE *debug_file; +static FILE *_debug_file; bool debug_display_time; +FILE *debug_file(void) +{ + if (!_debug_file) { + pr_warning_once("debug_file not set"); + debug_set_file(stderr); + } + return _debug_file; +} + void debug_set_file(FILE *file) { - debug_file = file; + _debug_file = file; } void debug_set_display_time(bool set) @@ -78,8 +87,8 @@ int veprintf(int level, int var, const char *fmt, va_list args) if (use_browser >= 1 && !redirect_to_stderr) { ui_helpline__vshow(fmt, args); } else { - ret = fprintf_time(debug_file); - ret += vfprintf(debug_file, fmt, args); + ret = fprintf_time(debug_file()); + ret += vfprintf(debug_file(), fmt, args); } } @@ -107,9 +116,8 @@ static int veprintf_time(u64 t, const char *fmt, va_list args) nsecs -= secs * NSEC_PER_SEC; usecs = nsecs / NSEC_PER_USEC; - ret = fprintf(stderr, "[%13" PRIu64 ".%06" PRIu64 "] ", - secs, usecs); - ret += vfprintf(stderr, fmt, args); + ret = fprintf(debug_file(), "[%13" PRIu64 ".%06" PRIu64 "] ", secs, usecs); + ret += vfprintf(debug_file(), fmt, args); return ret; } diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h index f99468a7f681..de8870980d44 100644 --- a/tools/perf/util/debug.h +++ b/tools/perf/util/debug.h @@ -77,6 +77,7 @@ int eprintf_time(int level, int var, u64 t, const char *fmt, ...) __printf(4, 5) int veprintf(int level, int var, const char *fmt, va_list args); int perf_debug_option(const char *str); +FILE *debug_file(void); void debug_set_file(FILE *file); void debug_set_display_time(bool set); void perf_debug_setup(void); -- 2.43.0.rc1.413.gea7ed67945-goog