Merge "Adds StatsLatencyLogger library." into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
18b9d159ce
@@ -110,6 +110,11 @@ public class StatsLogCompatManager extends StatsLogManager {
|
|||||||
return new StatsCompatLogger(mContext, mActivityContext);
|
return new StatsCompatLogger(mContext, mActivityContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected StatsLatencyLogger createLatencyLogger() {
|
||||||
|
return new StatsCompatLatencyLogger(mContext, mActivityContext);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Synchronously writes an itemInfo to stats log
|
* Synchronously writes an itemInfo to stats log
|
||||||
*/
|
*/
|
||||||
@@ -422,6 +427,61 @@ public class StatsLogCompatManager extends StatsLogManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helps to construct and log statsd compatible latency events.
|
||||||
|
*/
|
||||||
|
private static class StatsCompatLatencyLogger implements StatsLatencyLogger {
|
||||||
|
private final Context mContext;
|
||||||
|
private final Optional<ActivityContext> mActivityContext;
|
||||||
|
private InstanceId mInstanceId = DEFAULT_INSTANCE_ID;
|
||||||
|
private LatencyType mType = LatencyType.UNKNOWN;
|
||||||
|
private long mLatencyInMillis;
|
||||||
|
|
||||||
|
StatsCompatLatencyLogger(Context context, ActivityContext activityContext) {
|
||||||
|
mContext = context;
|
||||||
|
mActivityContext = Optional.ofNullable(activityContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StatsLatencyLogger withInstanceId(InstanceId instanceId) {
|
||||||
|
this.mInstanceId = instanceId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StatsLatencyLogger withType(LatencyType type) {
|
||||||
|
this.mType = type;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StatsLatencyLogger withLatency(long latencyInMillis) {
|
||||||
|
this.mLatencyInMillis = latencyInMillis;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void log(EventEnum event) {
|
||||||
|
if (IS_VERBOSE) {
|
||||||
|
String name = (event instanceof Enum) ? ((Enum) event).name() :
|
||||||
|
event.getId() + "";
|
||||||
|
|
||||||
|
Log.d(TAG, mInstanceId == DEFAULT_INSTANCE_ID
|
||||||
|
? String.format("\n%s = %dms\n", name, mLatencyInMillis)
|
||||||
|
: String.format("\n%s = %dms (InstanceId:%s)\n", name,
|
||||||
|
mLatencyInMillis, mInstanceId));
|
||||||
|
}
|
||||||
|
|
||||||
|
SysUiStatsLog.write(SysUiStatsLog.LAUNCHER_LATENCY,
|
||||||
|
event.getId(), // event_id
|
||||||
|
mInstanceId.getId(), // instance_id
|
||||||
|
0, // package_id
|
||||||
|
mLatencyInMillis, // latency_in_millis
|
||||||
|
mType.getId() //type
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static int getCardinality(LauncherAtom.ItemInfo info) {
|
private static int getCardinality(LauncherAtom.ItemInfo info) {
|
||||||
switch (info.getContainerInfo().getContainerCase()) {
|
switch (info.getContainerInfo().getContainerCase()) {
|
||||||
case PREDICTED_HOTSEAT_CONTAINER:
|
case PREDICTED_HOTSEAT_CONTAINER:
|
||||||
|
|||||||
@@ -562,7 +562,7 @@ public class StatsLogManager implements ResourceBasedOverride {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helps to construct and write the log message.
|
* Helps to construct and log launcher event.
|
||||||
*/
|
*/
|
||||||
public interface StatsLogger {
|
public interface StatsLogger {
|
||||||
|
|
||||||
@@ -661,6 +661,58 @@ public class StatsLogManager implements ResourceBasedOverride {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helps to construct and log latency event.
|
||||||
|
*/
|
||||||
|
public interface StatsLatencyLogger {
|
||||||
|
|
||||||
|
enum LatencyType {
|
||||||
|
UNKNOWN(0),
|
||||||
|
COLD(1),
|
||||||
|
HOT(2);
|
||||||
|
|
||||||
|
private final int mId;
|
||||||
|
|
||||||
|
LatencyType(int id) {
|
||||||
|
this.mId = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return mId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets {@link InstanceId} of log message.
|
||||||
|
*/
|
||||||
|
default StatsLatencyLogger withInstanceId(InstanceId instanceId) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets latency of the event.
|
||||||
|
*/
|
||||||
|
default StatsLatencyLogger withLatency(long latencyInMillis) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets {@link LatencyType} of log message.
|
||||||
|
*/
|
||||||
|
default StatsLatencyLogger withType(LatencyType type) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the final message and logs it as {@link EventEnum}.
|
||||||
|
*/
|
||||||
|
default void log(EventEnum event) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns new logger object.
|
* Returns new logger object.
|
||||||
*/
|
*/
|
||||||
@@ -672,11 +724,27 @@ public class StatsLogManager implements ResourceBasedOverride {
|
|||||||
return logger;
|
return logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns new latency logger object.
|
||||||
|
*/
|
||||||
|
public StatsLatencyLogger latencyLogger() {
|
||||||
|
StatsLatencyLogger logger = createLatencyLogger();
|
||||||
|
if (mInstanceId != null) {
|
||||||
|
logger.withInstanceId(mInstanceId);
|
||||||
|
}
|
||||||
|
return logger;
|
||||||
|
}
|
||||||
|
|
||||||
protected StatsLogger createLogger() {
|
protected StatsLogger createLogger() {
|
||||||
return new StatsLogger() {
|
return new StatsLogger() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected StatsLatencyLogger createLatencyLogger() {
|
||||||
|
return new StatsLatencyLogger() {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets InstanceId to every new {@link StatsLogger} object returned by {@link #logger()} when
|
* Sets InstanceId to every new {@link StatsLogger} object returned by {@link #logger()} when
|
||||||
* not-null.
|
* not-null.
|
||||||
|
|||||||
Reference in New Issue
Block a user