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

Commit 4e008a8a authored by Kean Mariotti's avatar Kean Mariotti
Browse files

Traces with real-to-elapsed time offset

Add real_to_elapsed_time_offset_nanos field to protobuf traces:
- Accessibility
- IME
- WindowManager

Bug: 235196806
Change-Id: I922a85edb940719c27028623c26208ece016b9b2
Test: record and view accessibility + IME + WindowManager traces with winscope
parent ce2a426a
Loading
Loading
Loading
Loading
+15 −1
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.os.Build.IS_USER;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.ServiceManager.ServiceNotFoundException;
import android.os.ServiceManager.ServiceNotFoundException;
import android.os.SystemClock;
import android.util.Log;
import android.util.Log;
import android.util.proto.ProtoOutputStream;
import android.util.proto.ProtoOutputStream;
import android.view.inputmethod.InputMethodEditorTraceProto.InputMethodClientsTraceFileProto;
import android.view.inputmethod.InputMethodEditorTraceProto.InputMethodClientsTraceFileProto;
@@ -34,6 +35,7 @@ import com.android.internal.util.TraceBuffer;
import java.io.File;
import java.io.File;
import java.io.IOException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.PrintWriter;
import java.util.concurrent.TimeUnit;


/**
/**
 * An implementation of {@link ImeTracing} for the system_server process.
 * An implementation of {@link ImeTracing} for the system_server process.
@@ -139,18 +141,30 @@ class ImeTracingServerImpl extends ImeTracing {


    private void writeTracesToFilesLocked() {
    private void writeTracesToFilesLocked() {
        try {
        try {
            long timeOffsetNs =
                    TimeUnit.NANOSECONDS.convert(System.currentTimeMillis(), TimeUnit.NANOSECONDS)
                    - SystemClock.elapsedRealtimeNanos();

            ProtoOutputStream clientsProto = new ProtoOutputStream();
            ProtoOutputStream clientsProto = new ProtoOutputStream();
            clientsProto.write(InputMethodClientsTraceFileProto.MAGIC_NUMBER,
            clientsProto.write(InputMethodClientsTraceFileProto.MAGIC_NUMBER,
                    MAGIC_NUMBER_CLIENTS_VALUE);
                    MAGIC_NUMBER_CLIENTS_VALUE);
            clientsProto.write(InputMethodClientsTraceFileProto.REAL_TO_ELAPSED_TIME_OFFSET_NANOS,
                    timeOffsetNs);
            mBufferClients.writeTraceToFile(mTraceFileClients, clientsProto);
            mBufferClients.writeTraceToFile(mTraceFileClients, clientsProto);


            ProtoOutputStream imsProto = new ProtoOutputStream();
            ProtoOutputStream imsProto = new ProtoOutputStream();
            imsProto.write(InputMethodServiceTraceFileProto.MAGIC_NUMBER, MAGIC_NUMBER_IMS_VALUE);
            imsProto.write(InputMethodServiceTraceFileProto.MAGIC_NUMBER,
                    MAGIC_NUMBER_IMS_VALUE);
            imsProto.write(InputMethodServiceTraceFileProto.REAL_TO_ELAPSED_TIME_OFFSET_NANOS,
                    timeOffsetNs);
            mBufferIms.writeTraceToFile(mTraceFileIms, imsProto);
            mBufferIms.writeTraceToFile(mTraceFileIms, imsProto);


            ProtoOutputStream immsProto = new ProtoOutputStream();
            ProtoOutputStream immsProto = new ProtoOutputStream();
            immsProto.write(InputMethodManagerServiceTraceFileProto.MAGIC_NUMBER,
            immsProto.write(InputMethodManagerServiceTraceFileProto.MAGIC_NUMBER,
                    MAGIC_NUMBER_IMMS_VALUE);
                    MAGIC_NUMBER_IMMS_VALUE);
            immsProto.write(
                    InputMethodManagerServiceTraceFileProto.REAL_TO_ELAPSED_TIME_OFFSET_NANOS,
                    timeOffsetNs);
            mBufferImms.writeTraceToFile(mTraceFileImms, immsProto);
            mBufferImms.writeTraceToFile(mTraceFileImms, immsProto);


            resetBuffers();
            resetBuffers();
+4 −0
Original line number Original line Diff line number Diff line
@@ -39,6 +39,10 @@ message AccessibilityTraceFileProto {


    optional fixed64 magic_number = 1;  /* Must be the first field, set to value in MagicNumber */
    optional fixed64 magic_number = 1;  /* Must be the first field, set to value in MagicNumber */
    repeated AccessibilityTraceProto entry = 2;
    repeated AccessibilityTraceProto entry = 2;

    /* offset between real-time clock and elapsed time clock in nanoseconds.
       Calculated as: 1000000 * System.currentTimeMillis() - SystemClock.elapsedRealtimeNanos() */
    optional fixed64 real_to_elapsed_time_offset_nanos = 3;
}
}


/* one accessibility trace entry. */
/* one accessibility trace entry. */
+4 −0
Original line number Original line Diff line number Diff line
@@ -38,6 +38,10 @@ message WindowManagerTraceFileProto {


    optional fixed64 magic_number = 1;  /* Must be the first field, set to value in MagicNumber */
    optional fixed64 magic_number = 1;  /* Must be the first field, set to value in MagicNumber */
    repeated WindowManagerTraceProto entry = 2;
    repeated WindowManagerTraceProto entry = 2;

    /* offset between real-time clock and elapsed time clock in nanoseconds.
       Calculated as: 1000000 * System.currentTimeMillis() - SystemClock.elapsedRealtimeNanos() */
    optional fixed64 real_to_elapsed_time_offset_nanos = 3;
}
}


