Android 打印调用堆栈
内核
添加头文件:
#include
#include
添加打印函数:
dump_stack();
C++
添加头文件:
#include
添加打印函数:
android:CallStack stack;
stack.update();
stack.log(TAG); //TAG为日志标签,字符串类型
Java
import:
import android.util.Log;
添加打印函数
Log.d(TAG,Log.getStackTraceString(new Throwable()));//TAG为日志标签,字符串类型
(1)Java中添加
Java中添加callstack常见以下几种方式。
import android.util.Log;
//(1)
Exception e = new Exception(“this is a log”);
e.printStackTrace();
//(2)
Thread.currentThread().getStackTrace();
//(3)
Log.e(“dump_test” , Log.getStackTraceString(new Throwable()));
(2)C++中添加
(A)Mtk Camera Hal中有自定义的stack
//vendor/mediatek/proprietary/hardware/mtkcam/include/mtkcam/utils/std
//Misc.h
namespace NSCam {
namespace Utils {
void dumpCallStack(char const* prefix = 0);
bool saveBufToFile(char const*const fname, unsigned char*const buf, unsigned int const size);
unsigned int loadFileToBuf(char const*const fname, unsigned char*const buf, unsigned int const capacity);
}
}
//vendor/mediatek/proprietary/hardware/mtkcam/utils/std
//Misc.cpp