Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp468800lqd; Wed, 24 Apr 2024 07:47:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUd4iimWj1wV9HwVwQYO4ONVxEpnY5ekJ/2SUh/BGZhM73RJE9C5skF+Ms4cPavR9OCvRaVt9nuO0AvWGwYHexIGwm91x1SvTJaAfnuQQ== X-Google-Smtp-Source: AGHT+IHONNEdCoIojoKu8MG32wVL3w4P/AWyBFtmx7pCHyXyLAk2caqNf7XTcquttd9uULxWeggt X-Received: by 2002:a05:6870:32d6:b0:229:e6c6:1f13 with SMTP id r22-20020a05687032d600b00229e6c61f13mr2816517oac.14.1713970054438; Wed, 24 Apr 2024 07:47:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713970054; cv=pass; d=google.com; s=arc-20160816; b=JiN+LbemomQaS4UlruJXvDfRjlVZe0B2tuiSLZhOOTbJv01Pz2rZIEtp4CYPIBhGZI WawEU5yx7435j55TEQuDnq77y0/+MwfhcrQPdBJj1qbOiO/sSO996b655uuYb4PB8LXQ U9wyExbPoNIJ70dQa3LpRdUIVRbGHo0mPfb77ZVYU0FJd5Uv9shtJ4Bxa1Rv/VyKMn9v 0uz+yTBBjoFKVhuWirFFUL77csiIQMKQsOznniDQe/ZBcPY94thAfSCER2XTh5Ay6sGZ qhFprdSPcvgsZMqPNtg8J8NjypgJj9JLtQDqDWsk+BvpEydOKFe4OfBcyWqVMgtvSt/h z0PA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Xg0XmGcKJNs/iN73iewkDC9tFUuF9SsJnJsVL3BAI68=; fh=dAFyoeb4mNleYvVLT04jG4V2YmdJAMhIAA3/3tuFxCc=; b=dksEvhULBY2kgODkqszyF1m8KqXVD4HZTcSlKBx85FOBZrnzZMzv+cctZ3Gf9ddtQt 4S0oIIeiQkV5jd6j99dzEA7g5Dy1GJgFv7k5euO1h6p2/BakkEWZp559MPsmVYeKSmzK vvehoJT22fHWWEQ06oIi/EH4nmbJNRk67GN1haChBnIeLArZTncyLHMR8redC+vmPEHk I9Kz6cmmQ1ZVyEfLfZl3eR6FnZ1fpAtUZHwyeZqGBl0hZMhsuFbtFGYdCTkVuSOA08m7 kZFb7+DpQfsjchtf1oCGY6YUN9+SmaYLwkJ9khUEOJjdwJgcwg+ypAVdWQlLNPlcTGcc s7DA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="cb/Nprvb"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-157090-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157090-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d20-20020a63d654000000b005f05c950b97si11213631pgj.101.2024.04.24.07.47.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 07:47:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-157090-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="cb/Nprvb"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-157090-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157090-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D607B28AF4E for ; Wed, 24 Apr 2024 14:38:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1489915F3F3; Wed, 24 Apr 2024 14:37:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cb/Nprvb" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 347B815F314; Wed, 24 Apr 2024 14:37:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713969432; cv=none; b=ukeZU7YCOKdgHwHMGZyX6pTDoLYFRWCaZmsYos6OlL147/RWEMc/TwZoKox0GE4qhUBySgvzHva4j5Ld6miMeEj8WbxA7KH5xFF+roldpg/RsAcdehgd8afoxsxZ4T6+bMmmeuUJX4y3Veqan+QvXhj7qc8Kq4b1vLoyVI9Y3Ak= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713969432; c=relaxed/simple; bh=j0YRjq89mh1z9ilQ9W1YlxmSrjLRKNllnP5X8Z2EVek=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p6WqfMsH2P25xxc/lKKx78c59SiGvF4ULPH1UgYpNciNbybs1dfzLVrYem1Etx64V3+Wk1Z8d9FXFfqPuPLozrYQA0bJLlpMzWA2YA7H25GTtjoh00q3MYTeEg4/f4576ejcemMFWDs5s6qo2l+Xz5puBk0IiwgvXx/xZPqW7UU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cb/Nprvb; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26894C113CD; Wed, 24 Apr 2024 14:37:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713969431; bh=j0YRjq89mh1z9ilQ9W1YlxmSrjLRKNllnP5X8Z2EVek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cb/NprvbwxGw0UkgQem5u9klDFeieqidScTiMeDYEyTMHs4YiHTfTAUPRaQaszgvx s/NQWo7A5bsWjTEr4qYdilBDBEZuL4yCG0qVqW/cjnY+wH9AR/dSpVwJp5Cl3j26rk kdvP3phGObMsa4uOTf7b0axS+zYzzEjxoMJDHocgcVOW/+6UWhj1E8A93D/wVm1nnS Ft4DGcepyio90rmM+PjC9WwOiM/om2FFDZwy+WwN1kLwUTbEvjxWpdmCEejnSo9uLL P65qWYFctca3Dc8s1DckNs1+OkyAEanZfDq2h8gNd5mGqRBfIQIKuEZnszXCdQYQ7Y 6S5QwvSlYWUQQ== From: Daniel Bristot de Oliveira To: Daniel Bristot de Oliveira , Steven Rostedt , linux-trace-kernel@vger.kernel.org Cc: Jonathan Corbet , Juri Lelli , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/8] rtla/timerlat: Use pretty formatting only on interactive tty Date: Wed, 24 Apr 2024 16:36:52 +0200 Message-ID: <8288e1544ceab21557d5dda93a0f00339497c649.1713968967.git.bristot@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit timerlat top does some background/font color formatting. While useful on terminal, it breaks the output on other formats. For example, when piping the output for pastebin tools, the format strings are printed as characters. For instance: [2;37;40m Timer Latency [0;0;0m 0 00:00:01 | IRQ Timer Latency (us) | Thread Timer Latency (us) [2;30;47mCPU COUNT | cur min avg max | cur min avg max[0;0;0m 0 #1013 | 1 0 1 54 | 5 2 4 57 1 #1013 | 3 0 1 10 | 6 2 4 15 To avoid this problem, do the formatting only if running on a tty, and in !quiet mode. Signed-off-by: Daniel Bristot de Oliveira --- tools/tracing/rtla/src/timerlat_top.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src/timerlat_top.c index 2665e0bb5f1e..c9cf90ed4e6d 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -44,6 +44,7 @@ struct timerlat_top_params { int hk_cpus; int user_top; int user_workload; + int pretty_output; cpu_set_t hk_cpu_set; struct sched_attr sched_param; struct trace_events *events; @@ -179,19 +180,22 @@ timerlat_top_handler(struct trace_seq *s, struct tep_record *record, /* * timerlat_top_header - print the header of the tool output */ -static void timerlat_top_header(struct osnoise_tool *top) +static void timerlat_top_header(struct timerlat_top_params *params, struct osnoise_tool *top) { - struct timerlat_top_params *params = top->params; struct trace_seq *s = top->trace.seq; char duration[26]; get_duration(top->start_time, duration, sizeof(duration)); - trace_seq_printf(s, "\033[2;37;40m"); + if (params->pretty_output) + trace_seq_printf(s, "\033[2;37;40m"); + trace_seq_printf(s, " Timer Latency "); if (params->user_top) trace_seq_printf(s, " "); - trace_seq_printf(s, "\033[0;0;0m"); + + if (params->pretty_output) + trace_seq_printf(s, "\033[0;0;0m"); trace_seq_printf(s, "\n"); trace_seq_printf(s, "%-6s | IRQ Timer Latency (%s) | Thread Timer Latency (%s)", duration, @@ -204,11 +208,15 @@ static void timerlat_top_header(struct osnoise_tool *top) } trace_seq_printf(s, "\n"); - trace_seq_printf(s, "\033[2;30;47m"); + if (params->pretty_output) + trace_seq_printf(s, "\033[2;30;47m"); + trace_seq_printf(s, "CPU COUNT | cur min avg max | cur min avg max"); if (params->user_top) trace_seq_printf(s, " | cur min avg max"); - trace_seq_printf(s, "\033[0;0;0m"); + + if (params->pretty_output) + trace_seq_printf(s, "\033[0;0;0m"); trace_seq_printf(s, "\n"); } @@ -305,7 +313,7 @@ timerlat_print_stats(struct timerlat_top_params *params, struct osnoise_tool *to if (!params->quiet) clear_terminal(trace->seq); - timerlat_top_header(top); + timerlat_top_header(params, top); for (i = 0; i < nr_cpus; i++) { if (params->cpus && !CPU_ISSET(i, ¶ms->monitored_cpus)) @@ -693,6 +701,9 @@ timerlat_top_apply_config(struct osnoise_tool *top, struct timerlat_top_params * } } + if (isatty(1) && !params->quiet) + params->pretty_output = 1; + return 0; out_err: -- 2.44.0