We have a bunch of multi-threaded time-critical C# applications communicating with the outside
world via TCP/IP sockets. UI of any of these applications can occasionally get
frozen for a few seconds (in extreme cases up to 30 seconds). This does not happen
often and can perhaps be explained by some unusual conditions that occur from
time to time on any Windows system. As far as we could ascertain from the logs,
these delays only occur on the UI thread, which is usually running with lower
priority than worker threads of the application.
Since the applications in question are time-critical as I
said, even those rare delays are subject of our investigation; however their
random character greatly hinders any analysis. It is possible that there is no
miracle solution to the problem, but we need at least to be able to determine
in each particular case, what was the cause of the delay.
Now my question: is there any way to:
1)
Detect an "abnormal" delay (i.e. determine that
the application is not just idle, it's waiting for something).
2)
Determine the cause of such delay.
Obviously either some internal tracing/debugging/hooking or/and usage of an external observing tool is needed. Any ideas and suggestions will be greatly welcomed.
TIA
Sam HobbsPosted Jul 29, 2010, 3:50 AM
Sam HobbsPosted Jul 29, 2010, 11:25 AM
AlexPosted Jul 29, 2010, 5:28 AM
At the moment I'm thinking about periodically noting down CPU usage with PerformanceCounter, introducing a special thread for that. That way we will perhaps be able to answer the question from your first post, whether the CPU is the bottleneck. Do you see any problems with this approach?
Also, do you know whether there are ways to log context switches and CPU usage by threads? I believe there are tools (ProcessMonitor?) that visualise this information but what we need is logging.
AlexPosted Jul 29, 2010, 3:00 AM
Sam HobbsPosted Jul 29, 2010, 2:22 AM
AlexPosted Jul 28, 2010, 8:56 PM
Sam HobbsPosted Jul 28, 2010, 8:40 PM
One very simple diagnostic technique is to use the Task Manager. I keep it running. You can minimize it to the status area and still see a graph that indicates processor utilization. When the UI freezes, glance down at the Task Manager wherever it is to determine if the processor is maxed out. If the UI freezes with the processor maxed out, then you know it is futile to attempt to satisfy both incompatible requirements. If tyhe processor is not busy, then you know you must proceed in a very different direction.