Modern apps tend to be multithreaded. Background data caching, background search, and so on: Even in a simple app you’ll definitely find a process that can be run in a separate thread. Unfortunately, in addition to obvious benefits, this also makes your app more complicated and more difficult for debugging.
What Is Timeline?
To help you profile multithreaded apps, dotTrace 6.0 introduces a new view called Timeline. Timeline is a set of filters and diagrams that allow you to quickly visualize and analyze threads and thread-to-thread relationships in your app. The purpose of Timeline is answering main questions related to poor performance of multithreaded apps:
- What causes UI freezes in my app? Is this excessive computational work in the main thread, multiple garbage collections in worker threads, or maybe it’s an overuse of I/O operations?
- Is poor performance caused by a concurrency issue like lock contention, irregular work distribution, or other?
Timeline Is Not “Just a View”
Nevertheless, don’t think of Timeline as of just one more dotTrace view made “specifically for multithreading”. It is much, much more than that. In addition to capabilities described above, you can use Timeline as an ordinary profiler: dig into the call stack, view execution times and the source code of methods in the stack, and so on. Actually, you can do performance profiling in Timeline without the need in other views at all. Yep, Timeline is more a profiler in a profiler than just a view.
In this “Getting Started” tutorial we will take a detailed look at the Timeline user interface and even try to solve a very common task – finding a reason of UI freezes in an app.
As an example, we’ll use a small app used to reverse lines (e.g., "ABC" > "CBA") in text files. Briefly: With the Select Files button, a user specifies text files to be processed. The Process Files button runs a separate BackgroundWorker thread which reverses lines in the files. The progress of file processing is displayed in a label on the main window. After the processing is finished, the label shows the "All files were successfully processed" message.
The source code of the app is available here.
The app has a serious drawback. After starting file processing, users experience long UI lags that last until the processing is over.
Let’s use Timeline to determine the cause of these freezes!*