Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2186649rda; Tue, 24 Oct 2023 15:29:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEKp9DpeqqGItCF1vbkx3RsPiJV2R0XKUakK01/PaDf12NVMYIfCHIFmw9FYbhIQmbWJbU1 X-Received: by 2002:a92:c54f:0:b0:357:cfcc:f483 with SMTP id a15-20020a92c54f000000b00357cfccf483mr10451696ilj.20.1698186543076; Tue, 24 Oct 2023 15:29:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698186543; cv=none; d=google.com; s=arc-20160816; b=L828IPDpruxO7n65VUX4hqN2NEeggt7n+yjl09GXuEW+A3IWYkMtVWscRhF+Oo7iS8 SvHwlwakHpTjD34LKb4w/4Yk4ezLM0MEHJOjUfcWKxh6hk0iOLljQoKecLw5fA8yr0OY TFUwgYyfBvNTJfzMwQh0ODFJuHApeuUyghzjgqSSPjnZdouOCQLz9R5ZP4SirkOEmFqa o4dNee5L85f3IF7o1S6sHy/n2auT2AM8+1QJH74qOpDxvHtRy4cnV442lcS43Dc7y8OZ 8i9TrxTTLjUQxtL6TQrdX6xpFteCeDnmeQzwhePG5EeaMpdclsJ1eISAq80/YvO5RbWa 8DlQ== 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=zKJ+MtJQ0m3usmVnmVc1PXHVWWmmWPISerzupGC9o9o=; fh=NAro5oTsDEB2Or99ABwb774QJkwQSkr6EoLVqn/Yde0=; b=xH0j2sE6tL9yAbPHaVckTm2OGFD5AoxgaC4U7uhA+eOiqaIAUEUyyKL4SEDgEdE0j0 eah7lc7WtfiOJVNhW76ZkHKuDZJJqUwazBUWIW8HTW/9jsEMIrnhhu+313zU8PqymkKR B1Mp8VcaPpHF4aDBxg0zTDxMm6/J3MvDMO+c4JDM0HInnBhRq3+URNiujGIicImwycT+ Ysz0gfEdCf3NKiJx8uS/OUGrHBVsxPOPHoTz/4UbCOnRKldvTap3OPyHC+M2CZucjC/y DXd9ZObXoMbb/tZcLnQUZV+JWXlDlVJf8e9M+zFXFWOSVmItNwtqDImdoKA2VvvEeTIw iK1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=WjFIzqui; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id w8-20020a63f508000000b005b8eacb29c1si2013015pgh.437.2023.10.24.15.29.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 15:29:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=WjFIzqui; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id C5C2B808FA55; Tue, 24 Oct 2023 15:28:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344554AbjJXW0j (ORCPT + 99 others); Tue, 24 Oct 2023 18:26:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344520AbjJXWZ6 (ORCPT ); Tue, 24 Oct 2023 18:25:58 -0400 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 97CDD2706 for ; Tue, 24 Oct 2023 15:25:22 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a92864859bso45299357b3.0 for ; Tue, 24 Oct 2023 15:25:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698186321; x=1698791121; 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=zKJ+MtJQ0m3usmVnmVc1PXHVWWmmWPISerzupGC9o9o=; b=WjFIzquiFxSHREY+b5v7HReFVePOCy0rewrxOZVoMVT9dUg5oz4RrLCg4C3GTAf/9M 1XI2OOtYV8YYuvB9g9K5RrxU60ROgFhyrKCOzhFsrFD5K3U3l4S9J/EXpyWZ4/fYBnIj Q0j6kcbPv6Yy1Q6ZoCifsFccsqmhpJmn7CnnZ0G364+ArXWLdw3AXhlyYTFsslDdXovM oKZ8IiC7fi/c+RJOBZAhiaA3J+BGVVQ0q8dyIo4a8TwxBw0ouqvzE+Ss5CN5L4s27uUL zQZV6QnK2Ik0ronIPg+QwKoG0JWFHy+lMJ7/2sfvFL9TnQB+kC/8ljFqpDyZKbJBdj4G qq2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698186321; x=1698791121; 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=zKJ+MtJQ0m3usmVnmVc1PXHVWWmmWPISerzupGC9o9o=; b=uz9A/qIVYv+aSsSFrlChmlU08NRKjpuOedgZVo4trWnikabkc8nXZnIwgiR81hKC7J Eadc9enhJ/p5v/FBjv2wYkiJ5tL37O+ArdeuViOgo1ip7rvm7LF89p2+D8aUkecQcrL8 rU6CgOURD+YS91MgCeHRZTCIBV2+EIXukefgezanFoSHGcHrvzn6LSmoa9DjZf2I0a6m xe64HnQP9RCcXc0vuli2LOZDwP5sovPlnnx0RNXbDMwWygQny3sJDOfGxeSTP3+yj6ea HMma53IApBIJRwXCT5Ev9pItVDhYFKUsoW4CqjvRLjV/t21+1KIABCLn4qV09LR+WFyz nILw== X-Gm-Message-State: AOJu0YwKHvh3NWA19ZcXrNlCg8fCogEHZUMglS9ixk/r3+jiT1C/WlAU PovqDY5LJJJ4JQ/XZcHZPbEw98Io2fRa X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:93d2:18cc:4d63:45ba]) (user=irogers job=sendgmr) by 2002:a0d:d644:0:b0:5a7:f73d:e69 with SMTP id y65-20020a0dd644000000b005a7f73d0e69mr271131ywd.4.1698186320786; Tue, 24 Oct 2023 15:25:20 -0700 (PDT) Date: Tue, 24 Oct 2023 15:23:33 -0700 In-Reply-To: <20231024222353.3024098-1-irogers@google.com> Message-Id: <20231024222353.3024098-31-irogers@google.com> Mime-Version: 1.0 References: <20231024222353.3024098-1-irogers@google.com> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog Subject: [PATCH v3 30/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 , Leo Yan , Song Liu , Sandipan Das , James Clark , Anshuman Khandual , Miguel Ojeda , Liam Howlett , Yang Jihong , Athira Rajeev , Kajol Jain , K Prateek Nayak , Sean Christopherson , Yanteng Si , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Masami Hiramatsu , liuwenyu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org 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,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 howler.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 (howler.vger.email [0.0.0.0]); Tue, 24 Oct 2023 15:28:45 -0700 (PDT) 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.42.0.758.gaed0368e0e-goog