Android debugging tools in print function call stack information

The following simply describes a method for the debugging of android.

In the android app development and debugging process, often you need to use to fight Log ways to view the function call site.

Here are a way to print the current function call stack relations

 

    	StackTraceElement[] ste = new Throwable().getStackTrace();	
    	if(ste.length >=1)
    	{
    		for(int i = 1; i < ste.length; i++)
    		{
    			Log.d(TAG, "File:" + ste[i].getFileName() + ", Line: " + ste[i].getLineNumber() + ", MethodName:" + ste[i].getMethodName());
    		}
    	}


Here I in the above-described block functions LabelDisplayItem updateContent class, printed below Log

 

D/AlbumSetDir( 1554): File:AlbumSetSlidingWindow.java Line: 550 MethodName:render
D/AlbumSetDir( 1554): File:SlotView.java  Line: 375 MethodName:renderItem
D/AlbumSetDir( 1554): File:SlotView.java  Line: 304 MethodName:render
D/AlbumSetDir( 1554): File:AlbumSetView.java   Line: 203  MethodName:render
D/AlbumSetDir( 1554): File:GLView.java  Line: 244 MethodName:renderChild
D/AlbumSetDir( 1554): File:GLView.java  Line: 218 MethodName:render
D/AlbumSetDir( 1554): File:AlbumSetPage.java   Line: 175  MethodName:render
D/AlbumSetDir( 1554): File:GLRootView.java  Line: 305 MethodName:onDrawFrameLocked
D/AlbumSetDir( 1554): File:GLRootView.java  Line: 266 MethodName:onDrawFrame
D/AlbumSetDir( 1554): File:GLSurfaceView.java   Line: 1468  MethodName:guardedRun
D/AlbumSetDir( 1554): File:GLSurfaceView.java   Line: 1222  MethodName:run

Note that this is the stack, call the relationship is to look from the bottom up

If you just want to add some output in a file, for example, you want to output current which line, in which file, use the following test code on it

 

public class Test  
{  
    public static void main(String args[])  
    {  
        System.out.println("This is " + getLineInfo());  
    }  
   
    public static String getLineInfo()  
    {  
        StackTraceElement ste = new Throwable().getStackTrace()[1];  
        return ste.getFileName() + ": Line " + ste.getLineNumber();  
    }  
} 


打印函数调用栈的方法:Log.d(TAG,Log.getStackTraceString(new Throwable())); 

 

In the android app development and debugging process, often you need to use to fight Log ways to view the function call site.

Here are a way to print the current function call stack relations

 

    	StackTraceElement[] ste = new Throwable().getStackTrace();	
    	if(ste.length >=1)
    	{
    		for(int i = 1; i < ste.length; i++)
    		{
    			Log.d(TAG, "File:" + ste[i].getFileName() + ", Line: " + ste[i].getLineNumber() + ", MethodName:" + ste[i].getMethodName());
    		}
    	}


Here I in the above-described block functions LabelDisplayItem updateContent class, printed below Log

 

D/AlbumSetDir( 1554): File:AlbumSetSlidingWindow.java Line: 550 MethodName:render
D/AlbumSetDir( 1554): File:SlotView.java  Line: 375 MethodName:renderItem
D/AlbumSetDir( 1554): File:SlotView.java  Line: 304 MethodName:render
D/AlbumSetDir( 1554): File:AlbumSetView.java   Line: 203  MethodName:render
D/AlbumSetDir( 1554): File:GLView.java  Line: 244 MethodName:renderChild
D/AlbumSetDir( 1554): File:GLView.java  Line: 218 MethodName:render
D/AlbumSetDir( 1554): File:AlbumSetPage.java   Line: 175  MethodName:render
D/AlbumSetDir( 1554): File:GLRootView.java  Line: 305 MethodName:onDrawFrameLocked
D/AlbumSetDir( 1554): File:GLRootView.java  Line: 266 MethodName:onDrawFrame
D/AlbumSetDir( 1554): File:GLSurfaceView.java   Line: 1468  MethodName:guardedRun
D/AlbumSetDir( 1554): File:GLSurfaceView.java   Line: 1222  MethodName:run

Note that this is the stack, call the relationship is to look from the bottom up

If you just want to add some output in a file, for example, you want to output current which line, in which file, use the following test code on it

 

public class Test  
{  
    public static void main(String args[])  
    {  
        System.out.println("This is " + getLineInfo());  
    }  
   
    public static String getLineInfo()  
    {  
        StackTraceElement ste = new Throwable().getStackTrace()[1];  
        return ste.getFileName() + ": Line " + ste.getLineNumber();  
    }  
} 


打印函数调用栈的方法:Log.d(TAG,Log.getStackTraceString(new Throwable())); 

 

Guess you like

Origin www.cnblogs.com/bluestorm/p/11545971.html