Merge "Add ability to dump events in a timeline view."
This commit is contained in:
@@ -268,6 +268,23 @@ public class Log {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dumps the events in a timeline format.
|
||||||
|
* @param pw The {@link IndentingPrintWriter} to write to.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static void dumpEventsTimeline(IndentingPrintWriter pw) {
|
||||||
|
// If the Events logger has not been initialized, then there have been no events logged.
|
||||||
|
// Don't load it now!
|
||||||
|
synchronized (sSingletonSync) {
|
||||||
|
if (sEventManager != null) {
|
||||||
|
getEventManager().dumpEventsTimeline(pw);
|
||||||
|
} else {
|
||||||
|
pw.println("No Historical Events Logged.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable or disable extended telecom logging.
|
* Enable or disable extended telecom logging.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package android.telecom.Logging;
|
|||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.telecom.Log;
|
import android.telecom.Log;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.Pair;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.internal.util.IndentingPrintWriter;
|
import com.android.internal.util.IndentingPrintWriter;
|
||||||
@@ -27,6 +28,7 @@ import java.text.DateFormat;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.IllegalFormatException;
|
import java.util.IllegalFormatException;
|
||||||
@@ -35,6 +37,7 @@ import java.util.List;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A utility class that provides the ability to define Events that a subsystem deems important, and
|
* A utility class that provides the ability to define Events that a subsystem deems important, and
|
||||||
@@ -49,6 +52,7 @@ public class EventManager {
|
|||||||
public static final String TAG = "Logging.Events";
|
public static final String TAG = "Logging.Events";
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static final int DEFAULT_EVENTS_TO_CACHE = 10; // Arbitrarily chosen.
|
public static final int DEFAULT_EVENTS_TO_CACHE = 10; // Arbitrarily chosen.
|
||||||
|
private final DateFormat sDateFormat = new SimpleDateFormat("HH:mm:ss.SSS");
|
||||||
|
|
||||||
public interface Loggable {
|
public interface Loggable {
|
||||||
/**
|
/**
|
||||||
@@ -169,7 +173,6 @@ public class EventManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final DateFormat sDateFormat = new SimpleDateFormat("HH:mm:ss.SSS");
|
|
||||||
private final List<Event> mEvents = new LinkedList<>();
|
private final List<Event> mEvents = new LinkedList<>();
|
||||||
private final Loggable mRecordEntry;
|
private final Loggable mRecordEntry;
|
||||||
|
|
||||||
@@ -308,6 +311,41 @@ public class EventManager {
|
|||||||
pw.decreaseIndent();
|
pw.decreaseIndent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dumps events in a timeline format.
|
||||||
|
* @param pw The {@link IndentingPrintWriter} to output the timeline to.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public void dumpEventsTimeline(IndentingPrintWriter pw) {
|
||||||
|
pw.println("Historical Events (sorted by time):");
|
||||||
|
|
||||||
|
// Flatten event records out for sorting.
|
||||||
|
List<Pair<Loggable, Event>> events = new ArrayList<>();
|
||||||
|
for (EventRecord er : mEventRecords) {
|
||||||
|
for (Event ev : er.getEvents()) {
|
||||||
|
events.add(new Pair<>(er.getRecordEntry(), ev));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort by event time.
|
||||||
|
Comparator<Pair<Loggable, Event>> byEventTime = (e1, e2) -> {
|
||||||
|
return Long.compare(e1.second.time, e2.second.time);
|
||||||
|
};
|
||||||
|
events.sort(byEventTime);
|
||||||
|
|
||||||
|
pw.increaseIndent();
|
||||||
|
for (Pair<Loggable, Event> event : events) {
|
||||||
|
pw.print(sDateFormat.format(new Date(event.second.time)));
|
||||||
|
pw.print(",");
|
||||||
|
pw.print(event.first.getId());
|
||||||
|
pw.print(",");
|
||||||
|
pw.print(event.second.eventId);
|
||||||
|
pw.print(",");
|
||||||
|
pw.println(event.second.data);
|
||||||
|
}
|
||||||
|
pw.decreaseIndent();
|
||||||
|
}
|
||||||
|
|
||||||
public void changeEventCacheSize(int newSize) {
|
public void changeEventCacheSize(int newSize) {
|
||||||
|
|
||||||
// Resize the event queue.
|
// Resize the event queue.
|
||||||
|
|||||||
Reference in New Issue
Block a user