|Home > Chapter 6. The Code View|
This chapter gives you an in-depth look at the code view. It includes an overview, a description of how to navigate to the code view, a detailed look at the source view and a description of the data provided by the disassembly view.
While the other reports provide a wealth of data and code exploration options to zero in on the functions and instances that are the most likely targets for optimization, the code view is where you will dissect these functions line-by-line to see where a subtle tweak to your source code could cause a dramatic improvement in the way your code interacts with hardware. Scan your source code to see how each line faired in terms of code coverage, execution counts, and time, and then look to the disassembly view to see how each line was broken down into annotated machine code instructions and how those instructions performed against expectations.
6.2 Navigating to the code view
To open the code view, click on the 'Code View' link in the navigation section of the summary report. This will open the code view for the top-of-tree function in your code hierarchy, like the one pictured in Figure 6.1:
Figure 6.1. The Code View
In order to see a code view for a specific function, you will need to use the 'Select in Code View' contextual menu option, available by right-clicking most items in all of RealView Profiler's reports.
6.2.1 Navigating to the code view using the bar charts
To gain quick access to a code view report for one of the top five functions presented in the summary report's bar charts, double-click on any of the bars or bar titles. All of the chosen function's pertinent lines of code will be highlighted in the new code view as well as each line of its associated disassembly. Right-clicking a bar or bar title to open a contextual menu and choosing the 'Select in Code View' option from the list will have the same effect.
6.2.2 Navigating to the code view from the other reports
While the summary report allows you quick access to the code view via the link in the navigation section and the bar charts' contextual menus, you can also access a code view for a specific function or class from within some of RealView Profiler's other report types. You can access a code view report from any of the following report types:
Open a code view from the function, class and call chain reports by right-clicking on a function or class' row and choosing the 'Select in Code View' navigation option from the resulting contextual menu. Navigation from the call graph and call summary work in much the same way. Right-click on a function's representative icon in either of these graphs and choose the 'Select in Code View' menu option.
6.3 Basic code view functionality
Although the two sections of the code view, the source view and the disassembly view, show different versions of the code alongside a different set of profiling data, there are some ways in which they work in concert and some commonality in their utility. This section explores these features that are universal to the code view.
6.3.1 Selection behavior
You will notice that if you select a line in either the source or disassembly view that line will appear as dark blue with white lettering. If this selection is made in the disassembly view, its associated code line will be highlighted in light blue in the source view. Selecting a row in the source view will have a similar effect. The code line will appear as dark blue in the source view and all of its associated disassembly instructions will be highlighted in light blue. If the source code line is a comment or any other line not associated with any disassembly instructions, nothing will be highlighted in light blue in the disassembly view.
Double-clicking an instruction in the disassembly view will select all of the instructions that relate to a single line of code, and double-clicking on a function label in the disassembly view will select all of the instructions that make up that function. Both are a good way to select a series of related instructions.
To select multiple rows, hold down the mouse button and drag it across a range of rows. Selection behavior you have become accustomed to in other applications is also present here. Hold down the shift key and select the first and last row of the series to select the entire sequence of rows. Hold down the control key if you would like to select additional rows without selecting all of the rows in between.
If selected source code lines or disassembly instructions contain too many rows to fit in the bounds of the Eclipse editor, small selection indicators will appear on the right hand side of the code view. If there are more selected rows than can fit in the view, the indicators will show you how many more are present off screen.
Figure 6.2. A Selection Indicator
Scroll up or down to see all of the selected rows.
6.3.2 Adjusting views
By default, the source view and the disassembly view each take up half the space of Eclipse's editor, but you can adjust this proportion by clicking and dragging the line that divides the two views. Move the line so that either the source view or disassembly view uses more of the available space, according to your preference.
In the menu bar of the source view, there is a pop-menu that enables you to see either the source view or the disassembly view exclusively. By default, this is set to 'Source & Disassembly', but you can choose 'Source Only' or 'Disassembly Only' to see one of the views exclusively.
6.3.3 The find command
To find a specific function in your code, press the magnifying glass icon in the toolbar or hit control + f on your keyboard. A new 'Find' field will appear in the totals panel that enables you to search your code and instructions for a function name or a hex-numbered instruction address. Enter a string and the field on the right hand side will update to show the current match, if there is one. Pressing the enter key will take you to the first match in the code and subsequent presses of the enter key will cycle you through all of the available matches. Hit the icon again or press control + f on the keyboard to remove the field.
6.4 The source view
The top section of the code view is the source view, where you can see your original source code next to line-by-line profiling data, as pictured in Figure 6.3:
Figure 6.3. The Source View
All of the pertinent lines of the function used to navigate to the code view are highlighted in light blue in the source view when the code view is opened. Comment lines and lines of code that are not directly linked to assembly code instructions, such as variable declarations, are not selected and have no profiling data associated with them.
6.4.1 Locating source files
If you have not moved your source files used in the creation of the current analysis file, RealView Profiler will automatically locate and display the source code in the source view. If, however, the source files are not located in the same directory location they are in during the profiling execution, the source code view will not be populated. A source code view missing the location of its source file is pictured in Figure 6.4:
Figure 6.4. An Empty Source View
To populate the source view, you will need to locate the exact version of the source file used to create the analysis report. Clicking the link in the source view will open a file navigation dialog like the one pictured in Figure 6.5:
Figure 6.5. The Locate Source Dialog
The locate source dialog is a standard file navigation window, and varies depending on your operating system. Locate the source file, select it and press the 'Open' button. When you return to the code view, the source section will now be populated with the source code and profiling data columns.
6.4.2 Source view column headers
In addition to providing a look at your original source code, the source view also gives you line-by-line statistics for all pertinent lines of code. Each of these statistical categories are explained here:
6.5 The disassembly view
The disassembly view shows you the disassembly code from the image file used in the profiling run next to statistics relevant to that instruction. A sample disassembly view is pictured in Figure 6.6:
Figure 6.6. The Disassembly View
You can use the data presented here to see which instructions are taking a bigger chunk of time than you expected due to an interlock and see the cycle per instruction efficiency of each and every line of disassembly code.
6.5.1 Disassembly view column headers
This section provides an explanation of each of the column headers present in the disassembly view.
6.5.2 Code view totals panel
The totals panel in the code view is similar to the totals panel you find in the various table reports in that it shows you the accumulated data for a range of selected rows. It gives you aggregate values for time, average CPI and code coverage. The code view totals panel fields are: