-
Notifications
You must be signed in to change notification settings - Fork 592
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
Conversation
Timer
timebase to elapsedRealtime
elapsedRealtime
Coverage Report 1Affected Products
Test Logs
Notes |
firebase-perf/src/main/java/com/google/firebase/perf/util/Timer.java
Outdated
Show resolved
Hide resolved
firebase-perf/src/main/java/com/google/firebase/perf/util/Timer.java
Outdated
Show resolved
Hide resolved
firebase-perf/src/main/java/com/google/firebase/perf/util/Timer.java
Outdated
Show resolved
Hide resolved
firebase-perf/src/main/java/com/google/firebase/perf/util/Timer.java
Outdated
Show resolved
Hide resolved
firebase-perf/src/main/java/com/google/firebase/perf/util/Timer.java
Outdated
Show resolved
Hide resolved
firebase-perf/src/main/java/com/google/firebase/perf/metrics/AppStartTrace.java
Outdated
Show resolved
Hide resolved
Size Report 1Affected Products
Test Logs
Notes |
firebase-perf/src/main/java/com/google/firebase/perf/util/Timer.java
Outdated
Show resolved
Hide resolved
/retest |
/retest |
firebase-perf/src/main/java/com/google/firebase/perf/util/Timer.java
Outdated
Show resolved
Hide resolved
firebase-perf/src/main/java/com/google/firebase/perf/util/Timer.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
/** 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 |
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.
Why do we need reset API? Is there a place where this is used?
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.
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() { |
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.
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)
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.
+1
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 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.
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.
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.
firebase-perf/src/test/java/com/google/firebase/perf/util/TimerTest.java
Outdated
Show resolved
Hide resolved
firebase-perf/src/test/java/com/google/firebase/perf/util/TimerTest.java
Outdated
Show resolved
Hide resolved
firebase-perf/src/test/java/com/google/firebase/perf/util/TimerTest.java
Show resolved
Hide resolved
* 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
b/243537606
Blocked by #4027
Main change
Change
Timer.java
's timebase toelapsedRealtime
for consistency with Android platform API. Platform APIs likeProcess.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.