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

Add tracing and JankStats #145

Merged
merged 24 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1033986
Add tracing library and start using it
keyboardsurfer May 20, 2022
4f57975
Add jankStats and rudamentary jank logging
keyboardsurfer May 20, 2022
895ec4c
Inject JankStats with Hilt
keyboardsurfer May 20, 2022
a37c932
Introduce view extension to track jank
keyboardsurfer May 20, 2022
ccb08a1
Add rememberMetricsStateHolder composable
mlykotom May 23, 2022
a076a50
Use rememberMetricsStateHolder for navigation
mlykotom May 23, 2022
1ac3b4d
Use DisposableEffect + rememberMetricsStateHolder for Interests tab s…
mlykotom May 23, 2022
24a876d
Remove InterestItem state
mlykotom May 23, 2022
dc97d15
Add JankMetricEffect
mlykotom May 23, 2022
57a7b5d
Add AuthorsCarousel scrolling state
mlykotom May 23, 2022
bc7270d
Add JankMetricDisposableEffect
mlykotom May 23, 2022
4dc1d0c
Add ForYou feed scrolling state
mlykotom May 23, 2022
5a1ece4
Add ForYou TopicSelection scrolling state
mlykotom May 23, 2022
e949749
Merge branch 'bw/initialMetrics' of github.com:android/nowinandroid i…
keyboardsurfer Jun 6, 2022
42878c5
Move JankStats metric gathering further down
keyboardsurfer Jun 6, 2022
fa16a25
Merge branch 'main' into bw/initialMetrics
keyboardsurfer Jun 13, 2022
5f690d1
Merge branch 'main' into bw/initialMetrics
keyboardsurfer Jun 17, 2022
0271a9d
Fix spotless
keyboardsurfer Jun 20, 2022
6509b6a
Merge branch 'main' into bw/initialMetrics
keyboardsurfer Jun 27, 2022
c3ca38d
Remove redundant dependency
keyboardsurfer Jul 3, 2022
9f92994
Address review comments
keyboardsurfer Jul 14, 2022
efb76d4
Merge branch 'main' into bw/initialMetrics
keyboardsurfer Jul 14, 2022
26bdcc9
Merge branch 'main' into bw/initialMetrics
keyboardsurfer Jul 14, 2022
7c2b584
Consistent tags & named parameter usage
keyboardsurfer Jul 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' into bw/initialMetrics
  • Loading branch information
keyboardsurfer committed Jul 14, 2022
commit efb76d49410b98eacef72de37138ada237a7a9c3
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.navigation.NavController
import androidx.navigation.NavDestination
import androidx.navigation.NavDestination.Companion.hierarchy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ package com.google.samples.apps.nowinandroid.feature.foryou

import androidx.compose.foundation.background
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
Expand Down Expand Up @@ -66,10 +68,14 @@ fun AuthorsCarousel(
modifier: Modifier = Modifier
) {
val lazyListState = rememberLazyListState()

TrackScrollJank(lazyListState, "ForYou:AuthorsCarousel")
keyboardsurfer marked this conversation as resolved.
Show resolved Hide resolved

LazyRow(modifier, lazyListState) {
LazyRow(
modifier = modifier.testTag("forYou:authors"),
contentPadding = PaddingValues(24.dp),
horizontalArrangement = Arrangement.spacedBy(24.dp),
state = lazyListState
) {
items(items = authors, key = { item -> item.author.id }) { followableAuthor ->
AuthorItem(
author = followableAuthor.author,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,35 @@ fun ForYouScreen(
else -> floor(maxWidth / 300.dp).toInt().coerceAtLeast(1)
}

// Workaround to call Activity.reportFullyDrawn from Jetpack Compose.
// This code should be called when the UI is ready for use
// and relates to Time To Full Display.
val interestsLoaded =
interestsSelectionState !is ForYouInterestsSelectionUiState.Loading
val feedLoaded = feedState !is ForYouFeedUiState.Loading

if (interestsLoaded && feedLoaded) {
val localView = LocalView.current
// We use Unit to call reportFullyDrawn only on the first recomposition,
// however it will be called again if this composable goes out of scope.
// Activity.reportFullyDrawn() has its own check for this
// and is safe to call multiple times though.
LaunchedEffect(Unit) {
// We're leveraging the fact, that the current view is directly set as content of Activity.
val activity = localView.context as? Activity ?: return@LaunchedEffect
// To be sure not to call in the middle of a frame draw.
localView.doOnPreDraw { activity.reportFullyDrawn() }
}
}

val lazyListState = rememberLazyListState()
TrackScrollJank(lazyListState, "ForYou:Feed")

LazyColumn(
modifier = Modifier
.fillMaxSize()
.testTag("forYou:feed"),
state = lazyListState,
modifier = Modifier.fillMaxSize(),
) {
InterestsSelection(
interestsSelectionState = interestsSelectionState,
Expand Down Expand Up @@ -299,9 +322,8 @@ private fun TopicSelection(
interestsSelectionState: ForYouInterestsSelectionUiState.WithInterestsSelection,
onTopicCheckedChanged: (String, Boolean) -> Unit,
modifier: Modifier = Modifier
) {
) = trace("TopicSelection") {
val lazyGridState = rememberLazyGridState()

TrackScrollJank(scrollableState = lazyGridState, stateName = "ForYou:TopicSelection")
keyboardsurfer marked this conversation as resolved.
Show resolved Hide resolved

LazyHorizontalGrid(
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.