Skip to content

Commit f96d117

Browse files
Romain GuyAndroid (Google) Code Review
authored andcommitted
Merge "Add extra systrace tracing" into jb-dev
2 parents fce2ec4 + 77e67cf commit f96d117

File tree

1 file changed

+43
-12
lines changed

1 file changed

+43
-12
lines changed

core/java/android/view/HardwareRenderer.java

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import android.os.Looper;
2828
import android.os.SystemClock;
2929
import android.os.SystemProperties;
30+
import android.os.Trace;
3031
import android.util.Log;
3132
import com.google.android.gles_jni.EGLImpl;
3233

@@ -40,6 +41,7 @@
4041

4142
import java.io.File;
4243
import java.io.PrintWriter;
44+
import java.util.concurrent.locks.ReentrantLock;
4345

4446
import static javax.microedition.khronos.egl.EGL10.*;
4547

@@ -623,6 +625,7 @@ static abstract class GlRenderer extends HardwareRenderer {
623625

624626
final boolean mProfileEnabled;
625627
final float[] mProfileData;
628+
final ReentrantLock mProfileLock;
626629
int mProfileCurrentFrame = -PROFILE_FRAME_DATA_COUNT;
627630

628631
final boolean mDebugDirtyRegions;
@@ -663,8 +666,11 @@ static abstract class GlRenderer extends HardwareRenderer {
663666
for (int i = 0; i < mProfileData.length; i += PROFILE_FRAME_DATA_COUNT) {
664667
mProfileData[i] = mProfileData[i + 1] = mProfileData[i + 2] = -1;
665668
}
669+
670+
mProfileLock = new ReentrantLock();
666671
} else {
667672
mProfileData = null;
673+
mProfileLock = null;
668674
}
669675

670676
property = SystemProperties.get(DEBUG_DIRTY_REGIONS_PROPERTY, "false");
@@ -678,15 +684,21 @@ static abstract class GlRenderer extends HardwareRenderer {
678684
void dumpGfxInfo(PrintWriter pw) {
679685
if (mProfileEnabled) {
680686
pw.printf("\n\tDraw\tProcess\tExecute\n");
681-
for (int i = 0; i < mProfileData.length; i += PROFILE_FRAME_DATA_COUNT) {
682-
if (mProfileData[i] < 0) {
683-
break;
687+
688+
mProfileLock.lock();
689+
try {
690+
for (int i = 0; i < mProfileData.length; i += PROFILE_FRAME_DATA_COUNT) {
691+
if (mProfileData[i] < 0) {
692+
break;
693+
}
694+
pw.printf("\t%3.2f\t%3.2f\t%3.2f\n", mProfileData[i], mProfileData[i + 1],
695+
mProfileData[i + 2]);
696+
mProfileData[i] = mProfileData[i + 1] = mProfileData[i + 2] = -1;
684697
}
685-
pw.printf("\t%3.2f\t%3.2f\t%3.2f\n", mProfileData[i], mProfileData[i + 1],
686-
mProfileData[i + 2]);
687-
mProfileData[i] = mProfileData[i + 1] = mProfileData[i + 2] = -1;
698+
mProfileCurrentFrame = mProfileData.length;
699+
} finally {
700+
mProfileLock.unlock();
688701
}
689-
mProfileCurrentFrame = mProfileData.length;
690702
}
691703
}
692704

@@ -1083,7 +1095,11 @@ boolean draw(View view, View.AttachInfo attachInfo, HardwareDrawCallbacks callba
10831095
if (surfaceState != SURFACE_STATE_ERROR) {
10841096
HardwareCanvas canvas = mCanvas;
10851097
attachInfo.mHardwareCanvas = canvas;
1086-
1098+
1099+
if (mProfileEnabled) {
1100+
mProfileLock.lock();
1101+
}
1102+
10871103
// We had to change the current surface and/or context, redraw everything
10881104
if (surfaceState == SURFACE_STATE_UPDATED) {
10891105
dirty = null;
@@ -1121,7 +1137,14 @@ boolean draw(View view, View.AttachInfo attachInfo, HardwareDrawCallbacks callba
11211137
getDisplayListStartTime = System.nanoTime();
11221138
}
11231139

1124-
DisplayList displayList = view.getDisplayList();
1140+
DisplayList displayList;
1141+
1142+
Trace.traceBegin(Trace.TRACE_TAG_VIEW, "getDisplayList");
1143+
try {
1144+
displayList = view.getDisplayList();
1145+
} finally {
1146+
Trace.traceEnd(Trace.TRACE_TAG_VIEW);
1147+
}
11251148

11261149
if (mProfileEnabled) {
11271150
long now = System.nanoTime();
@@ -1136,8 +1159,13 @@ boolean draw(View view, View.AttachInfo attachInfo, HardwareDrawCallbacks callba
11361159
drawDisplayListStartTime = System.nanoTime();
11371160
}
11381161

1139-
status |= canvas.drawDisplayList(displayList, mRedrawClip,
1140-
DisplayList.FLAG_CLIP_CHILDREN);
1162+
Trace.traceBegin(Trace.TRACE_TAG_VIEW, "drawDisplayList");
1163+
try {
1164+
status |= canvas.drawDisplayList(displayList, mRedrawClip,
1165+
DisplayList.FLAG_CLIP_CHILDREN);
1166+
} finally {
1167+
Trace.traceEnd(Trace.TRACE_TAG_VIEW);
1168+
}
11411169

11421170
if (mProfileEnabled) {
11431171
long now = System.nanoTime();
@@ -1174,7 +1202,6 @@ boolean draw(View view, View.AttachInfo attachInfo, HardwareDrawCallbacks callba
11741202
attachInfo.mIgnoreDirtyState = false;
11751203

11761204
if ((status & DisplayList.STATUS_DREW) == DisplayList.STATUS_DREW) {
1177-
11781205
long eglSwapBuffersStartTime = 0;
11791206
if (mProfileEnabled) {
11801207
eglSwapBuffersStartTime = System.nanoTime();
@@ -1191,6 +1218,10 @@ boolean draw(View view, View.AttachInfo attachInfo, HardwareDrawCallbacks callba
11911218
checkEglErrors();
11921219
}
11931220

1221+
if (mProfileEnabled) {
1222+
mProfileLock.unlock();
1223+
}
1224+
11941225
return dirty == null;
11951226
}
11961227
}

0 commit comments

Comments
 (0)