From f8e66f802aeb06e27321c534f86e0e88d741f55e Mon Sep 17 00:00:00 2001 From: Quildra Date: Fri, 1 Aug 2025 19:22:25 +0100 Subject: [PATCH] feat: add benchmarking infrastructure for CRITICAL-003 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add BENCHMARKING_MODE flag and detection timing collection - Add printBenchmarkStats() and resetBenchmarkStats() functions - Enhanced logging to track MULTI vs SINGLE preprocessing performance - Automatic stats reporting every 10 detections - Ready to benchmark current multi-processing performance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../pokegoalshelper/YOLOOnnxDetector.kt | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/app/src/main/java/com/quillstudios/pokegoalshelper/YOLOOnnxDetector.kt b/app/src/main/java/com/quillstudios/pokegoalshelper/YOLOOnnxDetector.kt index 7ea6a35..e894be9 100644 --- a/app/src/main/java/com/quillstudios/pokegoalshelper/YOLOOnnxDetector.kt +++ b/app/src/main/java/com/quillstudios/pokegoalshelper/YOLOOnnxDetector.kt @@ -39,6 +39,9 @@ class YOLOOnnxDetector(private val context: Context) { var DEBUG_CLASS_FILTER: String? = null // Set to class name to show only that class var SHOW_ALL_CONFIDENCES = false // Show all detections with their confidences + // Benchmarking for CRITICAL-003 + var BENCHMARKING_MODE = true // Enable detailed performance logging + private val detectionTimes = mutableListOf() fun setCoordinateMode(mode: String) { COORD_TRANSFORM_MODE = mode @@ -52,6 +55,26 @@ class YOLOOnnxDetector(private val context: Context) { Log.i(TAG, "📊 Show all confidences: $SHOW_ALL_CONFIDENCES") } + fun printBenchmarkStats() { + if (detectionTimes.isNotEmpty()) { + val avg = detectionTimes.average() + val min = detectionTimes.minOrNull() ?: 0L + val max = detectionTimes.maxOrNull() ?: 0L + val count = detectionTimes.size + Log.i(TAG, "📈 BENCHMARK STATS (${if (ENABLE_MULTI_PREPROCESSING) "MULTI" else "SINGLE"}-PROCESSING):") + Log.i(TAG, " Count: $count detections") + Log.i(TAG, " Average: ${String.format("%.1f", avg)}ms") + Log.i(TAG, " Min: ${min}ms") + Log.i(TAG, " Max: ${max}ms") + Log.i(TAG, " Total: ${detectionTimes.sum()}ms") + } + } + + fun resetBenchmarkStats() { + detectionTimes.clear() + Log.i(TAG, "📊 Benchmark stats reset") + } + // Preprocessing enhancement techniques private const val ENABLE_CONTRAST_ENHANCEMENT = true private const val ENABLE_SHARPENING = true @@ -372,6 +395,19 @@ class YOLOOnnxDetector(private val context: Context) { val finalDetections = mergeAndFilterDetections(allDetections, inputMat.cols(), inputMat.rows()) val totalTime = System.currentTimeMillis() - startTime + + // Record benchmark data + if (BENCHMARKING_MODE) { + detectionTimes.add(totalTime) + val preprocessingType = if (ENABLE_MULTI_PREPROCESSING) "MULTI" else "SINGLE" + Log.i(TAG, "📊 BENCHMARK: $preprocessingType-processing took ${totalTime}ms (${detectionTimes.size} samples)") + + // Print stats every 10 detections + if (detectionTimes.size % 10 == 0) { + printBenchmarkStats() + } + } + Log.i(TAG, "✅ Enhanced ONNX detection complete: ${finalDetections.size} objects in ${totalTime}ms") return finalDetections