Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CEEA3405E5 for ; Tue, 24 Oct 2023 22:26:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WjFIzqui" 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 983F92708 for ; Tue, 24 Oct 2023 15:25:22 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a7fb3f311bso64648647b3.2 for ; Tue, 24 Oct 2023 15:25:22 -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=hUitfFZRAjgv6sgNykLVzhSCNDK7FV53obZsU3/ZlPfaCM5VnaEQ+Ia2yYC9iyPxK8 3jMXhjAjTS6M10JXzETEklgN3XAZEsVBCRIqFvQRqHFa/ulGK93PGv3RovRFExiC+0h6 S2JHQvT6IAegRFIPetxbyX3RL+oPfJ/zR43KYacOeSsxRCXUvQHTrXv15+TBqmq6tGIL 4p0i5geLJjjuSDX/jJ1Zp7xxNyghQX5cr4xkntL+brOvmRPzADjE8ElVAHndslKiPiFP 0uI4lrmuCc2mRf9FL3Dc+dkslRC2Ysp+Gb5HFOvIaZLwxiQ9lMBFPismg/ofOHENf0HO ZoIg== X-Gm-Message-State: AOJu0YzP+SP0uqnHf7jhGVIK1uC9bLurCAX2j7M1TYav+Uk7xG/NC0qX N+cjG39g2QSaAf4Sse6MPurULOBfx7ov X-Google-Smtp-Source: AGHT+IEGfa+bbgNdmI/PGpBJGaemgihnReGqhdHNeMywurRc5ADtlpQhmpZjpLjYUXu/PpjX9AVsQVzdnU23 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> Precedence: bulk X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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" 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