Skip to content

[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

Closed
wants to merge 23 commits into from

Conversation

jeremyjiang-dev
Copy link
Contributor

@jeremyjiang-dev jeremyjiang-dev commented Mar 23, 2022

Please review #3592 instead

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Mar 23, 2022

Coverage Report 1

Affected Products

No changes between base commit (c08ebb7) and merge commit (a584202).

Test Logs

Notes

  • Commit (a584202) is created by Prow via merging PR base commit (c08ebb7) and head commit (a0e6491).
  • Run gradle <product>:checkCoverage to produce HTML coverage reports locally. After gradle commands finished, report files can be found under <product-build-dir>/reports/jacoco/.

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/zX29si0a3u.html

@google-oss-bot
Copy link
Contributor

The public api surface has changed for the subproject firebase-perf:
error: Added class com.google.firebase.perf.metrics.FrameMetricsCalculator [AddedClass]

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.

@jeremyjiang-dev jeremyjiang-dev changed the title Capture frame metrics in fragment mintor Capture frame metrics in fragment monitor Mar 23, 2022
@google-oss-bot
Copy link
Contributor

google-oss-bot commented Mar 23, 2022

Size Report 1

Affected Products

  • base

    TypeBase (c08ebb7)Merge (a584202)Diff
    apk (aggressive)?8.39 kB? (?)
    apk (release)?8.65 kB? (?)
  • firebase-abt

    TypeBase (c08ebb7)Merge (a584202)Diff
    aar?14.0 kB? (?)
    apk (aggressive)?84.9 kB? (?)
    apk (release)?685 kB? (?)
  • firebase-annotations

    TypeBase (c08ebb7)Merge (a584202)Diff
    apk (aggressive)?8.39 kB? (?)
    apk (release)?8.88 kB? (?)
  • firebase-common

    TypeBase (c08ebb7)Merge (a584202)Diff
    aar?48.0 kB? (?)
    apk (aggressive)?84.2 kB? (?)
    apk (release)?680 kB? (?)
  • firebase-components

    TypeBase (c08ebb7)Merge (a584202)Diff
    aar?41.4 kB? (?)
    apk (aggressive)?8.68 kB? (?)
    apk (release)?29.5 kB? (?)
  • firebase-config

    TypeBase (c08ebb7)Merge (a584202)Diff
    aar?62.7 kB? (?)
    apk (aggressive)?93.3 kB? (?)
    apk (release)?731 kB? (?)
  • firebase-datatransport

    TypeBase (c08ebb7)Merge (a584202)Diff
    aar?5.12 kB? (?)
    apk (aggressive)?130 kB? (?)
    apk (release)?767 kB? (?)
  • firebase-encoders

    TypeBase (c08ebb7)Merge (a584202)Diff
    apk (aggressive)?8.68 kB? (?)
    apk (release)?15.3 kB? (?)
  • firebase-encoders-json

    TypeBase (c08ebb7)Merge (a584202)Diff
    aar?10.5 kB? (?)
    apk (aggressive)?8.68 kB? (?)
    apk (release)?20.1 kB? (?)
  • firebase-encoders-proto

    TypeBase (c08ebb7)Merge (a584202)Diff
    apk (aggressive)?8.68 kB? (?)
    apk (release)?21.6 kB? (?)
  • firebase-installations

    TypeBase (c08ebb7)Merge (a584202)Diff
    aar?55.0 kB? (?)
    apk (aggressive)?85.8 kB? (?)
    apk (release)?702 kB? (?)
  • firebase-installations-interop

    TypeBase (c08ebb7)Merge (a584202)Diff
    aar?8.34 kB? (?)
    apk (aggressive)?65.0 kB? (?)
    apk (release)?651 kB? (?)
  • firebase-perf

    TypeBase (c08ebb7)Merge (a584202)Diff
    aar?306 kB? (?)
    apk (aggressive)?1.03 MB? (?)
    apk (release)?2.46 MB? (?)
  • protolite-well-known-types

    TypeBase (c08ebb7)Merge (a584202)Diff
    aar?993 kB? (?)
    apk (aggressive)?134 kB? (?)
    apk (release)?661 kB? (?)
  • transport-api

    TypeBase (c08ebb7)Merge (a584202)Diff
    aar?6.57 kB? (?)
    apk (aggressive)?8.68 kB? (?)
    apk (release)?14.9 kB? (?)
  • transport-backend-cct

    TypeBase (c08ebb7)Merge (a584202)Diff
    aar?53.5 kB? (?)
    apk (aggressive)?58.0 kB? (?)
    apk (release)?105 kB? (?)
  • transport-runtime

    TypeBase (c08ebb7)Merge (a584202)Diff
    aar?178 kB? (?)
    apk (aggressive)?43.8 kB? (?)
    apk (release)?82.6 kB? (?)

Test Logs

Notes

  • Commit (a584202) is created by Prow via merging PR base commit (c08ebb7) and head commit (a0e6491).

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/RFkttN0VYv.html

@jeremyjiang-dev jeremyjiang-dev changed the base branch from perfFragmentsEAP to fragment-trace March 23, 2022 20:43
@google-oss-bot
Copy link
Contributor

The public api surface has changed for the subproject firebase-perf:
error: Added class com.google.firebase.perf.metrics.FrameMetricsCalculator [AddedClass]

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.

Base automatically changed from fragment-trace to perfFragmentsEAP March 23, 2022 23:05
@jeremyjiang-dev jeremyjiang-dev requested review from leotianlizhan and visumickey and removed request for leotianlizhan March 24, 2022 16:42
@jeremyjiang-dev
Copy link
Contributor Author

/test check-changed

@visumickey
Copy link
Contributor

The public api surface has changed for the subproject firebase-perf: error: Added class com.google.firebase.perf.metrics.FrameMetricsCalculator [AddedClass]

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.

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());
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Comment on lines 104 to 121
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);
}
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Copy link
Contributor

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?

