Print call stack under android

Source: Internet
Author: User

1. How to print the call stack at the Java layer?

When optimizing the android startup process, colleagues provided a function to print the call stack. Share

Java. util. Map <thread, stacktraceelement []> TS = thread. getallstacktraces ();
Stacktraceelement [] ste = ts. Get (thread. currentthread ());
For (stacktraceelement S: STE ){
Android. util. slog. E ("SS", S. tostring (); // This is built-in to Android. If not, use other print functions.
}

To print all Java applications started by zygote at Android startup. In

// Frameworks/base/services/Java/COM/Android/Server/AM/activitymanagerservice. Java
Private final void startprocesslocked (processrecord app, string hostingtype, string hostingnamestr ){
// Debug add
Java. util. Map <thread, stacktraceelement []> TS = thread. getallstacktraces ();
Stacktraceelement [] ste = ts. Get (thread. currentthread ());
For (stacktraceelement S: STE ){
Android. util. slog. E ("SS", S. tostring ());
}
}

You can use the logcat command in the terminal to view the printed call stack.

 

2. How do I print the call stack on the C/C ++ layer?

Java can easily print the function call stack. C/C ++.
To show in VM/Misc. cpp who calls the dvmallocregion function, add the following red color to this functionCode:
# Include <utils/callstack. h>
...

Void * dvmallocregion (size_t bytecount, int Prot, const char * name)
{
...
# Ifdef _ arm _
Logw ("name = % s", name );
Android: callstack stack;
Stack. Update (1,100 );
Stack. Dump ("");
# Endif
...
}

In VM/DVM. mk, add:
Local_cflags + =-d_arm _
Local_shared_libraries + = libutils

"Mmm Dalvik" to obtain libdvm. So. Then
ADB Root
ADB remount
ADB push libdvm. So/system/lib
ADB reboot
After the system is restarted, the new libdvm. So will be put into use.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.