/** Create a drawable from an inputstream */ public static Drawable createFromStream(InputStream is, String srcName) { Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, srcName != null ? srcName : "Unknown drawable"); try { return createFromResourceStream(null, null, is, srcName); } finally { Trace.traceEnd(Trace.TRACE_TAG_RESOURCES); } }
/** * Create a drawable from an inputstream, using the given resources and value to determine density * information. */ public static Drawable createFromResourceStream( Resources res, TypedValue value, InputStream is, String srcName) { Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, srcName != null ? srcName : "Unknown drawable"); try { return createFromResourceStream(res, value, is, srcName, null); } finally { Trace.traceEnd(Trace.TRACE_TAG_RESOURCES); } }
private static void applicationInit(int targetSdkVersion, String[] argv, ClassLoader classLoader) throws ZygoteInit.MethodAndArgsCaller { // If the application calls System.exit(), terminate the process // immediately without running any shutdown hooks. It is not possible to // shutdown an Android application gracefully. Among other things, the // Android runtime shutdown hooks close the Binder driver, which can cause // leftover running threads to crash before the process actually exits. nativeSetExitWithoutCleanup(true); // We want to be fairly aggressive about heap utilization, to avoid // holding on to a lot of memory that isn't needed. VMRuntime.getRuntime().setTargetHeapUtilization(0.75f); VMRuntime.getRuntime().setTargetSdkVersion(targetSdkVersion); final Arguments args; try { args = new Arguments(argv); } catch (IllegalArgumentException ex) { Slog.e(TAG, ex.getMessage()); // let the process exit return; } // The end of of the RuntimeInit event (see #zygoteInit). Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); // Remaining arguments are passed to the start class's static main invokeStaticMain(args.startClass, args.startArgs, classLoader); }
/** Create a drawable from file path name. */ public static Drawable createFromPath(String pathName) { if (pathName == null) { return null; } Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, pathName); try { Bitmap bm = BitmapFactory.decodeFile(pathName); if (bm != null) { return drawableFromBitmap(null, bm, null, null, null, pathName); } } finally { Trace.traceEnd(Trace.TRACE_TAG_RESOURCES); } return null; }
/** * The main function called when started through the zygote process. This * could be unified with main(), if the native code in nativeFinishInit() * were rationalized with Zygote startup.<p> * * Current recognized args: * <ul> * <li> <code> [--] <start class name> <args> * </ul> * * @param targetSdkVersion target SDK version * @param argv arg strings */ public static final void zygoteInit(int targetSdkVersion, String[] argv, ClassLoader classLoader) throws ZygoteInit.MethodAndArgsCaller { if (DEBUG) Slog.d(TAG, "RuntimeInit: Starting application from zygote"); Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "RuntimeInit"); redirectLogStreams(); commonInit(); nativeZygoteInit(); applicationInit(targetSdkVersion, argv, classLoader); }
/** Returns true if animating. */ public boolean dismiss( SurfaceSession session, long maxAnimationDuration, float animationScale, int finalWidth, int finalHeight) { /// M: Add systrace for orientation chagnge performance analysis Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "ScreenRotationAnimation:Begin"); Slog.v(WindowManagerService.TAG, "Dismiss!"); Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); if (mSurface == null) { // Can't do animation. return false; } if (!mStarted) { startAnimation(session, maxAnimationDuration, animationScale, finalWidth, finalHeight, true); } if (!mStarted) { return false; } if (DEBUG_STATE) Slog.v(TAG, "Setting mFinishAnimReady = true"); mFinishAnimReady = true; return true; }
static void preload() { Log.d(TAG, "begin preload"); Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadClasses"); preloadClasses(); Trace.traceEnd(Trace.TRACE_TAG_DALVIK); Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadResources"); preloadResources(); Trace.traceEnd(Trace.TRACE_TAG_DALVIK); Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadOpenGL"); preloadOpenGL(); Trace.traceEnd(Trace.TRACE_TAG_DALVIK); preloadSharedLibraries(); preloadTextResources(); // Ask the WebViewFactory to do any initialization that must run in the zygote process, // for memory sharing purposes. WebViewFactory.prepareWebViewInZygote(); Log.d(TAG, "end preload"); }
public static void startProfileFirstFrameAvailable() { MMProfileWrapper.doMMProfileLog( EVENT_FIRST_FRAME_AVAILABLE, MMProfileWrapper.MMPROFILE_FLAG_START); Trace.traceEnd(Trace.TRACE_TAG_VIEW); }
public static void triggerFirstFrameAvailable() { MMProfileWrapper.doMMProfileLog( EVENT_FIRST_FRAME_AVAILABLE, MMProfileWrapper.MMPROFILE_FLAG_PULSE); Trace.traceBegin(Trace.TRACE_TAG_VIEW, "FrameAvailable"); }
public static void stopProfileApplyParameters() { MMProfileWrapper.doMMProfileLog(EVENT_APPLY_PARAMETERS, MMProfileWrapper.MMPROFILE_FLAG_END); Trace.traceEnd(Trace.TRACE_TAG_VIEW); }
public static void stopProfileCameraStartUp() { MMProfileWrapper.doMMProfileLog(EVENT_CAMERA_START_UP, MMProfileWrapper.MMPROFILE_FLAG_END); Trace.traceEnd(Trace.TRACE_TAG_VIEW); }
public static void stopProfileCameraOnResume() { MMProfileWrapper.doMMProfileLog(EVENT_CAMERA_ON_RESUME, MMProfileWrapper.MMPROFILE_FLAG_END); Trace.traceEnd(Trace.TRACE_TAG_VIEW); }
public static void startProfileCameraOnCreate() { MMProfileWrapper.doMMProfileLog(EVENT_CAMERA_ON_CREATE, MMProfileWrapper.MMPROFILE_FLAG_START); Trace.traceBegin(Trace.TRACE_TAG_VIEW, "CameraOncreate"); }
public void kill() { if (DEBUG_STATE) Slog.v(TAG, "Kill!"); if (mSurface != null) { /// M: Add systrace for orientation chagnge performance analysis Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "ScreenRotationAnimation:End"); Slog.i(WindowManagerService.TAG, " FREEZE " + mSurface + ": DESTROY"); Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); mSurface.destroy(); mSurface = null; } if (mCustomBlackFrame != null) { mCustomBlackFrame.kill(); mCustomBlackFrame = null; } if (mExitingBlackFrame != null) { mExitingBlackFrame.kill(); mExitingBlackFrame = null; } if (mEnteringBlackFrame != null) { mEnteringBlackFrame.kill(); mEnteringBlackFrame = null; } if (TWO_PHASE_ANIMATION) { if (mStartExitAnimation != null) { mStartExitAnimation.cancel(); mStartExitAnimation = null; } if (mStartEnterAnimation != null) { mStartEnterAnimation.cancel(); mStartEnterAnimation = null; } if (mFinishExitAnimation != null) { mFinishExitAnimation.cancel(); mFinishExitAnimation = null; } if (mFinishEnterAnimation != null) { mFinishEnterAnimation.cancel(); mFinishEnterAnimation = null; } } if (USE_CUSTOM_BLACK_FRAME) { if (mStartFrameAnimation != null) { mStartFrameAnimation.cancel(); mStartFrameAnimation = null; } if (mRotateFrameAnimation != null) { mRotateFrameAnimation.cancel(); mRotateFrameAnimation = null; } if (mFinishFrameAnimation != null) { mFinishFrameAnimation.cancel(); mFinishFrameAnimation = null; } } if (mRotateExitAnimation != null) { mRotateExitAnimation.cancel(); mRotateExitAnimation = null; } if (mRotateEnterAnimation != null) { mRotateEnterAnimation.cancel(); mRotateEnterAnimation = null; } }
public ScreenRotationAnimation( Context context, Display display, SurfaceSession session, boolean inTransaction, int originalWidth, int originalHeight, int originalRotation, int exitAnim, int enterAnim) { mContext = context; mDisplay = display; mExitAnimId = exitAnim; mEnterAnimId = enterAnim; // Screenshot does NOT include rotation! if (originalRotation == Surface.ROTATION_90 || originalRotation == Surface.ROTATION_270) { mWidth = originalHeight; mHeight = originalWidth; } else { mWidth = originalWidth; mHeight = originalHeight; } mOriginalRotation = originalRotation; mOriginalWidth = originalWidth; mOriginalHeight = originalHeight; if (!inTransaction) { if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(WindowManagerService.TAG, ">>> OPEN TRANSACTION ScreenRotationAnimation"); Surface.openTransaction(); } try { try { if (WindowManagerService.DEBUG_SURFACE_TRACE) { mSurface = new SurfaceTrace( session, "FreezeSurface", mWidth, mHeight, PixelFormat.OPAQUE, Surface.FX_SURFACE_SCREENSHOT | Surface.HIDDEN); } else { mSurface = new Surface( session, "FreezeSurface", mWidth, mHeight, PixelFormat.OPAQUE, Surface.FX_SURFACE_SCREENSHOT | Surface.HIDDEN); } if (!mSurface.isValid()) { // Screenshot failed, punt. mSurface = null; return; } mSurface.setLayerStack(mDisplay.getLayerStack()); mSurface.setLayer(FREEZE_LAYER + 1); mSurface.setAlpha(0); mSurface.show(); } catch (Surface.OutOfResourcesException e) { Slog.w(TAG, "Unable to allocate freeze surface", e); } /// M: Add systrace for orientation chagnge performance analysis Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "ScreenRotationAnimation:Create"); Slog.i(WindowManagerService.TAG, " FREEZE " + mSurface + ": CREATE"); Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); setRotationInTransaction(originalRotation); } finally { if (!inTransaction) { Surface.closeTransaction(); if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(WindowManagerService.TAG, "<<< CLOSE TRANSACTION ScreenRotationAnimation"); } } }
public static void startProfileDrawScreenNail() { MMProfileWrapper.doMMProfileLog(EVENT_DRAW_SCREEN_NAIL, MMProfileWrapper.MMPROFILE_FLAG_START); Trace.traceBegin(Trace.TRACE_TAG_VIEW, "DrawScreenNail"); }
public static void stopProfileDrawScreenNail() { MMProfileWrapper.doMMProfileLog(EVENT_DRAW_SCREEN_NAIL, MMProfileWrapper.MMPROFILE_FLAG_END); Trace.traceEnd(Trace.TRACE_TAG_VIEW); }
/** * Performs Zygote process initialization. Loads and initializes commonly used classes. * * <p>Most classes only cause a few hundred bytes to be allocated, but a few will allocate a dozen * Kbytes (in one case, 500+K). */ private static void preloadClasses() { final VMRuntime runtime = VMRuntime.getRuntime(); InputStream is; try { is = new FileInputStream(PRELOADED_CLASSES); } catch (FileNotFoundException e) { Log.e(TAG, "Couldn't find " + PRELOADED_CLASSES + "."); return; } Log.i(TAG, "Preloading classes..."); long startTime = SystemClock.uptimeMillis(); // Drop root perms while running static initializers. final int reuid = Os.getuid(); final int regid = Os.getgid(); // We need to drop root perms only if we're already root. In the case of "wrapped" // processes (see WrapperInit), this function is called from an unprivileged uid // and gid. boolean droppedPriviliges = false; if (reuid == ROOT_UID && regid == ROOT_GID) { try { Os.setregid(ROOT_GID, UNPRIVILEGED_GID); Os.setreuid(ROOT_UID, UNPRIVILEGED_UID); } catch (ErrnoException ex) { throw new RuntimeException("Failed to drop root", ex); } droppedPriviliges = true; } // Alter the target heap utilization. With explicit GCs this // is not likely to have any effect. float defaultUtilization = runtime.getTargetHeapUtilization(); runtime.setTargetHeapUtilization(0.8f); try { BufferedReader br = new BufferedReader(new InputStreamReader(is), 256); int count = 0; String line; while ((line = br.readLine()) != null) { // Skip comments and blank lines. line = line.trim(); if (line.startsWith("#") || line.equals("")) { continue; } Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadClass " + line); try { if (false) { Log.v(TAG, "Preloading " + line + "..."); } // Load and explicitly initialize the given class. Use // Class.forName(String, boolean, ClassLoader) to avoid repeated stack lookups // (to derive the caller's class-loader). Use true to force initialization, and // null for the boot classpath class-loader (could as well cache the // class-loader of this class in a variable). Class.forName(line, true, null); count++; } catch (ClassNotFoundException e) { Log.w(TAG, "Class not found for preloading: " + line); } catch (UnsatisfiedLinkError e) { Log.w(TAG, "Problem preloading " + line + ": " + e); } catch (Throwable t) { Log.e(TAG, "Error preloading " + line + ".", t); if (t instanceof Error) { throw (Error) t; } if (t instanceof RuntimeException) { throw (RuntimeException) t; } throw new RuntimeException(t); } Trace.traceEnd(Trace.TRACE_TAG_DALVIK); } Log.i( TAG, "...preloaded " + count + " classes in " + (SystemClock.uptimeMillis() - startTime) + "ms."); } catch (IOException e) { Log.e(TAG, "Error reading " + PRELOADED_CLASSES + ".", e); } finally { IoUtils.closeQuietly(is); // Restore default. runtime.setTargetHeapUtilization(defaultUtilization); // Fill in dex caches with classes, fields, and methods brought in by preloading. Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadDexCaches"); runtime.preloadDexCaches(); Trace.traceEnd(Trace.TRACE_TAG_DALVIK); // Bring back root. We'll need it later if we're in the zygote. if (droppedPriviliges) { try { Os.setreuid(ROOT_UID, ROOT_UID); Os.setregid(ROOT_GID, ROOT_GID); } catch (ErrnoException ex) { throw new RuntimeException("Failed to restore root", ex); } } } }
public static void startProfileCameraOnResume() { MMProfileWrapper.doMMProfileLog(EVENT_CAMERA_ON_RESUME, MMProfileWrapper.MMPROFILE_FLAG_START); Trace.traceBegin(Trace.TRACE_TAG_VIEW, "CameraOnResume"); }
public static void main(String argv[]) { try { Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "ZygoteInit"); RuntimeInit.enableDdms(); // Start profiling the zygote initialization. SamplingProfilerIntegration.start(); boolean startSystemServer = false; String socketName = "zygote"; String abiList = null; for (int i = 1; i < argv.length; i++) { if ("start-system-server".equals(argv[i])) { startSystemServer = true; } else if (argv[i].startsWith(ABI_LIST_ARG)) { abiList = argv[i].substring(ABI_LIST_ARG.length()); } else if (argv[i].startsWith(SOCKET_NAME_ARG)) { socketName = argv[i].substring(SOCKET_NAME_ARG.length()); } else { throw new RuntimeException("Unknown command line argument: " + argv[i]); } } if (abiList == null) { throw new RuntimeException("No ABI list supplied."); } registerZygoteSocket(socketName); Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "ZygotePreload"); EventLog.writeEvent(LOG_BOOT_PROGRESS_PRELOAD_START, SystemClock.uptimeMillis()); preload(); EventLog.writeEvent(LOG_BOOT_PROGRESS_PRELOAD_END, SystemClock.uptimeMillis()); Trace.traceEnd(Trace.TRACE_TAG_DALVIK); // Finish profiling the zygote initialization. SamplingProfilerIntegration.writeZygoteSnapshot(); // Do an initial gc to clean up after startup Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PostZygoteInitGC"); gcAndFinalize(); Trace.traceEnd(Trace.TRACE_TAG_DALVIK); Trace.traceEnd(Trace.TRACE_TAG_DALVIK); // Disable tracing so that forked processes do not inherit stale tracing tags from // Zygote. Trace.setTracingEnabled(false); if (startSystemServer) { startSystemServer(abiList, socketName); } Log.i(TAG, "Accepting command socket connections"); runSelectLoop(abiList); closeServerSocket(); } catch (MethodAndArgsCaller caller) { caller.run(); } catch (RuntimeException ex) { Log.e(TAG, "Zygote died with exception", ex); closeServerSocket(); throw ex; } }
public static void startProfileCameraStartUp() { MMProfileWrapper.doMMProfileLog(EVENT_CAMERA_START_UP, MMProfileWrapper.MMPROFILE_FLAG_START); Trace.traceBegin(Trace.TRACE_TAG_VIEW, "CameraStartUp"); }
public static void startProfileStartPreview() { MMProfileWrapper.doMMProfileLog(EVENT_START_PREVIEW, MMProfileWrapper.MMPROFILE_FLAG_START); Trace.traceBegin(Trace.TRACE_TAG_VIEW, "StartPreview"); }
public static void startProfileApplyParameters() { MMProfileWrapper.doMMProfileLog(EVENT_APPLY_PARAMETERS, MMProfileWrapper.MMPROFILE_FLAG_START); Trace.traceBegin(Trace.TRACE_TAG_VIEW, "ApplyParameters"); }
public static void stopProfileStartPreview() { MMProfileWrapper.doMMProfileLog(EVENT_START_PREVIEW, MMProfileWrapper.MMPROFILE_FLAG_END); Trace.traceEnd(Trace.TRACE_TAG_VIEW); }
@Override boolean draw( View view, View.AttachInfo attachInfo, HardwareDrawCallbacks callbacks, Rect dirty) { if (canDraw()) { if (!hasDirtyRegions()) { dirty = null; } attachInfo.mIgnoreDirtyState = true; attachInfo.mDrawingTime = SystemClock.uptimeMillis(); view.mPrivateFlags |= View.PFLAG_DRAWN; final int surfaceState = checkCurrent(); if (surfaceState != SURFACE_STATE_ERROR) { HardwareCanvas canvas = mCanvas; attachInfo.mHardwareCanvas = canvas; if (mProfileEnabled) { mProfileLock.lock(); } // We had to change the current surface and/or context, redraw everything if (surfaceState == SURFACE_STATE_UPDATED) { dirty = null; beginFrame(null); } else { int[] size = mSurfaceSize; beginFrame(size); if (size[1] != mHeight || size[0] != mWidth) { mWidth = size[0]; mHeight = size[1]; canvas.setViewport(mWidth, mHeight); dirty = null; } } int saveCount = 0; int status = DisplayList.STATUS_DONE; try { view.mRecreateDisplayList = (view.mPrivateFlags & View.PFLAG_INVALIDATED) == View.PFLAG_INVALIDATED; view.mPrivateFlags &= ~View.PFLAG_INVALIDATED; long getDisplayListStartTime = 0; if (mProfileEnabled) { mProfileCurrentFrame += PROFILE_FRAME_DATA_COUNT; if (mProfileCurrentFrame >= mProfileData.length) { mProfileCurrentFrame = 0; } getDisplayListStartTime = System.nanoTime(); } canvas.clearLayerUpdates(); DisplayList displayList; Trace.traceBegin(Trace.TRACE_TAG_VIEW, "getDisplayList"); try { displayList = view.getDisplayList(); } finally { Trace.traceEnd(Trace.TRACE_TAG_VIEW); } Trace.traceBegin(Trace.TRACE_TAG_VIEW, "prepareFrame"); try { status = onPreDraw(dirty); } finally { Trace.traceEnd(Trace.TRACE_TAG_VIEW); } saveCount = canvas.save(); callbacks.onHardwarePreDraw(canvas); if (mProfileEnabled) { long now = System.nanoTime(); float total = (now - getDisplayListStartTime) * 0.000001f; //noinspection PointlessArithmeticExpression mProfileData[mProfileCurrentFrame] = total; } if (displayList != null) { long drawDisplayListStartTime = 0; if (mProfileEnabled) { drawDisplayListStartTime = System.nanoTime(); } Trace.traceBegin(Trace.TRACE_TAG_VIEW, "drawDisplayList"); try { status |= canvas.drawDisplayList( displayList, mRedrawClip, DisplayList.FLAG_CLIP_CHILDREN); } finally { Trace.traceEnd(Trace.TRACE_TAG_VIEW); } if (mProfileEnabled) { long now = System.nanoTime(); float total = (now - drawDisplayListStartTime) * 0.000001f; mProfileData[mProfileCurrentFrame + 1] = total; } handleFunctorStatus(attachInfo, status); } else { // Shouldn't reach here view.draw(canvas); } } finally { callbacks.onHardwarePostDraw(canvas); canvas.restoreToCount(saveCount); view.mRecreateDisplayList = false; mFrameCount++; if (mDebugDirtyRegions) { if (mDebugPaint == null) { mDebugPaint = new Paint(); mDebugPaint.setColor(0x7fff0000); } if (dirty != null && (mFrameCount & 1) == 0) { canvas.drawRect(dirty, mDebugPaint); } } } onPostDraw(); attachInfo.mIgnoreDirtyState = false; if ((status & DisplayList.STATUS_DREW) == DisplayList.STATUS_DREW) { long eglSwapBuffersStartTime = 0; if (mProfileEnabled) { eglSwapBuffersStartTime = System.nanoTime(); } sEgl.eglSwapBuffers(sEglDisplay, mEglSurface); if (mProfileEnabled) { long now = System.nanoTime(); float total = (now - eglSwapBuffersStartTime) * 0.000001f; mProfileData[mProfileCurrentFrame + 2] = total; } checkEglErrors(); } if (mProfileEnabled) { mProfileLock.unlock(); } return dirty == null; } } return false; }
public static void triggerFrameAvailable() { Trace.traceCounter(Trace.TRACE_TAG_VIEW, "triggerFrameAvailable", 1); MMProfileWrapper.doMMProfileLog(EVENT_FRAME_AVAILABLE, MMProfileWrapper.MMPROFILE_FLAG_PULSE); Trace.traceCounter(Trace.TRACE_TAG_VIEW, "triggerFrameAvailable", 0); }