Copy link
Contributor Author

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 {
Copy link
Contributor

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

Copy link
Contributor Author

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];
Copy link
Contributor

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?

Copy link
Contributor Author

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.


@Test
public void
lifecycleCallbacks_differentFrameMetricsCapturedByFma_logFragmentScreenTraceWithCorrectFrames() {
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Done!

@jeremyjiang-dev
Copy link
Contributor Author

The public api surface has changed for the subproject firebase-perf: error: Added class com.google.firebase.perf.metrics.FrameMetricsCalculator [AddedClass]
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.

Has the public surface changed at all? Can we make sure to have the visibility of APIs rightly set?

This is a stale comment as I have fixed the issue in a following commit :)

@jeremyjiang-dev jeremyjiang-dev changed the base branch from perfFragmentsEAP to master March 25, 2022 15:27
@jeremyjiang-dev jeremyjiang-dev changed the base branch from master to perfFragmentsEAP March 25, 2022 15:27
@jeremyjiang-dev jeremyjiang-dev changed the base branch from perfFragmentsEAP to master March 25, 2022 15:43
@jeremyjiang-dev jeremyjiang-dev changed the base branch from master to perfFragmentsEAP March 25, 2022 15:43
@jeremyjiang-dev
Copy link
Contributor Author

/retest

1 similar comment
@jeremyjiang-dev
Copy link
Contributor Author

/retest

rachaprince and others added 15 commits March 25, 2022 16:18
* Update CHANGELOG from m112 release

* include full link to docsite

* Fix typo
#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.
* move screen trace start to onResum

* gjf

* comment

* fix tests
* 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]>
@google-oss-bot
Copy link
Contributor

@jeremyjiang-dev: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
copyright-check 79b62dc link /test copyright-check
api-information 79b62dc link /test api-information
check-changed 79b62dc link /test check-changed
smoke-tests 79b62dc link /test smoke-tests
device-check-changed 79b62dc link /test device-check-changed
check-coverage-changed 79b62dc link /test check-coverage-changed
binary-size 79b62dc link /run binary-size

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.

@jeremyjiang-dev jeremyjiang-dev changed the title Capture frame metrics in fragment monitor [Obsolete] Capture frame metrics in fragment monitor Mar 25, 2022
@firebase firebase locked and limited conversation to collaborators Apr 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.