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

[Fireperf][AASA] change timebase to elapsedRealtime #4024

Merged
merged 13 commits into from
Sep 2, 2022

Conversation

leotianlizhan
Copy link
Contributor

@leotianlizhan leotianlizhan commented Aug 24, 2022

b/243537606
Blocked by #4027

Main change

Change Timer.java's timebase to elapsedRealtime for consistency with Android platform API. Platform APIs like Process.startElapsedRealtime() are in that timebase, so if we want to find duration between our timestamps and Android API's, then they must be the same timebase.

Additional code health improvement

Changed variable names and some Javadoc, because the old ones are incorrect and misleading. We aren not using different APIs for wallclock time (timeInMicros) and duration-calculating-time (highResTime) because duration-calculating-time is high-resolution. We are separating them because wall-clock is not monotonic. See the top of this doc https://developer.android.com/reference/android/os/SystemClock to learn more.

@leotianlizhan leotianlizhan changed the title [Fireperf][AASA] change Timer timebase to elapsedRealtime [Fireperf][AASA] change timebase to elapsedRealtime Aug 24, 2022
@google-oss-bot
Copy link
Contributor

google-oss-bot commented Aug 24, 2022

Coverage Report 1

Affected Products

  • firebase-perf

    Overall coverage changed from ? (f5c9e3b) to 71.35% (9ded389) by ?.

    101 individual files with coverage change

    FilenameBase (f5c9e3b)Merge (9ded389)Diff
    AddTrace.java?0.00%?
    AndroidApplicationInfo.java?34.71%?
    AndroidApplicationInfoOrBuilder.java?0.00%?
    AndroidLogger.java?100.00%?
    AndroidMemoryReading.java?38.36%?
    AndroidMemoryReadingOrBuilder.java?0.00%?
    ApplicationInfo.java?45.00%?
    ApplicationInfoOrBuilder.java?0.00%?
    ApplicationProcessState.java?73.91%?
    AppStartTrace.java?86.54%?
    AppStateMonitor.java?86.71%?
    AppStateUpdateHandler.java?92.86%?
    Clock.java?100.00%?
    ConfigResolver.java?97.38%?
    ConfigurationConstants.java?99.25%?
    ConfigurationFlag.java?100.00%?
    ConsoleUrlGenerator.java?37.50%?
    Constants.java?95.65%?
    Counter.java?90.91%?
    CpuGaugeCollector.java?92.77%?
    CpuMetricReading.java?39.33%?
    CpuMetricReadingOrBuilder.java?0.00%?
    DaggerFirebasePerformanceComponent.java?100.00%?
    DeviceCacheManager.java?76.03%?
    FirebasePerfApplicationInfoValidator.java?92.86%?
    FirebasePerfGaugeMetricValidator.java?100.00%?
    FirebasePerfHttpClient.java?93.85%?
    FirebasePerfMetricProto.java?0.00%?
    FirebasePerfNetworkValidator.java?86.67%?
    FirebasePerfOkHttpClient.java?44.90%?
    FirebasePerformance.java?79.12%?
    FirebasePerformanceAttributable.java?0.00%?
    FirebasePerformanceComponent.java?0.00%?
    FirebasePerformanceInitializer.java?33.33%?
    FirebasePerformanceModule.java?100.00%?
    FirebasePerformanceModule_ProvidesConfigResolverFactory.java?100.00%?
    FirebasePerformanceModule_ProvidesFirebaseAppFactory.java?100.00%?
    FirebasePerformanceModule_ProvidesFirebaseInstallationsFactory.java?100.00%?
    FirebasePerformanceModule_ProvidesRemoteConfigComponentFactory.java?100.00%?
    FirebasePerformanceModule_ProvidesRemoteConfigManagerFactory.java?100.00%?
    FirebasePerformanceModule_ProvidesSessionManagerFactory.java?100.00%?
    FirebasePerformanceModule_ProvidesTransportFactoryProviderFactory.java?100.00%?
    FirebasePerformance_Factory.java?100.00%?
    FirebasePerfProvider.java?76.92%?
    FirebasePerfRegistrar.java?100.00%?
    FirebasePerfTraceValidator.java?85.87%?
    FirebasePerfUrlConnection.java?44.26%?
    FlgTransport.java?83.33%?
    FragmentStateMonitor.java?94.87%?
    FrameMetricsCalculator.java?96.77%?
    FrameMetricsRecorder.java?78.38%?
    GaugeManager.java?98.43%?
    GaugeMetadata.java?32.21%?
    GaugeMetadataManager.java?84.21%?
    GaugeMetadataOrBuilder.java?0.00%?
    GaugeMetric.java?39.47%?
    GaugeMetricOrBuilder.java?0.00%?
    HttpMetric.java?92.65%?
    ImmutableBundle.java?100.00%?
    InstrHttpInputStream.java?92.86%?
    InstrHttpOutputStream.java?98.00%?
    InstrHttpsURLConnection.java?94.32%?
    InstrHttpURLConnection.java?93.42%?
    InstrumentApacheHttpResponseHandler.java?100.00%?
    InstrumentOkHttpEnqueueCallback.java?100.00%?
    InstrURLConnectionBase.java?94.86%?
    LogWrapper.java?23.08%?
    MemoryGaugeCollector.java?91.38%?
    NetworkConnectionInfo.java?0.00%?
    NetworkConnectionInfoOrBuilder.java?0.00%?
    NetworkRequestMetric.java?49.16%?
    NetworkRequestMetricBuilder.java?95.97%?
    NetworkRequestMetricBuilderUtil.java?75.00%?
    NetworkRequestMetricOrBuilder.java?0.00%?
    Optional.java?86.67%?
    PendingPerfEvent.java?100.00%?
    PerfMetric.java?33.67%?
    PerfMetricOrBuilder.java?0.00%?
    PerfMetricValidator.java?93.55%?
    PerfSession.java?93.22%?
    PerfSessionOrBuilder.java?0.00%?
    Rate.java?100.00%?
    RateLimiter.java?90.77%?
    RemoteConfigManager.java?92.86%?
    ResourceType.java?0.00%?
    ScreenTraceUtil.java?94.12%?
    SessionAwareObject.java?0.00%?
    SessionManager.java?100.00%?
    SessionVerbosity.java?68.42%?
    StorageUnit.java?57.89%?
    Timer.java?90.63%?
    Trace.java?96.67%?
    TraceMetric.java?43.14%?
    TraceMetricBuilder.java?100.00%?
    TraceMetricOrBuilder.java?0.00%?
    TransportInfo.java?0.00%?
    TransportInfoOrBuilder.java?0.00%?
    TransportManager.java?94.88%?
    URLAllowlist.java?94.44%?
    URLWrapper.java?0.00%?
    Utils.java?78.57%?

