public bool HandleLogEvent(Int64 eventTimeMS, string counterName, string counterUnitTag, float value) { bool bSuccess = true; BasicPerformanceCounter perfCounter = null; foreach (var counter in _counters) { if (counter._description == counterName) { perfCounter = counter; break; } } if (perfCounter == null) { perfCounter = CreatePerformanceCounter(PerformanceCounterType.Custom); perfCounter.Initialize(null, counterName, counterUnitTag); _treeViewItem.Items.Add(perfCounter._treeViewItem); } perfCounter.HandleLogEvent(eventTimeMS, value); return(bSuccess); }
private BasicPerformanceCounter CreatePerformanceCounter(PerformanceCounterType type) { BasicPerformanceCounter counter = null; switch (type) { case PerformanceCounterType.CPU_Time: case PerformanceCounterType.RAM_Used: case PerformanceCounterType.DISK_Read: case PerformanceCounterType.DISK_Write: case PerformanceCounterType.Custom: counter = new BasicPerformanceCounter(type, _enabled); break; case PerformanceCounterType.NET_Received: case PerformanceCounterType.NET_Sent: counter = new NetworkPerformanceCounter(type, _enabled); break; } Debug.Assert(counter != null); _counters.Add(counter); return(counter); }
private BasicPerformanceCounter CreatePerformanceCounter(PerformanceCounterType type) { BasicPerformanceCounter counter = null; switch (type) { case PerformanceCounterType.CPU_Time: case PerformanceCounterType.RAM_Used: case PerformanceCounterType.DISK_Read: case PerformanceCounterType.DISK_Write: case PerformanceCounterType.Custom: counter = new BasicPerformanceCounter(type, _enabled); break; case PerformanceCounterType.NET_Received: case PerformanceCounterType.NET_Sent: counter = new NetworkPerformanceCounter(type, _enabled); break; } Debug.Assert(counter != null); _counters.Add(counter); return counter; }
public PerformanceCountersGroup(string groupName, bool bEnabled, TreeView parentTreeView, PerformanceCountersGroupsType groupType, PerformanceCounterType[] counterTypes, int targetProcessID) { Debug.Assert(!(groupType == PerformanceCountersGroupsType.Custom && counterTypes != null), "Pre-defined PerformanceCounterTypes cannot be used with a custom PerformanceCountersGroupsType"); _groupType = groupType; _groupName = groupName; _enabled = bEnabled; System.Diagnostics.Process targetProcess = null; bool bCreateGroup = true; // first find our target process if (targetProcessID != 0) { System.Diagnostics.Process[] processlist = System.Diagnostics.Process.GetProcesses(); foreach (System.Diagnostics.Process proc in processlist) { if (proc.Id == targetProcessID) { targetProcess = proc; break; } } if (targetProcess != null) { _groupName += string.Format("({0}.exe)", targetProcess.ProcessName); } else { bCreateGroup = false; _enabled = false; } } if (bCreateGroup) { _treeViewItem = new TreeViewItem(); StackPanel stackPanel = new StackPanel(); _treeViewItem.Header = stackPanel; _treeViewItem.Foreground = VisualStyle.Foreground; stackPanel.Orientation = Orientation.Horizontal; _checkBox = new CheckBox(); _checkBox.IsChecked = _enabled = bEnabled; stackPanel.Children.Add(_checkBox); TextBlock textBlock = new TextBlock() { Text = _groupName }; stackPanel.Children.Add(textBlock); if (counterTypes != null) { for (int i = 0; i < counterTypes.Length; ++i) { BasicPerformanceCounter newCounter = CreatePerformanceCounter(counterTypes[i]); newCounter.Initialize(targetProcess); _treeViewItem.Items.Add(newCounter._treeViewItem); } } parentTreeView.Items.Add(_treeViewItem); _initialized = true; } }