mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-18 13:00:18 +03:00
Analytics: report performance event about sync request - send number of joined rooms
This commit is contained in:
parent
cab06c4b52
commit
f6d856d828
3 changed files with 55 additions and 14 deletions
|
@ -23,15 +23,15 @@ sealed interface StatisticEvent {
|
||||||
/**
|
/**
|
||||||
* Initial sync request and response downloading, not including parsing and storage of response
|
* Initial sync request and response downloading, not including parsing and storage of response
|
||||||
*/
|
*/
|
||||||
data class InitialSyncRequest(val durationMs: Int) : StatisticEvent
|
data class InitialSyncRequest(val durationMs: Int, val nbOfRooms: Int) : StatisticEvent
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initial sync treatment: parsing and storage of response
|
* Initial sync treatment: parsing and storage of response
|
||||||
*/
|
*/
|
||||||
data class InitialSyncTreatment(val durationMs: Int) : StatisticEvent
|
data class InitialSyncTreatment(val durationMs: Int, val nbOfRooms: Int) : StatisticEvent
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Incremental sync event
|
* Incremental sync event
|
||||||
*/
|
*/
|
||||||
data class SyncTreatment(val durationMs: Int, val afterPause: Boolean) : StatisticEvent
|
data class SyncTreatment(val durationMs: Int, val afterPause: Boolean, val nbOfRooms: Int) : StatisticEvent
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,7 @@ internal class DefaultSyncTask @Inject constructor(
|
||||||
val readTimeOut = (params.timeout + TIMEOUT_MARGIN).coerceAtLeast(TimeOutInterceptor.DEFAULT_LONG_TIMEOUT)
|
val readTimeOut = (params.timeout + TIMEOUT_MARGIN).coerceAtLeast(TimeOutInterceptor.DEFAULT_LONG_TIMEOUT)
|
||||||
|
|
||||||
var syncResponseToReturn: SyncResponse? = null
|
var syncResponseToReturn: SyncResponse? = null
|
||||||
var start = SystemClock.elapsedRealtime()
|
val syncStatisticsData = SyncStatisticsData(isInitialSync, params.afterPause)
|
||||||
if (isInitialSync) {
|
if (isInitialSync) {
|
||||||
Timber.tag(loggerTag.value).d("INIT_SYNC with filter: ${requestParams["filter"]}")
|
Timber.tag(loggerTag.value).d("INIT_SYNC with filter: ${requestParams["filter"]}")
|
||||||
val initSyncStrategy = initialSyncStrategy
|
val initSyncStrategy = initialSyncStrategy
|
||||||
|
@ -122,8 +122,7 @@ internal class DefaultSyncTask @Inject constructor(
|
||||||
roomSyncEphemeralTemporaryStore.reset()
|
roomSyncEphemeralTemporaryStore.reset()
|
||||||
workingDir.mkdirs()
|
workingDir.mkdirs()
|
||||||
val file = downloadInitSyncResponse(requestParams)
|
val file = downloadInitSyncResponse(requestParams)
|
||||||
sendStatistics(StatisticEvent.InitialSyncRequest((SystemClock.elapsedRealtime() - start).toInt()))
|
syncStatisticsData.intermediateTime = SystemClock.elapsedRealtime()
|
||||||
start = SystemClock.elapsedRealtime()
|
|
||||||
syncResponseToReturn = reportSubtask(defaultSyncStatusService, InitSyncStep.ImportingAccount, 1, 0.7F) {
|
syncResponseToReturn = reportSubtask(defaultSyncStatusService, InitSyncStep.ImportingAccount, 1, 0.7F) {
|
||||||
handleSyncFile(file, initSyncStrategy)
|
handleSyncFile(file, initSyncStrategy)
|
||||||
}
|
}
|
||||||
|
@ -138,8 +137,7 @@ internal class DefaultSyncTask @Inject constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sendStatistics(StatisticEvent.InitialSyncRequest((SystemClock.elapsedRealtime() - start).toInt()))
|
syncStatisticsData.intermediateTime = SystemClock.elapsedRealtime()
|
||||||
start = SystemClock.elapsedRealtime()
|
|
||||||
logDuration("INIT_SYNC Database insertion", loggerTag) {
|
logDuration("INIT_SYNC Database insertion", loggerTag) {
|
||||||
syncResponseHandler.handleResponse(syncResponse, token, defaultSyncStatusService)
|
syncResponseHandler.handleResponse(syncResponse, token, defaultSyncStatusService)
|
||||||
}
|
}
|
||||||
|
@ -147,7 +145,6 @@ internal class DefaultSyncTask @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
defaultSyncStatusService.endAll()
|
defaultSyncStatusService.endAll()
|
||||||
sendStatistics(StatisticEvent.InitialSyncTreatment((SystemClock.elapsedRealtime() - start).toInt()))
|
|
||||||
} else {
|
} else {
|
||||||
Timber.tag(loggerTag.value).d("Start incremental sync request")
|
Timber.tag(loggerTag.value).d("Start incremental sync request")
|
||||||
defaultSyncStatusService.setStatus(SyncStatusService.Status.IncrementalSyncIdle)
|
defaultSyncStatusService.setStatus(SyncStatusService.Status.IncrementalSyncIdle)
|
||||||
|
@ -174,8 +171,9 @@ internal class DefaultSyncTask @Inject constructor(
|
||||||
syncResponseToReturn = syncResponse
|
syncResponseToReturn = syncResponse
|
||||||
Timber.tag(loggerTag.value).d("Incremental sync done")
|
Timber.tag(loggerTag.value).d("Incremental sync done")
|
||||||
defaultSyncStatusService.setStatus(SyncStatusService.Status.IncrementalSyncDone)
|
defaultSyncStatusService.setStatus(SyncStatusService.Status.IncrementalSyncDone)
|
||||||
sendStatistics(StatisticEvent.SyncTreatment((SystemClock.elapsedRealtime() - start).toInt(), params.afterPause))
|
|
||||||
}
|
}
|
||||||
|
syncStatisticsData.nbOfRooms = syncResponseToReturn?.rooms?.join?.size ?: 0
|
||||||
|
sendStatistics(syncStatisticsData)
|
||||||
Timber.tag(loggerTag.value).d("Sync task finished on Thread: ${Thread.currentThread().name}")
|
Timber.tag(loggerTag.value).d("Sync task finished on Thread: ${Thread.currentThread().name}")
|
||||||
// Should throw if null as it's a mandatory value.
|
// Should throw if null as it's a mandatory value.
|
||||||
return syncResponseToReturn!!
|
return syncResponseToReturn!!
|
||||||
|
@ -254,7 +252,38 @@ internal class DefaultSyncTask @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sendStatistics(statisticEvent: StatisticEvent) {
|
/**
|
||||||
|
* Aggregator to send stat event.
|
||||||
|
*/
|
||||||
|
class SyncStatisticsData(
|
||||||
|
val isInitSync: Boolean,
|
||||||
|
val isAfterPause: Boolean
|
||||||
|
) {
|
||||||
|
val startTime = SystemClock.elapsedRealtime()
|
||||||
|
var intermediateTime: Long = 0
|
||||||
|
var nbOfRooms: Int = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun sendStatistics(data: SyncStatisticsData) {
|
||||||
|
if (data.isInitSync) {
|
||||||
|
sendStatisticEvent(StatisticEvent.InitialSyncRequest(
|
||||||
|
durationMs = (data.intermediateTime - data.startTime).toInt(),
|
||||||
|
nbOfRooms = data.nbOfRooms
|
||||||
|
))
|
||||||
|
sendStatisticEvent(StatisticEvent.InitialSyncTreatment(
|
||||||
|
durationMs = (SystemClock.elapsedRealtime() - data.intermediateTime).toInt(),
|
||||||
|
nbOfRooms = data.nbOfRooms
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
sendStatisticEvent(StatisticEvent.SyncTreatment(
|
||||||
|
durationMs = (SystemClock.elapsedRealtime() - data.startTime).toInt(),
|
||||||
|
afterPause = data.isAfterPause,
|
||||||
|
nbOfRooms = data.nbOfRooms
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun sendStatisticEvent(statisticEvent: StatisticEvent) {
|
||||||
session.dispatchTo(sessionListeners) { session, listener ->
|
session.dispatchTo(sessionListeners) { session, listener ->
|
||||||
listener.onStatisticsEvent(session, statisticEvent)
|
listener.onStatisticsEvent(session, statisticEvent)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,12 +22,24 @@ import org.matrix.android.sdk.api.session.statistics.StatisticEvent
|
||||||
fun StatisticEvent.toPerformanceTimer(): PerformanceTimer? {
|
fun StatisticEvent.toPerformanceTimer(): PerformanceTimer? {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is StatisticEvent.InitialSyncRequest ->
|
is StatisticEvent.InitialSyncRequest ->
|
||||||
PerformanceTimer(name = PerformanceTimer.Name.InitialSyncRequest, timeMs = durationMs)
|
PerformanceTimer(
|
||||||
|
name = PerformanceTimer.Name.InitialSyncRequest,
|
||||||
|
timeMs = durationMs,
|
||||||
|
itemCount = nbOfRooms
|
||||||
|
)
|
||||||
is StatisticEvent.InitialSyncTreatment ->
|
is StatisticEvent.InitialSyncTreatment ->
|
||||||
PerformanceTimer(name = PerformanceTimer.Name.InitialSyncParsing, timeMs = durationMs)
|
PerformanceTimer(
|
||||||
|
name = PerformanceTimer.Name.InitialSyncParsing,
|
||||||
|
timeMs = durationMs,
|
||||||
|
itemCount = nbOfRooms
|
||||||
|
)
|
||||||
is StatisticEvent.SyncTreatment ->
|
is StatisticEvent.SyncTreatment ->
|
||||||
if (afterPause) {
|
if (afterPause) {
|
||||||
PerformanceTimer(name = PerformanceTimer.Name.StartupIncrementalSync, timeMs = durationMs)
|
PerformanceTimer(
|
||||||
|
name = PerformanceTimer.Name.StartupIncrementalSync,
|
||||||
|
timeMs = durationMs,
|
||||||
|
itemCount = nbOfRooms
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
// We do not report
|
// We do not report
|
||||||
null
|
null
|
||||||
|
|
Loading…
Add table
Reference in a new issue