(Go: >> BACK << -|- >> HOME <<)

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pageLoadLatency logic for upcoming network latency measurement #3675

Merged
merged 6 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions app/src/main/java/org/wikipedia/analytics/SessionData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.wikipedia.util.MathUtil
@Serializable
class SessionData {

@Transient private val leadLatency = MathUtil.Averaged<Long>()
@Transient private val pageLatency = MathUtil.Averaged<Long>()
var startTime: Long
var lastTouchTime: Long
var pagesFromSearch = 0
Expand Down Expand Up @@ -41,12 +41,12 @@ class SessionData {
}
}

fun getLeadLatency(): Long {
return leadLatency.average.toLong()
fun getPageLatency(): Long {
return pageLatency.average.toLong()
}

fun addLeadLatency(leadLatency: Long) {
this.leadLatency.addSample(leadLatency)
fun addPageLatency(pageLatency: Long) {
this.pageLatency.addSample(pageLatency)
}

fun addPageFromBack() {
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/org/wikipedia/analytics/SessionFunnel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.wikipedia.settings.Prefs
class SessionFunnel(app: WikipediaApp) : Funnel(app, SCHEMA_NAME, REVISION) {

private var sessionData: SessionData
private var leadSectionStartTime: Long = 0
private var pageLoadStartTime: Long = 0

init {
sessionData = Prefs.sessionData
Expand Down Expand Up @@ -59,12 +59,12 @@ class SessionFunnel(app: WikipediaApp) : Funnel(app, SCHEMA_NAME, REVISION) {
sessionData.addPageWithNoDescription()
}

fun leadSectionFetchStart() {
leadSectionStartTime = System.currentTimeMillis()
fun pageFetchStart() {
pageLoadStartTime = System.currentTimeMillis()
}

fun leadSectionFetchEnd() {
sessionData.addLeadLatency(System.currentTimeMillis() - leadSectionStartTime)
fun pageFetchEnd() {
sessionData.addPageLatency(System.currentTimeMillis() - pageLoadStartTime)
}

private fun hasTimedOut(): Boolean {
Expand All @@ -86,7 +86,7 @@ class SessionFunnel(app: WikipediaApp) : Funnel(app, SCHEMA_NAME, REVISION) {
"noDescription", sessionData.pagesWithNoDescription,
"fromSuggestedEdits", sessionData.pagesFromSuggestedEdits,
"totalPages", sessionData.totalPages,
"pageLoadLatency", sessionData.getLeadLatency(),
"pageLoadLatency", sessionData.getPageLatency(),
"languages", JsonUtil.encodeToString(app.languageState.appLanguageCodes),
"apiMode", 1
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ abstract class OkHttpWebViewClient : WebViewClient() {
}
var response: WebResourceResponse
try {
val shouldLogLatency = request.url.encodedPath?.contains(RestService.PAGE_HTML_ENDPOINT) == true
if (shouldLogLatency) {
WikipediaApp.instance.sessionFunnel.pageFetchStart()
}
val rsp = request(request)
if (rsp.networkResponse != null && rsp.cacheResponse == null && shouldLogLatency) {
WikipediaApp.instance.sessionFunnel.pageFetchEnd()
}
response = if (CONTENT_TYPE_OGG == rsp.header(HEADER_CONTENT_TYPE) ||
CONTENT_TYPE_WEBM == rsp.header(HEADER_CONTENT_TYPE)) {
rsp.close()
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/org/wikipedia/page/PageFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@ class PageFragment : Fragment(), BackPressedHandler, CommunicationBridge.Communi
}
updateProgressBar(false)
webView.visibility = View.VISIBLE
app.sessionFunnel.leadSectionFetchEnd()
bridge.evaluate(JavaScriptActionHandler.getRevision()) { value ->
if (!isAdded || value == null || value == "null") {
return@evaluate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ class PageFragmentLoadState(private var model: PageViewModel,
}
fragment.requireActivity().invalidateOptionsMenu()
fragment.callback()?.onPageUpdateProgressBar(true)
app.sessionFunnel.leadSectionFetchStart()
model.page = null
val delayLoadHtml = title.prefixedText.contains(":")
if (!delayLoadHtml) {
Expand Down