Difference between revisions of "Tracking Library Use"

From AtlasWiki
Jump to: navigation, search
Line 11: Line 11:
 
We are doing development on the <code>onConfigurationChanged</code> method, and we find references to static fields in the <code>android.content.pm</code> package of the library.  Let us investigate all other uses of this package throughout ConnectBot.  Accomplishing a complete survey of references is a task made significantly easier with Atlas.
 
We are doing development on the <code>onConfigurationChanged</code> method, and we find references to static fields in the <code>android.content.pm</code> package of the library.  Let us investigate all other uses of this package throughout ConnectBot.  Accomplishing a complete survey of references is a task made significantly easier with Atlas.
  
Put the package into the <b>Connection View</b> Leaves pane; this will display a reverse call graph of the entire package.  Enter the package into the view either by dragging and dropping it into the Leaves pane or by right-clicking the package and selecting <code>Atlas -&gt; Connection View -&gt; Add To Leaves</code>.  Be sure that the "graph kind" selected is <b>Call</b>.
+
Enter the package into the <b>Connection View</b> Leaves pane to display a reverse call graph of the entire package.  Enter the package into the view either by dragging and dropping it into the Leaves pane or by right-clicking the package and selecting <code>Atlas -&gt; Connection View -&gt; Add To Leaves</code>.  Be sure that the "graph kind" selected is <b>Call</b>.
  
  
Line 17: Line 17:
  
  
The resulting graph shows us a graph of all calls that lead to the <code>android.content.pm</code> package.  We can see that the package we're concerned with is used by three methods in two classes.   
+
The resulting graph shows all calls in ConnectBot that eventually lead to the <code>android.content.pm</code> package.  We can see that the package we're concerned with is used by three methods in two classes.  Also visible is one method further up the call tree.  In many cases, a reverse graph of this kind can include a large number of nodes.  We can use the Connection View to focus on only the methods we care about.  To remove specific elements from the graph, right-click on the elements and add them to the Omissions pane.  Alternatively, we can specify exactly how far back the call graph should go by adding only relevant call roots to the Roots pane.  When provided with both roots and leaves, the view displays only connections between these two sets of elements.  Building a graph between roots and leaves is a powerful way to zoom-in on important code interactions, and this utility is the primary function of the Connection View.
  
4. Either put relevant classes and methods into roots pane, or put items into omissions pane.  We will do the former.
 
  
 
+
[[File:LibraryAddRoots.png|500px|border]]
[[File:LibraryAddRoots.png|450px|border]]
+
  
  

Revision as of 15:29, 1 May 2015

"Where is this library being used?"

Have you ever needed to know where a certain library is used? It can be an important task to find proper use patterns or to replace calls to deprecated code. Finding references to a library can be fast, and Atlas can even show details about how callers use the library. This tutorial will explore strategies for finding library use in ConnectBot, an open source Secure Shell client for the Android operating system. The library we are concerned with is the android library, which we find called from within the ConsoleActivity class.

In this tutorial, we will look at strategies for finding all links to larger portions of a library. If you are concerned with tracking only particular methods or fields in a library, the Smart View is a good way to see all of their uses in your workspace. Select the piece of code you wish to follow, and choose the appropriate Smart View script- dataflow for fields, and calls for methods. For more information on investigating the flow of individual values, see Tracking Variables.


OnConfigurationChanged.png


We are doing development on the onConfigurationChanged method, and we find references to static fields in the android.content.pm package of the library. Let us investigate all other uses of this package throughout ConnectBot. Accomplishing a complete survey of references is a task made significantly easier with Atlas.

Enter the package into the Connection View Leaves pane to display a reverse call graph of the entire package. Enter the package into the view either by dragging and dropping it into the Leaves pane or by right-clicking the package and selecting Atlas -> Connection View -> Add To Leaves. Be sure that the "graph kind" selected is Call.


LibraryReverseCall.png


The resulting graph shows all calls in ConnectBot that eventually lead to the android.content.pm package. We can see that the package we're concerned with is used by three methods in two classes. Also visible is one method further up the call tree. In many cases, a reverse graph of this kind can include a large number of nodes. We can use the Connection View to focus on only the methods we care about. To remove specific elements from the graph, right-click on the elements and add them to the Omissions pane. Alternatively, we can specify exactly how far back the call graph should go by adding only relevant call roots to the Roots pane. When provided with both roots and leaves, the view displays only connections between these two sets of elements. Building a graph between roots and leaves is a powerful way to zoom-in on important code interactions, and this utility is the primary function of the Connection View.


LibraryAddRoots.png


5. Calls now visible more explicitly


LibraryFiltered.png


6. Double-click on other calls to examine them in the source code. Let's look at the other method in our class that calls android.content.pm first. Double-clicking the method takes us to the method declaration, or double-clicking the edge directly highlights the line where the library is called.


ConfigureOrientation.png        FollowEdge.png


7. Next, we can see that the only other class accessing the library in question has multiple reads from one method.


TerminalViewLibraryAccess.png