-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathState.cs
More file actions
105 lines (81 loc) · 3.99 KB
/
Copy pathState.cs
File metadata and controls
105 lines (81 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Collections.Generic;
using System.Threading;
using Microsoft.Diagnostics.Tracing.Session;
namespace IoMonitor
{
/// <summary>
/// Shared global state for the interactive I/O monitor.
/// </summary>
internal static partial class Program
{
// Per-process historical totals and last-seen values.
private static readonly Dictionary<int, ProcessIoHistory> _history = new();
// ETW-aggregated byte totals per process.
private static readonly Dictionary<int, (long read, long write)> _etwTotals = new();
// Last ETW snapshot per process so that deltas can be derived.
private static readonly Dictionary<int, (long read, long write)> _etwLast = new();
// Per-process, per-drive I/O totals.
private static readonly Dictionary<int, Dictionary<string, (long read, long write)>> _processIoByDrive = new();
// Rolling bytes-per-second history, used for thrashing detection.
private static readonly Dictionary<int, List<long>> _ioHistory = new();
// Global per-file I/O statistics (trimmed to top 1000 entries).
private static readonly Dictionary<string, (long read, long write)> _fileIoStats = new();
// In-memory CSV batch state; flushed infrequently to reduce monitor-generated disk writes.
private static readonly Dictionary<int, ProcessIoLogEntry> _pendingLogEntries = new();
// Synchronizes access to shared collections and cached samples.
private static readonly object _dataLock = new();
private static readonly object _sampleLock = new();
// ETW session and worker thread.
private static TraceEventSession? _etwSession;
private static Thread? _etwThread;
private static bool _hasAdmin;
private static bool _hasDebug;
private static bool _etwActive;
// Application lifecycle state.
private static bool _running = true;
private static bool _csvLoggingOn;
private static bool _isPaused;
// Update interval and UI configuration.
private static int _updateMs = 1000;
private static int _tableRows = 15;
private const int CsvMaxRowsPerFlush = 20;
private static readonly TimeSpan CsvWriteInterval = TimeSpan.FromSeconds(30);
private static DateTime _lastCsvWrite = DateTime.MinValue;
private static DateTime _programStartTime;
// Last sampled snapshot; guarded by _dataLock.
private static List<ProcessIoSample> _cachedSamples = new();
// Optional drive letter filter (e.g. "C").
private static string _driveFilter = string.Empty;
private static List<string> _availableDriveLetters = new();
private static DateTime _nextDriveRefresh = DateTime.MinValue;
// Bytes per second threshold used by thrashing heuristics.
private static long _thrashingThreshold = 50L * 1024 * 1024; // 50 MB/s
private static bool _showAlerts = true;
// Text-based process name filter.
private static string _searchFilter = string.Empty;
private static bool _inSearchMode;
// Last effective sample interval in seconds.
private static double _lastSampleIntervalSeconds = 1.0;
// Single-instance guard.
private static Mutex? _singleInstanceMutex;
// Drive selection menu state.
private static bool _inDriveMenu;
private static List<string> _driveMenuItems = new();
private static List<string> _driveMenuLetters = new();
private static int _driveMenuIndex;
private static bool _showClosedProcesses;
// Active sort mode for the main table.
private enum SortMode
{
TotalWrite,
TotalRead,
WriteDelta,
ReadDelta,
Handles,
IoOps,
WorkingSet
}
private static SortMode _sortMode = SortMode.TotalWrite;
}
}