From nobody Mon Feb 9 00:43:17 2026 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 965ED3D3CFB for ; Thu, 8 Jan 2026 09:51:16 +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=1767865883; cv=none; b=P9pIbeSKih+1grTqp82m6XIA50EHpRCiXpfC9u12eVlqjH8kTUA245ANKuj5TGqYJYzf1aBoTSoE2aORIzQAiWcFyxSwuwBrqb4MQGhQOzbk0QjIpT3rqiHqvjznTrIHd6BBzB/ByXuCjLEleRk7u92chVUHsCS5gIgPBcnfOiM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767865883; c=relaxed/simple; bh=SuLNrz3Wes0/pJvpNloKTunHGX7P3Yn5n5zDeoT2tGM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=uceTOu4FLhCLquQ4+Hlui03aEX1N/3xinMypNOOGGEwt2HzEAOsqcmfcET+tr6jcx0fL2H7jZjYQCdZV2RVF/MU/bkPLdc/UdpZvmkBG2xlz5wN2vgqtQr4mVhocY8xFCX6HcEQ3SpuicUMbz8GK7CakDTZ6MIVwvwXzyI5r5/c= 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=gUZCwEKT; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=OEznmbzI; 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="gUZCwEKT"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="OEznmbzI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767865870; 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=n/qG/vo5uiZxrmVn+D6q59bRYSUzjsYV+KJyxKKhli0=; b=gUZCwEKTJU8zd5HbSpvkB9NIum0IrYuI+B8SsrWQ1TVWrpG0wHMCL2AzjXAuQSlU7Au59v MCYP+kxqnRiCJPcHq82K7uffqvDa9RnYDRUy1KXjfSGQ3BuS5HKpfxUPKnsdv8TynU9IHt mFmf7lnpKh/QVriWq5/g0MAa/ITlu98= 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-362-gJ63hhiTOgSAB4zy46pTuA-1; Thu, 08 Jan 2026 04:51:09 -0500 X-MC-Unique: gJ63hhiTOgSAB4zy46pTuA-1 X-Mimecast-MFC-AGG-ID: gJ63hhiTOgSAB4zy46pTuA_1767865868 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-430ffa9fccaso2201315f8f.1 for ; Thu, 08 Jan 2026 01:51:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1767865868; x=1768470668; 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=n/qG/vo5uiZxrmVn+D6q59bRYSUzjsYV+KJyxKKhli0=; b=OEznmbzIrqfgzFYo0kiU6N/eFHLzozc2i9AlQfM89XhtzqKdtfNVaDhYszvEOQPG3O 15FvyQyQRIM5tGKzjsqAkVj86FlgbBQ+a8K39NA4fmTB6oJmwX8I1W38gICcuY3+TqOz 1TDSnBqr5h5Y1tJbaPuNTuKTqHb9N9w9koQMce5zz9K4JMHFr+bgHu5LNy1qWCHf4Z7p y/RipFW12hh/S+As7Fe0FGIL3nGORx3Gepz0r9Ws75yZZU0Pvmg4skK1DiQy8QMGAr6o ED/k64UtPjyyTxzhr2s15UyVUyVNS0gBDj4dNTAPmLIKqowTzP7evrW9Dx5Tkag3IYqw Y6pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767865868; x=1768470668; 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=n/qG/vo5uiZxrmVn+D6q59bRYSUzjsYV+KJyxKKhli0=; b=naNk4wtrt5pVntN6Eej9ERr8LYqlspJAvXR9RePpLLT2MNzX/UtJFEBZTwoa4s0259 8nIcrTgKXWesksVpVlyoECT4UyyQwfZZRJowj08Tbq67BblMGZWkQZPVuRMF4Q3UtTjg 4R95bgijN5KX1oN0WZjw94RjUQc0OvUN8bIHpfbXsaa185H3/ilR6AU7IEXIX+F1jM2g jjLGRpwtn3o6iBQP6+acgJZMQtG9qJfRCJn4brs+FctXSwsxY8vpvsPQsPSk+Gv97xcv YCWR3ME5k6+0CJjiUru8mXYzT2K8OUt2+xdL0L2OhgPRiap5+2511OyTgHokMphLQ1KE B09g== X-Forwarded-Encrypted: i=1; AJvYcCVz1VKfZFe0ZIcGYy8RzRJtTCL1pli0M6aG63D0xiAhrX9MWVjucPok+zzU6LsoHRA6kFjyewaCMGrtJXY=@vger.kernel.org X-Gm-Message-State: AOJu0YwkU1TKixAnx2HpqHflumY/Qf2Y/BTZK1jbb/isEEgQaHjs7XzH A1skjA6a7ofGgd6QvK8U7hyVJ/ZTolJ1C8TPWsuJoF1FkZIpfcgNq8E8Z5Y9JOxk0DuzTHLykvN wk8pMy0h7bHQTcI+z3r1NymuIH1zRh09pHigMfB9glDKsXjIzG/fP1RmFo7q8DZQbug== X-Gm-Gg: AY/fxX6vs/NJiiXViL+XbeGU5aakNvn/6OYFJ6NF2/7UYuyaKzBKQoNvaFMGi95dM7M Z/oW/EsrDalzb/K9YhV6237zmIPZI1iDW4szE8kNQ6xsYZd6OlXABNiLTpPQYQMUI0KyvX16rtr bvlcQhy0PsnvUarBK4P5lvDik7uAfPN0A0jvSAYj1iSEysIY8heSXfr98zUdlvZjc7Shqaz9kdE /7wtElUIjPJXo/u+TTr4wfEzy/kFa8udomxX6yJwrHxtVw3aS/mnJOFBaGDzURA87yNvYcGDTAf XeOIHaMaSSgpMJ+KnbT6n98t103Fb/cAKwjxiA/TavT1iO2r73M1LEqNtFzSK3dCjyJFroCBLIJ ZWTXrV97+b5l+murVIJQn3w== X-Received: by 2002:a05:6000:1886:b0:432:a9f0:48c with SMTP id ffacd0b85a97d-432c38d26f6mr7083932f8f.63.1767865868146; Thu, 08 Jan 2026 01:51:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IEkqw8qcmUgoA8mC0TH98TFcHP34mNo4yMgAAgBUIPtadXeGFTh50WxGruEp0kESFHrPnWmjw== X-Received: by 2002:a05:6000:1886:b0:432:a9f0:48c with SMTP id ffacd0b85a97d-432c38d26f6mr7083902f8f.63.1767865867666; Thu, 08 Jan 2026 01:51:07 -0800 (PST) Received: from costa-tp.bos2.lab ([2a00:a041:e23c:600:cadf:120:2b7f:a706]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-432bd5df939sm15128268f8f.21.2026.01.08.01.51.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jan 2026 01:51:07 -0800 (PST) From: Costa Shulyupin To: Steven Rostedt , Tomas Glozar , Costa Shulyupin , Crystal Wood , Wander Lairson Costa , John Kacur , Ivan Pravdin , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1] tools/rtla: Generate optstring from long options Date: Thu, 8 Jan 2026 11:49:55 +0200 Message-ID: <20260108095011.2115719-1-costa.shul@redhat.com> X-Mailer: git-send-email 2.52.0 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" getopt_long() processes short and long options independently. RTLA, like the majority of applications, uses both short and long variants for each logical option. Since the val member of struct option holds the letter of the short variant, the string of short options can be reconstructed from the array of long options. Add getopt_auto() to generate optstring from an array of long options, eliminating the need to maintain separate short option strings. Signed-off-by: Costa Shulyupin Reviewed-by: Wander Lairson Costa --- tools/tracing/rtla/src/common.c | 32 +++++++++++++++++++++++++- tools/tracing/rtla/src/common.h | 2 ++ tools/tracing/rtla/src/osnoise_hist.c | 3 +-- tools/tracing/rtla/src/osnoise_top.c | 3 +-- tools/tracing/rtla/src/timerlat_hist.c | 3 +-- tools/tracing/rtla/src/timerlat_top.c | 3 +-- 6 files changed, 37 insertions(+), 9 deletions(-) diff --git a/tools/tracing/rtla/src/common.c b/tools/tracing/rtla/src/commo= n.c index ceff76a62a30..f310b0d59ad3 100644 --- a/tools/tracing/rtla/src/common.c +++ b/tools/tracing/rtla/src/common.c @@ -39,6 +39,36 @@ static void set_signals(struct common_params *params) } } =20 +/* + * getopt_auto - auto-generates optstring from long_options + */ +int getopt_auto(int argc, char **argv, const struct option *long_opts) +{ + char opts[256]; + int n =3D 0; + + for (int i =3D 0; long_opts[i].name; i++) { + if (long_opts[i].val < 32 || long_opts[i].val > 127) + continue; + + if (n + 4 >=3D sizeof(opts)) + fatal("optstring buffer overflow"); + + opts[n++] =3D long_opts[i].val; + + if (long_opts[i].has_arg =3D=3D required_argument) + opts[n++] =3D ':'; + else if (long_opts[i].has_arg =3D=3D optional_argument) { + opts[n++] =3D ':'; + opts[n++] =3D ':'; + } + } + + opts[n] =3D '\0'; + + return getopt_long(argc, argv, opts, long_opts, NULL); +} + /* * common_parse_options - parse common command line options * @@ -69,7 +99,7 @@ int common_parse_options(int argc, char **argv, struct co= mmon_params *common) }; =20 opterr =3D 0; - c =3D getopt_long(argc, argv, "c:C::Dd:e:H:P:", long_options, NULL); + c =3D getopt_auto(argc, argv, long_options); opterr =3D 1; =20 switch (c) { diff --git a/tools/tracing/rtla/src/common.h b/tools/tracing/rtla/src/commo= n.h index 7602c5593ef5..d4b3715700be 100644 --- a/tools/tracing/rtla/src/common.h +++ b/tools/tracing/rtla/src/common.h @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0 */ #pragma once =20 +#include #include "actions.h" #include "timerlat_u.h" #include "trace.h" @@ -156,6 +157,7 @@ int osnoise_set_stop_us(struct osnoise_context *context= , long long stop_us); int osnoise_set_stop_total_us(struct osnoise_context *context, long long stop_total_us); =20 +int getopt_auto(int argc, char **argv, const struct option *long_opts); int common_parse_options(int argc, char **argv, struct common_params *comm= on); int common_apply_config(struct osnoise_tool *tool, struct common_params *p= arams); int top_main_loop(struct osnoise_tool *tool); diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src= /osnoise_hist.c index 9d70ea34807f..5c863e7aad28 100644 --- a/tools/tracing/rtla/src/osnoise_hist.c +++ b/tools/tracing/rtla/src/osnoise_hist.c @@ -506,8 +506,7 @@ static struct common_params if (common_parse_options(argc, argv, ¶ms->common)) continue; =20 - c =3D getopt_long(argc, argv, "a:b:E:hp:r:s:S:t::T:01234:5:6:7:", - long_options, NULL); + c =3D getopt_auto(argc, argv, long_options); =20 /* detect the end of the options. */ if (c =3D=3D -1) diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/= osnoise_top.c index d54d47947fb4..b7aed40fd216 100644 --- a/tools/tracing/rtla/src/osnoise_top.c +++ b/tools/tracing/rtla/src/osnoise_top.c @@ -358,8 +358,7 @@ struct common_params *osnoise_top_parse_args(int argc, = char **argv) if (common_parse_options(argc, argv, ¶ms->common)) continue; =20 - c =3D getopt_long(argc, argv, "a:hp:qr:s:S:t::T:0:1:2:3:", - long_options, NULL); + c =3D getopt_auto(argc, argv, long_options); =20 /* Detect the end of the options. */ if (c =3D=3D -1) diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/sr= c/timerlat_hist.c index 4e8c38a61197..096de8ba3efb 100644 --- a/tools/tracing/rtla/src/timerlat_hist.c +++ b/tools/tracing/rtla/src/timerlat_hist.c @@ -825,8 +825,7 @@ static struct common_params if (common_parse_options(argc, argv, ¶ms->common)) continue; =20 - c =3D getopt_long(argc, argv, "a:b:E:hi:knp:s:t::T:uU0123456:7:8:9\1\2:\= 3:", - long_options, NULL); + c =3D getopt_auto(argc, argv, long_options); =20 /* detect the end of the options. */ if (c =3D=3D -1) diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src= /timerlat_top.c index 284b74773c2b..27c14aa71a8b 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -588,8 +588,7 @@ static struct common_params if (common_parse_options(argc, argv, ¶ms->common)) continue; =20 - c =3D getopt_long(argc, argv, "a:hi:knp:qs:t::T:uU0:1:2:345:6:7:", - long_options, NULL); + c =3D getopt_auto(argc, argv, long_options); =20 /* detect the end of the options. */ if (c =3D=3D -1) --=20 2.52.0