android系统堆栈打印

一. java层

Java 堆栈打印:Log.d(TAG,Log.getStackTraceString(new Throwable()));

二.C++层堆栈打印
 #include <utils/CallStack.h>
 android::CallStack stack(LOG_TAG);
加入库 libutilscallstack.so

三.C层

四.kernel层

  dump_stack();

五.实例

以下为从java层调用到C++层打开音频设备的完整流程:
函数传递的参数中包含了打开音频设备的卡号,和设备号。

//C++打开音频设备的函数调用, 从C到binder。
01-01 05:30:51.562 D/AudioFlinger( 3118): #00 pc 000165b7  /system/lib/libaudioflinger.so (android::AudioFlinger::openOutput(int, int*, audio_config*, unsigned int*, android::String8 const&, unsigned int*, audio_output_flags_t)+78)
01-01 05:30:51.562 D/AudioFlinger( 3118): #01 pc 0000e4b9  /system/lib/libaudiopolicyservice.so (android::AudioPolicyService::AudioPolicyClient::openOutput(int, int*, audio_config*, unsigned int*, android::String8 const&, unsigned int*, audio_output_flags_t)+60)
01-01 05:30:51.562 D/AudioFlinger( 3118): #02 pc 000336b3  /system/lib/libaudiopolicymanagerdefault.so (android::SwAudioOutputDescriptor::open(audio_config const*, unsigned int, android::String8 const&, audio_stream_type_t, audio_output_flags_t, int*)+202)
01-01 05:30:51.562 D/AudioFlinger( 3118): #03 pc 0001d799  /system/lib/libaudiopolicymanagerdefault.so (android::AudioPolicyManager::checkOutputsForDevice(android::sp<android::DeviceDescriptor> const&, audio_policy_dev_state_t, android::SortedVector<int>&, android::String8 const&)+1644)
01-01 05:30:51.562 D/AudioFlinger( 3118): #04 pc 0001cdcf  /system/lib/libaudiopolicymanagerdefault.so (android::AudioPolicyManager::setDeviceConnectionStateInt(unsigned int, audio_policy_dev_state_t, char const*, char const*)+1450)
01-01 05:30:51.562 D/AudioFlinger( 3118): #05 pc 0001c801  /system/lib/libaudiopolicymanagerdefault.so (android::AudioPolicyManager::setDeviceConnectionState(unsigned int, audio_policy_dev_state_t, char const*, char const*)+12)
01-01 05:30:51.562 D/AudioFlinger( 3118): #06 pc 0000c2a9  /system/lib/libaudiopolicyservice.so (android::AudioPolicyService::setDeviceConnectionState(unsigned int, audio_policy_dev_state_t, char const*, char const*)+88)
01-01 05:30:51.562 D/AudioFlinger( 3118): #07 pc 0003f599  /system/lib/libaudioclient.so (android::BnAudioPolicyService::onTransact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+4544)
01-01 05:30:51.562 D/AudioFlinger( 3118): #08 pc 000361cf  /system/lib/libbinder.so (android::BBinder::transact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+70)
01-01 05:30:51.562 D/AudioFlinger( 3118): #09 pc 0003da17  /system/lib/libbinder.so (android::IPCThreadState::executeCommand(int)+410)
01-01 05:30:51.562 D/AudioFlinger( 3118): #10 pc 0003d7a3  /system/lib/libbinder.so (android::IPCThreadState::getAndExecuteCommand()+106)
01-01 05:30:51.562 D/AudioFlinger( 3118): #11 pc 0003dccb  /system/lib/libbinder.so (android::IPCThreadState::joinThreadPool(bool)+38)
01-01 05:30:51.562 D/AudioFlinger( 3118): #12 pc 0005471d  /system/lib/libbinder.so (android::PoolThread::threadLoop()+12)
01-01 05:30:51.562 D/AudioFlinger( 3118): #13 pc 0000c147  /system/lib/libutils.so (android::Thread::_threadLoop(void*)+166)
01-01 05:30:51.562 D/AudioFlinger( 3118): #14 pc 00063c15  /system/lib/libc.so (__pthread_start(void*)+22)
01-01 05:30:51.562 D/AudioFlinger( 3118): #15 pc 0001e065  /system/lib/libc.so (__start_thread+22)