Test Logs

Notes

  • Commit (9ded389) is created by Prow via merging PR base commit (f5c9e3b) and head commit (d2b9225).
  • 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/gTDH4BDxzc.html

@github-actions
Copy link
Contributor

github-actions bot commented Aug 24, 2022

Unit Test Results

972 tests  +3   972 ✔️ +3   1m 19s ⏱️ -9s
  50 suites ±0       0 💤 ±0 
  50 files   ±0       0 ±0 

Results for commit d2b9225. ± Comparison against base commit 087083f.

♻️ This comment has been updated with latest results.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Aug 26, 2022

Size Report 1

Affected Products

  • firebase-perf

    TypeBase (f5c9e3b)Merge (9ded389)Diff
    aar311 kB311 kB+225 B (+0.1%)
    apk (aggressive)1.03 MB1.03 MB+100 B (+0.0%)
    apk (release)2.48 MB2.48 MB+180 B (+0.0%)

Test Logs

Notes

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

@leotianlizhan
Copy link
Contributor Author

/retest

@raymondlam raymondlam self-requested a review August 30, 2022 18:15
@leotianlizhan
Copy link
Contributor Author

/retest

}

/** resets the start time */
public void reset() {
timeInMicros = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis());
highResTime = System.nanoTime();
// TODO: consider removing this method and make Timer immutable thus fully thread-safe
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need reset API? Is there a place where this is used?

Copy link
Contributor Author

@leotianlizhan leotianlizhan Aug 31, 2022

Choose a reason for hiding this comment

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

It's used for networking classes like FirebasePerfHttpClient and its tests.

I also don't think we need this API when we can just do timerVariable = new Timer(); if you want to "reset" timerVariable. I also want to create a new Timer.now() static factory method to replace Timer() constructor in the future, so timerVariable = Timer.now() also makes more sense to read than reset().

However both of these changes touch a lot of files so I don't think this PR is the place to do it.

highResTime = System.nanoTime();
// TODO: consider removing this method and make Timer immutable thus fully thread-safe
wallClockMicros = wallClockMicros();
elapsedRealtimeMicros = elapsedRealtimeMicros();
}

/** Return wall-clock time in microseconds. */
public long getMicros() {
Copy link
Contributor

Choose a reason for hiding this comment

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

All the public APIs are hard to understand. How hard/tricky is to refactor them?

For eg:
getMicros could be getCurrentWallClockTimeMicros
gerDurationMacros to getDurationFromStarttime
gerDurationMacros(Timer) to getDurationBetweenTimersMicros(Timer)

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For getMicros, I don't know the original author's thoughts exactly but I'd imagine it's because they wanted to encapsulate "wall-clock" and "elapsedRealtime" so anyone who uses Timer don't need to understand them. Unfortunately they added getElapsedRealtimeMicros() for testing purposes which makes getMicros confusing and defeats the whole purpose of encapsulation.

I'm not against changing the name because I also like more explicit names, but I also propose that we remove getElapsedRealtimeMicros() because it's test-only.

Copy link
Contributor Author

@leotianlizhan leotianlizhan Aug 31, 2022

Choose a reason for hiding this comment

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

How hard/tricky is to refactor them?

It's hard as in these changes touch a lot of files and I don't feel like it makes sense to make a feature-implementation PR heavy with other things for reviewers. I feel like this PR should be focused on getting the elapsedRealtime-change right, and I would like to do other code health improvements in a separate PR.

@leotianlizhan leotianlizhan merged commit a84fe26 into master Sep 2, 2022
@leotianlizhan leotianlizhan deleted the fireperf-elapsedRealtime branch September 2, 2022 18:36
qdpham13 pushed a commit that referenced this pull request Sep 13, 2022
* change Timer timebase to elapsedRealtime

* address comments

* remove code that should be left to another CL

* remove unnecessaryy new object in constructor

* small change

* revert to store in microseconds due to too many tests being broken if not

* fix comment

* add tests for ofElapsedRealtime

* deflake time comparison tests

* ShadowSystemClock and remove getElapsedRealtimeMicros

* grammar

* stylize and add comments to test
@firebase firebase locked and limited conversation to collaborators Oct 3, 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.

5 participants