https://github.com/zaibot/threadwatchdog
.NET Thread Watchdog
https://github.com/zaibot/threadwatchdog
Last synced: 10 months ago
JSON representation
.NET Thread Watchdog
- Host: GitHub
- URL: https://github.com/zaibot/threadwatchdog
- Owner: Zaibot
- License: mit
- Created: 2015-03-30T08:55:57.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2018-10-25T04:10:19.000Z (about 7 years ago)
- Last Synced: 2025-01-11T16:40:12.316Z (12 months ago)
- Language: C#
- Size: 22.5 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ThreadWatchdog
Generate traces on threads occupying the CPU above a certain threshold.
Allowing to debug infinite loops in production environments without the need to be connected until it happens.
## Example use case
Used to debug a website application that was in production, it took text input and detected arbitrary links using a regular expression. This had caused a infinite loop on certain inputs due to an error in regular expression. There was no information of what went wrong and more importantly where, this is where the watchdog came in.
## Usage
```csharp
void ApplicationStartup()
{
Watchdog.Instance.Subscribe(new TextReportToFile(@"C:\Temp\ThreadWatchdog.txt"));
Watchdog.Instance.Start();
}
void SuspiciousCode()
{
Watchdog.Instance.MonitorCurrentThread();
}
```
## ASP.NET Example
Add the following calls to the Global application class.
```csharp
void Application_Start()
{
Watchdog.Instance.Subscribe(new TextReportToFile(@"C:\Temp\ThreadWatchdog.txt"));
Watchdog.Instance.Start();
}
void Application_BeginRequest()
{
Watchdog.Instance.MonitorCurrentThread();
}
```
## Example Output
```
2015-03-30 22:40:59 +02:00
Zaibot.ThreadWatchdog.DemoConsole [1] @ 99.97 % CPU usage
Thread exceeded threshold CPU usage.
at Zaibot.ThreadWatchdog.DemoConsole.Program.Main(String[] args) in D:\...\Zaibot.ThreadWatchdog.DemoConsole\Program.cs:line 36
```