From nobody Sun Feb 8 21:33:54 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 D6FB93C1FEF for ; Thu, 15 Jan 2026 17:26:28 +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=1768497990; cv=none; b=Ov2FWKBhS2MdWPdZd1W2aNgBVJIQLNUkSUa2VGsRHh20PkNCJemwGTYlc0UNGvaVZLPjMeFfz5+E9zdY07o3bTVx8VeOTDXelfEt+hiGKyFiles0+sdg2tlB5yJgsZeTU7Tz29JcZ9S/X87efFNu4PHcjRGuEYsFg/jttPomugY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768497990; c=relaxed/simple; bh=T7o0zP6EJubXjuBW2C/9GrQT2Gye/tqv6VQ1VxV83rs=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VAakhZCnBwrW+s4Fw5SBAmYaMhTn/Bz5MgFfVZMEl+5deWlq/P+IX6aC8TK91N1ZagoNCN6WfSh7ZwU6KMhlkid9QGYVaUdXNMkHoLAzco9If75K6fGmO8TPsD9TR+3Ck7sLDVUMGLB+OxfOCRS1HkWGmfGfBNrvBa0Nehx8LdE= 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=FkCk0Xt3; 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="FkCk0Xt3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768497987; 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: in-reply-to:in-reply-to:references:references; bh=E8KTz5utFl7V46Z0aDTcTYKhxj6BI+IbgWi2PWVNcmE=; b=FkCk0Xt3o0GIDB3MXM5OEc1ibrH29Ulvb8SJd/UAxK0T+SadYSWSlBGRI8Vai+ywbg2Bmc OHZDjCKFgttFRrU+1CBLC8cxWKNy3CnmRh8Y0rKd085to7NMCqFHaD2sqpvPVeXs81rNl4 aBC6M4CdDb3r6T5Hrc3Y+GpaaBHDx+0= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-660-tbDEcCIEOoufTouSJuJYug-1; Thu, 15 Jan 2026 12:26:24 -0500 X-MC-Unique: tbDEcCIEOoufTouSJuJYug-1 X-Mimecast-MFC-AGG-ID: tbDEcCIEOoufTouSJuJYug_1768497983 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C509B18005AD; Thu, 15 Jan 2026 17:26:22 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.87]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 35FB918004D8; Thu, 15 Jan 2026 17:26:17 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Ivan Pravdin , Crystal Wood , Costa Shulyupin , John Kacur , Tiezhu Yang , Daniel Wagner , Daniel Bristot de Oliveira , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [PATCH v3 06/18] rtla: Simplify code by caching string lengths Date: Thu, 15 Jan 2026 13:31:49 -0300 Message-ID: <20260115163650.118910-7-wander@redhat.com> In-Reply-To: <20260115163650.118910-1-wander@redhat.com> References: <20260115163650.118910-1-wander@redhat.com> 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 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Simplify trace_event_save_hist() and set_comm_cgroup() by computing string lengths once and storing them in local variables, rather than calling strlen() multiple times on the same unchanged strings. This makes the code clearer by eliminating redundant function calls and improving readability. In trace_event_save_hist(), the write loop previously called strlen() on the hist buffer twice per iteration for both the size calculation and loop condition. Store the length in hist_len before entering the loop. In set_comm_cgroup(), strlen() was called on cgroup_path up to three times in succession. Store the result in cg_path_len to use in both the offset calculation and size parameter for subsequent append operations. This simplification makes the code easier to read and maintain without changing program behavior. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/trace.c | 6 ++++-- tools/tracing/rtla/src/utils.c | 11 +++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c index e1af54f9531b8..2f529aaf8deef 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -346,6 +346,7 @@ static void trace_event_save_hist(struct trace_instance= *instance, mode_t mode =3D 0644; char path[MAX_PATH]; char *hist; + size_t hist_len; =20 if (!tevent) return; @@ -376,9 +377,10 @@ static void trace_event_save_hist(struct trace_instanc= e *instance, } =20 index =3D 0; + hist_len =3D strlen(hist); do { - index +=3D write(out_fd, &hist[index], strlen(hist) - index); - } while (index < strlen(hist)); + index +=3D write(out_fd, &hist[index], hist_len - index); + } while (index < hist_len); =20 free(hist); out_close: diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c index 75cdcc63d5a15..b5a6007b108d2 100644 --- a/tools/tracing/rtla/src/utils.c +++ b/tools/tracing/rtla/src/utils.c @@ -811,6 +811,7 @@ static int open_cgroup_procs(const char *cgroup) char cgroup_procs[MAX_PATH]; int retval; int cg_fd; + size_t cg_path_len; =20 retval =3D find_mount("cgroup2", cgroup_path, sizeof(cgroup_path)); if (!retval) { @@ -818,16 +819,18 @@ static int open_cgroup_procs(const char *cgroup) return -1; } =20 + cg_path_len =3D strlen(cgroup_path); + if (!cgroup) { - retval =3D get_self_cgroup(&cgroup_path[strlen(cgroup_path)], - sizeof(cgroup_path) - strlen(cgroup_path)); + retval =3D get_self_cgroup(&cgroup_path[cg_path_len], + sizeof(cgroup_path) - cg_path_len); if (!retval) { err_msg("Did not find self cgroup\n"); return -1; } } else { - snprintf(&cgroup_path[strlen(cgroup_path)], - sizeof(cgroup_path) - strlen(cgroup_path), "%s/", cgroup); + snprintf(&cgroup_path[cg_path_len], + sizeof(cgroup_path) - cg_path_len, "%s/", cgroup); } =20 snprintf(cgroup_procs, MAX_PATH, "%s/cgroup.procs", cgroup_path); --=20 2.52.0