当前位置: 首页 > news >正文

【Android 系统中使用CallStack类来追踪获取和操作调用栈信息】

Android系统CallStack类的使用

    • 定义
    • 使用方法
    • 使用场景
    • 注意事项
    • 应用举例

定义

在 Android 系统中,CallStack 类是一个用于获取和操作调用栈信息的工具类。这个类通常用于调试和日志记录,以帮助开发者了解函数调用的顺序和位置。以下是您提供的代码片段的解释和使用场景:

使用方法

  1. 在调试的文件中添加头文件
#include <utils/CallStack.h>
  1. 在构建脚本中添加库:libutilscallstack
    在Android.bp或者Android.mk文件中把libutilscallstack库文件包进去。
  • 对于 Android.bp
    cc_library {name: "libmylibrary",srcs: ["my_file.cpp"],static_libs: ["libutilscallstack"],
    }
    
  • 对于 Android.mk
    LOCAL_SHARED_LIBRARIES+= libutilscallstack
    
  1. 创建 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.cpp10-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

http://www.mrgr.cn/news/68470.html

相关文章:

  • Java教学新动力:SpringBoot辅助平台
  • 基于vue+neo4j 的中药方剂知识图谱可视化系统
  • C#的Event事件示例小白级剖析
  • [JAVAEE] 网络基础
  • 【Spring Security】 Spring Security 使用案例详细教程
  • Flutter中文字体设置指南:打造个性化的应用体验
  • windows server和sqlserver的版本更新
  • 扩展坞映射名称
  • MySQL DATETIME 和 DATE
  • linux基础理解和使用 iptables 防火墙
  • AssertionError: weight model.layers.0.self_attn.q_proj.weight does not exist
  • 十七:Spring Boot (2)-- spring-boot-starter-web 依赖详解
  • godot--自定义边框/选中时样式 StyleBoxTexture
  • 项目管理必备的5款项目管理软件
  • 海南华志亿星电子商务有限公司赋能抖音商家成长
  • 一款绘制3D架构图的在线神器,iCraft Editor
  • redis 原理篇 21 网络模型 IO多路复用 poll
  • 探索呼叫中心的奥秘:从基础到前沿进展
  • redis 原理篇 25 网络模型 信号驱动IO 及 异步IO
  • wordpress搬家迁移后怎么修改数据库用户名
  • TEMU测评:在挑战与机遇中寻求突破
  • 2024 信友队 noip 冲刺 10.8
  • Instagram 青少年账户:安全新升级
  • 第七部分:1. STM32之ADC实验--单通道实验(滑动变阻器调节电压)
  • ChronoUnit.DAYS.between()计算两个日期或时间之间的天数差
  • 【热插拔冗余电源】