Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android]added generic performance event
Browse files Browse the repository at this point in the history
  • Loading branch information
osana committed Jan 28, 2019
1 parent b53ea9b commit 366f43b
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.mapbox.mapboxsdk.maps;

import android.os.Bundle;

import com.mapbox.mapboxsdk.offline.OfflineRegionDefinition;

/**
* Definition of TelemetryImpl collection
* Definition of TelemetryImpl collection.
* Use{@link TelemetryDefinition} for posting the event.
*/
public interface TelemetryDefinition {

Expand Down Expand Up @@ -46,4 +49,11 @@ public interface TelemetryDefinition {
* @param offlineDefinition the offline region definition
*/
void onCreateOfflineRegion(OfflineRegionDefinition offlineDefinition);

/**
* Register a performance event.
*
* @param data performance event data
*/
void onPerformanceEvent(Bundle data);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.mapbox.mapboxsdk.module.telemetry;

import com.mapbox.android.telemetry.Event;

import android.os.Bundle;
import android.os.Parcel;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
* Generic Performance Event that can be used for performance measurements.
* Customer measurements can be added to the bundle.
*/
public class PerformanceEvent extends Event {
private static final String PERFORMANCE_TRACE = "performance.trace";

private final String event;

private final String created;

private final String sessionId;

private final Bundle data;

private static final SimpleDateFormat DATE_FORMAT =
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US);

PerformanceEvent(String sessionId, Bundle data) {
this.event = PERFORMANCE_TRACE;
this.created = DATE_FORMAT.format(new Date());
this.sessionId = sessionId;
this.data = data;
}

private PerformanceEvent(Parcel in) {
this.event = in.readString();
this.created = in.readString();
this.sessionId = in.readString();
this.data = in.readBundle();
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeString(event);
parcel.writeString(created);
parcel.writeString(sessionId);
parcel.writeBundle(data);
}

public static final Creator<PerformanceEvent> CREATOR = new Creator<PerformanceEvent>() {
@Override
public PerformanceEvent createFromParcel(Parcel in) {
return new PerformanceEvent(in);
}

@Override
public PerformanceEvent[] newArray(int size) {
return new PerformanceEvent[size];
}
};
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mapbox.mapboxsdk.module.telemetry;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.mapbox.android.telemetry.AppUserTurnstile;
Expand All @@ -17,6 +18,8 @@
import com.mapbox.mapboxsdk.offline.OfflineRegionDefinition;
import com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition;

import java.util.UUID;

public class TelemetryImpl implements TelemetryDefinition {

@Nullable
Expand Down Expand Up @@ -105,4 +108,11 @@ public void onCreateOfflineRegion(@NonNull OfflineRegionDefinition offlineDefini
offlineDefinition.getStyleURL())
);
}

@Override
public void onPerformanceEvent(Bundle data) {
if (data != null && !data.isEmpty()) {
telemetry.push(new PerformanceEvent(UUID.randomUUID().toString(), data));
}
}
}

0 comments on commit 366f43b

Please sign in to comment.