Skip to content

Commit a85ca37

Browse files
author
Jamie Gennis
committed
Add tracing to various graphics components.
This change adds ATRACE call tracing to BufferQueue, SurfaceTextureClient, SurfaceTexture, SurfaceFlinger, Layer, and EGL. Change-Id: I9d75ed26f5a3f0d1af635da38289520134cfbbb7
1 parent 6835237 commit a85ca37

File tree

6 files changed

+56
-0
lines changed

6 files changed

+56
-0
lines changed

libs/gui/BufferQueue.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#define LOG_TAG "BufferQueue"
1818
//#define LOG_NDEBUG 0
19+
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
1920

2021
#define GL_GLEXT_PROTOTYPES
2122
#define EGL_EGLEXT_PROTOTYPES
@@ -29,6 +30,7 @@
2930

3031
#include <utils/Log.h>
3132
#include <gui/SurfaceTexture.h>
33+
#include <utils/Trace.h>
3234

3335
// This compile option causes SurfaceTexture to return the buffer that is currently
3436
// attached to the GL texture from dequeueBuffer when no other buffers are
@@ -191,6 +193,7 @@ status_t BufferQueue::setBufferCount(int bufferCount) {
191193

192194
int BufferQueue::query(int what, int* outValue)
193195
{
196+
ATRACE_CALL();
194197
Mutex::Autolock lock(mMutex);
195198

196199
if (mAbandoned) {
@@ -221,6 +224,7 @@ int BufferQueue::query(int what, int* outValue)
221224
}
222225

223226
status_t BufferQueue::requestBuffer(int slot, sp<GraphicBuffer>* buf) {
227+
ATRACE_CALL();
224228
ST_LOGV("requestBuffer: slot=%d", slot);
225229
Mutex::Autolock lock(mMutex);
226230
if (mAbandoned) {
@@ -239,6 +243,7 @@ status_t BufferQueue::requestBuffer(int slot, sp<GraphicBuffer>* buf) {
239243

240244
status_t BufferQueue::dequeueBuffer(int *outBuf, uint32_t w, uint32_t h,
241245
uint32_t format, uint32_t usage) {
246+
ATRACE_CALL();
242247
ST_LOGV("dequeueBuffer: w=%d h=%d fmt=%#x usage=%#x", w, h, format, usage);
243248

244249
if ((w && !h) || (!w && h)) {
@@ -458,6 +463,7 @@ status_t BufferQueue::dequeueBuffer(int *outBuf, uint32_t w, uint32_t h,
458463
}
459464

460465
status_t BufferQueue::setSynchronousMode(bool enabled) {
466+
ATRACE_CALL();
461467
ST_LOGV("setSynchronousMode: enabled=%d", enabled);
462468
Mutex::Autolock lock(mMutex);
463469

@@ -490,6 +496,7 @@ status_t BufferQueue::setSynchronousMode(bool enabled) {
490496

491497
status_t BufferQueue::queueBuffer(int buf, int64_t timestamp,
492498
uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform) {
499+
ATRACE_CALL();
493500
ST_LOGV("queueBuffer: slot=%d time=%lld", buf, timestamp);
494501

495502
sp<FrameAvailableListener> listener;
@@ -553,6 +560,8 @@ status_t BufferQueue::queueBuffer(int buf, int64_t timestamp,
553560
*outWidth = mDefaultWidth;
554561
*outHeight = mDefaultHeight;
555562
*outTransform = 0;
563+
564+
ATRACE_INT(mConsumerName.string(), mQueue.size());
556565
} // scope for the lock
557566

558567
// call back without lock held
@@ -563,6 +572,7 @@ status_t BufferQueue::queueBuffer(int buf, int64_t timestamp,
563572
}
564573

565574
void BufferQueue::cancelBuffer(int buf) {
575+
ATRACE_CALL();
566576
ST_LOGV("cancelBuffer: slot=%d", buf);
567577
Mutex::Autolock lock(mMutex);
568578

@@ -586,6 +596,7 @@ void BufferQueue::cancelBuffer(int buf) {
586596
}
587597

588598
status_t BufferQueue::setCrop(const Rect& crop) {
599+
ATRACE_CALL();
589600
ST_LOGV("setCrop: crop=[%d,%d,%d,%d]", crop.left, crop.top, crop.right,
590601
crop.bottom);
591602

@@ -599,6 +610,7 @@ status_t BufferQueue::setCrop(const Rect& crop) {
599610
}
600611

601612
status_t BufferQueue::setTransform(uint32_t transform) {
613+
ATRACE_CALL();
602614
ST_LOGV("setTransform: xform=%#x", transform);
603615
Mutex::Autolock lock(mMutex);
604616
if (mAbandoned) {
@@ -610,6 +622,7 @@ status_t BufferQueue::setTransform(uint32_t transform) {
610622
}
611623

612624
status_t BufferQueue::setScalingMode(int mode) {
625+
ATRACE_CALL();
613626
ST_LOGV("setScalingMode: mode=%d", mode);
614627

615628
switch (mode) {
@@ -628,6 +641,7 @@ status_t BufferQueue::setScalingMode(int mode) {
628641

629642
status_t BufferQueue::connect(int api,
630643
uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform) {
644+
ATRACE_CALL();
631645
ST_LOGV("connect: api=%d", api);
632646
Mutex::Autolock lock(mMutex);
633647

@@ -664,6 +678,7 @@ status_t BufferQueue::connect(int api,
664678
}
665679

666680
status_t BufferQueue::disconnect(int api) {
681+
ATRACE_CALL();
667682
ST_LOGV("disconnect: api=%d", api);
668683
Mutex::Autolock lock(mMutex);
669684

@@ -818,6 +833,8 @@ status_t BufferQueue::acquire(BufferItem *buffer) {
818833

819834
mSlots[buf].mBufferState = BufferSlot::ACQUIRED;
820835
mQueue.erase(front);
836+
837+
ATRACE_INT(mConsumerName.string(), mQueue.size());
821838
}
822839
else {
823840
return -EINVAL; //should be a better return code
@@ -875,6 +892,7 @@ status_t BufferQueue::setDefaultBufferSize(uint32_t w, uint32_t h)
875892
}
876893

877894
status_t BufferQueue::setBufferCountServer(int bufferCount) {
895+
ATRACE_CALL();
878896
Mutex::Autolock lock(mMutex);
879897
return setBufferCountServerLocked(bufferCount);
880898
}

libs/gui/SurfaceTexture.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
#define LOG_TAG "SurfaceTexture"
18+
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
1819
//#define LOG_NDEBUG 0
1920

2021
#define GL_GLEXT_PROTOTYPES
@@ -36,6 +37,7 @@
3637

3738
#include <utils/Log.h>
3839
#include <utils/String8.h>
40+
#include <utils/Trace.h>
3941

4042
// This compile option makes SurfaceTexture use the EGL_KHR_fence_sync extension
4143
// to synchronize access to the buffers. It will cause dequeueBuffer to stall,
@@ -143,6 +145,7 @@ status_t SurfaceTexture::setDefaultBufferSize(uint32_t w, uint32_t h)
143145
}
144146

145147
status_t SurfaceTexture::updateTexImage() {
148+
ATRACE_CALL();
146149
ST_LOGV("updateTexImage");
147150
Mutex::Autolock lock(mMutex);
148151

libs/gui/SurfaceTextureClient.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
*/
1616

1717
#define LOG_TAG "SurfaceTextureClient"
18+
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
1819
//#define LOG_NDEBUG 0
1920

2021
#include <utils/Log.h>
22+
#include <utils/Trace.h>
2123

2224
#include <gui/ISurfaceComposer.h>
2325
#include <gui/SurfaceComposerClient.h>
@@ -121,6 +123,7 @@ int SurfaceTextureClient::hook_perform(ANativeWindow* window, int operation, ...
121123
}
122124

123125
int SurfaceTextureClient::setSwapInterval(int interval) {
126+
ATRACE_CALL();
124127
// EGL specification states:
125128
// interval is silently clamped to minimum and maximum implementation
126129
// dependent values before being stored.
@@ -138,6 +141,7 @@ int SurfaceTextureClient::setSwapInterval(int interval) {
138141
}
139142

140143
int SurfaceTextureClient::dequeueBuffer(android_native_buffer_t** buffer) {
144+
ATRACE_CALL();
141145
ALOGV("SurfaceTextureClient::dequeueBuffer");
142146
Mutex::Autolock lock(mMutex);
143147
int buf = -1;
@@ -167,6 +171,7 @@ int SurfaceTextureClient::dequeueBuffer(android_native_buffer_t** buffer) {
167171
}
168172

169173
int SurfaceTextureClient::cancelBuffer(android_native_buffer_t* buffer) {
174+
ATRACE_CALL();
170175
ALOGV("SurfaceTextureClient::cancelBuffer");
171176
Mutex::Autolock lock(mMutex);
172177
int i = getSlotFromBufferLocked(buffer);
@@ -213,6 +218,7 @@ int SurfaceTextureClient::lockBuffer(android_native_buffer_t* buffer) {
213218
}
214219

215220
int SurfaceTextureClient::queueBuffer(android_native_buffer_t* buffer) {
221+
ATRACE_CALL();
216222
ALOGV("SurfaceTextureClient::queueBuffer");
217223
Mutex::Autolock lock(mMutex);
218224
int64_t timestamp;
@@ -236,6 +242,7 @@ int SurfaceTextureClient::queueBuffer(android_native_buffer_t* buffer) {
236242
}
237243

238244
int SurfaceTextureClient::query(int what, int* value) const {
245+
ATRACE_CALL();
239246
ALOGV("SurfaceTextureClient::query");
240247
{ // scope for the lock
241248
Mutex::Autolock lock(mMutex);
@@ -404,6 +411,7 @@ int SurfaceTextureClient::dispatchUnlockAndPost(va_list args) {
404411

405412

406413
int SurfaceTextureClient::connect(int api) {
414+
ATRACE_CALL();
407415
ALOGV("SurfaceTextureClient::connect");
408416
Mutex::Autolock lock(mMutex);
409417
int err = mSurfaceTexture->connect(api,
@@ -415,6 +423,7 @@ int SurfaceTextureClient::connect(int api) {
415423
}
416424

417425
int SurfaceTextureClient::disconnect(int api) {
426+
ATRACE_CALL();
418427
ALOGV("SurfaceTextureClient::disconnect");
419428
Mutex::Autolock lock(mMutex);
420429
freeAllBuffers();
@@ -441,6 +450,7 @@ int SurfaceTextureClient::setUsage(uint32_t reqUsage)
441450

442451
int SurfaceTextureClient::setCrop(Rect const* rect)
443452
{
453+
ATRACE_CALL();
444454
ALOGV("SurfaceTextureClient::setCrop");
445455
Mutex::Autolock lock(mMutex);
446456

@@ -459,6 +469,7 @@ int SurfaceTextureClient::setCrop(Rect const* rect)
459469

460470
int SurfaceTextureClient::setBufferCount(int bufferCount)
461471
{
472+
ATRACE_CALL();
462473
ALOGV("SurfaceTextureClient::setBufferCount");
463474
Mutex::Autolock lock(mMutex);
464475

@@ -475,6 +486,7 @@ int SurfaceTextureClient::setBufferCount(int bufferCount)
475486

476487
int SurfaceTextureClient::setBuffersDimensions(int w, int h)
477488
{
489+
ATRACE_CALL();
478490
ALOGV("SurfaceTextureClient::setBuffersDimensions");
479491
Mutex::Autolock lock(mMutex);
480492

@@ -508,6 +520,7 @@ int SurfaceTextureClient::setBuffersFormat(int format)
508520

509521
int SurfaceTextureClient::setScalingMode(int mode)
510522
{
523+
ATRACE_CALL();
511524
ALOGV("SurfaceTextureClient::setScalingMode(%d)", mode);
512525
Mutex::Autolock lock(mMutex);
513526
// mode is validated on the server
@@ -520,6 +533,7 @@ int SurfaceTextureClient::setScalingMode(int mode)
520533

521534
int SurfaceTextureClient::setBuffersTransform(int transform)
522535
{
536+
ATRACE_CALL();
523537
ALOGV("SurfaceTextureClient::setBuffersTransform");
524538
Mutex::Autolock lock(mMutex);
525539
status_t err = mSurfaceTexture->setTransform(transform);

opengl/libs/EGL/eglApi.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
** limitations under the License.
1515
*/
1616

17+
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
18+
1719
#include <ctype.h>
1820
#include <stdlib.h>
1921
#include <string.h>
@@ -34,6 +36,7 @@
3436
#include <utils/KeyedVector.h>
3537
#include <utils/SortedVector.h>
3638
#include <utils/String8.h>
39+
#include <utils/Trace.h>
3740

3841
#include "egl_impl.h"
3942
#include "egl_tls.h"
@@ -348,6 +351,7 @@ EGLBoolean eglQuerySurface( EGLDisplay dpy, EGLSurface surface,
348351
}
349352

350353
void EGLAPI eglBeginFrame(EGLDisplay dpy, EGLSurface surface) {
354+
ATRACE_CALL();
351355
clearError();
352356

353357
egl_display_t const * const dp = validate_display(dpy);
@@ -712,6 +716,7 @@ __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname)
712716

713717
EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface draw)
714718
{
719+
ATRACE_CALL();
715720
clearError();
716721

717722
egl_display_t const * const dp = validate_display(dpy);

services/surfaceflinger/Layer.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
18+
1719
#include <stdlib.h>
1820
#include <stdint.h>
1921
#include <sys/types.h>
@@ -26,6 +28,7 @@
2628
#include <utils/Errors.h>
2729
#include <utils/Log.h>
2830
#include <utils/StopWatch.h>
31+
#include <utils/Trace.h>
2932

3033
#include <ui/GraphicBuffer.h>
3134
#include <ui/PixelFormat.h>
@@ -267,6 +270,8 @@ void Layer::setPerFrameData(hwc_layer_t* hwcl) {
267270

268271
void Layer::onDraw(const Region& clip) const
269272
{
273+
ATRACE_CALL();
274+
270275
if (CC_UNLIKELY(mActiveBuffer == 0)) {
271276
// the texture has not been created yet, this Layer has
272277
// in fact never been drawn into. This happens frequently with
@@ -365,6 +370,8 @@ bool Layer::isProtected() const
365370

366371
uint32_t Layer::doTransaction(uint32_t flags)
367372
{
373+
ATRACE_CALL();
374+
368375
const Layer::State& front(drawingState());
369376
const Layer::State& temp(currentState());
370377

@@ -418,6 +425,8 @@ bool Layer::onPreComposition() {
418425

419426
void Layer::lockPageFlip(bool& recomputeVisibleRegions)
420427
{
428+
ATRACE_CALL();
429+
421430
if (mQueuedFrames > 0) {
422431

423432
// if we've already called updateTexImage() without going through
@@ -540,6 +549,8 @@ void Layer::lockPageFlip(bool& recomputeVisibleRegions)
540549
void Layer::unlockPageFlip(
541550
const Transform& planeTransform, Region& outDirtyRegion)
542551
{
552+
ATRACE_CALL();
553+
543554
Region postedRegion(mPostedDirtyRegion);
544555
if (!postedRegion.isEmpty()) {
545556
mPostedDirtyRegion.clear();

services/surfaceflinger/SurfaceFlinger.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
18+
1719
#include <stdlib.h>
1820
#include <stdio.h>
1921
#include <stdint.h>
@@ -39,6 +41,7 @@
3941
#include <utils/String8.h>
4042
#include <utils/String16.h>
4143
#include <utils/StopWatch.h>
44+
#include <utils/Trace.h>
4245

4346
#include <ui/GraphicBufferAllocator.h>
4447
#include <ui/PixelFormat.h>
@@ -402,6 +405,7 @@ bool SurfaceFlinger::threadLoop()
402405

403406
void SurfaceFlinger::onMessageReceived(int32_t what)
404407
{
408+
ATRACE_CALL();
405409
switch (what) {
406410
case MessageQueue::REFRESH: {
407411
// case MessageQueue::INVALIDATE: {
@@ -737,6 +741,7 @@ void SurfaceFlinger::commitTransaction()
737741

738742
void SurfaceFlinger::handlePageFlip()
739743
{
744+
ATRACE_CALL();
740745
const DisplayHardware& hw = graphicPlane(0).displayHardware();
741746
const Region screenRegion(hw.bounds());
742747

0 commit comments

Comments
 (0)