Skip to content

Commit

Permalink
feat(performance): add missing methods (#505)
Browse files Browse the repository at this point in the history
Remove record implementation from android.
  • Loading branch information
ebarooni committed Dec 11, 2024
1 parent 9aa213d commit a83e826
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 115 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package io.capawesome.capacitorjs.plugins.firebase.performance;

import androidx.annotation.Nullable;

import com.google.firebase.perf.metrics.Trace;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class FirebasePerformance {

private HashMap<String, Trace> traces = new HashMap<String, Trace>();
private ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);

public void startTrace(String traceName) {
Trace trace = this.getFirebasePerformanceInstance().newTrace(traceName);
Expand Down Expand Up @@ -70,36 +65,6 @@ public static long getMetric(Trace trace, String metricName) {
return trace.getLongMetric(metricName);
}

public void record(
Trace trace,
String traceName,
long startTime,
long duration,
@Nullable Map<String, String> attributes,
@Nullable Map<String, Long> metrics
) {
long currentTime = System.currentTimeMillis();
long startDelay = Math.max(0, (startTime - currentTime));
if (attributes != null) {
for (String key : attributes.keySet()) {
FirebasePerformance.putAttribute(trace, key, attributes.get(key));
}
}
if (metrics != null) {
for (String key : metrics.keySet()) {
FirebasePerformance.putMetric(trace, key, metrics.get(key));
}
}
this.scheduler.schedule(
() -> {
this.startTrace(traceName);
scheduler.schedule(() -> this.stopTrace(traceName), duration, TimeUnit.MILLISECONDS);
},
startDelay,
TimeUnit.MILLISECONDS
);
}

private com.google.firebase.perf.FirebasePerformance getFirebasePerformanceInstance() {
return com.google.firebase.perf.FirebasePerformance.getInstance();
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -297,44 +297,6 @@ public void getMetric(PluginCall call) {

@PluginMethod(returnType = PluginMethod.RETURN_NONE)
public void record(PluginCall call) {
try {
String traceName = call.getString("traceName");
if (traceName == null) {
call.reject(FirebasePerformancePlugin.ERROR_TRACE_NAME_MISSING);
return;
}
Long startTime = call.getLong("startTime");
if (startTime == null) {
call.reject(FirebasePerformancePlugin.ERROR_START_TIME_MISSING);
return;
}
Long duration = call.getLong("duration");
if (duration == null) {
call.reject(FirebasePerformancePlugin.ERROR_DURATION_MISSING);
return;
}

JSObject options = call.getObject("options");
Map<String, Long> mappedMetrics = null;
Map<String, String> mappedAttributes = null;

if (options != null) {
JSObject metrics = options.getJSObject("metrics");
mappedMetrics = FirebasePerformanceHelper.jsObjectToMetricsMap(metrics == null ? new JSObject() : metrics);
JSObject attributes = options.getJSObject("attributes");
mappedAttributes = FirebasePerformanceHelper.jsObjectToAttributesMap(attributes == null ? new JSObject() : attributes);
}

Trace trace = implementation.getTraceByName(traceName);
if (trace == null) {
call.reject(ERROR_TRACE_NOT_FOUND);
return;
}
implementation.record(trace, traceName, startTime, duration, mappedAttributes, mappedMetrics);
call.resolve();
} catch (Exception exception) {
Logger.error(TAG, exception.getMessage(), exception);
call.reject(exception.getMessage());
}
call.unimplemented("Not implemented on Android.");
}
}

0 comments on commit a83e826

Please sign in to comment.