Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 66686890 authored by Tyler Gunn's avatar Tyler Gunn Committed by android-build-merger
Browse files

Merge "Add ability to dump events in a timeline view." am: 255a171c am: 3b27d696 am: a1c22593

am: bfea5cdb

Change-Id: Ib1a0fa4221890b02937bc44d3293a65b5508d12f
parents 34cccbf5 bfea5cdb
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -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.
     *
+39 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.telecom.Logging;
import android.annotation.NonNull;
import android.telecom.Log;
import android.text.TextUtils;
import android.util.Pair;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.IndentingPrintWriter;
@@ -27,6 +28,7 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.IllegalFormatException;
@@ -35,6 +37,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
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
@@ -49,6 +52,7 @@ public class EventManager {
    public static final String TAG = "Logging.Events";
    @VisibleForTesting
    public static final int DEFAULT_EVENTS_TO_CACHE = 10;  // Arbitrarily chosen.
    private final DateFormat sDateFormat = new SimpleDateFormat("HH:mm:ss.SSS");

    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 Loggable mRecordEntry;

@@ -308,6 +311,41 @@ public class EventManager {
        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) {

        // Resize the event queue.