From 2d8e55f45e52ac0b18c0e46de602e6a6d5ab1001 Mon Sep 17 00:00:00 2001 From: Igor Murashkin Date: Mon, 4 Nov 2013 16:42:51 -0800 Subject: camera2: Add tracing to AutoFocusStateMachine (lens-locking actions only) Bug: 11071158 Change-Id: I6a1d0130b6ca36c853f539ef3f1afb363a70df24 --- .../ex/camera2/pos/AutoFocusStateMachine.java | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/camera2/public/src/com/android/ex/camera2/pos/AutoFocusStateMachine.java b/camera2/public/src/com/android/ex/camera2/pos/AutoFocusStateMachine.java index 5b11c2b..ce66285 100644 --- a/camera2/public/src/com/android/ex/camera2/pos/AutoFocusStateMachine.java +++ b/camera2/public/src/com/android/ex/camera2/pos/AutoFocusStateMachine.java @@ -21,6 +21,8 @@ import android.hardware.camera2.CaptureRequest; import android.hardware.camera2.CaptureResult; import android.util.Log; +import com.android.ex.camera2.utils.SysTrace; + /** * Manage the auto focus state machine for CameraDevice. * @@ -72,6 +74,10 @@ public class AutoFocusStateMachine { private int mCurrentAfMode = AF_UNINITIALIZED; private int mCurrentAfTrigger = AF_UNINITIALIZED; + private int mCurrentAfCookie = AF_UNINITIALIZED; + private String mCurrentAfTrace = ""; + private int mLastAfCookie = 0; + public AutoFocusStateMachine(AutoFocusStateListener listener) { if (listener == null) { throw new IllegalArgumentException("listener should not be null"); @@ -146,9 +152,11 @@ public class AutoFocusStateMachine { switch (afState) { case CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED: mListener.onAutoFocusSuccess(result, /*locked*/true); + endTraceAsync(); break; case CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED: mListener.onAutoFocusFail(result, /*locked*/true); + endTraceAsync(); break; case CaptureResult.CONTROL_AF_STATE_PASSIVE_FOCUSED: mListener.onAutoFocusSuccess(result, /*locked*/false); @@ -195,6 +203,8 @@ public class AutoFocusStateMachine { throw new IllegalStateException("AF mode was not enabled"); } + beginTraceAsync("AFSM_lockAutoFocus"); + mCurrentAfTrigger = CaptureRequest.CONTROL_AF_TRIGGER_START; repeatingBuilder.set(CaptureRequest.CONTROL_AF_MODE, mCurrentAfMode); @@ -275,6 +285,8 @@ public class AutoFocusStateMachine { CaptureRequest.Builder requestBuilder) { if (VERBOSE_LOGGING) Log.v(TAG, "setActiveAutoFocus"); + beginTraceAsync("AFSM_setActiveAutoFocus"); + mCurrentAfMode = CaptureRequest.CONTROL_AF_MODE_AUTO; repeatingBuilder.set(CaptureRequest.CONTROL_AF_MODE, mCurrentAfMode); @@ -311,4 +323,27 @@ public class AutoFocusStateMachine { repeatingBuilder.set(CaptureRequest.CONTROL_AF_MODE, mCurrentAfMode); } + + private synchronized void beginTraceAsync(String sectionName) { + if (mCurrentAfCookie != AF_UNINITIALIZED) { + // Terminate any currently active async sections before beginning another section + SysTrace.endSectionAsync(mCurrentAfTrace, mCurrentAfCookie); + } + + mLastAfCookie++; + mCurrentAfCookie = mLastAfCookie; + mCurrentAfTrace = sectionName; + + SysTrace.beginSectionAsync(sectionName, mCurrentAfCookie); + } + + private synchronized void endTraceAsync() { + if (mCurrentAfCookie == AF_UNINITIALIZED) { + Log.w(TAG, "endTraceAsync - no current trace active"); + return; + } + + SysTrace.endSectionAsync(mCurrentAfTrace, mCurrentAfCookie); + mCurrentAfCookie = AF_UNINITIALIZED; + } } -- cgit v1.2.3