Skip to content

Commit 99243ed

Browse files
committed
Remove the logging of GaugeMetadata based on AppStart
1 parent bc01620 commit 99243ed

File tree

4 files changed

+28
-22
lines changed

4 files changed

+28
-22
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
@@ -188,7 +188,6 @@ public static FirebasePerformance getInstance() {
188188
.initialize(firebaseApp, firebaseInstallationsApi, transportFactoryProvider);
189189

190190
Context appContext = firebaseApp.getApplicationContext();
191-
// TODO(b/110178816): Explore moving off of main thread.
192191
mMetadataBundle = extractMetadata(appContext);
193192

194193
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
@@ -75,20 +75,13 @@ public SessionManager(
7575
* (currently that is before onResume finishes) to ensure gauge collection starts on time.
7676
*/
7777
public void setApplicationContext(final Context appContext) {
78-
// Get PerfSession in main thread first, because it is possible that app changes fg/bg state
79-
// which creates a new perfSession, before the following is executed in background thread
80-
final PerfSession appStartSession = perfSession;
8178
// TODO(b/258263016): Migrate to go/firebase-android-executors
8279
@SuppressLint("ThreadPoolCreation")
8380
ExecutorService executorService = Executors.newSingleThreadExecutor();
8481
syncInitFuture =
8582
executorService.submit(
8683
() -> {
8784
gaugeManager.initializeGaugeMetadataManager(appContext);
88-
if (appStartSession.isGaugeAndEventCollectionEnabled()) {
89-
gaugeManager.logGaugeMetadata(
90-
appStartSession.sessionId(), ApplicationProcessState.FOREGROUND);
91-
}
9285
});
9386
}
9487

@@ -134,9 +127,6 @@ public void updatePerfSession(PerfSession perfSession) {
134127
}
135128
}
136129

137-
// Log the gauge metadata event if data collection is enabled.
138-
logGaugeMetadataIfCollectionEnabled(appStateMonitor.getAppState());
139-
140130
// Start of stop the gauge data collection.
141131
startOrStopCollectingGauges(appStateMonitor.getAppState());
142132
}
@@ -148,7 +138,6 @@ public void updatePerfSession(PerfSession perfSession) {
148138
* this does not reset the perfSession.
149139
*/
150140
public void initializeGaugeCollection() {
151-
logGaugeMetadataIfCollectionEnabled(ApplicationProcessState.FOREGROUND);
152141
startOrStopCollectingGauges(ApplicationProcessState.FOREGROUND);
153142
}
154143

@@ -176,12 +165,6 @@ public void unregisterForSessionUpdates(WeakReference<SessionAwareObject> client
176165
}
177166
}
178167

179-
private void logGaugeMetadataIfCollectionEnabled(ApplicationProcessState appState) {
180-
if (perfSession.isGaugeAndEventCollectionEnabled()) {
181-
gaugeManager.logGaugeMetadata(perfSession.sessionId(), appState);
182-
}
183-
}
184-
185168
private void startOrStopCollectingGauges(ApplicationProcessState appState) {
186169
if (perfSession.isGaugeAndEventCollectionEnabled()) {
187170
gaugeManager.startCollectingGauges(perfSession, appState);

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
@@ -73,16 +73,16 @@ private GaugeManager() {
7373
TransportManager.getInstance(),
7474
ConfigResolver.getInstance(),
7575
null,
76-
new Lazy<>(() -> new CpuGaugeCollector()),
77-
new Lazy<>(() -> new MemoryGaugeCollector()));
76+
new Lazy<>(CpuGaugeCollector::new),
77+
new Lazy<>(MemoryGaugeCollector::new));
7878
}
7979

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

@@ -141,7 +141,7 @@ public void startCollectingGauges(
141141
gaugeManagerDataCollectionJob =
142142
gaugeManagerExecutor
143143
.get()
144-
.scheduleAtFixedRate(
144+
.scheduleWithFixedDelay(
145145
() -> {
146146
syncFlush(sessionIdForScheduledTask, applicationProcessStateForScheduledTask);
147147
},

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
import com.google.firebase.perf.util.StorageUnit;
2323
import com.google.firebase.perf.util.Utils;
2424
import com.google.firebase.perf.v1.GaugeMetadata;
25+
import java.io.BufferedReader;
26+
import java.io.FileReader;
27+
import java.io.IOException;
28+
import java.util.regex.Matcher;
29+
import java.util.regex.Pattern;
2530

2631
/**
2732
* The {@code GaugeMetadataManager} class is responsible for collecting {@link GaugeMetadata}
@@ -68,4 +73,23 @@ public int getMaxEncouragedAppJavaHeapMemoryKb() {
6873
public int getDeviceRamSizeKb() {
6974
return Utils.saturatedIntCast(StorageUnit.BYTES.toKilobytes(memoryInfo.totalMem));
7075
}
76+
77+
/** Returns the total ram size of the device (in kilobytes) by reading the "proc/meminfo" file. */
78+
@VisibleForTesting
79+
int readTotalRAM(String procFileName) {
80+
try (BufferedReader br = new BufferedReader(new FileReader(procFileName))) {
81+
for (String s = br.readLine(); s != null; s = br.readLine()) {
82+
if (s.startsWith("MemTotal")) {
83+
Matcher m = Pattern.compile("\\d+").matcher(s);
84+
return m.find() ? Integer.parseInt(m.group()) : 0;
85+
}
86+
}
87+
} catch (IOException ioe) {
88+
logger.warn("Unable to read '" + procFileName + "' file: " + ioe.getMessage());
89+
} catch (NumberFormatException nfe) {
90+
logger.warn("Unable to parse '" + procFileName + "' file: " + nfe.getMessage());
91+
}
92+
93+
return 0;
94+
}
7195
}

0 commit comments

Comments
 (0)