-
Notifications
You must be signed in to change notification settings - Fork 617
Migrate fireperf content provider to component #4242
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
Changes from 1 commit
f2c4fdb
a495cb7
c2d7476
b4f9ccc
8071823
fd7c0e3
18b98fb
b32aa04
14235e2
f074d74
23b36d4
9e31558
ea9339c
5e10d8f
e7c4f34
7d8062b
66a5f05
1f668dd
b5af211
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2022 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.firebase; | ||
|
||
import com.google.auto.value.AutoValue; | ||
|
||
/** | ||
* Represents the time at which Firebase began initialization, both in unix time/epoch milliseconds | ||
* and in nanoseconds since the startup of the JVM. The absence of a StartupTime indicates an | ||
* unreliable or misleading time, such as a launch in direct boot mode. Because of this, StartupTime | ||
* cannot be guarenteed to be present, and instead should be optionally depended on, and its absence | ||
* handled. | ||
*/ | ||
@AutoValue | ||
public abstract class StartupTime { | ||
|
||
/** @return The epoch time that Firebase began initializing, in milliseconds */ | ||
public abstract long getEpochMillis(); | ||
|
||
/** | ||
* @return The number of nanoseconds from the start of the program to when Firebase began | ||
* initializing, measured by the JVM | ||
*/ | ||
public abstract long getStartupNanos(); | ||
emilypgoogle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* @param epochMillis Time in milliseconds since epoch | ||
* @param startupNanos Time in nanoseconds since JVM start | ||
*/ | ||
public static StartupTime create(long epochMillis, long startupNanos) { | ||
return new AutoValue_StartupTime(epochMillis, startupNanos); | ||
} | ||
|
||
/** @return A StartupTime represented by the current epoch time and JVM nano time */ | ||
public static StartupTime now() { | ||
return create(System.currentTimeMillis(), System.nanoTime()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2022 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.firebase.perf; | ||
|
||
import android.content.Context; | ||
import android.os.Handler; | ||
import android.os.Looper; | ||
import androidx.annotation.NonNull; | ||
import com.google.firebase.FirebaseApp; | ||
import com.google.firebase.StartupTime; | ||
import com.google.firebase.perf.application.AppStateMonitor; | ||
import com.google.firebase.perf.config.ConfigResolver; | ||
import com.google.firebase.perf.metrics.AppStartTrace; | ||
import com.google.firebase.perf.session.SessionManager; | ||
|
||
/** | ||
* The Firebase Performance early initialization. | ||
* | ||
* <p>Responsible for initializing the AppStartTrace, and early initialization of ConfigResolver | ||
*/ | ||
public class FirebasePerfEarly { | ||
private final Handler mainHandler = new Handler(Looper.getMainLooper()); | ||
|
||
@NonNull | ||
public static FirebasePerfEarly getInstance() { | ||
return FirebaseApp.getInstance().get(FirebasePerfEarly.class); | ||
} | ||
emilypgoogle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public FirebasePerfEarly(FirebaseApp app) { | ||
Context context = app.getApplicationContext(); | ||
|
||
// Initialize ConfigResolver early for accessing device caching layer. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vkryachko I wonder if we could merge the 2-part initialization ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have full context on why the 2-part logic was in place, but my understanding that part of it was to speed up the SDK and delay a lot of work as much as possible(i.e. see #2518). But I trust your judgement to evolve this in a way that makes sense, after this initial migration. Happy to discuss it more. |
||
ConfigResolver configResolver = ConfigResolver.getInstance(); | ||
configResolver.setApplicationContext(context); | ||
|
||
AppStateMonitor appStateMonitor = AppStateMonitor.getInstance(); | ||
appStateMonitor.registerActivityLifecycleCallbacks(context); | ||
appStateMonitor.registerForAppColdStart(new FirebasePerformanceInitializer()); | ||
|
||
if (app.get(StartupTime.class) != null) { | ||
AppStartTrace appStartTrace = AppStartTrace.getInstance(); | ||
appStartTrace.registerActivityLifecycleCallbacks(context); | ||
mainHandler.post(new AppStartTrace.StartFromBackgroundRunnable(appStartTrace)); | ||
} | ||
|
||
// In the case of cold start, we create a session and start collecting gauges as early as | ||
// possible. | ||
// There is code in SessionManager that prevents us from resetting the session twice in case | ||
// of app cold start. | ||
SessionManager.getInstance().initializeGaugeCollection(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,10 @@ | |
import androidx.annotation.Keep; | ||
import androidx.annotation.Nullable; | ||
import com.google.android.gms.common.util.VisibleForTesting; | ||
import com.google.firebase.FirebaseApp; | ||
import com.google.firebase.StartupTime; | ||
import com.google.firebase.inject.Provider; | ||
import com.google.firebase.perf.logging.AndroidLogger; | ||
import com.google.firebase.perf.provider.FirebasePerfProvider; | ||
import com.google.firebase.perf.util.Optional; | ||
import com.google.firebase.remoteconfig.FirebaseRemoteConfig; | ||
import com.google.firebase.remoteconfig.FirebaseRemoteConfigValue; | ||
|
@@ -93,8 +94,12 @@ private RemoteConfigManager() { | |
firebaseRemoteConfig == null | ||
? new ConcurrentHashMap<>() | ||
: new ConcurrentHashMap<>(firebaseRemoteConfig.getAll()); | ||
this.appStartTimeInMs = | ||
TimeUnit.MICROSECONDS.toMillis(FirebasePerfProvider.getAppStartTime().getMicros()); | ||
StartupTime startupTime = FirebaseApp.getInstance().get(StartupTime.class); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can this be provided as a dependency instead of looking it up from firebaseApp? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've attempted to resolve this but it's more just shuffling the method around to be cleaner, |
||
if (startupTime != null) { | ||
this.appStartTimeInMs = startupTime.getEpochMillis(); | ||
} else { | ||
this.appStartTimeInMs = System.currentTimeMillis(); | ||
} | ||
this.appStartConfigFetchDelayInMs = appStartConfigFetchDelayInMs; | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.