-
Notifications
You must be signed in to change notification settings - Fork 624
[Obsolete] Capture frame metrics in fragment monitor #3584
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
Conversation
Coverage Report 1Affected ProductsNo changes between base commit (c08ebb7) and merge commit (a584202).Test Logs
Notes |
The public api surface has changed for the subproject firebase-perf: Please update the api.txt files for the subprojects being affected by this change by running ./gradlew ${subproject}:generateApiTxtFile. Also perform a major/minor bump accordingly. |
Size Report 1Affected Products
Test Logs
Notes |
The public api surface has changed for the subproject firebase-perf: Please update the api.txt files for the subprojects being affected by this change by running ./gradlew ${subproject}:generateApiTxtFile. Also perform a major/minor bump accordingly. |
9bc559e
to
8757b15
Compare
firebase-perf/src/test/java/com/google/firebase/perf/application/FragmentStateMonitorTest.java
Outdated
Show resolved
Hide resolved
/test check-changed |
Has the public surface changed at all? Can we make sure to have the visibility of APIs rightly set? |
fragmentToTraceMap.put(f, fragmentTrace); | ||
|
||
FrameMetrics frameMetrics = | ||
FrameMetricsCalculator.calculateFrameMetrics(this.frameMetricsAggregator.getMetrics()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is the start of the fragment trace, should we calculateFramemetrics here? I would assume that would be empty. If that is true, can we replace this with an empty instance of FrameMetrics?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The frameMetrics
will not be empty because we are not resetting the frameMetricsAggregator
before fragment starts. The approach here is to take a snapshot of the frame metrics when a fragment starts and another snapshot when a fragment finishes. We will calculate the difference between these two snapshots as the fragment's screen performance.
int totalFrames = curFrameMetrics.getTotalFrames() - preFrameMetrics.getTotalFrames(); | ||
int slowFrames = curFrameMetrics.getSlowFrames() - preFrameMetrics.getSlowFrames(); | ||
int frozenFrames = curFrameMetrics.getFrozenFrames() - preFrameMetrics.getFrozenFrames(); | ||
|
||
if (totalFrames == 0 && slowFrames == 0 && frozenFrames == 0) { | ||
// All metrics are zero, no need to send screen trace. | ||
return; | ||
} | ||
// Only putMetric if corresponding metric is non-zero. | ||
if (totalFrames > 0) { | ||
fragmentTrace.putMetric(Constants.CounterNames.FRAMES_TOTAL.toString(), totalFrames); | ||
} | ||
if (slowFrames > 0) { | ||
fragmentTrace.putMetric(Constants.CounterNames.FRAMES_SLOW.toString(), slowFrames); | ||
} | ||
if (frozenFrames > 0) { | ||
fragmentTrace.putMetric(Constants.CounterNames.FRAMES_FROZEN.toString(), frozenFrames); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this a ScreenTrace/TraceUtil method that takes the FrameMetrics as an input and adds all necessary counters internally? This method could also be used in the AppState Monitor for the screen trace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also update AppStateMonitor
to also use the newer utils like FrameMetricsCalculator
and ScreenTraceUtils
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in the new PR #3592
* | ||
* @hide | ||
*/ | ||
public class FrameMetricsCalculator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a package-info.java to qualify the visibility of the package across the SDK?
A sample reference would be https://github.com/firebase/firebase-android-sdk/blob/master/firebase-perf/src/main/java/com/google/firebase/perf/metrics/validator/package-info.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot add package level visibility to com.google.firebase.perf.metrics
since Trace.java
needs to be publicly visible.
int frozenFrames = 0; | ||
|
||
if (arr != null) { | ||
SparseIntArray frameTimes = arr[FrameMetricsAggregator.TOTAL_INDEX]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For learning - Can you clarify what is FrameMetricsAggregator.TOTAL_INDEX? Curious if we should pass the frameMetricsAggregator instance here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Total index: The index in the metrics array where the data for TOTAL_DURATION is stored. We calculate the slow/frozen frames from the TOTAL_DURATION.
The reason that I did not pass the frameMetricsAggregator instance is that we might get the arr from different methods from frameMetricsAggregator, such as getMetrics(), remove(), or reset(). Let me know if you think passing the instance is better.
firebase-perf/src/test/java/com/google/firebase/perf/application/FragmentStateMonitorTest.java
Outdated
Show resolved
Hide resolved
|
||
@Test | ||
public void | ||
lifecycleCallbacks_differentFrameMetricsCapturedByFma_logFragmentScreenTraceWithCorrectFrames() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a testcase where the "onPaused" method of the fragment gets called more than once and ensure that we do not trigger event dispatch more than once?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, vicecersa where "onResume" method is not called for a fragment and ensure that we do not break/crash when "onPaused" is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great ideas! Done!
// Slow frames have duration greater than 16ms and frozen frames have duration greater than | ||
// 700ms. The key value pair means (duration, num_of_samples). | ||
SparseIntArray sparseIntArray = new SparseIntArray(); | ||
sparseIntArray.append(5, 3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also add an entry that is neither a slow/frozen frame to ensure that we exclude that as a part of calculation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Done!
This is a stale comment as I have fixed the issue in a following commit :) |
/retest |
1 similar comment
/retest |
2f24380
to
a0e6491
Compare
* Update CHANGELOG from m112 release * include full link to docsite * Fix typo
… in the given Map (#3518)
#3538 * Added catching RuntimeException when trying to get the analytics data Bundle from the Activity Intent since it's possible that the extras could contain invalid or incorrectly formatted data that will throw an Exception when trying to get the Bundle.
* Fix refresh logic for App Check custom providers. * Update tests. * Extract 1000L into a constant.
* Extending test-app * Removing comment * responding to comments * Delete MainActivityTest.java * running linter * removing unnecessary additions to gradle * Fixing lint errors Co-authored-by: Manny Jimenez <[email protected]>
Co-authored-by: rachaprince <[email protected]>
@jeremyjiang-dev: The following tests failed, say
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
Please review #3592 instead