com.eg.agent.android.trace.TraceMachine Maven / Gradle / Ivy
package com.eg.agent.android.trace;
import com.eg.agent.android.AndroidAgentImpl;
import com.eg.agent.android.DataSendToRum;
import com.eg.agent.android.harvest.ActivityHistory;
import com.eg.agent.android.harvest.ActivitySighting;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public class TraceMachine {
public static final String ACTIVITY_METRIC_PREFIX = "Mobile/Activity/Name/";
public static final String ACTIVITY_BACKGROUND_METRIC_PREFIX = "Mobile/Activity/Background/Name/";
private static final Collection traceListeners = new CopyOnWriteArrayList();
private static final List activityHistory = new CopyOnWriteArrayList();
static long entryTime;
static long exitTime;
static String method="";
static String category="";
static String APItype="";
public static void startTracing(String className) {
Trace.ActiviteClassName = className;
}
public static void enterMethod(String method, String category, String APItype) {
entryTime = System.currentTimeMillis();
TraceMachine.method = method;
TraceMachine.category = category;
TraceMachine.APItype = APItype;
}
public static void exitMethod() {
exitTime = System.currentTimeMillis();
long excution_time = exitTime - entryTime;
try {
/*Log.e("Trace exit method","Main ");
Log.e("Trace exit method","getActiviteClassName "+Trace.getActiviteClassName());
Log.e("Trace exit method","method "+method);
Log.e("Trace exit method","category "+category);*/
AndroidAgentImpl androidAgent=new AndroidAgentImpl();
/* Log.e("Trace exit method","excution_time "+excution_time);
Log.e("Trace exit method","APItype "+APItype);
Log.e("Trace exit method","app "+androidAgent.getApplicationInformation().getAppName());
Log.e("Trace exit method","dev "+androidAgent.getDeviceInformation());
Log.e("Trace exit method","resrc "+androidAgent.getResourceInforamtion());*/
DataSendToRum.SendData(Trace.getActiviteClassName(), method, category, excution_time, APItype);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void enterMethod(Trace trace, String method, ArrayList APItype1) {
entryTime = System.currentTimeMillis();
System.out.println(" Trace method in " + method.substring(method.indexOf("#") + 1));
System.out.println(" Trace displayName in " + method);
TraceMachine.method = method;
TraceMachine.category = "traceEnter";
TraceMachine.APItype = "traceEnter";
enterMethod(method, category, APItype);
}
public static void setCurrentTraceParam(String key, Object value) {
System.out.println(" key " + key + " value " + value);
}
public static String getCurrentScope() {
try {
/*if (isTracingInactive()) {
return null;
}
if (traceMachineInterface == null || traceMachineInterface.isUIThread()) {
return traceMachine.activityTrace.rootTrace.metricName;
}
return traceMachine.activityTrace.rootTrace.metricBackgroundName;*/
} catch (Exception e) {
/* log.error("Caught error while calling getCurrentScope()", e);
AgentHealth.noticeException(e);*/
return null;
}
return null;
}
public static String formatActivityMetricName(String name) {
return ACTIVITY_METRIC_PREFIX + name;
}
public static String formatActivityBackgroundMetricName(String name) {
return ACTIVITY_BACKGROUND_METRIC_PREFIX + name;
}
public static void addTraceListener(TraceLifecycleAware listener) {
traceListeners.add(listener);
}
public static void removeTraceListener(TraceLifecycleAware listener) {
traceListeners.remove(listener);
}
public static ActivityHistory getActivityHistory() {
return new ActivityHistory(activityHistory);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy