From nobody Tue Dec 2 01:04:39 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 065972E1EE7 for ; Mon, 24 Nov 2025 06:32:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763965950; cv=none; b=k0AzaAJyvJSHA5p5+z6o7MmVMDpEgp9R5oRRzQueGix/TSy1CI0vEi5+mgH1fgTZHzrs74dHKk8i+DNBPLWshGJu7edk6uXpEHfDnzxNjH0h3PKV3XcxGcIVjp7AI55FK0qMhcGwex6z90NTikDGhRiuV+TEQcJgWi2tYmTxHmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763965950; c=relaxed/simple; bh=jvhIYdmBV7WMh9lpR7C7Sy/+S3cErNUU1G3Spu735eI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=fpAD0r0l58mjiPT/lGzbY77GM4SKH0MuXxYx30ihguT5FG1c3+2HaO6Ge8CXDfaX/Da0AmgA49rspU6Y7jesuMxtkA8epiJqxAua1h0hluKlUKOsaHISihn5Gak8xJe5Jlo2gEImMArXSj9mhdbghl5O33c84PSDkZZEFhZqggM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=WFBQk2UW; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Hlku4AXC; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WFBQk2UW"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Hlku4AXC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763965946; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=v5yar6OuDB0ADcv8NH2WOeZJwh0vqiudRWLgOAL+k3Y=; b=WFBQk2UWXSlyKYjN7T2oDElMXu1h6J3yzb+QfgBYSJyiEM6whzdW6zVQqnXeSzgIn8vkpV OrJ3DQvBKSnik2xcCp2iAvY1gm8WwNlJxwSQAcdBJFOB51/oih1C6E+vpN/l0x1O2OmpQN I5SKANMFk4Nd8trEV5LBB/7Rd37irCw= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-336-euSfq3uNPKatepDXgperjg-1; Mon, 24 Nov 2025 01:32:25 -0500 X-MC-Unique: euSfq3uNPKatepDXgperjg-1 X-Mimecast-MFC-AGG-ID: euSfq3uNPKatepDXgperjg_1763965944 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4779b3749a8so33787765e9.1 for ; Sun, 23 Nov 2025 22:32:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1763965944; x=1764570744; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=v5yar6OuDB0ADcv8NH2WOeZJwh0vqiudRWLgOAL+k3Y=; b=Hlku4AXCY0kNIlbMKxFFMpVjsozQDM2F2kcbULouzUFEAxaVP4XXGUav52h1h9zbCY b4kXimy96KssMfnVfG8GowmhMfbK4vwfKFW4Jv+mwXE0RNAN3XyrMnqW9OBezwj5wXDl W7zZUVRu9HBYOW3yJTSYTvdeK7SuKW7w4fuhJBd2sfJ7ghbIbgoHJ9PUlbKShMStFISB RrrOTn30qsgFZPhbf4JGIkwdkWP3vDn1r/DyFrbgneDhmgZBBW9HOxNei6KO9khiCLDL 9yowquPYhz1Qin4ylY2W9s76+eeBhNGdm9VZQllTdVx3UhmF0hOZBkMQ+A+Brdb6c0zg rjXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763965944; x=1764570744; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=v5yar6OuDB0ADcv8NH2WOeZJwh0vqiudRWLgOAL+k3Y=; b=EcPHUfN9lCT8CB9fPj2dLU6/J650salT3Sa2ZgQ/KE/boBtuFLMUTobmgi1741Fn4u KyDrclTrGDqBTxYlyhAUkMIOEPebE7qWzduura8Zut/DObFIX5g3pJYNBQEZ7dw19Esd bMX+iR9ClRtbrT1OHbNan8TiqW8BORzCWmT9K/OHJo0nbRz8eq/Oup6rBqQsO851axHE h2zk2PZw3git2hSrm+Pq9CT56tKQL8EYy30rqfrqyh5/nZejZS1vI+RRsuyd+JzzCWtu XS3aAG46iNnFj4jswD0DicQK/BPWpCCgJcjW3y0gaPu6IhDNEwyGkfEnCdhTjsb6AAa9 xFNg== X-Forwarded-Encrypted: i=1; AJvYcCUUyuat+RLb5+V7dyXuvbOilzMfaUxsAYwuJnKbx8sasILAZaMeprgXItwaxzFHpqNTvyyznHRRwHWlMhw=@vger.kernel.org X-Gm-Message-State: AOJu0YwGEbTY+GMiAT5Io49h8u4vABhC6DO0KasUSQer61DIQBhnbm6e 7p79H4ouBdWLzj/YzllO0h7gW5xF+UMweuHXTw6GNak7dKMlLMQnQrFiV8quOXM1eQ6SZuqtEQb BTyi5Vcwbu2Ez8eo9zRQIZl9d3gmUV90rU7GkNWSlEdtQ+FJlEReUAzfcdfQ4aHtrQg== X-Gm-Gg: ASbGncu9i5WD56TJZxVjZsUdfcFGc0vVHwhw9VB9pspgpl7FikBJvYVXGeJXTLVRsqz WmdKGk/dzWex3689ZtpWPbifIoPryZcb8Nt8LFxEJwJhGY8PM02YSeXUJm0C0kDMw+nuf3PPamr tFx7GfQu/TSPRW9qyk0yzwGAx2tJ+G4OK+nOciw5dHAUAhAPbZpcVRSHs+ylIL+CXwTdU5c1btZ y/eSSGTIyTBB5cakYJqq1k/GyWzUoSQtBwlm/LAAL5dLqUQ+a9GxHlnW72MgDkd48Bui7bV8aUP O4ISk6sfEyYMtO18WIQHbtKlVq3UR/xuGzr+monRTnriktQ/tGae9g+ccU8T65+IZyoLFuojnr1 iLFiM5Qg7rNBykZuUJ+dzqIIgEOM= X-Received: by 2002:a05:600c:3b09:b0:477:a3f9:fda5 with SMTP id 5b1f17b1804b1-477c016e425mr78181455e9.9.1763965943516; Sun, 23 Nov 2025 22:32:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IFPJb4dKcAq+naHixjVdeC3U+dNG95F4YpemwqmrEUxnYdSW/kUpDzgh7GZ3Iu9BIDXr2931Q== X-Received: by 2002:a05:600c:3b09:b0:477:a3f9:fda5 with SMTP id 5b1f17b1804b1-477c016e425mr78181255e9.9.1763965943093; Sun, 23 Nov 2025 22:32:23 -0800 (PST) Received: from costa-tp.redhat.com ([2a00:a041:e294:5000:b694:8e49:4f51:966d]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-477aa387473sm143912575e9.4.2025.11.23.22.32.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Nov 2025 22:32:22 -0800 (PST) From: Costa Shulyupin To: Steven Rostedt , Tomas Glozar , Crystal Wood , Costa Shulyupin , Wander Lairson Costa , Ivan Pravdin , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1] tools/rtla: Add common_usage() Date: Mon, 24 Nov 2025 08:31:46 +0200 Message-ID: <20251124063204.845425-1-costa.shul@redhat.com> X-Mailer: git-send-email 2.51.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The rtla tools have significant code quadruplication in their usage functions. Each tool implements its own version of the same help text formatting and option descriptions, leading to maintenance overhead and inconsistencies. Documentation/tools/rtla/common_options.rst lists 14 common options. Add common_usage() infrastructure to consolidate help formatting. Subsequent patches will extend this to handle other common options. The refactored output is almost identical to the original, with the following changes: - add square brackets to specify optionality: `usage: [rtla] ...` - remove `-q` from timerlat hist because hist tools don't support it - minor spacing Signed-off-by: Costa Shulyupin --- tools/tracing/rtla/src/common.c | 39 ++++++++++++++++++++++++++ tools/tracing/rtla/src/common.h | 3 ++ tools/tracing/rtla/src/osnoise_hist.c | 22 ++++++--------- tools/tracing/rtla/src/osnoise_top.c | 37 ++++++++++-------------- tools/tracing/rtla/src/timerlat_hist.c | 22 ++++++--------- tools/tracing/rtla/src/timerlat_top.c | 22 ++++++--------- 6 files changed, 81 insertions(+), 64 deletions(-) diff --git a/tools/tracing/rtla/src/common.c b/tools/tracing/rtla/src/commo= n.c index b197037fc58b..18b92c5e4b1a 100644 --- a/tools/tracing/rtla/src/common.c +++ b/tools/tracing/rtla/src/common.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "common.h" =20 @@ -348,3 +349,41 @@ int hist_main_loop(struct osnoise_tool *tool) =20 return retval; } + +static void print_msg_array(const char * const *msgs) +{ + if (!msgs) + return; + + for (int i =3D 0; msgs[i]; i++) + fprintf(stderr, "%s\n", msgs[i]); +} + +/* + * common_usage - print complete usage information + */ +void common_usage(const char *tool, const char *mode, + const char *desc, const char * const *start_msgs, const char * const *= opt_msgs) +{ + static const char * const common_options[] =3D { + " -h/--help: print this menu", + NULL + }; + fprintf(stderr, "rtla %s", tool); + if (strcmp(mode, "")) + fprintf(stderr, " %s", mode); + fprintf(stderr, ": %s (version %s)\n\n", desc, VERSION); + fprintf(stderr, " usage: [rtla] %s ", tool); + + if (strcmp(mode, "top") =3D=3D 0) + fprintf(stderr, "[top] [-h] "); + else + fprintf(stderr, "%s [-h] ", mode); + + print_msg_array(start_msgs); + fprintf(stderr, "\n"); + print_msg_array(common_options); + print_msg_array(opt_msgs); + + exit(EXIT_SUCCESS); +} diff --git a/tools/tracing/rtla/src/common.h b/tools/tracing/rtla/src/commo= n.h index 9ec2b7632c37..b44e910ba72c 100644 --- a/tools/tracing/rtla/src/common.h +++ b/tools/tracing/rtla/src/common.h @@ -156,3 +156,6 @@ bool osnoise_trace_is_off(struct osnoise_tool *tool, st= ruct osnoise_tool *record int common_apply_config(struct osnoise_tool *tool, struct common_params *p= arams); int top_main_loop(struct osnoise_tool *tool); int hist_main_loop(struct osnoise_tool *tool); + +void common_usage(const char *tool, const char *mode, + const char *desc, const char * const *start_msgs, const char * const *= opt_msgs); diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src= /osnoise_hist.c index ff8c231e47c4..372128db9e4a 100644 --- a/tools/tracing/rtla/src/osnoise_hist.c +++ b/tools/tracing/rtla/src/osnoise_hist.c @@ -409,16 +409,15 @@ osnoise_print_stats(struct osnoise_tool *tool) */ static void osnoise_hist_usage(void) { - int i; - - static const char * const msg[] =3D { - "", - " usage: rtla osnoise hist [-h] [-D] [-d s] [-a us] [-p us] [-r us] [-s= us] [-S us] \\", + static const char * const msg_start[] =3D { + "[-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\", " [-T us] [-t [file]] [-e sys[:event]] [--filter ] [--trigger = ] \\", " [-c cpu-list] [-H cpu-list] [-P priority] [-b N] [-E N] [--no-header= ] [--no-summary] \\", " [--no-index] [--with-zeros] [-C [cgroup_name]] [--warm-up]", - "", - " -h/--help: print this menu", + NULL, + }; + + static const char * const msg_opts[] =3D { " -a/--auto: set automatic trace mode, stopping the session if argumen= t in us sample is hit", " -p/--period us: osnoise period in us", " -r/--runtime us: osnoise runtime in us", @@ -453,13 +452,8 @@ static void osnoise_hist_usage(void) NULL, }; =20 - fprintf(stderr, "rtla osnoise hist: a per-cpu histogram of the OS noise (= version %s)\n", - VERSION); - - for (i =3D 0; msg[i]; i++) - fprintf(stderr, "%s\n", msg[i]); - - exit(EXIT_SUCCESS); + common_usage("osnoise", "hist", "a per-cpu histogram of the OS noise", + msg_start, msg_opts); } =20 /* diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/= osnoise_top.c index 04c699bdd736..1db1d946b600 100644 --- a/tools/tracing/rtla/src/osnoise_top.c +++ b/tools/tracing/rtla/src/osnoise_top.c @@ -257,14 +257,16 @@ osnoise_print_stats(struct osnoise_tool *top) */ static void osnoise_top_usage(struct osnoise_params *params) { - int i; + const char *tool, *mode, *desc; =20 - static const char * const msg[] =3D { - " [-h] [-q] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\", + static const char * const msg_start[] =3D { + "[-q] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\", " [-T us] [-t [file]] [-e sys[:event]] [--filter ] [--trigger = ] \\", " [-c cpu-list] [-H cpu-list] [-P priority] [-C [cgroup_name]] [--warm= -up s]", - "", - " -h/--help: print this menu", + NULL, + }; + + static const char * const msg_opts[] =3D { " -a/--auto: set automatic trace mode, stopping the session if argumen= t in us sample is hit", " -p/--period us: osnoise period in us", " -r/--runtime us: osnoise runtime in us", @@ -295,25 +297,16 @@ static void osnoise_top_usage(struct osnoise_params *= params) }; =20 if (params->mode =3D=3D MODE_OSNOISE) { - fprintf(stderr, - "rtla osnoise top: a per-cpu summary of the OS noise (version %s)\n", - VERSION); - - fprintf(stderr, " usage: rtla osnoise [top]"); + tool =3D "osnoise"; + mode =3D "top"; + desc =3D "a per-cpu summary of the OS noise"; + } else { + tool =3D "hwnoise"; + mode =3D ""; + desc =3D "a summary of hardware-related noise"; } =20 - if (params->mode =3D=3D MODE_HWNOISE) { - fprintf(stderr, - "rtla hwnoise: a summary of hardware-related noise (version %s)\n", - VERSION); - - fprintf(stderr, " usage: rtla hwnoise"); - } - - for (i =3D 0; msg[i]; i++) - fprintf(stderr, "%s\n", msg[i]); - - exit(EXIT_SUCCESS); + common_usage(tool, mode, desc, msg_start, msg_opts); } =20 /* diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/sr= c/timerlat_hist.c index 1fb471a787b7..2a5c543217ba 100644 --- a/tools/tracing/rtla/src/timerlat_hist.c +++ b/tools/tracing/rtla/src/timerlat_hist.c @@ -696,17 +696,16 @@ timerlat_print_stats(struct osnoise_tool *tool) */ static void timerlat_hist_usage(void) { - int i; - - char *msg[] =3D { - "", - " usage: [rtla] timerlat hist [-h] [-q] [-d s] [-D] [-n] [-a us] [-p us= ] [-i us] [-T us] [-s us] \\", + static const char * const msg_start[] =3D { + "[-d s] [-D] [-n] [-a us] [-p us] [-i us] [-T us] [-s us] \\", " [-t [file]] [-e sys[:event]] [--filter ] [--trigger ] [-c cpu-list] [-H cpu-list]\\", " [-P priority] [-E N] [-b N] [--no-irq] [--no-thread] [--no-header] [= --no-summary] \\", " [--no-index] [--with-zeros] [--dma-latency us] [-C [cgroup_name]] [-= -no-aa] [--dump-task] [-u|-k]", " [--warm-up s] [--deepest-idle-state n]", - "", - " -h/--help: print this menu", + NULL, + }; + + static const char * const msg_opts[] =3D { " -a/--auto: set automatic trace mode, stopping the session if argumen= t in us latency is hit", " -p/--period us: timerlat period in us", " -i/--irq us: stop trace if the irq latency is higher than the argume= nt in us", @@ -750,13 +749,8 @@ static void timerlat_hist_usage(void) NULL, }; =20 - fprintf(stderr, "rtla timerlat hist: a per-cpu histogram of the timer lat= ency (version %s)\n", - VERSION); - - for (i =3D 0; msg[i]; i++) - fprintf(stderr, "%s\n", msg[i]); - - exit(EXIT_SUCCESS); + common_usage("timerlat", "hist", "a per-cpu histogram of the timer latenc= y", + msg_start, msg_opts); } =20 /* diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src= /timerlat_top.c index 29c2c1f717ed..9ed8b931552f 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -476,15 +476,14 @@ timerlat_print_stats(struct osnoise_tool *top) */ static void timerlat_top_usage(void) { - int i; - - static const char *const msg[] =3D { - "", - " usage: rtla timerlat [top] [-h] [-q] [-a us] [-d s] [-D] [-n] [-p us]= [-i us] [-T us] [-s us] \\", + static const char *const msg_start[] =3D { + "[-q] [-a us] [-d s] [-D] [-n] [-p us] [-i us] [-T us] [-s us] \\", " [[-t [file]] [-e sys[:event]] [--filter ] [--trigger ] [-c cpu-list] [-H cpu-list]\\", " [-P priority] [--dma-latency us] [--aa-only us] [-C [cgroup_name]] [= -u|-k] [--warm-up s] [--deepest-idle-state n]", - "", - " -h/--help: print this menu", + NULL, + }; + + static const char *const msg_opts[] =3D { " -a/--auto: set automatic trace mode, stopping the session if argumen= t in us latency is hit", " --aa-only us: stop if latency is hit, only printing the auto= analysis (reduces CPU usage)", " -p/--period us: timerlat period in us", @@ -522,13 +521,8 @@ static void timerlat_top_usage(void) NULL, }; =20 - fprintf(stderr, "rtla timerlat top: a per-cpu summary of the timer latenc= y (version %s)\n", - VERSION); - - for (i =3D 0; msg[i]; i++) - fprintf(stderr, "%s\n", msg[i]); - - exit(EXIT_SUCCESS); + common_usage("timerlat", "top", "a per-cpu summary of the timer latency", + msg_start, msg_opts); } =20 /* --=20 2.51.1