/* one window manager trace entry. */
/* one window manager trace entry. */
+12 −0
Original line number Original line Diff line number Diff line
@@ -50,6 +50,10 @@ message InputMethodClientsTraceFileProto {
        in MagicNumber */
        in MagicNumber */
    optional fixed64 magic_number = 1;
    optional fixed64 magic_number = 1;
    repeated InputMethodClientsTraceProto entry = 2;
    repeated InputMethodClientsTraceProto entry = 2;

    /* offset between real-time clock and elapsed time clock in nanoseconds.
       Calculated as: 1000000 * System.currentTimeMillis() - SystemClock.elapsedRealtimeNanos() */
    optional fixed64 real_to_elapsed_time_offset_nanos = 3;
}
}


/* One dump entry for clients that use InputMethod. */
/* One dump entry for clients that use InputMethod. */
@@ -96,6 +100,10 @@ message InputMethodServiceTraceFileProto {
        in MagicNumber */
        in MagicNumber */
    optional fixed64 magic_number = 1;
    optional fixed64 magic_number = 1;
    repeated InputMethodServiceTraceProto entry = 2;
    repeated InputMethodServiceTraceProto entry = 2;

    /* offset between real-time clock and elapsed time clock in nanoseconds.
       Calculated as: 1000000 * System.currentTimeMillis() - SystemClock.elapsedRealtimeNanos() */
    optional fixed64 real_to_elapsed_time_offset_nanos = 3;
}
}


/* One dump entry for InputMethodService. */
/* One dump entry for InputMethodService. */
@@ -129,6 +137,10 @@ message InputMethodManagerServiceTraceFileProto {
        in MagicNumber */
        in MagicNumber */
    optional fixed64 magic_number = 1;
    optional fixed64 magic_number = 1;
    repeated InputMethodManagerServiceTraceProto entry = 2;
    repeated InputMethodManagerServiceTraceProto entry = 2;

    /* offset between real-time clock and elapsed time clock in nanoseconds.
       Calculated as: 1000000 * System.currentTimeMillis() - SystemClock.elapsedRealtimeNanos() */
    optional fixed64 real_to_elapsed_time_offset_nanos = 3;
}
}


/* One dump entry for InputMethodManagerService. */
/* One dump entry for InputMethodManagerService. */
+7 −0
Original line number Original line Diff line number Diff line
@@ -30,6 +30,7 @@ import static com.android.server.accessibility.AccessibilityTraceFileProto.ENTRY
import static com.android.server.accessibility.AccessibilityTraceFileProto.MAGIC_NUMBER;
import static com.android.server.accessibility.AccessibilityTraceFileProto.MAGIC_NUMBER;
import static com.android.server.accessibility.AccessibilityTraceFileProto.MAGIC_NUMBER_H;
import static com.android.server.accessibility.AccessibilityTraceFileProto.MAGIC_NUMBER_H;
import static com.android.server.accessibility.AccessibilityTraceFileProto.MAGIC_NUMBER_L;
import static com.android.server.accessibility.AccessibilityTraceFileProto.MAGIC_NUMBER_L;
import static com.android.server.accessibility.AccessibilityTraceFileProto.REAL_TO_ELAPSED_TIME_OFFSET_NANOS;
import static com.android.server.accessibility.AccessibilityTraceProto.ACCESSIBILITY_SERVICE;
import static com.android.server.accessibility.AccessibilityTraceProto.ACCESSIBILITY_SERVICE;
import static com.android.server.accessibility.AccessibilityTraceProto.CALENDAR_TIME;
import static com.android.server.accessibility.AccessibilityTraceProto.CALENDAR_TIME;
import static com.android.server.accessibility.AccessibilityTraceProto.CALLING_PARAMS;
import static com.android.server.accessibility.AccessibilityTraceProto.CALLING_PARAMS;
@@ -116,6 +117,7 @@ import java.util.Date;
import java.util.HashSet;
import java.util.HashSet;
import java.util.List;
import java.util.List;
import java.util.Set;
import java.util.Set;
import java.util.concurrent.TimeUnit;


/**
/**
 * This class contains the accessibility related logic of the window manager.
 * This class contains the accessibility related logic of the window manager.
@@ -2215,6 +2217,11 @@ final class AccessibilityController {
            try {
            try {
                ProtoOutputStream proto = new ProtoOutputStream();
                ProtoOutputStream proto = new ProtoOutputStream();
                proto.write(MAGIC_NUMBER, MAGIC_NUMBER_VALUE);
                proto.write(MAGIC_NUMBER, MAGIC_NUMBER_VALUE);
                long timeOffsetNs =
                        TimeUnit.NANOSECONDS.convert(System.currentTimeMillis(),
                                                     TimeUnit.NANOSECONDS)
                        - SystemClock.elapsedRealtimeNanos();
                proto.write(REAL_TO_ELAPSED_TIME_OFFSET_NANOS, timeOffsetNs);
                mBuffer.writeTraceToFile(mTraceFile, proto);
                mBuffer.writeTraceToFile(mTraceFile, proto);
            } catch (IOException e) {
            } catch (IOException e) {
                Slog.e(TAG, "Unable to write buffer to file", e);
                Slog.e(TAG, "Unable to write buffer to file", e);
Loading