From nobody Tue Dec 2 01:06:08 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 18A3A239E75 for ; Sat, 22 Nov 2025 18:11:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763835092; cv=none; b=RUkcB8ug1RaWUW6lzfY8MGw+cOMOy/L0V8UrfKsAJMo8VBQwN9d2FoLiSgQOqbJIfi+sLgNSosm/DJUJqFC10GPQ3DUya2X6/vS35OHzwf+HCmsuawysISWkTkSQHHy9ll4pKUFpb2QyXxp0pOoBLZeuS/lN9riIMqgq2Gnbcc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763835092; c=relaxed/simple; bh=hNRkJszpmONpH7M+H648/cMwW8E8Ceo7gW4GD7VBLoA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=s/yWZTT6B+tEAlic6r7BqmaU8Oy+KWGxXnbvudn5q6+6c6GMgMT3adg3ytuSiziNzSPOVV6C3m4N3h91eTkwNtpRxqj0HYizq8GJkaHupPcbUpsCBlOzmo8hkajS766EC/oZo6dDt1ELGQ74Qv2a44U9M4kRqI7szoLx+oaO+Hw= 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=a/S3f/Fg; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=ByJYPCl1; arc=none smtp.client-ip=170.10.129.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="a/S3f/Fg"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="ByJYPCl1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763835089; 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=64FDk5QPM+r1304yXPnboc9hDTs3kZ1joofpjnZosCw=; b=a/S3f/FgaZwvJOHgbvk+QzZMB5EkmmphEh7KGDjSwUGHrvrC1Yql3iwsPz7kdLmHYeAEN1 H1a6MyCEWBdU/G1UL0/VYl6N2uHlEhHPm+feczT44bcEPpzpbEl6m0uCwFAct8MhqisXbB KofS0fDJ7eId6OX8gMxqF2qmO9X7vFs= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-615-6oYHG58bNYm6ixnr-1D9Lw-1; Sat, 22 Nov 2025 13:11:27 -0500 X-MC-Unique: 6oYHG58bNYm6ixnr-1D9Lw-1 X-Mimecast-MFC-AGG-ID: 6oYHG58bNYm6ixnr-1D9Lw_1763835087 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-42b2c8fb84fso1679149f8f.2 for ; Sat, 22 Nov 2025 10:11:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1763835086; x=1764439886; 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=64FDk5QPM+r1304yXPnboc9hDTs3kZ1joofpjnZosCw=; b=ByJYPCl1JyN9i6moMdClnmzdzKRNqu/E+oJFHQUwWFulNG/MjFhZjCWIDA0cdKtw+7 cEYmLHBEgkfBihnbCbUU47D5vyvcHcuf/RrKuCHZiX2K/TJTWddXJRGX7J7CIrHpZK8z tRUn4JnhH3zSHB2YgSm2G61Am1L3+8vDU+j/00zmh82n00PAZtOHuBawXU/R0AxL56ci NpzNuSVf5hHl3YZpmwXNYgSvCm8z/pOdlMk7Ju4jziL/yfEqyqEGbLsLPaeasSkt7tg/ qcmTeuXnv5R0gy/ImKZytWC2+tg8u7G0+hkIPIjctmR+Fdgs/4ET6ixiNn5aqS4KCyzF 1ujA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763835086; x=1764439886; 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=64FDk5QPM+r1304yXPnboc9hDTs3kZ1joofpjnZosCw=; b=FDUlojgAqXRor4cC2o/ANeM/znE6PJA0ivfFyT8fhnTP0sDnFHKnRl+XVXjIsWUsRi 0gJu6dvy8KbGWXrAwkqjkWaxfkLg/sWIAS/m9TTwzAlHZlM4YaQ39+JTT5H2KPgveiUv QMI+V48paPdBRoQNC4bOXi9x5wmwt01GaeruEb+f6a7FYrUI8AOnoYV/h+rARAsFmL59 2g8KqKXYeu/hl2CRvq6NjrRArgzW3+70rHeT0Op/yRMuUnseBXP3p0A4Vk2gLT/nmOmW Gr8uZp0G1MAlok+pKv0J22bT3nm9ZmFMX9prhKOdjg3JrnifJNRJUr6Rq66GftSwJ/Jx 6/kQ== X-Forwarded-Encrypted: i=1; AJvYcCU+yJK7bHbpJKeICEj70xyms8nnMTMKtH0YKvrZ8Mb6vNhbuSrVHxJdwWv9Xpx4HWFMbIDRkOS4TfDIIzw=@vger.kernel.org X-Gm-Message-State: AOJu0YxplBDA1yyGUE4LdbmQ/d2J15LB8NeE51PcT5NlveiF2wBP8Xem 22eWvLUbSIouizGXC5AbJrtYk021tXvqR1aM7tHcmrzQ7YHqdc6OuVMK8aeBO4JeisB3Vk41iG7 OWKKL4KwbP7x1PSLrFOTOqRsY4qEevTFQKKu3dycxnSwoPduGpV4AzrMHhvTBAqpA6Q== X-Gm-Gg: ASbGncsyUPe9zOTpGxYXyjeUH3KSo1Qi3N6SMpab9zhNtuc0yekzLKReYpnGTTh0fGn NvHQhpxSgLr9ATnmBUrxzFcVGqVe5SMNoat+6nf/6o2cRbzxTjYOWGITrcOlvCvsrR97hfe1hlU w40XZGeE7YsoCW2c1M4/2fQyB44Xjc58cIPyJ9LeW5mOlaWvJwczVka2znfSSSaDTxc2ZudocxZ 9b55Ym9WdPJsvuHfBekqwa11zGRn9Sg+bUhQ4REGVUOQwJCDbF3V4T7N+ftsinJ00aPrS57DxbU /s8Dgsj6TI2qbB0Sn+xyQ0dSHVKj9h98DFnbsJKUut/toy1WoAFuMwJCurZ/RxOsIZx2aHMNwuD /2yz10Oh9sr/LjLz+cdxKqGzx X-Received: by 2002:a5d:5f48:0:b0:427:6c6:4e31 with SMTP id ffacd0b85a97d-42cc1cc0a61mr6832672f8f.22.1763835086341; Sat, 22 Nov 2025 10:11:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IG+Jtt9QEkPgTduqChbJfYqpEOz9bvWcy5YTNoYq4/C8oY0Sor3oPk9GYBsHdCI9lYIMy3Sng== X-Received: by 2002:a5d:5f48:0:b0:427:6c6:4e31 with SMTP id ffacd0b85a97d-42cc1cc0a61mr6832651f8f.22.1763835085864; Sat, 22 Nov 2025 10:11:25 -0800 (PST) Received: from costa-tp.bos2.lab ([2a00:a041:e294:5000:b694:8e49:4f51:966d]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42cb7fd8d97sm17583651f8f.42.2025.11.22.10.11.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Nov 2025 10:11:25 -0800 (PST) From: Costa Shulyupin To: Steven Rostedt , Tomas Glozar , Crystal Wood , Wander Lairson Costa , Costa Shulyupin , John Kacur , Ivan Pravdin , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1] tools/rtla: Add common_usage() Date: Sat, 22 Nov 2025 20:09:57 +0200 Message-ID: <20251122181058.656668-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 (osnoise and timerlat, both hist and top) have significant code duplication 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