【Android 系统中使用CallStack类来追踪获取和操作调用栈信息】
定义
在 Android 系统中,CallStack 类是一个用于获取和操作调用栈信息的工具类。这个类通常用于调试和日志记录,以帮助开发者了解函数调用的顺序和位置。以下是您提供的代码片段的解释和使用场景:
使用方法
- 在调试的文件中添加头文件
#include <utils/CallStack.h>
- 在构建脚本中添加库:libutilscallstack
在Android.bp或者Android.mk文件中把libutilscallstack库文件包进去。
- 对于 Android.bp:
cc_library { name: "libmylibrary", srcs: ["my_file.cpp"], static_libs: ["libutilscallstack"], }
- 对于 Android.mk:
LOCAL_STATIC_LIBRARIES += libutilscallstack
- 创建 CallStack 实例:
这行代码创建了一个android::CallStack cs("String");
CallStack
对象cs
,并初始化它。"String"
是一个标签,用于标识这个调用栈的用途或来源。这个标签可以是任何字符串,有助于在日志或调试输出中识别特定的调用栈实例。
使用场景
CallStack
类通常用于以下场景:
- 异常处理:在捕获异常时,使用
CallStack
来记录导致异常的函数调用序列。 - 性能分析:在性能关键的部分,使用
CallStack
来追踪函数调用,以便了解哪些函数是性能瓶颈。 - 日志记录:在日志消息中包含调用栈信息,以帮助开发者或技术支持人员了解日志消息的来源。
- 调试辅助:在调试过程中,使用
CallStack
来验证函数调用的顺序和层次结构。
注意事项
CallStack
类的具体实现和功能可能会根据不同的 Android 版本和平台有所不同。- 使用
CallStack
可能会引入一定的性能开销,因为它需要捕获和存储调用栈信息。因此,在性能敏感的应用中,应谨慎使用。 - 确保在您的项目中正确包含了
CallStack
所需的头文件和库文件,否则您的代码可能会编译失败。
应用举例
打印没有
10-25 10:15:56.707 2531 3090 D Vaccine : #00 pc 000000000001e684 /vendor/lib64/libcam.hal3a.v3.so (NS3Av3::Hal3AAdapter3::parseMeta(std::__1::vector<NS3Av3::MetaSet_T*, std::__1::allocator<NS3Av3::MetaSet_T*> > const&, char const*)+172)
10-25 10:15:56.707 2531 3090 D Vaccine : #01 pc 000000000001b764 /vendor/lib64/libcam.hal3a.v3.so (NS3Av3::Hal3AAdapter3::setNormal(std::__1::vector<NS3Av3::MetaSet_T*, std::__1::allocator<NS3Av3::MetaSet_T*> > const&)+1960)
10-25 10:15:56.707 2531 3090 D Vaccine : #02 pc 000000000001e3dc /vendor/lib64/libcam.hal3a.v3.so (NS3Av3::Hal3AAdapter3::set(std::__1::vector<NS3Av3::MetaSet_T*, std::__1::allocator<NS3Av3::MetaSet_T*> > const&)+8)
10-25 10:15:56.707 2531 3090 D Vaccine : #03 pc 000000000001e284 /vendor/lib64/libcam.hal3a.v3.so (NS3Av3::Hal3AAdapter3::startRequestQ(std::__1::vector<NS3Av3::MetaSet_T*, std::__1::allocator<NS3Av3::MetaSet_T*> > const&)+2084)
10-25 10:15:56.707 2531 3090 D Vaccine : #04 pc 00000000000dea24 /vendor/lib64/libmtkcam_hwnode.so (NSCam::v3::NSP1Node::P1NodeImp::hardwareOps_request()+2812)
10-25 10:15:56.707 2531 3090 D Vaccine : #05 pc 00000000000c8794 /vendor/lib64/libmtkcam_hwnode.so (NSCam::v3::NSP1Node::P1NodeImp::runQueue(android::sp<NSCam::v3::IPipelineFrame> const&)+9912)
10-25 10:15:56.707 2531 3090 D Vaccine : #06 pc 00000000000d69d4 /vendor/lib64/libmtkcam_hwnode.so (NSCam::v3::NSP1Node::P1NodeImp::queue(android::sp<NSCam::v3::IPipelineFrame>)+444)
10-25 10:15:56.707 2531 3090 D Vaccine : #07 pc 0000000000072a78 /vendor/lib64/libmtkcam_pipeline.so (NSCam::v3::pipeline::NSPipelineContext::PipelineContext::PipelineContextImpl::sendFrameToRootNodes(android::sp<NSCam::v3::IPipelineFrame> const&, android::Vector<android::sp<NSCam::v3::IPipelineNode> >&)+428)
10-25 10:15:56.707 2531 3090 D Vaccine : #08 pc 0000000000072154 /vendor/lib64/libmtkcam_pipeline.so (NSCam::v3::pipeline::NSPipelineContext::PipelineContext::PipelineContextImpl::sendFrame(android::sp<NSCam::v3::IPipelineFrame> const&)+1628)
10-25 10:15:56.707 2531 3090 D Vaccine : #09 pc 0000000000071ac8 /vendor/lib64/libmtkcam_pipeline.so (NSCam::v3::pipeline::NSPipelineContext::PipelineContext::PipelineContextImpl::submitOneFrame(android::sp<NSCam::v3::IPipelineFrame> const&)+392)
10-25 10:15:56.707 2531 3090 D Vaccine : #10 pc 0000000000071794 /vendor/lib64/libmtkcam_pipeline.so (NSCam::v3::pipeline::NSPipelineContext::PipelineContext::PipelineContextImpl::submitFrame(std::__1::vector<android::sp<NSCam::v3::IPipelineFrame>, std::__1::allocator<android::sp<NSCam::v3::IPipelineFrame> > > const&)+116)
10-25 10:15:56.707 2531 3090 D Vaccine : #11 pc 000000000003d7a0 /vendor/lib64/libmtkcam_pipelinemodel_session.so (NSCam::v3::pipeline::model::PipelineModelSessionDefault::onProcessEvaluatedFrame(unsigned int&, unsigned int&, NSCam::v3::pipeline::model::PipelineModelSessionBasic::ProcessEvaluatedFrame const&)+3584)
10-25 10:15:56.708 2531 3090 D Vaccine : #12 pc 0000000000038f38 /vendor/lib64/libmtkcam_pipelinemodel_session.so (NSCam::v3::pipeline::model::PipelineModelSessionBasic::processEvaluatedFrame(NSCam::v3::pipeline::model::PipelineModelSessionBasic::ProcessEvaluatedFrame const&)+616)
10-25 10:15:56.708 2531 3090 D Vaccine : #13 pc 0000000000047438 /vendor/lib64/libmtkcam_pipelinemodel_session.so (NSCam::v3::pipeline::model::PipelineModelSession4Cell::submitOneRequest(std::__1::shared_ptr<NSCam::v3::pipeline::model::ParsedAppRequest> const&)+3224)
10-25 10:15:56.708 2531 3090 D Vaccine : #14 pc 0000000000032090 /vendor/lib64/libmtkcam_pipelinemodel_session.so (NSCam::v3::pipeline::model::PipelineModelSessionBase::submitRequest(std::__1::vector<std::__1::shared_ptr<NSCam::v3::pipeline::model::UserRequestParams>, std::__1::allocator<std::__1::shared_ptr<NSCam::v3::pipeline::model::UserRequestParams> > > const&, unsigned int&)+1072)
10-25 10:15:56.708 2531 3090 D Vaccine : #15 pc 000000000000e468 /vendor/lib64/libmtkcam_pipelinemodel.so (NSCam::v3::pipeline::model::PipelineModelImpl::submitRequest(std::__1::vector<std::__1::shared_ptr<NSCam::v3::pipeline::model::UserRequestParams>, std::__1::allocator<std::__1::shared_ptr<NSCam::v3::pipeline::model::UserRequestParams> > > const&, unsigned int&)+212)
10-25 10:15:56.708 2531 3090 D Vaccine : #16 pc 0000000000025f00 /vendor/lib64/libmtkcam_device3_hal.so (NSCam::v3::CameraDevice3SessionImpl::onProcessCaptureRequest(std::__1::vector<NSCam::v3::CaptureRequest, std::__1::allocator<NSCam::v3::CaptureRequest> > const&, unsigned int&)+5668)
10-25 10:15:56.708 2531 3090 D Vaccine : #17 pc 000000000002c124 /vendor/lib64/libmtkcam_device3_hal.so (NSCam::v3::CameraDevice3SessionImpl::processCaptureRequest(std::__1::vector<NSCam::v3::CaptureRequest, std::__1::allocator<NSCam::v3::CaptureRequest> > const&, unsigned int&)+260)
10-25 10:15:56.708 2531 3090 D Vaccine : #18 pc 000000000001af98 /vendor/lib64/libmtkcam_device3_hidl.so (NSCam::hidl_dev3::HidlCameraDeviceSession::processCaptureRequest_3_4(android::hardware::hidl_vec<android::hardware::camera::device::V3_4::CaptureRequest> const&, android::hardware::hidl_vec<android::hardware::camera::device::V3_2::BufferCache> const&, std::__1::function<void (android::hardware::camera::common::V1_0::Status, unsigned int)>)+692)
10-25 10:15:56.708 2531 3090 D Vaccine : #19 pc 000000000001b524 /apex/com.android.vndk.v30/lib64/android.hardware.camera.device@3.4.so (android::hardware::camera::device::V3_4::BnHwCameraDeviceSession::_hidl_processCaptureRequest_3_4(android::hidl::base::V1_0::BnHwBase*, android::hardware::Parcel const&, android::hardware::Parcel*, std::__1::function<void (android::hardware::Parcel&)>)+564)
10-25 10:15:56.708 2531 3090 D Vaccine : #20 pc 00000000000265b8 /apex/com.android.vndk.v30/lib64/android.hardware.camera.device@3.6.so (android::hardware::camera::device::V3_6::BnHwCameraDeviceSession::onTransact(unsigned int, android::hardware::Parcel const&, android::hardware::Parcel*, unsigned int, std::__1::function<void (android::hardware::Parcel&)>)+1176)
10-25 10:15:56.708 2531 3090 D Vaccine : #21 pc 0000000000082700 /apex/com.android.vndk.v30/lib64/libhidlbase.so (android::hardware::BHwBinder::transact(unsigned int, android::hardware::Parcel const&, android::hardware::Parcel*, unsigned int, std::__1::function<void (android::hardware::Parcel&)>)+72)
10-25 10:15:56.708 2531 3090 D Vaccine : #22 pc 0000000000086678 /apex/com.android.vndk.v30/lib64/libhidlbase.so (android::hardware::IPCThreadState::getAndExecuteCommand()+1076)
10-25 10:15:56.708 2531 3090 D Vaccine : #23 pc 00000000000878e4 /apex/com.android.vndk.v30/lib64/libhidlbase.so (android::hardware::IPCThreadState::joinThreadPool(bool)+96)
10-25 10:15:56.708 2531 3090 D Vaccine : #24 pc 0000000000096b88 /apex/com.android.vndk.v30/lib64/libhidlbase.so (android::hardware::PoolThread::threadLoop()+24)
10-25 10:15:56.708 2531 3090 D Vaccine : #25 pc 0000000000015334 /apex/com.android.vndk.v30/lib64/libutils.so (android::Thread::_threadLoop(void*)+260)
10-25 10:15:56.708 2531 3090 D Vaccine : #26 pc 0000000000014bf8 /apex/com.android.vndk.v30/lib64/libutils.so (thread_data_t::trampoline(thread_data_t const*)+412)
10-25 10:15:56.708 2531 3090 D Vaccine : #27 pc 00000000000ecacc /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+64)
10-25 10:15:56.708 2531 3090 D Vaccine : #28 pc 000000000008d340 /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64)
10-25 10:15:56.708 2531 3090 D Hal3Av3 : ontim entry.tag is bad tag!
10-25 10:15:56.708 30039 30590 D InsetsAnimationCtrlImpl: Animation finished abruptly.
10-25 10:15:56.708 2531 3090 D Hal3Av3 : ontim entry isEmpty!
10-25 10:15:56.708 2531 3090 D Hal3Av3 : [parseMeta] Set Manual Pline Index back to 0
10-25 10:15:56.708 2531 3090 D Hal3Av3 : [parseMeta] Set Custom Pline Mode back to 0
整理调用关系如下
@startuml
vendor/mediatek/proprietary/hardware/mtkcam/aaa/source/common/hal3a/v3.0/Hal3AAdapter3.cpp
vendor/mediatek/proprietary/hardware/mtkcam3/pipeline/hwnode/p1/P1NodeImp.cpp
vendor/mediatek/proprietary/hardware/mtkcam3/pipeline/pipeline/PipelineContextImpl.cpp
vendor/mediatek/proprietary/hardware/mtkcam3/pipeline/pipeline/PipelineContext.cpp
vendor/mediatek/proprietary/hardware/mtkcam3/pipeline/model/session/PipelineModelSessionDefault.cpp
vendor/mediatek/proprietary/hardware/mtkcam3/pipeline/model/session/PipelineModelSessionBasic.cpp
vendor/mediatek/proprietary/hardware/mtkcam3/pipeline/model/session/PipelineModelSession4Cell.cpp
vendor/mediatek/proprietary/hardware/mtkcam/middleware/v3/pipeline/adapter/PipelineModelManagerImpl.cpp
vendor/mediatek/proprietary/hardware/mtkcam3/pipeline/model/session/PipelineModelSessionBase.cpp
vendor/mediatek/proprietary/hardware/mtkcam3/pipeline/model/PipelineModelImpl.cpp
vendor/mediatek/proprietary/hardware/mtkcam/main/hal/device/3.x/device/CameraDevice3SessionImpl.cpp
vendor/mediatek/proprietary/hardware/mtkcam3/main/hal/entry/hidl/device/3.x/HidlCameraDeviceSession.cpp
10-25 10:15:56.708 2531 3090 D Vaccine : #19 pc 000000000001b524 /apex/com.android.vndk.v30/lib64/android.hardware.camera.device@3.4.so (android::hardware::camera::device::V3_4::BnHwCameraDeviceSession::_hidl_processCaptureRequest_3_4(android::hidl::base::V1_0::BnHwBase*, android::hardware::Parcel const&, android::hardware::Parcel*, std::__1::function<void (android::hardware::Parcel&)>)+564)
10-25 10:15:56.708 2531 3090 D Vaccine : #20 pc 00000000000265b8 /apex/com.android.vndk.v30/lib64/android.hardware.camera.device@3.6.so (android::hardware::camera::device::V3_6::BnHwCameraDeviceSession::onTransact(unsigned int, android::hardware::Parcel const&, android::hardware::Parcel*, unsigned int, std::__1::function<void (android::hardware::Parcel&)>)+1176)
10-25 10:15:56.708 2531 3090 D Vaccine : #21 pc 0000000000082700 /apex/com.android.vndk.v30/lib64/libhidlbase.so (android::hardware::BHwBinder::transact(unsigned int, android::hardware::Parcel const&, android::hardware::Parcel*, unsigned int, std::__1::function<void (android::hardware::Parcel&)>)+72)
10-25 10:15:56.708 2531 3090 D Vaccine : #22 pc 0000000000086678 /apex/com.android.vndk.v30/lib64/libhidlbase.so (android::hardware::IPCThreadState::getAndExecuteCommand()+1076)
10-25 10:15:56.708 2531 3090 D Vaccine : #23 pc 00000000000878e4 /apex/com.android.vndk.v30/lib64/libhidlbase.so (android::hardware::IPCThreadState::joinThreadPool(bool)+96)
10-25 10:15:56.708 2531 3090 D Vaccine : #24 pc 0000000000096b88 /apex/com.android.vndk.v30/lib64/libhidlbase.so (android::hardware::PoolThread::threadLoop()+24)
10-25 10:15:56.708 2531 3090 D Vaccine : #25 pc 0000000000015334 /apex/com.android.vndk.v30/lib64/libutils.so (android::Thread::_threadLoop(void*)+260)
10-25 10:15:56.708 2531 3090 D Vaccine : #26 pc 0000000000014bf8 /apex/com.android.vndk.v30/lib64/libutils.so (thread_data_t::trampoline(thread_data_t const*)+412)
10-25 10:15:56.708 2531 3090 D Vaccine : #27 pc 00000000000ecacc /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+64)
10-25 10:15:56.708 2531 3090 D Vaccine : #28 pc 000000000008d340 /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64)
HidlCameraDeviceSession.cpp --> CameraDevice3SessionImpl.cpp: static_cast<status_t>(mSession->processCaptureRequest(captureRequests, numRequestProcessed));
CameraDevice3SessionImpl.cpp --> CameraDevice3SessionImpl.cpp: onProcessCaptureRequest(v34Requests, cachesToRemove, numRequestProcessed);
CameraDevice3SessionImpl.cpp --> PipelineModelImpl.cpp: pPipelineModel->submitRequest(vPipelineRequests, numRequestProcessed);
PipelineModelImpl.cpp --> PipelineModelSessionBase.cpp: session->submitRequest(requests, numRequestProcessed);
PipelineModelSessionBase.cpp --> PipelineModelSession4Cell.cpp: submitOneRequest(reqs[i]);
PipelineModelSession4Cell.cpp --> PipelineModelSessionBasic.cpp: processEvaluatedFrame()
PipelineModelSessionBasic.cpp --> PipelineModelSessionDefault.cpp: onProcessEvaluatedFrame(lastFrameNo, lastZslFrameNo, in);
PipelineModelSessionDefault.cpp --> PipelineContext.cpp: in.pPipelineContext->queue(pplFrames)
PipelineContext.cpp --> P1NodeImp.cpp: getImpl()->submitFrame(frames);
P1NodeImp.cpp --> P1NodeImp.cpp: submitOneFrame(f);
P1NodeImp.cpp --> P1NodeImp.cpp: return sendFrame(pFrame);//PipelineContext::PipelineContextImpl::sendFrame();
P1NodeImp.cpp --> P1NodeImp.cpp: sendFrameToRootNodes(pFrame, vspPipelineNode)
P1NodeImp.cpp --> P1NodeImp.cpp: (*it)->queue(pFrame);
P1NodeImp.cpp --> P1NodeImp.cpp: runQueue(pFrame);
P1NodeImp.cpp --> P1NodeImp.cpp: hardwareOps_request();
P1NodeImp.cpp --> Hal3AAdapter3.cpp: mp3A->startRequestQ(ctrlQueue);
Hal3AAdapter3.cpp --> Hal3AAdapter3.cpp: Hal3AAdapter3::startRequestQ(const std::vector<MetaSet_T*>& requestQ)
Hal3AAdapter3.cpp --> Hal3AAdapter3.cpp: Hal3AAdapter3::set(const vector<MetaSet_T*>& requestQ)
Hal3AAdapter3.cpp --> Hal3AAdapter3.cpp: Hal3AAdapter3::setNormal(const vector<MetaSet_T*>& requestQ)
Hal3AAdapter3.cpp --> Hal3AAdapter3.cpp: parseMeta(requestQ, __FUNCTION__);\n case MTK_CONTROL_AF_MODE:
@enduml
原文地址:https://blog.csdn.net/weixin_43326587/article/details/143489904
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!