/* * Process Hacker - * system information window * * Copyright (C) 2008-2009 wj32 * Copyright (C) 2008 Dean * * This file is part of Process Hacker. * * Process Hacker is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Process Hacker is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Process Hacker. If not, see . */ using System; using System.Drawing; using System.Windows.Forms; using ProcessHacker.Components; namespace ProcessHacker { public partial class SysInfoWindow : Form { private Components.Plotter[] _cpuPlotters; private int _noOfCPUs = Program.HackerWindow.ProcessProvider.System.NumberOfProcessors; private int _pages = Program.HackerWindow.ProcessProvider.System.NumberOfPhysicalPages; private int _pageSize = Program.HackerWindow.ProcessProvider.System.PageSize; public SysInfoWindow() { InitializeComponent(); this.Location = Properties.Settings.Default.SysInfoWindowLocation; this.Size = Properties.Settings.Default.SysInfoWindowSize; plotterCPU.Data1 = Program.HackerWindow.ProcessProvider.FloatHistory["Kernel"]; plotterCPU.Data2 = Program.HackerWindow.ProcessProvider.FloatHistory["User"]; plotterCPU.GetToolTip = i => Program.HackerWindow.ProcessProvider.MostCpuHistory[i] + "\n" + ((plotterCPU.Data1[i] + plotterCPU.Data2[i]) * 100).ToString("N2") + "% (K " + (plotterCPU.Data1[i] * 100).ToString("N2") + "%, U " + (plotterCPU.Data2[i] * 100).ToString("N2") + "%)" + "\n" + Program.HackerWindow.ProcessProvider.TimeHistory[i].ToString(); plotterIO.LongData1 = Program.HackerWindow.ProcessProvider.LongHistory[SystemStats.IoReadOther]; plotterIO.LongData2 = Program.HackerWindow.ProcessProvider.LongHistory[SystemStats.IoWrite]; plotterIO.GetToolTip = i => Program.HackerWindow.ProcessProvider.MostIoHistory[i] + "\n" + "R+O: " + Misc.GetNiceSizeName(plotterIO.LongData1[i]) + "\n" + "W: " + Misc.GetNiceSizeName(plotterIO.LongData2[i]) + "\n" + Program.HackerWindow.ProcessProvider.TimeHistory[i].ToString(); plotterMemory.LongData1 = Program.HackerWindow.ProcessProvider.LongHistory[SystemStats.Commit]; plotterMemory.LongData2 = Program.HackerWindow.ProcessProvider.LongHistory[SystemStats.PhysicalMemory]; plotterMemory.GetToolTip = i => "Commit: " + Misc.GetNiceSizeName(plotterMemory.LongData1[i]) + "\n" + "Phys. Memory: " + Misc.GetNiceSizeName(plotterMemory.LongData2[i]) + "\n" + Program.HackerWindow.ProcessProvider.TimeHistory[i].ToString(); // create a plotter per CPU _cpuPlotters = new Plotter[_noOfCPUs]; tableCPUs.ColumnCount = _noOfCPUs; tableCPUs.ColumnStyles.Clear(); tableCPUs.Dock = DockStyle.Fill; for (int i = 0; i < _cpuPlotters.Length; i++) { Plotter plotter; tableCPUs.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 1.0f / _noOfCPUs)); _cpuPlotters[i] = plotter = new ProcessHacker.Components.Plotter(); plotter.BackColor = Color.Black; plotter.Dock = DockStyle.Fill; plotter.Margin = new Padding(i == 0 ? 0 : 3, 0, 0, 0); plotter.UseSecondLine = true; plotter.Data1 = Program.HackerWindow.ProcessProvider.FloatHistory[i.ToString() + " Kernel"]; plotter.Data2 = Program.HackerWindow.ProcessProvider.FloatHistory[i.ToString() + " User"]; plotter.GetToolTip = j => Program.HackerWindow.ProcessProvider.MostCpuHistory[j] + "\n" + ((plotter.Data1[j] + plotter.Data2[j]) * 100).ToString("N2") + "% (K " + (plotter.Data1[j] * 100).ToString("N2") + "%, U " + (plotter.Data2[j] * 100).ToString("N2") + "%)" + "\n" + Program.HackerWindow.ProcessProvider.TimeHistory[j].ToString(); tableCPUs.Controls.Add(plotter, i, 0); } tableCPUs.Visible = true; tableCPUs.Visible = false; checkShowOneGraphPerCPU.Checked = Properties.Settings.Default.ShowOneGraphPerCPU; if (_noOfCPUs == 1) checkShowOneGraphPerCPU.Enabled = false; this.UpdateGraphs(); this.UpdateInfo(); Program.HackerWindow.ProcessProvider.Updated += new ProcessSystemProvider.ProviderUpdateOnce(ProcessProvider_Updated); } private void SysInfoWindow_FormClosing(object sender, FormClosingEventArgs e) { if (this.WindowState == FormWindowState.Normal) { Properties.Settings.Default.SysInfoWindowLocation = this.Location; Properties.Settings.Default.SysInfoWindowSize = this.Size; } Program.HackerWindow.ProcessProvider.Updated -= new ProcessSystemProvider.ProviderUpdateOnce(ProcessProvider_Updated); Properties.Settings.Default.ShowOneGraphPerCPU = checkShowOneGraphPerCPU.Checked; } private void UpdateGraphs() { plotterCPU.LineColor1 = Properties.Settings.Default.PlotterCPUKernelColor; plotterCPU.LineColor2 = Properties.Settings.Default.PlotterCPUUserColor; plotterIO.LineColor1 = Properties.Settings.Default.PlotterIOROColor; plotterIO.LineColor2 = Properties.Settings.Default.PlotterIOWColor; plotterMemory.LineColor1 = Properties.Settings.Default.PlotterMemoryPrivateColor; plotterMemory.LineColor2 = Properties.Settings.Default.PlotterMemoryWSColor; for (int i = 0; i < _cpuPlotters.Length; i++) { _cpuPlotters[i].LineColor1 = Properties.Settings.Default.PlotterCPUKernelColor; _cpuPlotters[i].LineColor2 = Properties.Settings.Default.PlotterCPUUserColor; _cpuPlotters[i].Text = ((_cpuPlotters[i].Data1[0] + _cpuPlotters[i].Data2[0]) * 100).ToString("F2") + "% (K: " + (_cpuPlotters[i].Data1[0] * 100).ToString("F2") + "%, U: " + (_cpuPlotters[i].Data2[0] * 100).ToString("F2") + "%)"; _cpuPlotters[i].MoveGrid(); _cpuPlotters[i].Draw(); } plotterCPU.Text = ((plotterCPU.Data1[0] + plotterCPU.Data2[0]) * 100).ToString("F2") + "% (K: " + (plotterCPU.Data1[0] * 100).ToString("F2") + "%, U: " + (plotterCPU.Data2[0] * 100).ToString("F2") + "%)"; // update the I/O graph text plotterIO.Text = "R+O: " + Misc.GetNiceSizeName(plotterIO.LongData1[0]) + ", W: " + Misc.GetNiceSizeName(plotterIO.LongData2[0]); // update the memory graph text plotterMemory.Text = "Commit: " + Misc.GetNiceSizeName(plotterMemory.LongData1[0]) + ", Phys. Mem: " + Misc.GetNiceSizeName(plotterMemory.LongData2[0]); plotterCPU.MoveGrid(); plotterCPU.Draw(); plotterIO.MoveGrid(); plotterIO.Draw(); plotterMemory.MoveGrid(); plotterMemory.Draw(); } private void UpdateInfo() { Win32.SYSTEM_PERFORMANCE_INFORMATION perfInfo = Program.HackerWindow.ProcessProvider.Performance; Win32.PERFORMANCE_INFORMATION info = new Win32.PERFORMANCE_INFORMATION(); Win32.GetPerformanceInfo(ref info, System.Runtime.InteropServices.Marshal.SizeOf(info)); Win32.SYSTEM_CACHE_INFORMATION cacheInfo = new Win32.SYSTEM_CACHE_INFORMATION(); int retLen; Win32.ZwQuerySystemInformation(Win32.SYSTEM_INFORMATION_CLASS.SystemFileCacheInformation, ref cacheInfo, System.Runtime.InteropServices.Marshal.SizeOf(cacheInfo), out retLen); labelTotalsProcesses.Text = info.ProcessCount.ToString("N0"); labelTotalsThreads.Text = info.ThreadCount.ToString("N0"); labelTotalsHandles.Text = info.HandlesCount.ToString("N0"); labelCCC.Text = Misc.GetNiceSizeName((long)perfInfo.CommittedPages * _pageSize); labelCCP.Text = Misc.GetNiceSizeName((long)perfInfo.PeakCommitment * _pageSize); labelCCL.Text = Misc.GetNiceSizeName((long)perfInfo.CommitLimit * _pageSize); labelPMC.Text = Misc.GetNiceSizeName((long)(_pages - perfInfo.AvailablePages) * _pageSize); labelPSC.Text = Misc.GetNiceSizeName((long)info.SystemCache * _pageSize); labelPMT.Text = Misc.GetNiceSizeName((long)_pages * _pageSize); labelCacheCurrent.Text = Misc.GetNiceSizeName(cacheInfo.SystemCacheWsSize); labelCachePeak.Text = Misc.GetNiceSizeName(cacheInfo.SystemCacheWsPeakSize); labelCacheMinimum.Text = Misc.GetNiceSizeName((long)cacheInfo.SystemCacheWsMinimum * _pageSize); labelCacheMaximum.Text = Misc.GetNiceSizeName((long)cacheInfo.SystemCacheWsMaximum * _pageSize); labelKPPPU.Text = Misc.GetNiceSizeName((long)perfInfo.PagedPoolPages * _pageSize); labelKPPVU.Text = Misc.GetNiceSizeName((long)perfInfo.PagedPoolUsage * _pageSize); labelKPPA.Text = perfInfo.PagedPoolAllocs.ToString("N0"); labelKPPF.Text = perfInfo.PagedPoolFrees.ToString("N0"); labelKPNPU.Text = Misc.GetNiceSizeName((long)perfInfo.NonPagedPoolUsage * _pageSize); labelKPNPA.Text = perfInfo.NonPagedPoolAllocs.ToString("N0"); labelKPNPF.Text = perfInfo.NonPagedPoolFrees.ToString("N0"); labelPFTotal.Text = perfInfo.PageFaults.ToString("N0"); labelPFCOW.Text = perfInfo.CopyOnWriteFaults.ToString("N0"); labelPFTrans.Text = perfInfo.TransitionFaults.ToString("N0"); labelPFCacheTrans.Text = perfInfo.CacheTransitionFaults.ToString("N0"); labelPFDZ.Text = perfInfo.CacheTransitionFaults.ToString("N0"); labelPFCache.Text = cacheInfo.SystemCacheWsFaults.ToString("N0"); labelIOR.Text = perfInfo.IoReadOperationCount.ToString("N0"); labelIORB.Text = Misc.GetNiceSizeName(perfInfo.IoReadTransferCount); labelIOW.Text = perfInfo.IoWriteOperationCount.ToString("N0"); labelIOWB.Text = Misc.GetNiceSizeName(perfInfo.IoWriteTransferCount); labelIOO.Text = perfInfo.IoOtherOperationCount.ToString("N0"); labelIOOB.Text = Misc.GetNiceSizeName(perfInfo.IoOtherTransferCount); labelCPUContextSwitches.Text = perfInfo.ContextSwitches.ToString("N0"); labelCPUInterrupts.Text = Program.HackerWindow.ProcessProvider.ProcessorPerf.InterruptCount.ToString("N0"); labelCPUSystemCalls.Text = perfInfo.SystemCalls.ToString("N0"); } private void ProcessProvider_Updated() { this.BeginInvoke(new MethodInvoker(delegate { this.UpdateGraphs(); this.UpdateInfo(); })); } private void checkShowOneGraphPerCPU_CheckedChanged(object sender, EventArgs e) { if (checkShowOneGraphPerCPU.Checked) { tableCPUs.Visible = true; } else { tableCPUs.Visible = false; } } private void checkAlwaysOnTop_CheckedChanged(object sender, EventArgs e) { this.TopMost = checkAlwaysOnTop.Checked; } } }