Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1362221rdb; Wed, 6 Dec 2023 17:19:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IH/OA854Dm8P6t3Nu7zbp1pTlTXb2CqB57gxRe35oBcrU74BSMz1y7c6+zDJQ3pOfsAgtTr X-Received: by 2002:a05:6358:2919:b0:170:8ef:d223 with SMTP id y25-20020a056358291900b0017008efd223mr2542186rwb.25.1701911944987; Wed, 06 Dec 2023 17:19:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701911944; cv=none; d=google.com; s=arc-20160816; b=Fk4ZwB3lDpBpUQYn3aKlv5WxLIsqzQ5Uv/MhuVP+uHrJDp2103mQVEu+oV7B5DmQbV U+Bl8yYHwDgBmyEJzUtr9c6Evxx5IcPdl0KGKQtd1U+wewTqHzWxD8zb+drYrKUDTUDR ULX+sOICTLrbTOYnos5pSvS5avIlFD+JmSBoH0LXF9suiAJ+n9vDAWg4XrHHJUMG2emD i/T7E47QByabSw+zR8xaj9IfnHA8D5oTAmE2xyJlOFzCcBraIWQseWAzNxePg7/biB7Q QFMvvKdZqIu50F3as97KYOav2plQDW+Tks1/Kreq6ql/1Rte+CvKXbvUaZKUcTdGrIyr zskA== 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=07FiGpCpRwekHPiY2eAXlYGujYsi6QRvrXzBG4my8ro=; fh=Io7x3OacpefNRRNKoYAzVE0aWTDwD7FRzyCdD1e3AN4=; b=LtknUtFqRPraVrXNF5djQWXkP93JK0hTsMsEYdtrWqA2y7r1RQnbonMSOYR8n0ksuR BnMjlm2dW73dIb42UFDZuUOY2d/q5UN5dE486ipcd/3nmbXzCbQ4h5SYQelqN8ieaYHk 3RCQTP5l2RVd8muHKbJlvcivoGKQvlw44ZjaiyLRe7BDwckxDpYOWwRYqkj9nIN5y+cp jZ8ITUrkU3j9rUWYKpaQlPACTW8ObxpcDFR9UA/fJTHz464xP+9QftyKLg8gx1D3ihkd /YGQi3/LGKfvjmzizKxigXP5RpgsXWDoWKiLZsenYy6KCSRl7k+X2wWD5NFRFvBrHC5t B3UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=qIhxv5hW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id n189-20020a6327c6000000b005c6b4e4abe2si220312pgn.169.2023.12.06.17.19.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 17:19:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=qIhxv5hW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id B517D80236FD; Wed, 6 Dec 2023 17:19:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442113AbjLGBSu (ORCPT + 99 others); Wed, 6 Dec 2023 20:18:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442110AbjLGBSb (ORCPT ); Wed, 6 Dec 2023 20:18:31 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 965A21BDC for ; Wed, 6 Dec 2023 17:18:04 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-db5416d0fccso480559276.1 for ; Wed, 06 Dec 2023 17:18:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701911882; x=1702516682; 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=07FiGpCpRwekHPiY2eAXlYGujYsi6QRvrXzBG4my8ro=; b=qIhxv5hW3S3qKis0f+Q+G8ZTk6EVylrpqVFngUCChey0fj8WkrVH62mOQpG77rpKap mGP+CCZCtdI2gKT2ohREaHbF/u64B/gQ30Ovjb/LrOehRllAY7OeyQ5oPDPDYIfZqhvj uiqrNyPbADe+HeWQKyxsTuBpCtD5bj824nIxGVQm8RRiwE4Bx/rnIuIinrvs4vvQf8KD V+iJzrKNO1ZdLDKavKMKSfR1piuD5XWEtNZDV+RE/BFd+PPAsnA3TUxHjP65Z/Qxo4dP LMP/knLiqfV6FoOdJMJ9o/8bcCBihMHdmAH4lKXbc6GOH75ZFmFOWfC4gqw0lrPPzaGr 3JGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701911882; x=1702516682; 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=07FiGpCpRwekHPiY2eAXlYGujYsi6QRvrXzBG4my8ro=; b=XRM897gCDqEMBwhRkwn3HtsDuJNUgh8APUxVV81OP1Z5uOr0CTnu6QvQsMo731yOLl qwKKdfdIY+j29bHvaglmvX2+YY5TzpKr1RLtLYluKuXcnWwp3WvFLJSd5keVrYvvn1E5 0tWJUN6KrUx2uRAluzgjzHWtdu+nJtIgmVviKfc1imiVa8Kqh0vCWEiMWJBiqNMWTG10 M4prXDFbsBcZrMB0wp/VmAmmePIYGgT6o9hB5IvELg0BUAkZ7T5XjYGBaqxCP8E6u7lu qItz1rWqQdafZyJq6BmZjZLcNvB0rDq3rQYsd1pDDjvqr3vJQxT1LDphs4yfkeJplqui s7oQ== X-Gm-Message-State: AOJu0YzgIwqXbORgfgh2KLMJUcQjp9904p4fOUI6nXipyeXr/QzVV3OH J833+O0yZ0K2H9oP+yKGcSypVa4DFX8k X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:35bf:293e:7696:34e9]) (user=irogers job=sendgmr) by 2002:a25:dac7:0:b0:da0:3117:f35 with SMTP id n190-20020a25dac7000000b00da031170f35mr30196ybf.3.1701911882151; Wed, 06 Dec 2023 17:18:02 -0800 (PST) Date: Wed, 6 Dec 2023 17:16:49 -0800 In-Reply-To: <20231207011722.1220634-1-irogers@google.com> Message-Id: <20231207011722.1220634-16-irogers@google.com> Mime-Version: 1.0 References: <20231207011722.1220634-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog Subject: [PATCH v6 15/47] 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=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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 lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 06 Dec 2023 17:19:03 -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. Acked-by: Namhyung Kim 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.rc2.451.g8631bc7472-goog