mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 13:08:46 +00:00
Add additional logging around JobManager memory state.
This commit is contained in:
committed by
Cody Henthorne
parent
6379f9f453
commit
949bc8fb95
@@ -354,6 +354,7 @@ class JobController {
|
||||
List<JobSpec> jobs = jobStorage.debugGetJobSpecs(1000);
|
||||
List<ConstraintSpec> constraints = jobStorage.debugGetConstraintSpecs(1000);
|
||||
List<DependencySpec> dependencies = jobStorage.debugGetAllDependencySpecs();
|
||||
String additional = jobStorage.debugAdditionalDetails();
|
||||
|
||||
StringBuilder info = new StringBuilder();
|
||||
|
||||
@@ -378,6 +379,13 @@ class JobController {
|
||||
info.append("None\n");
|
||||
}
|
||||
|
||||
info.append("\n-- Additional Details\n");
|
||||
if (additional != null) {
|
||||
info.append(additional).append('\n');
|
||||
} else {
|
||||
info.append("None\n");
|
||||
}
|
||||
|
||||
return info.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -67,4 +67,7 @@ interface JobStorage {
|
||||
|
||||
@WorkerThread
|
||||
fun debugGetAllDependencySpecs(): List<DependencySpec>
|
||||
|
||||
@WorkerThread
|
||||
fun debugAdditionalDetails(): String?
|
||||
}
|
||||
|
||||
@@ -377,6 +377,23 @@ class FastJobStorage(private val jobDatabase: JobDatabase) : JobStorage {
|
||||
return dependenciesByJobId.values.flatten()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun debugAdditionalDetails(): String {
|
||||
return buildString {
|
||||
appendLine("minimalJobs: Size(${minimalJobs.size}), Items(${minimalJobs.joinToString(", ") { it.toLogString() }})")
|
||||
appendLine("jobSpecCache: Size(${jobSpecCache.size}), Items(${jobSpecCache.keys.joinToString(", ") { it.toLogString() }})")
|
||||
appendLine("eligibleJobs: Size(${eligibleJobs.size}), Items(${eligibleJobs.joinToString(", ") { it.toLogString() }})")
|
||||
appendLine("migrationJobs: Size(${migrationJobs.size}), Items(${migrationJobs.joinToString(", ") { it.toLogString() }})")
|
||||
appendLine("mostEligibleForQueue: Size(${mostEligibleJobForQueue.size}), Items(${mostEligibleJobForQueue.entries.joinToString(", ") { "[${it.key} => ${it.value.toLogString()}]" }})")
|
||||
appendLine("constraintsByJobId: Size(${constraintsByJobId.size}), Items(${constraintsByJobId.entries.joinToString(", ") { "[${it.key.toLogString()} => ${it.value.joinToString(", ") { c -> c.toLogString() }}]" }})")
|
||||
appendLine("dependenciesByJobId: Size(${dependenciesByJobId.size}), Items(${dependenciesByJobId.entries.joinToString(", ") { "[${it.key.toLogString()} => ${it.value.map { d -> d.toLogString() }}]" }})")
|
||||
}
|
||||
}
|
||||
|
||||
private fun String.toLogString(): String {
|
||||
return "JOB::$this"
|
||||
}
|
||||
|
||||
private fun updateCachedJobSpecs(filter: (MinimalJobSpec) -> Boolean, transformer: (MinimalJobSpec) -> MinimalJobSpec, singleUpdate: Boolean = false) {
|
||||
val iterator = minimalJobs.listIterator()
|
||||
|
||||
@@ -548,23 +565,32 @@ class FastJobStorage(private val jobDatabase: JobDatabase) : JobStorage {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Identical to [EligibleMinJobComparator], but for full jobs.
|
||||
*/
|
||||
private object EligibleFullJobComparator : Comparator<JobSpec> {
|
||||
override fun compare(o1: JobSpec, o2: JobSpec): Int {
|
||||
return when {
|
||||
o1.globalPriority > o2.globalPriority -> -1
|
||||
o1.globalPriority < o2.globalPriority -> 1
|
||||
o1.createTime < o2.createTime -> -1
|
||||
o1.createTime > o2.createTime -> 1
|
||||
else -> o1.id.compareTo(o2.id)
|
||||
}
|
||||
private fun debugStopwatch(label: String): Stopwatch? {
|
||||
return if (DEBUG) Stopwatch(label, decimalPlaces = 2) else null
|
||||
}
|
||||
|
||||
private fun MinimalJobSpec.toLogString(): String {
|
||||
return if (this.isMemoryOnly) {
|
||||
return "😶🌫️JOB::$this"
|
||||
} else {
|
||||
return "JOB::$this"
|
||||
}
|
||||
}
|
||||
|
||||
private fun debugStopwatch(label: String): Stopwatch? {
|
||||
return if (DEBUG) Stopwatch(label, decimalPlaces = 2) else null
|
||||
private fun ConstraintSpec.toLogString(): String {
|
||||
return if (this.isMemoryOnly) {
|
||||
return "😶🌫️JOB::$this"
|
||||
} else {
|
||||
return "JOB::$this"
|
||||
}
|
||||
}
|
||||
|
||||
private fun DependencySpec.toLogString(): String {
|
||||
return if (this.isMemoryOnly) {
|
||||
return "😶🌫️JOB::$this"
|
||||
} else {
|
||||
return "JOB::$this"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user