本讲是Android Camera性能分析专题的第9讲,我们介绍在Camera App或Java Framework添加trace,包括如下内容:
- Java Trace类说明
- 实战:在Camera App中添加Trace
- 实战:在Camera Java Framework中添加Trace
视频在线观看:
加入知识星球与更多Camera同学交流 – 星球名称:深入浅出Android Camera – 星球ID: 17296815
Java Trace类说明
android.os.Trace类 | 描述 |
---|
beginSection(String sectionName) | 在一个函数中打印Trace开始标记,会显示在某个线程中 | endSection() | 在一个函数中打印Trace结束标记,会显示在某个线程中 | beginAsyncSection(String methodName, int cookie) | 打印异步Trace开始标记,cookie用来区分相同methodName不同的异步Trace,会独立成一行Trace显示 | endAsyncSection(String methodName, int cookie) | 打印异步Trace结束标记,cookie用来区分相同methodName不同的异步Trace,会独立成一行Trace显示 | setCounter(String counterName, long counterValue) | 以给定计数器的值打印Trace | isEnabled() | 判断是否Trace打开了,建议打印Trace前都判断下避免创建一些无用的临时对象 |
实战:在Camera App中添加Trace
public class GeekCamera2Trace {
public static final String OPEN_CAMERA = "GC2_openCamera";
public static final String CREATE_CAPTURE_SESSION = "GC2_createCaptureSession";
public static final String FRAME_NUMBER = "GC2_FrameNumber";
public static void beginAsyncSection(String methodName, int cookie) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && Trace.isEnabled()) {
Trace.beginAsyncSection(methodName, cookie);
}
}
public static void endAsyncSection(String methodName, int cookie) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && Trace.isEnabled()) {
Trace.endAsyncSection(methodName, cookie);
}
}
public static void beginSection(String sectionName) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&Trace.isEnabled()) {
Trace.beginSection(sectionName);
}
}
public static void endSection() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&Trace.isEnabled()) {
Trace.endSection();
}
}
public static void setCounter(String counterName, long counterValue) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&Trace.isEnabled()) {
Trace.setCounter(counterName, counterValue);
}
}
}
实战:在Camera Java Framework中添加Trace
public void openCameraForUid(@NonNull String cameraId,
@NonNull final CameraDevice.StateCallback callback, @NonNull Executor executor,
int clientUid, int oomScoreOffset) throws CameraAccessException {
Log.i(TAG, "v.deepinout.com openCameraForUid cameraId:" + cameraId);
Trace.beginSection("GC2_FWK_openCameraForUid");
if (cameraId == null) {
throw new IllegalArgumentException("cameraId was null");
} else if (callback == null) {
throw new IllegalArgumentException("callback was null");
}
if (CameraManagerGlobal.sCameraServiceDisabled) {
throw new IllegalArgumentException("No cameras available on device");
}
openCameraDeviceUserAsync(cameraId, callback, executor, clientUid, oomScoreOffset);
Trace.endSection();
}
Android模拟器替换image后无法开机怎么办
?
|