You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
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>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user