//java打开音频设备的函数调用,从binder到上层的java.
01-01 05:30:53.083 D/AudioSystem( 3266): #00 pc 0002d9e7  /system/lib/libaudioclient.so (android::AudioSystem::setDeviceConnectionState(unsigned int, audio_policy_dev_state_t, char const*, char const*)+82)
01-01 05:30:53.083 D/AudioSystem( 3266): #01 pc 000e60bf  /system/lib/libandroid_runtime.so (android_media_AudioSystem_setDeviceConnectionState(_JNIEnv*, _jobject*, int, int, _jstring*, _jstring*)+58)
01-01 05:30:53.083 D/AudioSystem( 3266): #02 pc 003b65e7  /system/framework/arm/boot-framework.oat (offset 0x3ab000) (android.media.AudioSystem.setDeviceConnectionState [DEDUPED]+158)
01-01 05:30:53.083 D/AudioSystem( 3266): #03 pc 008a6149  /system/framework/oat/arm/services.odex (offset 0x5c2000) (com.android.server.audio.AudioService.handleDeviceConnection+1224)
01-01 05:30:53.083 D/AudioSystem( 3266): #04 pc 008abf29  /system/framework/oat/arm/services.odex (offset 0x5c2000) (com.android.server.audio.AudioService.onSetWiredDeviceConnectionState+688)
01-01 05:30:53.083 D/AudioSystem( 3266): #05 pc 0089218b  /system/framework/oat/arm/services.odex (offset 0x5c2000) (com.android.server.audio.AudioService$AudioHandler.handleMessage+1714)
01-01 05:30:53.083 D/AudioSystem( 3266): #06 pc 0090e8b9  /system/framework/arm/boot-framework.oat (offset 0x3ab000) (android.os.Handler.dispatchMessage+136)
01-01 05:30:53.083 D/AudioSystem( 3266): #07 pc 00910fb3  /system/framework/arm/boot-framework.oat (offset 0x3ab000) (android.os.Looper.loop+1162)
01-01 05:30:53.083 D/AudioSystem( 3266): #08 pc 00895873  /system/framework/oat/arm/services.odex (offset 0x5c2000) (com.android.server.audio.AudioService$AudioSystemThread.run+330)
01-01 05:30:53.083 D/AudioSystem( 3266): #09 pc 00417d75  /system/lib/libart.so (art_quick_invoke_stub_internal+68)
01-01 05:30:53.083 D/AudioSystem( 3266): #10 pc 003f12e7  /system/lib/libart.so (art_quick_invoke_stub+226)
01-01 05:30:53.083 D/AudioSystem( 3266): #11 pc 000a1031  /system/lib/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+136)
01-01 05:30:53.083 D/AudioSystem( 3266): #12 pc 00350a6d  /system/lib/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod*, art::(anonymous namespace)::ArgArray*, art::JValue*, char const*)+52)
01-01 05:30:53.083 D/AudioSystem( 3266): #13 pc 003517f9  /system/lib/libart.so (art::InvokeVirtualOrInterfaceWithJValues(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jmethodID*, jvalue*)+316)
01-01 05:30:53.083 D/AudioSystem( 3266): #14 pc 00373369  /system/lib/libart.so (art::Thread::CreateCallback(void*)+900)
01-01 05:30:53.083 D/AudioSystem( 3266): #15 pc 00063c15  /system/lib/libc.so (__pthread_start(void*)+22)
01-01 05:30:53.084 D/AudioSystem( 3266): #16 pc 0001e065  /system/lib/libc.so (__start_thread+22

//java层的log,添加USB,最后到函数monitorUsbHostBus
01-01 05:30:46.254 D/AudioService( 3275): java.lang.Throwable
01-01 05:30:46.254 D/AudioService( 3275):     at com.android.server.audio.AudioService.setWiredDeviceConnectionState(AudioService.java:4620)
01-01 05:30:46.254 D/AudioService( 3275):     at com.android.server.usb.UsbAlsaDevice.updateWiredDeviceConnectionState(UsbAlsaDevice.java:206)
01-01 05:30:46.254 D/AudioService( 3275):     at com.android.server.usb.UsbAlsaDevice.start(UsbAlsaDevice.java:168)
01-01 05:30:46.254 D/AudioService( 3275):     at com.android.server.usb.UsbAlsaManager.selectAlsaDevice(UsbAlsaManager.java:106)
01-01 05:30:46.254 D/AudioService( 3275):     at com.android.server.usb.UsbAlsaManager.usbDeviceAdded(UsbAlsaManager.java:193)
01-01 05:30:46.254 D/AudioService( 3275):     at com.android.server.usb.UsbHostManager.usbDeviceAdded(UsbHostManager.java:393)
01-01 05:30:46.254 D/AudioService( 3275):     at com.android.server.usb.UsbHostManager.monitorUsbHostBus(Native Method)
01-01 05:30:46.254 D/AudioService( 3275):     at com.android.server.usb.UsbHostManager.lambda$XT3F5aQci4H6VWSBYBQQNSzpnvs(Unknown Source:0)
01-01 05:30:46.254 D/AudioService( 3275):     at com.android.server.usb.-$$Lambda$UsbHostManager$XT3F5aQci4H6VWSBYBQQNSzpnvs.run(Unknown Source:2)
01-01 05:30:46.254 D/AudioService( 3275):     at java.lang.Thread.run(Thread.java:764)

//java层的log,移除USB,最后到函数monitorUsbHostBus
01-01 05:31:27.720 D/AudioService( 3275): java.lang.Throwable
01-01 05:31:27.720 D/AudioService( 3275):     at com.android.server.audio.AudioService.setWiredDeviceConnectionState(AudioService.java:4620)
01-01 05:31:27.720 D/AudioService( 3275):     at com.android.server.usb.UsbAlsaDevice.updateWiredDeviceConnectionState(UsbAlsaDevice.java:206)
01-01 05:31:27.720 D/AudioService( 3275):     at com.android.server.usb.UsbAlsaDevice.stop(UsbAlsaDevice.java:174)
01-01 05:31:27.720 D/AudioService( 3275):     at com.android.server.usb.UsbAlsaManager.deselectAlsaDevice(UsbAlsaManager.java:111)
01-01 05:31:27.720 D/AudioService( 3275):     at com.android.server.usb.UsbAlsaManager.usbDeviceRemoved(UsbAlsaManager.java:247)
01-01 05:31:27.720 D/AudioService( 3275):     at com.android.server.usb.UsbHostManager.usbDeviceRemoved(UsbHostManager.java:415)
01-01 05:31:27.720 D/AudioService( 3275):     at com.android.server.usb.UsbHostManager.monitorUsbHostBus(Native Method)
01-01 05:31:27.720 D/AudioService( 3275):     at com.android.server.usb.UsbHostManager.lambda$XT3F5aQci4H6VWSBYBQQNSzpnvs(Unknown Source:0)
01-01 05:31:27.720 D/AudioService( 3275):     at com.android.server.usb.-$$Lambda$UsbHostManager$XT3F5aQci4H6VWSBYBQQNSzpnvs.run(Unknown Source:2)
01-01 05:31:27.720 D/AudioService( 3275):     at java.lang.Thread.run(Thread.java:764)

 

 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