23
Analyzing Display and Performance with Systrace Peter.Pan

Analyzing Display and Performance with Systrace · What is Systrace •The Systrace tool helps analyze the performance of your application by capturing and displaying execution times

  • Upload
    others

  • View
    15

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Analyzing Display and Performance with Systrace · What is Systrace •The Systrace tool helps analyze the performance of your application by capturing and displaying execution times

Analyzing Display and Performance with Systrace

Peter.Pan

Page 2: Analyzing Display and Performance with Systrace · What is Systrace •The Systrace tool helps analyze the performance of your application by capturing and displaying execution times

What is Systrace

• The Systrace tool helps analyze the performance of your application by capturing and displaying execution times of your applications processes and other Android system processes.

Page 3: Analyzing Display and Performance with Systrace · What is Systrace •The Systrace tool helps analyze the performance of your application by capturing and displaying execution times

Command Line Usage

• Android 4.3 and higher options

$ cd $(project)/extenal/chromium-trace/ $ python systrace.py --time=10 -o mynewtrace.html –b 2048 sched gfx view wm

Page 4: Analyzing Display and Performance with Systrace · What is Systrace •The Systrace tool helps analyze the performance of your application by capturing and displaying execution times

ATRACE • Path

– frameworks/native/cmds/atrace/atrace.cpp

• Define (form system/core/include/cutils/trace.h)

– #define ATRACE_TAG ATRACE_TAG_GRAPHICS

• Function

– ATRACE_CALL()

• Variables

– ATRACE_INT(“Name”, Value);

– ATRACE_INT64(“Name”, Value64);

#define ATRACE_TAG ATRACE_TAG_GRAPHICS

… Void Function(){ ATRACE_CALL(); int value = 0; value = Random(); ATRACE_INT(“RandomValue”, value); } …

Page 5: Analyzing Display and Performance with Systrace · What is Systrace •The Systrace tool helps analyze the performance of your application by capturing and displaying execution times

GUI

Finder

CPU infor.

Control bar

Surceflinger

Other processes

Detail

Timeline

Page 6: Analyzing Display and Performance with Systrace · What is Systrace •The Systrace tool helps analyze the performance of your application by capturing and displaying execution times

Operation

Keyword

Shortcut: W: Zoom In S: Zoom Out A: Pan left D: Pan right

Page 7: Analyzing Display and Performance with Systrace · What is Systrace •The Systrace tool helps analyze the performance of your application by capturing and displaying execution times

CPU Scheduling

• $ python systrace.py --time=10 -o mynewtrace.html sched gfx view wm freq

Page 8: Analyzing Display and Performance with Systrace · What is Systrace •The Systrace tool helps analyze the performance of your application by capturing and displaying execution times

Process status

Status: *Uninterruptable sleep (usually IO) *Running or runnable (on run queue) *sleeping

Page 9: Analyzing Display and Performance with Systrace · What is Systrace •The Systrace tool helps analyze the performance of your application by capturing and displaying execution times

Vsync_On

Add/Remove a listener to DispVsyncSource.

Page 10: Analyzing Display and Performance with Systrace · What is Systrace •The Systrace tool helps analyze the performance of your application by capturing and displaying execution times

Vsync_On @EventThread.cpp Vector< sp<EventThread::Connection> EventThread::waitForEvent(…){ … if (timestamp && !waitForVSync) { disableVSyncLocked(); } else if (!timestamp && waitForVSync) { enableVSyncLocked(); } … }

@Sufaceflinger.cpp virtual void setVSyncEnabled(bool enable) { if (enable) { status_t err = mDispSync->addEventListener(mPhaseOffset, static_cast<DispSync::Callback*>(this)); … ATRACE_INT("VsyncOn", 1); } else { status_t err = mDispSync->removeEventListener(static_cast<DispSync::Callback*>(this)); … ATRACE_INT("VsyncOn", 0); } }

Page 11: Analyzing Display and Performance with Systrace · What is Systrace •The Systrace tool helps analyze the performance of your application by capturing and displaying execution times

VSYNC

DispVsyncSource produces the Vsync signal.

Page 12: Analyzing Display and Performance with Systrace · What is Systrace •The Systrace tool helps analyze the performance of your application by capturing and displaying execution times

Vsync @DispSync.cpp virtual bool threadLoop() { while (true) { … if (callbackInvocations.size() > 0) { fireCallbackInvocations(callbackInvocations); } … }… }

