Hands-On High Performance Programming with Qt 5
上QQ阅读APP看书,第一时间看更新

Recording and visualizing traces

To create an ETW trace for our example program, we open UI for ETW, start trace collecting, launch our example, work with it, close it eventually, and then click on Save Trace Buffers. You can stop trace collection by clicking on the Cancel Tracing button if you wish. Now, by double-clicking on the trace filename, as visible in the previous screenshot, we can open the WPA viewer, as shown in the following screenshot:

We can see that UI for ETW is not only a better GUI for the xperf tool, it also adds its own providers, recording power consumption, heat, keyboard input, flame graphs, and so on. Moreover, it provides its own preset analysis tab. In the previous screenshot, we can see the System Activity, Window in Focus, CPU Usage (Precise), CPU Usage (Sampled), and other analysis windows on the right-hand side. As there is very little documentation for the wealth of counters displayed in the UI, you will have to go to Bruce Dawson's blog, where he provides some descriptions of them.

On the left-hand side, several performance categories are shown. When we click and expand the System Activity category, the available counters will be displayed, as shown in the following screenshot:

Then, we can go to the Windows in Focus window and select our QmlWithModel.exe process. We see, in all the other windows, the relevant trace portions are highlighted as well! If you'd like to display some of the counters visible in the left Graph Explorer panel on the right-hand side, you can click it and choose Add Graph to New Analysis Window from its context menu. For example, when we do that for the CPU counter form, the Computation category, we will be presented with the view shown in the following screenshot:

We then select a portion of the Utilization by CPU diagram with the mouse and select the Zoom option to zoom into the section we are most interested in. You will see the light-green bars corresponding to our example program scheduled in in parallel with other programs. Beneath the diagram, the counter values for threads we have are displayed and can be examined.

As GPU events are also enabled by UI for ETW, there is another visualization available for collected traces. In UI for ETW, click on the trace filename in the trace list window, open its context menu, and select Open in GPUView. This tool (included in the WPT distribution) lets us investigate interactions between the CPU, the graphics driver, and the GPU, and is shown in the following screenshot. We won't discuss it here, though, as we only want to hint at a further possibility for ETW data visualization: