From 5b2b70f6d90e07a761721438c20a545dbb4d8ed4 Mon Sep 17 00:00:00 2001 From: David Vacca <515103+mdvacca@users.noreply.github.com> Date: Thu, 11 Jul 2024 11:07:21 -0700 Subject: [PATCH] Introduce Systrace.beginSection with args (#45392) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45392 In this diff I'm introducing a new overload of Systrace.beginSection to receive arguments by parameter changelog: [Android][Added] Introduce Systrace.beginSection with arguments Reviewed By: sammy-SC Differential Revision: D59639329 --- .../java/com/facebook/systrace/Systrace.kt | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/systrace/Systrace.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/systrace/Systrace.kt index d6feda993f1b..14b8a8b60551 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/systrace/Systrace.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/systrace/Systrace.kt @@ -8,6 +8,7 @@ package com.facebook.systrace import androidx.tracing.Trace +import kotlin.text.StringBuilder /** * Systrace stub that mostly does nothing but delegates to Trace for beginning/ending sections. The @@ -35,6 +36,28 @@ public object Systrace { Trace.beginSection(sectionName) } + @JvmStatic + public fun beginSection(tag: Long, sectionName: String, args: Array, argsLength: Int) { + Trace.beginSection(sectionName + "|" + convertArgsToText(args, argsLength)) + } + + private fun convertArgsToText(args: Array, argsLength: Int): String { + val argsText: StringBuilder = StringBuilder() + var ii = 1 + while (ii < argsLength) { + val key = args[ii - 1] + val value = args[ii] + argsText.append(key) + argsText.append('=') + argsText.append(value) + if (ii < argsLength - 1) { + argsText.append(';') + } + ii += 2 + } + return argsText.toString() + } + @JvmStatic public fun endSection(tag: Long) { Trace.endSection()