Skip to content
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

FEC-10148: Profiler Changes #624

Draft
wants to merge 11 commits into
base: dev
Choose a base branch
from
5 changes: 4 additions & 1 deletion playkit/src/main/java/com/kaltura/playkit/PKLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class PKLog {

@NonNull
public final String tag;
private int level = VERBOSE;
private int level;

public enum Level {
verbose(VERBOSE), debug(DEBUG), info(INFO), warn(WARN), error(ERROR), off(Integer.MAX_VALUE);
Expand Down Expand Up @@ -103,6 +103,9 @@ private PKLog(@NonNull String tag) {
return new PKLog(tag);
}

public boolean isLoggable(Level level) {
return Log.isLoggable(tag, level.value);
}

// VERBOSE

Expand Down
22 changes: 16 additions & 6 deletions playkit/src/main/java/com/kaltura/playkit/PlayKitManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import android.content.Context;
import androidx.annotation.Nullable;

import com.google.gson.Gson;
import com.kaltura.playkit.player.MediaSupport;
import com.kaltura.playkit.profiler.PlayKitProfiler;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -56,24 +58,32 @@ static PKPlugin createPlugin(String name) {
public static Player loadPlayer(Context context, @Nullable PKPluginConfigs pluginConfigs, MessageBus messageBus) {

MediaSupport.initializeDrm(context, null);
initializeProfiler(context);

if (shouldSendDeviceCapabilitiesReport) {
PKDeviceCapabilities.maybeSendReport(context);
}
PKDeviceCapabilities.maybeSendReport(context);

PlayerLoader playerLoader = new PlayerLoader(context, messageBus);
playerLoader.load(pluginConfigs != null ? pluginConfigs : new PKPluginConfigs());
return playerLoader;
}

public static Player loadPlayer(Context context, @Nullable PKPluginConfigs pluginConfigs) {
private static void initializeProfiler(Context context) {
Gson gson = new Gson();
// TODO: 07/06/2020 This should come from the backend
final String json = "{\"postURL\": \"https://dtvqq1tbxf.execute-api.us-east-1.amazonaws.com/default/profilerLogCollector\", \"sendPercentage\": 100}";
final ProfilerConfig profilerConfig = gson.fromJson(json, ProfilerConfig.class);
PlayKitProfiler.init(context, profilerConfig);
}

public static Player loadPlayer(Context context, @Nullable PKPluginConfigs pluginConfigs) {
return loadPlayer(context, pluginConfigs, null);
}

public static final class ProfilerConfig {
public String postURL;
public float sendPercentage;

public static void disableDeviceCapabilitiesReport() {
shouldSendDeviceCapabilitiesReport = false;
private ProfilerConfig() {}
}
}

80 changes: 78 additions & 2 deletions playkit/src/main/java/com/kaltura/playkit/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import androidx.annotation.NonNull;

import android.telephony.TelephonyManager;
import android.util.Base64;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;

import java.io.BufferedInputStream;
Expand Down Expand Up @@ -293,4 +296,77 @@ public static String getDeviceType(Context context) {
}
return deviceType;
}

public static class GsonObject {
private final JsonObject jo = new JsonObject();

public JsonObject jsonObject() {
return jo;
}

public GsonObject add(String key, String value) {
jo.addProperty(key, value);
return this;
}

public GsonObject add(String key, Number value) {
jo.addProperty(key, value);
return this;
}

public GsonObject add(String key, long value) {
jo.addProperty(key, value);
return this;
}

public GsonObject add(String key, float value) {
jo.addProperty(key, value);
return this;
}

public GsonObject add(String key, boolean value) {
jo.addProperty(key, value);
return this;
}

public GsonObject add(String key, Throwable value) {
jo.addProperty(key, "" + value);
return this;
}

public GsonObject add(String key, JsonElement value) {
jo.add(key, value);
return this;
}

public GsonObject add(String key, @Nullable GsonObject value) {
jo.add(key, value != null ? value.jo : null);
return this;
}

public GsonObject addAll(@Nullable JsonObject otherJo) {
if (otherJo != null) {
for (Map.Entry<String, JsonElement> entry : otherJo.entrySet()) {
jo.add(entry.getKey(), entry.getValue());
}
}
return this;
}

public GsonObject addAll(@Nullable GsonObject otherGo) {
if (otherGo != null) {
for (Map.Entry<String, JsonElement> entry : otherGo.jo.entrySet()) {
jo.add(entry.getKey(), entry.getValue());
}
}
return this;
}

public GsonObject addTime(String key, long millis) {
jo.addProperty(key, millis / 1000f);
return this;
}

public void end() {}
}
}
18 changes: 18 additions & 0 deletions playkit/src/main/java/com/kaltura/playkit/player/Profiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import com.kaltura.android.exoplayer2.analytics.AnalyticsListener;
import com.kaltura.playkit.PKMediaConfig;
import com.kaltura.playkit.Utils;
import com.kaltura.playkit.profiler.PlayKitProfiler;

import okhttp3.EventListener;

Expand All @@ -28,4 +30,20 @@ public void onDurationChanged(long duration) {/*NOOP*/}

public void onApplicationPaused() {/*NOOP*/}
public void onApplicationResumed() {/*NOOP*/}

public static class Event extends Utils.GsonObject {

private final PlayKitProfiler profiler;

public Event(PlayKitProfiler profiler, String name) {
this.profiler = profiler;
add("_ts", profiler.timestamp());
add("_name", name);
}

@Override
public void end() {
profiler.append(jsonObject());
}
}
}
Loading