Fixed
Status Update
Comments
ra...@google.com <ra...@google.com> #2
Yigit, do you have time to fix it?
reemission of the same liveData is racy
reemission of the same liveData is racy
cc...@google.com <cc...@google.com> #3
yea i'll take it.
wu...@gmail.com <wu...@gmail.com> #4
Thanks for the detailed analysis. This may not be an issue anymore since we've started using Main.immediate there but I' not sure; I'll try to create a test case.
ap...@google.com <ap...@google.com> #5
just emitting same live data reproduces the issue.
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
cc...@google.com <cc...@google.com> #6
With 2.2.0-alpha04 (that use Main.immediate), the issue seems to be still there (I tested it by calling emitSource() twice, like your test case)
Description
Version used:1.1.0-alpha13
Devices/Android versions reproduced on:R
测试工程说明:
测试项目为多进程项目,包名com.example.demo, 但是应用的所有UI界面实现在com.example.demo:ui进程。
问题原因分析:
getMetrics方法中调用StartupTimingQuery.getFrameSubMetrics 参数传入的是PackageName,参数来源是
Marcobenchmark.kt
val iterationResult = userspaceTrace("extract metrics") {
metrics
// capture list of Map<String,Long> per metric
.map { it.getMetrics(Metric.CaptureInfo(
targetPackageName = packageName,
testPackageName = macrobenchPackageName,
startupMode = startupModeMetricHint,
apiLevel = Build.VERSION.SDK_INT
), tracePath) }
// merge into one map
.reduce { sum, element -> sum + element }
}
查询语句:val queryResult = PerfettoTraceProcessor.rawQuery(
absoluteTracePath = absoluteTracePath,
query = getFullQuery(
testProcessName = testPackageName,
targetProcessName = targetPackageName
)
)
private fun getFullQuery(testProcessName: String, targetProcessName: String) = """
------ Select all startup-relevant slices from slice table
SELECT
slice.ts as ts,
slice.dur as dur
FROM slice
INNER JOIN thread_track on slice.track_id =
INNER JOIN thread USING(utid)
INNER JOIN process USING(upid)
WHERE (
(
(
(
(
(
(
)
) OR
(
-- Signals beginning of launch event, only present in API 29+
)
)
------ Add in async slices
UNION
SELECT
slice.ts as ts,
slice.dur as dur
FROM slice
INNER JOIN process_track on slice.track_id =
INNER JOIN process USING(upid)
WHERE (
-- API 23+: "launching: <target>"
-- API 19-22: "launching"
)
ORDER BY ts ASC
""".trimIndent()
会将packagename 作为限制条件,导致查询不到结果。
对于用户,不能修改这个参数,来达到查询正确进程的目的。
修改建议:
(1)对于Metric 对象是特定进程的时候,开放参数传入指定进程名(默认值是包名)。比如:FrameTimingGfxInfoMetric,FrameTimingMetric,StartupTimingMetric。
(2)目前Metric 是sealed的,建议开放给用户,给用户更多自定义Metric 的空间。