本讲是android camera性能分析专题的第9讲,我们介绍在camera app或java framework添加trace,包括如下内容:
- java trace类说明
- 实战:在camera app中添加trace
- 实战:在camera java framework中添加trace
资源 | 描述 |
---|---|
在线课程 | |
知识星球 | 星球名称:深入浅出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();
}