Profiler: cache disk benchmark for a week instead of rewriting 32 MB every launch
Browse files
app/src/main/java/io/github/abrarul/modularai/model/DeviceProfiler.kt
CHANGED
|
@@ -51,7 +51,7 @@ object DeviceProfiler {
|
|
| 51 |
availRamMb = mi.availMem / 1_048_576,
|
| 52 |
freeStorageMb = stat.availableBytes / 1_048_576,
|
| 53 |
vulkan = ctx.packageManager.hasSystemFeature(PackageManager.FEATURE_VULKAN_HARDWARE_LEVEL),
|
| 54 |
-
storageMBps =
|
| 55 |
tier = when {
|
| 56 |
total < 5_000 -> Tier.ULTRA_LIGHT
|
| 57 |
total < 10_000 -> Tier.BALANCED
|
|
@@ -60,6 +60,15 @@ object DeviceProfiler {
|
|
| 60 |
)
|
| 61 |
}
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
/** 32 MB sequential write benchmark. */
|
| 64 |
private fun benchStorage(dir: File): Double {
|
| 65 |
val f = File(dir, "bench.tmp")
|
|
@@ -73,8 +82,7 @@ object DeviceProfiler {
|
|
| 73 |
|
| 74 |
/**
|
| 75 |
* Heuristic: a Q4_K_M GGUF needs roughly 0.6 GB per billion params plus KV cache.
|
| 76 |
-
* Uses ~60% of currently available RAM as the budget. Tokens/s is a rough estimate only
|
| 77 |
-
* real numbers come from the in-app benchmark.
|
| 78 |
*/
|
| 79 |
fun recommend(p: Profile): Recommendation {
|
| 80 |
val budgetGb = p.availRamMb * 0.6 / 1024.0
|
|
|
|
| 51 |
availRamMb = mi.availMem / 1_048_576,
|
| 52 |
freeStorageMb = stat.availableBytes / 1_048_576,
|
| 53 |
vulkan = ctx.packageManager.hasSystemFeature(PackageManager.FEATURE_VULKAN_HARDWARE_LEVEL),
|
| 54 |
+
storageMBps = cachedBench(ctx),
|
| 55 |
tier = when {
|
| 56 |
total < 5_000 -> Tier.ULTRA_LIGHT
|
| 57 |
total < 10_000 -> Tier.BALANCED
|
|
|
|
| 60 |
)
|
| 61 |
}
|
| 62 |
|
| 63 |
+
private fun cachedBench(ctx: Context): Double {
|
| 64 |
+
val p = ctx.getSharedPreferences("profiler", Context.MODE_PRIVATE)
|
| 65 |
+
val age = System.currentTimeMillis() - p.getLong("bench_at", 0)
|
| 66 |
+
if (age < 7L * 24 * 3600 * 1000 && p.contains("bench")) return p.getFloat("bench", 0f).toDouble()
|
| 67 |
+
val v = runCatching { benchStorage(ctx.cacheDir) }.getOrDefault(0.0)
|
| 68 |
+
p.edit().putFloat("bench", v.toFloat()).putLong("bench_at", System.currentTimeMillis()).apply()
|
| 69 |
+
return v
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
/** 32 MB sequential write benchmark. */
|
| 73 |
private fun benchStorage(dir: File): Double {
|
| 74 |
val f = File(dir, "bench.tmp")
|
|
|
|
| 82 |
|
| 83 |
/**
|
| 84 |
* Heuristic: a Q4_K_M GGUF needs roughly 0.6 GB per billion params plus KV cache.
|
| 85 |
+
* Uses ~60% of currently available RAM as the budget. Tokens/s is a rough estimate only.
|
|
|
|
| 86 |
*/
|
| 87 |
fun recommend(p: Profile): Recommendation {
|
| 88 |
val budgetGb = p.availRamMb * 0.6 / 1024.0
|