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

Commit df1742ed authored by John Reck's avatar John Reck
Browse files

Overhaul GraphicsStatsService

* LRU cache of recently-used is dead, replaced
  disk storage
* ASHMEM size is read from native by the system service,
  no longer requires keeping a sizeof() in sync with a
  constant in Java
* Supports dumping in proto format by passing --proto
* Rotates logs on a daily basis
* Keeps a history of the most recent 3 days

Bug: 33705836
Test: Manual. Verified log rotating works by setting it up to
rotate every minute instead of day. Confirmed /data/system/graphicsstats
only has the most recent 3 entries after several minutes

Change-Id: Ib84bafb26c58701cc86f123236de4fff01aaa4aa
parent f8a42009
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -322,6 +322,7 @@ LOCAL_SRC_FILES += \
	core/java/android/view/IAppTransitionAnimationSpecsFuture.aidl \
	core/java/android/view/IDockedStackListener.aidl \
	core/java/android/view/IGraphicsStats.aidl \
	core/java/android/view/IGraphicsStatsCallback.aidl \
	core/java/android/view/IInputFilter.aidl \
	core/java/android/view/IInputFilterHost.aidl \
	core/java/android/view/IOnKeyguardExitResult.aidl \
@@ -1421,6 +1422,24 @@ endif

include $(BUILD_JAVA_LIBRARY)

# ====  c++ proto device library  ==============================
include $(CLEAR_VARS)
LOCAL_MODULE := libplatformprotos
# b/34740546, work around clang-tidy segmentation fault.
LOCAL_TIDY_CHECKS := -modernize*
LOCAL_PROTOC_OPTIMIZE_TYPE := lite
LOCAL_PROTOC_FLAGS := \
    --include_source_info \
    -Iexternal/protobuf/src
LOCAL_SRC_FILES := \
    $(call all-proto-files-under, core/proto) \
    $(call all-proto-files-under, libs/incident/proto)
LOCAL_C_INCLUDES := \
    $(call generated-sources-dir-for,STATIC_LIBRARIES,libplatformprotos,)/proto
LOCAL_EXPORT_C_INCLUDES := \
    $(call generated-sources-dir-for,STATIC_LIBRARIES,libplatformprotos,)/proto
include $(BUILD_STATIC_LIBRARY)

# ====  c++ proto host library  ==============================
include $(CLEAR_VARS)
LOCAL_MODULE := libplatformprotos
+2 −1
Original line number Diff line number Diff line
@@ -17,10 +17,11 @@
package android.view;

import android.os.ParcelFileDescriptor;
import android.view.IGraphicsStatsCallback;

/**
 * @hide
 */
interface IGraphicsStats {
    ParcelFileDescriptor requestBufferForProcess(String packageName, IBinder token);
    ParcelFileDescriptor requestBufferForProcess(String packageName, IGraphicsStatsCallback callback);
}
+24 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2017, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.view;

/**
 * @hide
 */
