- Understanding the Role of XAP Files
- The Windows Phone Capabilities Model
- The Threading Model for XAML-Based Graphics and Animation in Windows Phone
- Understanding the Frame Rate Counter
- The Windows Phone Application Analysis Tool
- Reading Device Information
- Applying the Model-View-ViewModel Pattern to a Windows Phone App
- Property Change Notification
- Using Commands
- Argument Validation
- A Platform-Agnostic Dialog Service
- Consuming Local Web Applications
- Summary
The Windows Phone Application Analysis Tool
Not only is performance important in ensuring that your app provides an enjoyable experience for your users, but it is also important in a stricter sense: for meeting the certification requirements of the Windows Phone Marketplace. Marketplace certification includes a number of performance related criteria that your app must adhere to. The requirements are as follows:
- If an application performs an operation that causes the device to appear to be unresponsive for more than 3 seconds, such as downloading data over a network connection, the app must display a visual progress or busy indicator.
- An app must display the first screen within 5 seconds after launch. You see how to work around this requirement for slow loading apps by creating a splash screen, in Chapter 3, “Understanding the Application Execution Model.”
- An app must be responsive to user input within 20 seconds after launch.
The Windows Phone Application Analysis tool comes with the Windows Phone SDK and is integrated into Visual Studio, allowing you to analyze and improve the performance of your apps. The tool profiles your app during runtime to gather either execution metrics or memory usage information.
Execution profiling may include method call counts and visual profiling, allowing you to view the frame rate of your app over time, while memory profiling allows you to analyze your app’s memory usage.
To launch the tool select Start Windows Phone Application Analysis from the Debug menu in Visual Studio. You can select the profiling type, along with other advanced metrics, by expanding the Advanced Settings node, as shown in Figure 2.4.
FIGURE 2.4. Configuring the Application Analysis settings.
To begin the profiling session, click the Start Session link.
Whenever the Application Analysis tool runs, it creates a .sap file in the root directory of your project. A .sap file is an XML file that contains the profiling information gathered during a profiling session and can later be opened by the profiling analysis tools built in to Visual Studio.
When done putting your app through its paces, click the End Session link, shown in Figure 2.5. You can, alternatively, use the device’s hardware Back button to end the profiling session.
FIGURE 2.5. Profiling in progress with the Application Analysis tool.
Once stopped, the analysis tool automatically parses the .sap file and presents a summary of the analyzed data. Clicking the Alerts link presents a graph view (see Figure 2.6).
FIGURE 2.6. Viewing performance metrics in the Application Analysis tool.
The .sap file can be reloaded into the analysis tools by double-clicking the .sap file in the Visual Studio Solution Explorer.
Each section of the analysis tools view is discussed in the following sections.
External Events
External events indicate user events, such as UI input, or simulated network changes.
Frame Rate Graph
The Frame Rate graph displays the number of screen redraws (in frames per second) that the app completed at the particular point in the timeline.
CPU Usage Graph
The CPU Usage graph displays the activity of various threads using different colors, as described in Table 2.2.
TABLE 2.2. CPU Graph Colors
Color |
Thread |
Notes |
Green |
UI Thread |
Green shading indicates screen updates and touch input. You should aim to keep the UI thread to less than 50% of CPU usage. |
Purple |
App Threads |
Purple indicates application activity that is not on the UI thread. Activity can be from the composition thread or from your apps background threads, such as those used from the AppPool. |
Gray |
System Threads |
Gray indicates activity that is independent of your app, such as background agent activity. |
White |
Idle Threads |
White indicates the available CPU percentage. The higher the idle thread percentage, the more responsive the app should be. |
Memory Usage MB Graph
Memory Usage MB shows the amount of RAM being consumed by your app in megabytes, at any point along the timeline. This graph allows you to identify excessive memory usage.
Storyboards
Storyboards are displayed as an S flag on the timeline to indicate the occurrence of a storyboard event, and typically indicate the start of an animation. There are two kinds of flags: A red flag indicates a storyboard that is CPU bound; a purple flag indicates a storyboard that is not CPU bound.
Image Loads
When an image is loaded into memory, an I flag is displayed on the graph. Although JPG and PNG files might have a small size when stored in isolated storage, when displayed using an Image control for example, images are expanded into bitmaps and consume a lot more memory. Use the image load flag to identify places in your app where excessive memory consumption is taking place.
GC Events
When the CLR performs garbage collection, a G flag is displayed on the graph. Garbage collection reclaims memory and ordinarily decreases the value shown in the Memory Usage MB graph.
Viewing Detailed Profiling Information
Within the analysis tool, a region can be selected within the graph to view detailed performance warnings for that period. Much like Visual Studio’s Error List view, the Performance Warnings view identifies three types of items: Information, Warning, and Error items (see Figure 2.7).
FIGURE 2.7. The Performance Warnings view.
The Observation Summary provides advice on how to rectify each particular warning item.
The CPU Usage breadcrumb can also be expanded and allows you to view various other CPU-related metrics, such as a function call tree.
The Application Analysis tool provides detailed runtime performance metrics and allows you to identify the source of performance bottlenecks, enabling you to improve the responsiveness of your app and in turn the user experience for your app.