Skip to content

RUMM-3216 use jank stats#1405

Merged
xgouchet merged 6 commits into
developfrom
xgouchet/RUMM-3216/jank_stats
May 24, 2023
Merged

RUMM-3216 use jank stats#1405
xgouchet merged 6 commits into
developfrom
xgouchet/RUMM-3216/jank_stats

Conversation

@xgouchet

Copy link
Copy Markdown
Contributor

What does this PR do?

Use the JankStats library to get the actual frame durations.

Motivation

Using the Choreographer like we did forced a redraw of all frames, which was not necessary if the content didn't require it.

Additional Notes

Anything else we should know when reviewing?

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@xgouchet
xgouchet requested a review from a team as a code owner April 28, 2023 07:11

@0xnm 0xnm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice solution! I've added few comments to clarify.

Comment on lines +233 to +236
@Suppress(
"UnsafeThirdPartyFu" +
"nctionCall"
) // pool size can't be <= 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like a wrong change

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed

// region JankStats.OnFrameListener

override fun onFrame(volatileFrameData: FrameData) {
println("$volatileFrameData")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be removed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

Comment thread gradle/libs.versions.toml
Comment on lines +3 to +4
kotlin = "1.8.10"
kotlinSP = "1.8.10-1.0.9"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need it as a part of this PR? I would rather handle it in the SDK v2 branch with Gradle 8 update (which is based on Kotlin 1.8 as well, so that we don't have conflicts for the build classpath), and also checking API/ABI compatibility.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I need to use this version otherwise there's an incompatibility with the Metrics library.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, we still have the following anyway in the Kotlin compiler configuration:

apiVersion = "1.6"
languageVersion = "1.6"

So shouldn't be any difference on the client side apart of the dependency resolution. It can be though the issue on the client side that Kotlin is resolved to 1.8 and thus produces bytecode not compatible with something else (like React Native), but at least from the SDK integration point should be good.

import androidx.lifecycle.ViewModelProviders
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment.findNavController
import androidx.navigation.fragment.NavHostFragment.Companion.findNavController

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to specify Companion now? Is it related to the Kotlin 1.8 change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's changed because of Kotlin 1.8

@xgouchet xgouchet changed the title Xgouchet/rumm 3216/jank stats RUMM-3216 use jank stats Apr 28, 2023

override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
try {
JankStats.createAndTrack(activity.window, this)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will work only for activity windows but will not measure the frame rate for DialogWindow or PopUpWindow. I guess once we add that ticket to support that in RUM we will have to find a different way to plugin in the JankStats into those windows too.

+ upgrade kotlin related dependencies (needed to be compatible with the
Metrics library)
@xgouchet
xgouchet force-pushed the xgouchet/RUMM-3216/jank_stats branch from 82c1637 to 3ccb996 Compare May 3, 2023 10:01
@xgouchet
xgouchet force-pushed the xgouchet/RUMM-3216/jank_stats branch from 3ccb996 to 2ce0d84 Compare May 3, 2023 12:04
@xgouchet
xgouchet requested review from 0xnm and mariusc83 May 3, 2023 12:04

@0xnm 0xnm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! I've left a comment wondering if we should change also the way we detect refresh rate.

)
}
jankStatsActivityLifecycleListener = JankStatsActivityLifecycleListener(frameRateVitalMonitor, internalLogger)
(appContext as? Application)?.registerActivityLifecycleCallbacks(jankStatsActivityLifecycleListener)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we modify the way we are checking refresh rate? currently we are using RumViewScope#detectRefreshRateScale, which relies on the view key and the presence of activity/fragment there (which may be missing in case of manual instrumentation or calls coming from cross-platform).

But now, since we are listening for activities anyway, we can access UI context at any time and basically pass this info with a sample, making things work properly even for cross-platform.

wdyt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes a lot of sense indeed


override fun onFrame(volatileFrameData: FrameData) {
val durationNs = volatileFrameData.frameDurationUiNanos
if (durationNs > 0.0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in which case it can be negative or zero?

@xgouchet
xgouchet requested a review from 0xnm May 23, 2023 12:35
@codecov-commenter

codecov-commenter commented May 24, 2023

Copy link
Copy Markdown

Codecov Report

Merging #1405 (f0c40b0) into develop (8586d84) will increase coverage by 0.16%.
The diff coverage is 86.49%.

@@             Coverage Diff             @@
##           develop    #1405      +/-   ##
===========================================
+ Coverage    81.94%   82.09%   +0.16%     
===========================================
  Files          363      363              
  Lines        13031    12974      -57     
  Branches      2191     2164      -27     
===========================================
- Hits         10677    10651      -26     
+ Misses        1688     1668      -20     
+ Partials       666      655      -11     
Impacted Files Coverage Δ
...ernal/vitals/JankStatsActivityLifecycleListener.kt 80.00% <80.00%> (ø)
...lin/com/datadog/android/rum/internal/RumFeature.kt 92.54% <100.00%> (-1.03%) ⬇️
...d/rum/internal/domain/scope/RumViewManagerScope.kt 96.15% <100.00%> (+0.77%) ⬆️
.../android/rum/internal/domain/scope/RumViewScope.kt 95.80% <100.00%> (+1.48%) ⬆️

... and 54 files with indirect coverage changes

@mariusc83 mariusc83 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work Xav ;)

@xgouchet
xgouchet merged commit e2074ea into develop May 24, 2023
@xgouchet
xgouchet deleted the xgouchet/RUMM-3216/jank_stats branch May 24, 2023 12:18
@xgouchet xgouchet added this to the 2.0.0 milestone Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants