Browse Source

feat: add benchmarking infrastructure for CRITICAL-003

- 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 <noreply@anthropic.com>
critical-003-parallel-processing
Quildra 5 months ago
parent
commit
f8e66f802a
  1. 36
      app/src/main/java/com/quillstudios/pokegoalshelper/YOLOOnnxDetector.kt

36
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<Long>()
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

Loading…
Cancel
Save