@Surfacefliger.cpp virtual void onDispSyncEvent(nsecs_t when) { sp<VSyncSource::Callback> callback; { Mutex::Autolock lock(mMutex); callback = mCallback; if (mTraceVsync) { mValue = (mValue + 1) % 2; ATRACE_INT("VSYNC", mValue); } } if (callback != NULL) { callback->onVSyncEvent(when); } }

@DispSync.cpp void fireCallbackInvocations(…) { for (size_t i = 0; i < callbacks.size(); i++) { callbacks[i].mCallback->onDispSyncEvent(callbacks[i].mEventTime); } }

Page 13: Analyzing Display and Performance with Systrace · What is Systrace •The Systrace tool helps analyze the performance of your application by capturing and displaying execution times

HW_Vsync0

Need HW Vsync

@HWComposer.cpp void vsync(int disp, int64_t timestamp) { … char tag[16]; snprintf(tag, sizeof(tag), "HW_VSYNC_%1u", disp); ATRACE_INT(tag, ++mVSyncCounts[disp] & 1); mEventHandler.onVSyncReceived(disp, timestamp); … }

Page 14: Analyzing Display and Performance with Systrace · What is Systrace •The Systrace tool helps analyze the performance of your application by capturing and displaying execution times

HW_Vsync0 @Surfaceflinger.cpp void surfaceflinger::onVSyncReceived(){ if (type == 0 && mPrimaryHWVsyncEnabled) { needsHwVsync = mPrimaryDispSync.addResyncSample(timestamp); } if (needsHwVsync) { enableHardwareVsync(); } else { disableHardwareVsync(false); }… }

@Surfaceflinger.cpp voidsurfaceflinger::onScreenAcquired(){ … mEventThread->onScreenAcquired(); resyncToHardwareVsync(true); … }

@Surfaceflinger.cpp void surfaceflinger:: onScreenReleased(){ … if (type== DisplayDevice::DISPLAY_PRIMARY) { disableHardwareVsync(true); } … }

Page 15: Analyzing Display and Performance with Systrace · What is Systrace •The Systrace tool helps analyze the performance of your application by capturing and displaying execution times

Sufacefliger

QueueBuffer()

Page 16: Analyzing Display and Performance with Systrace · What is Systrace •The Systrace tool helps analyze the performance of your application by capturing and displaying execution times

DequeueBuffer()/QueueBuffer()

DequeueBuffer() QueueBuffer()

Page 17: Analyzing Display and Performance with Systrace · What is Systrace •The Systrace tool helps analyze the performance of your application by capturing and displaying execution times

QueueBuffer()/AcquirBuffer()

QueueBuffer()

AcquirBuffer()

+1 -1

Page 18: Analyzing Display and Performance with Systrace · What is Systrace •The Systrace tool helps analyze the performance of your application by capturing and displaying execution times

QueueBuffer()/AcquirBuffer()

@BufferQueue.cpp status_t BufferQueue::acquireBuffer(BufferItem *buffer, nsecs_t expectedPresent) { … ATRACE_INT(mConsumerName.string(), Queue.size()); … }

@BufferQueue.cpp status_t BufferQueue::QueueuBuffer(BufferItem *buffer, nsecs_t expectedPresent) { … ATRACE_INT(mConsumerName.string(), Queue.size()); … }

Page 19: Analyzing Display and Performance with Systrace · What is Systrace •The Systrace tool helps analyze the performance of your application by capturing and displaying execution times

FramebufferSurface

QueueBuffer() AcquirBuffer()

Page 20: Analyzing Display and Performance with Systrace · What is Systrace •The Systrace tool helps analyze the performance of your application by capturing and displaying execution times

Case study(1)

DeliverInputEvent()

Status change

QueueBuffer()

Page 21: Analyzing Display and Performance with Systrace · What is Systrace •The Systrace tool helps analyze the performance of your application by capturing and displaying execution times

Case Study(2)

Animator

Page 22: Analyzing Display and Performance with Systrace · What is Systrace •The Systrace tool helps analyze the performance of your application by capturing and displaying execution times

Case Study(3)

Page 23: Analyzing Display and Performance with Systrace · What is Systrace •The Systrace tool helps analyze the performance of your application by capturing and displaying execution times

Reference

• http://developer.android.com/tools/debugging/systrace.html

• http://www.curious-creature.org/2012/12/01/android-performance-case-study/