Skip to content

Commit 8a8e8ed

Browse files
committed
Remove the logging of GaugeMetadata based on AppStart
1 parent b8803fc commit 8a8e8ed

File tree

6 files changed

+11
-44
lines changed

6 files changed

+11
-44
lines changed

firebase-perf/src/main/java/com/google/firebase/perf/FirebasePerformance.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ public static FirebasePerformance getInstance() {
182182
.initialize(firebaseApp, firebaseInstallationsApi, transportFactoryProvider);
183183

184184
Context appContext = firebaseApp.getApplicationContext();
185-
// TODO(b/110178816): Explore moving off of main thread.
186185
mMetadataBundle = extractMetadata(appContext);
187186

188187
remoteConfigManager.setFirebaseRemoteConfigProvider(firebaseRemoteConfigProvider);

firebase-perf/src/main/java/com/google/firebase/perf/session/SessionManager.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,13 @@ public SessionManager(
7979
* (currently that is before onResume finishes) to ensure gauge collection starts on time.
8080
*/
8181
public void setApplicationContext(final Context appContext) {
82-
// Get PerfSession in main thread first, because it is possible that app changes fg/bg state
83-
// which creates a new perfSession, before the following is executed in background thread
84-
final PerfSession appStartSession = perfSession;
8582
// TODO(b/258263016): Migrate to go/firebase-android-executors
8683
@SuppressLint("ThreadPoolCreation")
8784
ExecutorService executorService = Executors.newSingleThreadExecutor();
8885
syncInitFuture =
8986
executorService.submit(
9087
() -> {
9188
gaugeManager.initializeGaugeMetadataManager(appContext);
92-
if (appStartSession.isGaugeAndEventCollectionEnabled()) {
93-
gaugeManager.logGaugeMetadata(
94-
appStartSession.sessionId(), ApplicationProcessState.FOREGROUND);
95-
}
9689
});
9790
}
9891

@@ -164,9 +157,6 @@ public void updatePerfSession(PerfSession perfSession) {
164157
}
165158
}
166159

167-
// Log the gauge metadata event if data collection is enabled.
168-
logGaugeMetadataIfCollectionEnabled(appStateMonitor.getAppState());
169-
170160
// Start of stop the gauge data collection.
171161
startOrStopCollectingGauges(appStateMonitor.getAppState());
172162
}
@@ -178,7 +168,6 @@ public void updatePerfSession(PerfSession perfSession) {
178168
* this does not reset the perfSession.
179169
*/
180170
public void initializeGaugeCollection() {
181-
logGaugeMetadataIfCollectionEnabled(ApplicationProcessState.FOREGROUND);
182171
startOrStopCollectingGauges(ApplicationProcessState.FOREGROUND);
183172
}
184173

@@ -206,12 +195,6 @@ public void unregisterForSessionUpdates(WeakReference<SessionAwareObject> client
206195
}
207196
}
208197

