1.Java层调用栈打印:
(1)打印本地调用堆栈
Log.i(TAG, Log.getStackTraceString(new Throwable())); //打印本地调用堆栈
(2)打印远程调用堆栈
String processName = ""; int pid = Binder.getCallingPid(); //打印远程调用栈 //ActivityManager activityManager = (ActivityManager) ServiceManager.getService(Context.ACTIVITY_SERVICE); try { final IActivityManager am = ActivityManager.getService(); if (am != null) { List<ActivityManager.RunningAppProcessInfo> list = am.getRunningAppProcesses(); for (ActivityManager.RunningAppProcessInfo info : list) { if (info.pid == pid) { processName = info.processName; //打印调用接口的进程名 break; } } } } catch (RemoteException e) { Log.i(TAG, "peace error in getService", e); }
2.C层调用栈打印方法
#include <execinfo.h> #include <stdio.h> #include <stdlib.h> /* u8TraceSize : the size of backtrace you want to dump */ void FPP_PrintTrace (int u8TraceSize) { void *btArray[u8TraceSize]; size_t btSize; char **strings; size_t i; btSize = backtrace (btArray, u8TraceSize); strings = backtrace_symbols (btArray, btSize); printf ("SetVideoMute begin\n"); for (i = 0; i < btSize; i++) { printf ("SetVideoMute #%d:%s\n", i,strings[i]); } printf ("SetVideoMute end\n"); free (strings); }