[MTK] 如何在android native code 打callstack
文摘 MediaTek 2020-10-13 阅读:7708[DESCRIPTION]
分析native代码流程相关问题时可以用如下方式打出调用栈,适用于Android P及以上
[SOLUTION]
三个步骤
1.找到你需要添加callstack的源代码所在的Android.bp文件
frameworks/av/media/libmedia/Android.bp
2.在Android.bp文件中找到你需要添加callstack的源文件所对应的cc_library name,再在cc_library下面找到"header_libs"和"shared_libs" ,分别添加如下两行代码
在header_libs下面添加"libutils_headers",
在shared_libs下面添加"libutilscallstack",
3.在你需要添加callstack的源文件中引入CallStack的头文件,并在相应代码处添加log即可
#include <utils/CallStack.h>
@@ -378,6 +379,7 @@ status_t MediaPlayer::stop()
status_t MediaPlayer::pause()
{
ALOGV("pause");
+ CallStack stack("pause");
下面以在MediaPlayer.cpp代码的pause()方法和isPlaying()中加callstack为例来做说明,以下内容是git diff文件
media/libmedia/Android.bp | 2 ++
media/libmedia/mediaplayer.cpp | 3 +++
2 files changed, 5 insertions(+)
mode change 100644 => 100755 media/libmedia/mediaplayer.cpp
diff --git a/media/libmedia/Android.bp b/media/libmedia/Android.bp
index 1d335901c5..c8230645e3 100644
--- a/media/libmedia/Android.bp
+++ b/media/libmedia/Android.bp
@@ -270,6 +270,7 @@ cc_library {
header_libs: [
"libstagefright_headers",
"media_ndk_headers",
+ "libutils_headers",
],
export_header_lib_headers: [
@@ -283,6 +284,7 @@ cc_library {
"libcutils",
"libprocessgroup",
"libutils",
+ "libutilscallstack",
"libbinder",
"libsonivox",
"libandroidicu",
diff --git a/media/libmedia/mediaplayer.cpp b/media/libmedia/mediaplayer.cpp
old mode 100644
new mode 100755
index 6767bba75b..72d65e9564
--- a/media/libmedia/mediaplayer.cpp
+++ b/media/libmedia/mediaplayer.cpp
@@ -45,6 +45,7 @@
#include <system/audio.h>
#include <system/window.h>
+#include <utils/CallStack.h>
namespace android {
@@ -378,6 +379,7 @@ status_t MediaPlayer::stop()
status_t MediaPlayer::pause()
{
ALOGV("pause");
+ CallStack stack("pause");
Mutex::Autolock _l(mLock);
if (mCurrentState & (MEDIA_PLAYER_PAUSED|MEDIA_PLAYER_PLAYBACK_COMPLETE))
return NO_ERROR;
@@ -401,6 +403,7 @@ bool MediaPlayer::isPlaying()
bool temp = false;
mPlayer->isPlaying(&temp);
ALOGV("isPlaying: %d", temp);
+ CallStack stack("isPlaying");
if ((mCurrentState & MEDIA_PLAYER_STARTED) && ! temp) {
ALOGE("internal/external state mismatch corrected");
mCurrentState = MEDIA_PLAYER_PAUSED;
--
共0
条评论
作者
Pixiv日榜Top50