oneway interface IGraphicsStatsCallback {
    void onRotateGraphicsStatsBuffer();
}
+38 −30
Original line number Diff line number Diff line
@@ -25,9 +25,9 @@ import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.AnimatedVectorDrawable;
import android.os.Binder;
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.Trace;
import android.util.Log;
@@ -248,10 +248,10 @@ public final class ThreadedRenderer {
     *
     * @return A threaded renderer backed by OpenGL.
     */
    public static ThreadedRenderer create(Context context, boolean translucent) {
    public static ThreadedRenderer create(Context context, boolean translucent, String name) {
        ThreadedRenderer renderer = null;
        if (isAvailable()) {
            renderer = new ThreadedRenderer(context, translucent);
            renderer = new ThreadedRenderer(context, translucent, name);
        }
        return renderer;
    }
@@ -275,10 +275,6 @@ public final class ThreadedRenderer {
        nOverrideProperty(name, value);
    }

    public static void dumpProfileData(byte[] data, FileDescriptor fd) {
        nDumpProfileData(data, fd);
    }

    // Keep in sync with DrawFrameTask.h SYNC_* flags
    // Nothing interesting to report
    private static final int SYNC_OK = 0;
@@ -334,7 +330,7 @@ public final class ThreadedRenderer {
    private boolean mEnabled;
    private boolean mRequested = true;

    ThreadedRenderer(Context context, boolean translucent) {
    ThreadedRenderer(Context context, boolean translucent, String name) {
        final TypedArray a = context.obtainStyledAttributes(null, R.styleable.Lighting, 0, 0);
        mLightY = a.getDimension(R.styleable.Lighting_lightY, 0);
        mLightZ = a.getDimension(R.styleable.Lighting_lightZ, 0);
@@ -348,6 +344,7 @@ public final class ThreadedRenderer {
        mRootNode = RenderNode.adopt(rootNodePtr);
        mRootNode.setClipToBounds(false);
        mNativeProxy = nCreateProxy(translucent, rootNodePtr);
        nSetName(mNativeProxy, name);

        ProcessInitializer.sInstance.init(context, mNativeProxy);

@@ -814,15 +811,6 @@ public final class ThreadedRenderer {
        nCancelLayerUpdate(mNativeProxy, layer.getDeferredLayerUpdater());
    }

    /**
     * Optional, sets the name of the renderer. Useful for debugging purposes.
     *
     * @param name The name of this renderer, can be null
     */
    void setName(String name) {
        nSetName(mNativeProxy, name);
    }

    /**
     * Blocks until all previously queued work has completed.
     */
@@ -884,20 +872,29 @@ public final class ThreadedRenderer {

    private static class ProcessInitializer {
        static ProcessInitializer sInstance = new ProcessInitializer();
        private static IBinder sProcToken;

        private boolean mInitialized = false;

        private Context mAppContext;
        private IGraphicsStats mGraphicsStatsService;
        private IGraphicsStatsCallback mGraphicsStatsCallback = new IGraphicsStatsCallback.Stub() {
            @Override
            public void onRotateGraphicsStatsBuffer() throws RemoteException {
                rotateBuffer();
            }
        };

        private ProcessInitializer() {}

        synchronized void init(Context context, long renderProxy) {
            if (mInitialized) return;
            mInitialized = true;
            mAppContext = context.getApplicationContext();
            initSched(context, renderProxy);
            initGraphicsStats(context, renderProxy);
            initGraphicsStats();
        }

        private static void initSched(Context context, long renderProxy) {
        private void initSched(Context context, long renderProxy) {
            try {
                int tid = nGetRenderThreadTid(renderProxy);
                ActivityManager.getService().setRenderThread(tid);
@@ -906,17 +903,28 @@ public final class ThreadedRenderer {
            }
        }

        private static void initGraphicsStats(Context context, long renderProxy) {
        private void initGraphicsStats() {
            try {
                IBinder binder = ServiceManager.getService("graphicsstats");
                if (binder == null) return;
                IGraphicsStats graphicsStatsService = IGraphicsStats.Stub
                        .asInterface(binder);
                sProcToken = new Binder();
                final String pkg = context.getApplicationInfo().packageName;
                ParcelFileDescriptor pfd = graphicsStatsService.
                        requestBufferForProcess(pkg, sProcToken);
                nSetProcessStatsBuffer(renderProxy, pfd.getFd());
                mGraphicsStatsService = IGraphicsStats.Stub.asInterface(binder);
                requestBuffer();
            } catch (Throwable t) {
                Log.w(LOG_TAG, "Could not acquire gfx stats buffer", t);
            }
        }

        private void rotateBuffer() {
            nRotateProcessStatsBuffer();
            requestBuffer();
        }

        private void requestBuffer() {
            try {
                final String pkg = mAppContext.getApplicationInfo().packageName;
                ParcelFileDescriptor pfd = mGraphicsStatsService
                        .requestBufferForProcess(pkg, mGraphicsStatsCallback);
                nSetProcessStatsBuffer(pfd.getFd());
                pfd.close();
            } catch (Throwable t) {
                Log.w(LOG_TAG, "Could not acquire gfx stats buffer", t);
@@ -936,7 +944,8 @@ public final class ThreadedRenderer {

    static native void setupShadersDiskCache(String cacheFile);

    private static native void nSetProcessStatsBuffer(long nativeProxy, int fd);
    private static native void nRotateProcessStatsBuffer();
    private static native void nSetProcessStatsBuffer(int fd);
    private static native int nGetRenderThreadTid(long nativeProxy);

    private static native long nCreateRootRenderNode();
@@ -981,7 +990,6 @@ public final class ThreadedRenderer {

    private static native void nDumpProfileInfo(long nativeProxy, FileDescriptor fd,
            @DumpFlags int dumpFlags);
    private static native void nDumpProfileData(byte[] data, FileDescriptor fd);

    private static native void nAddRenderNode(long nativeProxy, long rootRenderNode,
             boolean placeFront);
+2 −2
Original line number Diff line number Diff line
@@ -887,9 +887,9 @@ public final class ViewRootImpl implements ViewParent,
                final boolean hasSurfaceInsets = insets.left != 0 || insets.right != 0
                        || insets.top != 0 || insets.bottom != 0;
                final boolean translucent = attrs.format != PixelFormat.OPAQUE || hasSurfaceInsets;
                mAttachInfo.mThreadedRenderer = ThreadedRenderer.create(mContext, translucent);
                mAttachInfo.mThreadedRenderer = ThreadedRenderer.create(mContext, translucent,
                        attrs.getTitle().toString());
                if (mAttachInfo.mThreadedRenderer != null) {
                    mAttachInfo.mThreadedRenderer.setName(attrs.getTitle().toString());
                    mAttachInfo.mHardwareAccelerated =
                            mAttachInfo.mHardwareAccelerationRequested = true;
                }
Loading