Analyzing UI Lag in a PC Client Using Windows Performance Toolkit and UIforETW
The article walks through diagnosing a noticeable UI lag in a PC client’s dial‑pad by capturing ETW traces with Windows Performance Toolkit and UIforETW, revealing that a costly LoadKeyboardLayout call during input‑method switching caused a 0.5‑second delay, and resolves it by filtering the keyboard‑layout state.
During PC client testing, performance problems such as UI lag and memory leaks often appear. This article presents a case discovered while testing the Qidian integration workbench, illustrating how to collect UI lag data, analyze it, and locate the root cause.
Case Introduction : Clicking the dial‑pad in the workbench shows a noticeable lag on the numeric buttons. Screenshots of the UI before and after the fix are provided.
Tool Introduction : Common Windows performance testing tools include:
WPT (Windows Performance Toolkit) : Microsoft’s official tool, bundled with the Windows SDK.
UIforETW : An open‑source tool (download link omitted).
A comparison shows that WPT has sparse documentation and a high usage threshold, while UIforETW offers abundant documentation and a low entry barrier. Both tools are built on Xperf , which relies on ETW (Event Tracing for Windows) . ETW follows a producer‑consumer model consisting of Controllers, Providers, and Consumers.
Case Analysis : When the UI thread delay exceeds 200 ms, the Microsoft-Windows-Win32k provider records an event that appears in the UI Delay graph.
1. Test Scenario : Click any numeric button on the dial‑pad five times.
2. Data Acquisition : Press Start Tracing , reproduce the lag, then click Save Trace Buffers . The generated trace file appears in the Traces tab.
Opening the trace in Graph Explorer shows graphs such as System Activity, CPU Usage, File I/O, and the UI Delay graph. Five lag events were found, each lasting about 0.5 s (total ≈ 2.7 s). CPU usage for these events is only ~10 ms, indicating the thread was idle.
To inspect the call stack, configure the PDB symbol path under the Trace section and load symbols. Sort by Time Since Last and examine the New Thread Stack column.
The stack reveals a single context switch by CCicEvent:Wait , moving the UI thread from a 533 ms suspended state to running. Further up the stack, the application calls LoadKeyboardLayoutW , which consumes about 0.54 s.
Source code screenshots show that the method LoadKeyboardLayout and ActivateKeyboardLayout are invoked to switch input methods, causing the UI lag because the dial‑pad restricts input to English.
Solution : Filter the input‑method editing state to avoid switching the keyboard layout, thereby eliminating the lag.
Summary : The article demonstrates a systematic approach to diagnosing client UI lag using Windows performance tools. Besides UI lag, Windows performance issues also include memory leaks and disk I/O. UIforETW is highlighted as a powerful tool for a broad range of Windows performance problems, though further exploration is needed.
Tencent Cloud Developer
Official Tencent Cloud community account that brings together developers, shares practical tech insights, and fosters an influential tech exchange community.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.