209-
private void logGaugeMetadataIfCollectionEnabled(ApplicationProcessState appState) {
210-
if (perfSession.isGaugeAndEventCollectionEnabled()) {
211-
gaugeManager.logGaugeMetadata(perfSession.sessionId(), appState);
212-
}
213-
}
214-
215198
private void startOrStopCollectingGauges(ApplicationProcessState appState) {
216199
if (perfSession.isGaugeAndEventCollectionEnabled()) {
217200
gaugeManager.startCollectingGauges(perfSession, appState);

firebase-perf/src/main/java/com/google/firebase/perf/session/gauges/CpuGaugeCollector.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import static android.system.Os.sysconf;
1818

1919
import android.annotation.SuppressLint;
20-
import android.os.Build.VERSION;
21-
import android.os.Build.VERSION_CODES;
2220
import android.system.OsConstants;
2321
import androidx.annotation.Nullable;
2422
import androidx.annotation.VisibleForTesting;
@@ -163,7 +161,7 @@ private synchronized void scheduleCpuMetricCollectionWithRate(
163161
this.cpuMetricCollectionRateMs = cpuMetricCollectionRate;
164162
try {
165163
cpuMetricCollectorJob =
166-
cpuMetricCollectorExecutor.scheduleAtFixedRate(
164+
cpuMetricCollectorExecutor.scheduleWithFixedDelay(
167165
() -> {
168166
CpuMetricReading currCpuReading = syncCollectCpuMetric(referenceTime);
169167
if (currCpuReading != null) {
@@ -181,7 +179,7 @@ private synchronized void scheduleCpuMetricCollectionWithRate(
181179
private synchronized void scheduleCpuMetricCollectionOnce(Timer referenceTime) {
182180
try {
183181
@SuppressWarnings("FutureReturnValueIgnored")
184-
ScheduledFuture unusedFuture =
182+
ScheduledFuture<?> unusedFuture =
185183
cpuMetricCollectorExecutor.schedule(
186184
() -> {
187185
CpuMetricReading currCpuReading = syncCollectCpuMetric(referenceTime);
@@ -227,12 +225,7 @@ private CpuMetricReading syncCollectCpuMetric(Timer referenceTime) {
227225
}
228226

229227
private long getClockTicksPerSecond() {
230-
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
231-
return sysconf(OsConstants._SC_CLK_TCK);
232-
} else {
233-
// TODO(b/110779408): Figure out how to collect this info for Android API 20 and below.
234-
return INVALID_SC_PER_CPU_CLOCK_TICK;
235-
}
228+
return sysconf(OsConstants._SC_CLK_TCK);
236229
}
237230

238231
private long convertClockTicksToMicroseconds(long clockTicks) {

firebase-perf/src/main/java/com/google/firebase/perf/session/gauges/GaugeManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,16 @@ private GaugeManager() {
7272
TransportManager.getInstance(),
7373
ConfigResolver.getInstance(),
7474
null,
75-
new Lazy<>(() -> new CpuGaugeCollector()),
76-
new Lazy<>(() -> new MemoryGaugeCollector()));
75+
new Lazy<>(CpuGaugeCollector::new),
76+
new Lazy<>(MemoryGaugeCollector::new));
7777
}
7878

7979
@VisibleForTesting
8080
GaugeManager(
8181
Lazy<ScheduledExecutorService> gaugeManagerExecutor,
8282
TransportManager transportManager,
8383
ConfigResolver configResolver,
84-
GaugeMetadataManager gaugeMetadataManager,
84+
@Nullable GaugeMetadataManager gaugeMetadataManager,
8585
Lazy<CpuGaugeCollector> cpuGaugeCollector,
8686
Lazy<MemoryGaugeCollector> memoryGaugeCollector) {
8787

@@ -140,7 +140,7 @@ public void startCollectingGauges(
140140
gaugeManagerDataCollectionJob =
141141
gaugeManagerExecutor
142142
.get()
143-
.scheduleAtFixedRate(
143+
.scheduleWithFixedDelay(
144144
() -> {
145145
syncFlush(sessionIdForScheduledTask, applicationProcessStateForScheduledTask);
146146
},

firebase-perf/src/main/java/com/google/firebase/perf/session/gauges/GaugeMetadataManager.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import android.app.ActivityManager;
1818
import android.app.ActivityManager.MemoryInfo;
1919
import android.content.Context;
20-
import android.os.Build.VERSION;
21-
import android.os.Build.VERSION_CODES;
2220
import androidx.annotation.VisibleForTesting;
2321
import com.google.firebase.perf.logging.AndroidLogger;
2422
import com.google.firebase.perf.util.StorageUnit;
@@ -41,7 +39,6 @@ class GaugeMetadataManager {
4139
private final Runtime runtime;
4240
private final ActivityManager activityManager;
4341
private final MemoryInfo memoryInfo;
44-
private final Context appContext;
4542

4643
GaugeMetadataManager(Context appContext) {
4744
this(Runtime.getRuntime(), appContext);
@@ -50,7 +47,6 @@ class GaugeMetadataManager {
5047
@VisibleForTesting
5148
GaugeMetadataManager(Runtime runtime, Context appContext) {
5249
this.runtime = runtime;
53-
this.appContext = appContext;
5450
this.activityManager = (ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE);
5551
memoryInfo = new ActivityManager.MemoryInfo();
5652
activityManager.getMemoryInfo(memoryInfo);
@@ -75,11 +71,7 @@ public int getMaxEncouragedAppJavaHeapMemoryKb() {
7571

7672
/** Returns the total memory (in kilobytes) accessible by the kernel (called the RAM size). */
7773
public int getDeviceRamSizeKb() {
78-
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
79-
return Utils.saturatedIntCast(StorageUnit.BYTES.toKilobytes(memoryInfo.totalMem));
80-
}
81-
82-
return readTotalRAM(/* procFileName= */ "/proc/meminfo");
74+
return Utils.saturatedIntCast(StorageUnit.BYTES.toKilobytes(memoryInfo.totalMem));
8375
}
8476

8577
/** Returns the total ram size of the device (in kilobytes) by reading the "proc/meminfo" file. */

firebase-perf/src/main/java/com/google/firebase/perf/session/gauges/MemoryGaugeCollector.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class MemoryGaugeCollector {
5050
public final ConcurrentLinkedQueue<AndroidMemoryReading> memoryMetricReadings;
5151
private final Runtime runtime;
5252

53-
@Nullable private ScheduledFuture memoryMetricCollectorJob = null;
53+
@Nullable private ScheduledFuture<?> memoryMetricCollectorJob = null;
5454
private long memoryMetricCollectionRateMs = UNSET_MEMORY_METRIC_COLLECTION_RATE;
5555

5656
// TODO(b/258263016): Migrate to go/firebase-android-executors
@@ -124,7 +124,7 @@ private synchronized void scheduleMemoryMetricCollectionWithRate(
124124

125125
try {
126126
memoryMetricCollectorJob =
127-
memoryMetricCollectorExecutor.scheduleAtFixedRate(
127+
memoryMetricCollectorExecutor.scheduleWithFixedDelay(
128128
() -> {
129129
AndroidMemoryReading memoryReading = syncCollectMemoryMetric(referenceTime);
130130
if (memoryReading != null) {
@@ -142,7 +142,7 @@ private synchronized void scheduleMemoryMetricCollectionWithRate(
142142
private synchronized void scheduleMemoryMetricCollectionOnce(Timer referenceTime) {
143143
try {
144144
@SuppressWarnings("FutureReturnValueIgnored")
145-
ScheduledFuture unusedFuture =
145+
ScheduledFuture<?> unusedFuture =
146146
memoryMetricCollectorExecutor.schedule(
147147
() -> {
148148
AndroidMemoryReading memoryReading = syncCollectMemoryMetric(referenceTime);

0 commit comments

Comments
 (0)