Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp555382rdb; Thu, 2 Nov 2023 11:01:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFgjINp+zKvyMdy5pAZCYLlKrx7aBkkY16qcszCzDHnsmz7dzvhtlEZ64E4Ai1+bK1K2c4x X-Received: by 2002:a17:90b:3107:b0:27d:348:94a8 with SMTP id gc7-20020a17090b310700b0027d034894a8mr17969978pjb.6.1698948099547; Thu, 02 Nov 2023 11:01:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698948099; cv=none; d=google.com; s=arc-20160816; b=ZiaIAwKY9SR8brzqt2rVqCU3gb8MvPO6vtU7za4FcV+bfA95OW2oWnNnDkTbPFvyR4 VEerrosWCRMYJZK69Te4EmBusH5/C3UdEU5kKQTC42v0IgrEB9puu6szkch6HWJTL5xt XL7t1MnYv8PmSrubdPVoTJWpMS++6mqc+SeG7xfHf1R7d+90itQ3c2pqF4E0XAYFjvgS K2w5BIk+GU70IFCjMMeighI2gBngK49otXN5HZ5A/jmyPJy4+MfVucDPvzD2Ayj3deyb 9Jv9Ev+OV40b2rQubCiOTPPjAyzdIzq4mbkwb39IaOJPkKYS7ptETIvAV3UDUGcNQnQG NOZg== 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=vTgDtxbYigIx0l7l8yxmVGmQ3YjDCKbQz5YbC6NLkeU=; fh=z1KcSqUpYQ9oC4uLSeIkhAYTnJ2bvP0QbNW2xqV5NqA=; b=nAhFPwIzDRwvGktDxzE29rjxzsfvj/ZAh1QQsrfKHYvtnLL3HwWkngAci+WxtfVDJN id8I4EW+o3v5wogRTunxVHKcJrycV5NkDy6H7vxYvXh7ynbpdOKNAYbI4KYEnc55LEgs HRanOP+hbkHq2ufJQawWtPe8QhUQOekjXHfym8/gCj+cISIpGE+8+es7TXBlcmEbETcA Rzr9RR6DQZPrMa7wUMEMnflvDgZTZU673ATNIRii+0m4Jhz/dfiiEyhDgxC1B+E0HPHp 99zPBsy+PCB3rAq155RI36aJFy1jd4dTztWpCeXStdoxAJDnj/AStyTNHLRNF4LFLdHz 298A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=x8QRJv9O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id mu7-20020a17090b388700b0025c1d114af0si105551pjb.93.2023.11.02.11.01.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 11:01:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=x8QRJv9O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 2433282157A7; Thu, 2 Nov 2023 11:01:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234928AbjKBR74 (ORCPT + 99 others); Thu, 2 Nov 2023 13:59:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345505AbjKBR7H (ORCPT ); Thu, 2 Nov 2023 13:59:07 -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 332E41728 for ; Thu, 2 Nov 2023 10:58:43 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5afa071d100so25594797b3.1 for ; Thu, 02 Nov 2023 10:58:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698947922; x=1699552722; 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=vTgDtxbYigIx0l7l8yxmVGmQ3YjDCKbQz5YbC6NLkeU=; b=x8QRJv9OoUqot16R90umaoBpzuvKCn2FkD3cARBsCcLiL1WeGukknK12Ee9ILa+1qa fD2gOwXocsngaNt8Ar77m4vKAHuqY+kkRVrzeK/pR7liiZtSPSTxzHHFCQnYs0/rnzOf NMGiYXcyymKbs2WjCWrudMoPGweT1XvyO2y67VOrhqxRXRSBbNHdS/mLMHHGc9O++8jp VN5rinyLWaGUE1zoVNAmdFs4D17iNKnfQkm+cly+5hwVHZPPWYCkt4y+MknRFIixVJkN AV8Eo4+msRQ58dSJLKSwnkp/Xf9QxJdygn+UDhWzWmwLm1zGdaEGPXF89XPYdpX/vKnT jIMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698947922; x=1699552722; 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=vTgDtxbYigIx0l7l8yxmVGmQ3YjDCKbQz5YbC6NLkeU=; b=L9BlyKDskQMGd/23IjvIVtQEKgNSH4/ReIj8hDLUco01vJoC3amWqwNh2SfHpY9Adb yrvVUoPxzxBEE3Lj7sk9MXfIeWwHl/gvoLV5iaWQKN7cshFRH4s1kjxXSgMiObwVZnc4 uLuRKdgyfNirVCnoFmOIOaNpigdIu5vbLI6/r57zb+dgBdHpKYCZpFaf/FTXi/HIxkSW aUOsI1+6G9ZBx19W7sfVu3ixDUpaaWMjnkUwau1DqgTzMCbD7KPu1hY03gIdsnnqcjRB LdNwc7BPPItL2JFZFB1CUaxfD4Q3ZWHNT07cdPZPVxT0kC6ftHKk1A6gc13Q0aNTkyjp 277A== X-Gm-Message-State: AOJu0Yw3GUV5sMdc4CMoDn6NCFagDzJcj1kIpmCeoZ+V/q5+9uXEp68P VgTbgHa1bI3uRJ/Kx1bASe/zWpWDOk1x X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:bb34:df9c:836c:afca]) (user=irogers job=sendgmr) by 2002:a81:4f12:0:b0:59b:ebe0:9fcd with SMTP id d18-20020a814f12000000b0059bebe09fcdmr7405ywb.7.1698947922233; Thu, 02 Nov 2023 10:58:42 -0700 (PDT) Date: Thu, 2 Nov 2023 10:57:02 -0700 In-Reply-To: <20231102175735.2272696-1-irogers@google.com> Message-Id: <20231102175735.2272696-21-irogers@google.com> Mime-Version: 1.0 References: <20231102175735.2272696-1-irogers@google.com> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Subject: [PATCH v4 20/53] 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 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 02 Nov 2023 11:01:23 -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.869.gea05f2083d-goog