2024年10月28日 第9讲 在Camera App或Java Framework添加trace 极客笔记
本讲是Android Camera性能分析专题的第9讲,我们介绍在Camera App或Java Framework添加trace,包括如下内容:
资源 | 描述 |
---|---|
在线课程 | 极客笔记在线课程 |
知识星球 | 星球名称:深入浅出Android Camera 星球ID: 17296815 |
极客笔记圈 |
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前都判断下避免创建一些无用的临时对象 |
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);
}
}
}
public void openCameraForUid(@NonNull String cameraId,
@NonNull final CameraDevice.StateCallback callback, @NonNull Executor executor,
int clientUid, int oomScoreOffset) throws CameraAccessException {
Log.i(TAG, "v.lmcjl.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();
}
本文链接:http://so.lmcjl.com/news/16427/