summaryrefslogtreecommitdiffstats
path: root/platform/android/java/lib/src/org/godotengine/godot
diff options
context:
space:
mode:
authorYuri Sizov <yuris@humnom.net>2023-12-08 12:52:49 +0100
committerYuri Sizov <yuris@humnom.net>2023-12-08 12:53:04 +0100
commitfc3f40f37d24090d6de4e45190ea2c7df3a27179 (patch)
treee9defb0ceebb684862d43003d0e598486c89941a /platform/android/java/lib/src/org/godotengine/godot
parentd5ad37afcd44f4ba953e3473b5ab3afb18068134 (diff)
downloadredot-engine-fc3f40f37d24090d6de4e45190ea2c7df3a27179.tar.gz
Improve engine startup/shutdown benchmarks
- Add contexts to give a better sense of benchmarked areas. - Add missing benchmarks and adjust some begin/end points. - Clean up names. - Improve Android's internal benchmarks in a similar manner. Co-authored-by: Fredia Huya-Kouadio <fhuya@meta.com>
Diffstat (limited to 'platform/android/java/lib/src/org/godotengine/godot')
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/Godot.kt12
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/GodotFragment.java4
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/utils/BenchmarkUtils.kt37
3 files changed, 32 insertions, 21 deletions
diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt
index 2278b46f6c..217e7a2b60 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt
+++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt
@@ -184,7 +184,7 @@ class Godot(private val context: Context) : SensorEventListener {
return
}
- beginBenchmarkMeasure("Godot::onCreate")
+ beginBenchmarkMeasure("Startup", "Godot::onCreate")
try {
this.primaryHost = primaryHost
val activity = requireActivity()
@@ -286,7 +286,7 @@ class Godot(private val context: Context) : SensorEventListener {
initializationStarted = false
throw e
} finally {
- endBenchmarkMeasure("Godot::onCreate");
+ endBenchmarkMeasure("Startup", "Godot::onCreate");
}
}
@@ -1016,13 +1016,13 @@ class Godot(private val context: Context) : SensorEventListener {
}
@Keep
- private fun nativeBeginBenchmarkMeasure(label: String) {
- beginBenchmarkMeasure(label)
+ private fun nativeBeginBenchmarkMeasure(scope: String, label: String) {
+ beginBenchmarkMeasure(scope, label)
}
@Keep
- private fun nativeEndBenchmarkMeasure(label: String) {
- endBenchmarkMeasure(label)
+ private fun nativeEndBenchmarkMeasure(scope: String, label: String) {
+ endBenchmarkMeasure(scope, label)
}
@Keep
diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotFragment.java b/platform/android/java/lib/src/org/godotengine/godot/GodotFragment.java
index 120e1722e5..f1c029e7a1 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/GodotFragment.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/GodotFragment.java
@@ -172,7 +172,7 @@ public class GodotFragment extends Fragment implements IDownloaderClient, GodotH
@Override
public void onCreate(Bundle icicle) {
- BenchmarkUtils.beginBenchmarkMeasure("GodotFragment::onCreate");
+ BenchmarkUtils.beginBenchmarkMeasure("Startup", "GodotFragment::onCreate");
super.onCreate(icicle);
final Activity activity = getActivity();
@@ -180,7 +180,7 @@ public class GodotFragment extends Fragment implements IDownloaderClient, GodotH
godot = new Godot(requireContext());
performEngineInitialization();
- BenchmarkUtils.endBenchmarkMeasure("GodotFragment::onCreate");
+ BenchmarkUtils.endBenchmarkMeasure("Startup", "GodotFragment::onCreate");
}
private void performEngineInitialization() {
diff --git a/platform/android/java/lib/src/org/godotengine/godot/utils/BenchmarkUtils.kt b/platform/android/java/lib/src/org/godotengine/godot/utils/BenchmarkUtils.kt
index 1552c8f082..69748c0a8d 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/utils/BenchmarkUtils.kt
+++ b/platform/android/java/lib/src/org/godotengine/godot/utils/BenchmarkUtils.kt
@@ -41,7 +41,7 @@ import org.godotengine.godot.io.file.FileAccessFlags
import org.godotengine.godot.io.file.FileAccessHandler
import org.json.JSONObject
import java.nio.ByteBuffer
-import java.util.concurrent.ConcurrentSkipListMap
+import java.util.Collections
/**
* Contains benchmark related utilities methods
@@ -51,44 +51,47 @@ private const val TAG = "GodotBenchmark"
var useBenchmark = false
var benchmarkFile = ""
-private val startBenchmarkFrom = ConcurrentSkipListMap<String, Long>()
-private val benchmarkTracker = ConcurrentSkipListMap<String, Double>()
+private val startBenchmarkFrom = Collections.synchronizedMap(LinkedHashMap<Pair<String, String>, Long>())
+private val benchmarkTracker = Collections.synchronizedMap(LinkedHashMap<Pair<String, String>, Double>())
/**
- * Start measuring and tracing the execution of a given section of code using the given label.
+ * Start measuring and tracing the execution of a given section of code using the given label
+ * within the given scope.
*
* Must be followed by a call to [endBenchmarkMeasure].
*
* Note: Only enabled on 'editorDev' build variant.
*/
-fun beginBenchmarkMeasure(label: String) {
+fun beginBenchmarkMeasure(scope: String, label: String) {
if (BuildConfig.FLAVOR != "editor" || BuildConfig.BUILD_TYPE != "dev") {
return
}
- startBenchmarkFrom[label] = SystemClock.elapsedRealtime()
+ val key = Pair(scope, label)
+ startBenchmarkFrom[key] = SystemClock.elapsedRealtime()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
- Trace.beginAsyncSection(label, 0)
+ Trace.beginAsyncSection("[$scope] $label", 0)
}
}
/**
- * End measuring and tracing of the section of code with the given label.
+ * End measuring and tracing of the section of code with the given label within the given scope.
*
* Must be preceded by a call [beginBenchmarkMeasure]
*
* * Note: Only enabled on 'editorDev' build variant.
*/
-fun endBenchmarkMeasure(label: String) {
+fun endBenchmarkMeasure(scope: String, label: String) {
if (BuildConfig.FLAVOR != "editor" || BuildConfig.BUILD_TYPE != "dev") {
return
}
- val startTime = startBenchmarkFrom[label] ?: return
+ val key = Pair(scope, label)
+ val startTime = startBenchmarkFrom[key] ?: return
val total = SystemClock.elapsedRealtime() - startTime
- benchmarkTracker[label] = total / 1000.0
+ benchmarkTracker[key] = total / 1_000.0
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
- Trace.endAsyncSection(label, 0)
+ Trace.endAsyncSection("[$scope] $label", 0)
}
}
@@ -107,8 +110,16 @@ fun dumpBenchmark(fileAccessHandler: FileAccessHandler?, filepath: String? = ben
return
}
+ val results = LinkedHashMap<String, String>()
+ for (entry in benchmarkTracker) {
+ if (!results.containsKey(entry.key.first)) {
+ results[entry.key.first] = ""
+ }
+ results[entry.key.first] += "\t\t- ${entry.key.second}: ${entry.value * 1_000.0} msec.\n"
+ }
+
val printOut =
- benchmarkTracker.map { "\t- ${it.key} : ${it.value} sec." }.joinToString("\n")
+ results.map { "\t- [${it.key}]\n ${it.value}" }.joinToString("\n")
Log.i(TAG, "BENCHMARK:\n$printOut")
if (fileAccessHandler != null && !filepath.isNullOrBlank()) {