analyzing display and performance with systrace

23
Analyzing Display and Performance with Systrace Peter.Pan

Upload: rouyun-pan

Post on 21-Apr-2017

6.873 views

Category:

Engineering


4 download

TRANSCRIPT

Page 1: Analyzing Display and Performance with Systrace

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 of your applications processes and other Android system processes.

Page 3: Analyzing Display and Performance with Systrace

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

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

GUI

FinderCPU infor.

Control bar

Surceflinger

Other processes

Detail

Timeline

Page 6: Analyzing Display and Performance with Systrace

Operation

Keyword

Shortcut:W: Zoom InS: Zoom OutA: Pan leftD: Pan right

Page 7: Analyzing Display and Performance with Systrace

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

Page 8: Analyzing Display and Performance with Systrace

Process status

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

Page 9: Analyzing Display and Performance with Systrace

Vsync_OnAdd/Remove a listener to DispVsyncSource.

Page 10: Analyzing Display and Performance with Systrace

[email protected]< sp<EventThread::Connection> EventThread::waitForEvent(…){ … if (timestamp && !waitForVSync) { disableVSyncLocked(); } else if (!timestamp && waitForVSync) { enableVSyncLocked(); }…}

@Sufaceflinger.cppvirtual 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

VSYNC

DispVsyncSource produces the Vsync signal.

Page 12: Analyzing Display and Performance with Systrace

[email protected] 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.cppvoid 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

HW_Vsync0Need 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

[email protected] 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

Sufacefliger

QueueBuffer()

Page 16: Analyzing Display and Performance with Systrace

DequeueBuffer()/QueueBuffer()

DequeueBuffer() QueueBuffer()

Page 17: Analyzing Display and Performance with Systrace

QueueBuffer()/AcquirBuffer()

QueueBuffer()

AcquirBuffer()

+1 -1

Page 18: Analyzing Display and Performance with Systrace

QueueBuffer()/AcquirBuffer()

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

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

Page 19: Analyzing Display and Performance with Systrace

FramebufferSurface

QueueBuffer() AcquirBuffer()

Page 20: Analyzing Display and Performance with Systrace

Case study(1)

DeliverInputEvent()

Status change

QueueBuffer()

Page 21: Analyzing Display and Performance with Systrace

Case Study(2)

Animator

Page 22: Analyzing Display and Performance with Systrace

Case Study(3)

Page 23: Analyzing Display and Performance with Systrace

Reference• http://developer.android.com/tools/debugging/systrace.html• http://www.curious-creature.org/2012/12/01/android-

performance-case-study/