public void Update() { // We're clearing and recreating the process list each time, but the list is typically long (150-250 processes), // so we can't use the same add/remove/update technique we use for packaged apps, because it's too slow. Clear(); IReadOnlyList <ProcessDiagnosticInfo> processes = ProcessDiagnosticInfo.GetForProcesses(); if (processes != null) { foreach (ProcessDiagnosticInfo process in processes) { BitmapImage image = null; if (process.IsPackaged) { image = defaultAppImage; } else { image = defaultProcessImage; } ProcRowInfo processInfo = new ProcRowInfo(process, image); Add(processInfo); } } }
/// <summary> /// request for process info /// </summary> private void LoadProcesses() { mainViewModel.ProcessList.Clear(); List <ProcessDiagnosticInfo> processList = ProcessDiagnosticInfo.GetForProcesses().ToList(); processList.ForEach(o => mainViewModel.ProcessList.Add(new ProcessInfoModel(o))); }
private void GetProcessDiagnostics() { try { ProcessDiagnosticInfo info = ProcessDiagnosticInfo.GetForCurrentProcess(); //ProcessCpuUsageReport cpuReport = info.CpuUsage.GetReport(); //TimeSpan kernelTime = cpuReport.KernelTime; //TimeSpan userTime = cpuReport.UserTime; ProcessMemoryUsageReport memoryReport = info.MemoryUsage.GetReport(); //ulong nonPagedPool = memoryReport.NonPagedPoolSizeInBytes; //ulong pagedPool = memoryReport.PagedPoolSizeInBytes; //ulong peakNonPagedPool = memoryReport.PeakNonPagedPoolSizeInBytes; //ulong peakPagedPool = memoryReport.PeakPagedPoolSizeInBytes; ulong virtualMemory = memoryReport.VirtualMemorySizeInBytes; ulong workingSet = memoryReport.WorkingSetSizeInBytes; //ulong peakVirtualMemory = memoryReport.PeakVirtualMemorySizeInBytes; //ulong peakWorkingSet = memoryReport.PeakWorkingSetSizeInBytes; //ulong pageFaults = memoryReport.PageFaultCount; //ulong pageFile = memoryReport.PageFileSizeInBytes; //ulong privatePages = memoryReport.PrivatePageCount; //ulong peakPageFile = memoryReport.PeakPageFileSizeInBytes; virtualMemoryText.Text = string.Format(CultureInfo.CurrentCulture, "{0:N}", (double)virtualMemory / MB); workingSetText.Text = string.Format(CultureInfo.CurrentCulture, "{0:N}", (double)workingSet / MB); } catch (Exception ex) { status.Log(ex.Message); } }
public IOMonitor(bool monitorIOWrites, bool monitorIOReads, bool monitorIOData, int monitorPeriodInMilliseconds) { if (!monitorIOWrites && !monitorIOReads && !monitorIOData) { throw new ArgumentException("At least one flag has to be true."); } this.monitorIOWrites = monitorIOWrites; this.monitorIOReads = monitorIOReads; this.monitorIOData = monitorIOData; this.monitorPerionInMilliseconds = monitorPeriodInMilliseconds; #if NETFX_CORE CurrentProcess = ProcessDiagnosticInfo.GetForCurrentProcess().DiskUsage; #else string processName = Process.GetCurrentProcess().ProcessName; if (monitorIOWrites) { writesCounter = new PerformanceCounter("Process", "IO Write Bytes/sec", processName); } if (monitorIOReads) { readsCounter = new PerformanceCounter("Process", "IO Read Bytes/sec", processName); } if (monitorIOData) { dataCounter = new PerformanceCounter("Process", "IO Data Bytes/sec", processName); } #endif timer = new Timer(DoMonitor, null, Timeout.Infinite, MonitorPeriodInMilliseconds); }
string cpuLoadReport() { var rv = "..."; var pdi = ProcessDiagnosticInfo.GetForCurrentProcess(); var cpu = pdi.CpuUsage.GetReport().UserTime; var now = DateTimeOffset.Now; var pst = now - pdi.ProcessStartTime; if (pst == TimeSpan.Zero) { return("now == prcs start"); } if (_prevt > DateTimeOffset.MinValue) { var t = now - _prevt; var u = cpu - _prevu; if (t.TotalMilliseconds > 0) { rv = $"{(100d * u.TotalMilliseconds / t.TotalMilliseconds),6:N0} / {(100d * cpu.TotalMilliseconds / pst.TotalMilliseconds):N0} "; } } _prevt = now; _prevu = cpu; return(rv); }
/// <summary> /// 获取所有进程 /// </summary> public ObservableCollection <RunningProcess> GetProcessNow() { bool judge; int j; ObservableCollection <RunningProcess> processes = new ObservableCollection <RunningProcess>(); var details = ProcessDiagnosticInfo.GetForProcesses().OrderByDescending(x => x.ExecutableFileName); foreach (var detail in details) { if (detail.Parent != null) { if ((!detail.ExecutableFileName.Equals("winlogon.exe")) && (!detail.ExecutableFileName.Equals("System")) && (!detail.ExecutableFileName.Equals("svchost.exe")) && (!detail.Parent.ExecutableFileName.Equals("svchost.exe") && (!detail.Parent.ExecutableFileName.Equals("wininit.exe")))) { for (j = 0, judge = false; j < processes.Count; j++) { if (processes[j].id == detail.Parent.ProcessId) { judge = true; } } if (judge == false) { var temp2 = new RunningProcess(detail.ExecutableFileName, detail.ProcessId, detail.Parent.ExecutableFileName, detail.Parent.ProcessId); processes.Add(temp2); } } } } return(processes); }
private async void Page_LoadedAsync(object sender, RoutedEventArgs e) { foreach (var info in await AppDiagnosticInfo.RequestInfoAsync()) { /*Items.Add(new AppInfo * { * Id = info.AppInfo.Id, * PackageFamilyName = info.AppInfo.PackageFamilyName, * Description = info.AppInfo.DisplayInfo.Description, * DisplayName = info.AppInfo.DisplayInfo.DisplayName, * AppUserModelId = info.AppInfo.AppUserModelId, * });*/ } foreach (var info in ProcessDiagnosticInfo.GetForProcesses()) { /*ProcessItems.Add(new ProcessInfo * { * ExecutableFileName = info.ExecutableFileName, * ProcessId = $"{info.ProcessId}", * CpuUsage = $"{info.CpuUsage.GetReport().UserTime:hh':'mm':'ss}", * MemoryUsage = $"{info.MemoryUsage.GetReport().WorkingSetSizeInBytes:N0}", * });*/ } }
public ProcessInfoModel(ProcessDiagnosticInfo process) { ProcessCpuUsageReport cpuReport = process.CpuUsage.GetReport(); if (cpuReport != null) { TimeSpan cpuUsageTime = cpuReport.KernelTime + cpuReport.UserTime; CpuUsageTime = string.Format("{0:hh\\:mm\\:ss}", cpuUsageTime); } ProcessDiskUsageReport diskReport = process.DiskUsage.GetReport(); if (diskReport != null) { DiskBytesCount = diskReport.BytesReadCount + diskReport.BytesWrittenCount; } ProcessMemoryUsageReport memoryReport = process.MemoryUsage.GetReport(); if (memoryReport != null) { PageFileSize = memoryReport.PageFileSizeInBytes; WorkingSetSize = memoryReport.WorkingSetSizeInBytes; } ProcessId = process.ProcessId; ExeName = process.ExecutableFileName; }
/// <summary> /// Use this function if you don't want the message to be batched /// </summary> /// <param name="txt"></param> public static void SystemLog(string txt) { string toPrint; lock (_stringBuilder) { #if NETFX_CORE string currentTimeString = DateTime.UtcNow.ToString("dd/mm/yy hh:ii:ss"); string processTimeString = (DateTime.UtcNow - ProcessDiagnosticInfo. GetForCurrentProcess().ProcessStartTime.DateTime.ToUniversalTime()).ToString(); #else string currentTimeString = DateTime.UtcNow.ToLongTimeString(); //ensure includes seconds string processTimeString = (DateTime.UtcNow - Process.GetCurrentProcess().StartTime.ToUniversalTime()).ToString(); #endif _stringBuilder.Length = 0; _stringBuilder.Append("[").Append(currentTimeString); _stringBuilder.Append("][").Append(processTimeString); _stringBuilder.Length = _stringBuilder.Length - 3; //remove some precision that we don't need _stringBuilder.Append("] ").AppendLine(txt); toPrint = _stringBuilder.ToString(); } #if !UNITY_EDITOR #if !NETFX_CORE System.Console.WriteLine(toPrint); #else //find a way to adopt a logger externally, if this is still needed #endif #else UnityEngine.Debug.Log(toPrint); #endif }
public void LogMessage(string message) { var processId = ProcessDiagnosticInfo.GetForCurrentProcess().ProcessId; singleInstance.logger.Information(processId + " " + message); Debug.WriteLine("Message " + message); }
public AddProcess() { this.InitializeComponent(); foreach (ProcessDiagnosticInfo ii in ProcessDiagnosticInfo.GetForProcesses()) { procces.Items.Add(ii.ExecutableFileName); } }
public ProcRowInfo(ProcessDiagnosticInfo p, BitmapImage bmp) { pdi = p; cpuReport = pdi.CpuUsage.GetReport(); diskReport = pdi.DiskUsage.GetReport(); memoryReport = pdi.MemoryUsage.GetReport(); Logo = bmp; AppType = p.IsPackaged ? "Packaged" : "Win32"; }
private int getMemoryPerformance() { IReadOnlyList <ProcessDiagnosticInfo> list = ProcessDiagnosticInfo.GetForProcesses(); var a = MemoryManager.GetProcessMemoryReport(); long b = (long)a.TotalWorkingSetUsage; long c = (long)a.PrivateWorkingSetUsage; return((int)(c * 100 / b)); }
private async Task <IList <TableRowView> > LoadRowsAsync(CancellationToken token, uint count, int baseIndex) { var result = await _rowsList.LoadRowsAsync(token, count, baseIndex); ulong memSize = ProcessDiagnosticInfo.GetForCurrentProcess().MemoryUsage.GetReport().WorkingSetSizeInBytes; StatusText.Text = string.Format("total: {0:N0} | cached: {1:N0} | memory used: {2}", _rowsList.MaxItemCount, _rowsList.CachedRowsCount, ((long)memSize).ToFileSizeUiString()); return(result); }
public Temperature() { var a = ProcessDiagnosticInfo.GetForProcesses(); foreach (var i in a) { string s = i.CpuUsage.GetReport().KernelTime.TotalMilliseconds.ToString(); s += 1; } }
static MessageSourceFactory() { #if WINDOWS_UAP _processId = ProcessDiagnosticInfo.GetForCurrentProcess().ProcessId; var localHost = NetworkInformation.GetHostNames().FirstOrDefault(host => host.DisplayName.Contains(".local")); _machineName = localHost?.DisplayName.Replace(".local", ""); #else _processId = Process.GetCurrentProcess().Id; _machineName = Process.GetCurrentProcess().MachineName; #endif }
public static async Task <bool> CheckForRunningProcess(string processName) { //Requests permission for app. await AppDiagnosticInfo.RequestAccessAsync(); //Gets the running processes. var processes = ProcessDiagnosticInfo.GetForProcesses(); //Returns result of searching for process name. return(processes.Any(processDiagnosticInfo => processDiagnosticInfo.ExecutableFileName.Contains(processName))); }
private static string GetUwpId(Window application) { var process = ProcessDiagnosticInfo.TryGetForProcessId((uint)application.process.Id); foreach (var appDiagnosticInfo in process.GetAppDiagnosticInfos()) { return(appDiagnosticInfo.AppInfo.AppUserModelId); } return("None"); }
public LogLineList() : base() { Add(new LogLineItem("Memory(MB)", new Func <float>(() => { return(MemoryManager.AppMemoryUsage / 1_000_000); }))); Add(new LogLineItem("CPU User Time (Second)", new Func <float>(() => { return((float)ProcessDiagnosticInfo.GetForCurrentProcess().CpuUsage.GetReport().UserTime.TotalSeconds); }))); Add(new LogLineItem("CPU Kernel Time (Second)", new Func <float>(() => { return((float)ProcessDiagnosticInfo.GetForCurrentProcess().CpuUsage.GetReport().KernelTime.TotalSeconds); }))); Add(new LogLineItem("Disk Read", new Func <float>(() => { return(ProcessDiagnosticInfo.GetForCurrentProcess().DiskUsage.GetReport().ReadOperationCount); }))); Add(new LogLineItem("Disk Write", new Func <float>(() => { return(ProcessDiagnosticInfo.GetForCurrentProcess().DiskUsage.GetReport().WriteOperationCount); }))); }
private ulong GetProcessPrivateCommit(ProcessDiagnosticInfo process) { ulong privateCommit = 0; if (process.MemoryUsage != null) { ProcessMemoryUsageReport pmReport = process.MemoryUsage.GetReport(); if (pmReport != null) { privateCommit = pmReport.PageFileSizeInBytes; } } return(privateCommit); }
private int getCpuPerformance() { IReadOnlyList <ProcessDiagnosticInfo> list = ProcessDiagnosticInfo.GetForProcesses(); double sumUsage = 0, sumTotal = 0; foreach (var item in list) { sumUsage += item.CpuUsage.GetReport().UserTime.Milliseconds; sumTotal += item.CpuUsage.GetReport().UserTime.Milliseconds + item.CpuUsage.GetReport().KernelTime.Milliseconds; } sumTotal = (sumUsage * 100 / sumTotal); return((int)sumTotal); }
private static ImageSource GetUwpIcon(Window application) { var uwpProcess = ProcessDiagnosticInfo.TryGetForProcessId((uint)application.process.Id); var appInfos = uwpProcess.GetAppDiagnosticInfos(); var appInfoCount = appInfos.Count; var appInfo = appInfos[0].AppInfo; var name = appInfo.AppUserModelId; var shellItem = InstalledApplications.First(item => ApplicationUtils.GetAppModelUserId(item) == appInfo.AppUserModelId); var bitmap = ApplicationUtils.GetIcon(shellItem); return(bitmap); }
private static bool NotSuspended(Window window) { var diagnosticInfo = ProcessDiagnosticInfo.TryGetForProcessId((uint)window.process.Id); if (!diagnosticInfo.IsPackaged) { return(true); } var appDiagnosticInfos = diagnosticInfo.GetAppDiagnosticInfos(); var anySuspended = appDiagnosticInfos.Any(info => info.GetResourceGroups().Any(resourceInfo => resourceInfo.GetStateReport().ExecutionState == AppResourceGroupExecutionState.Suspended ) ); return(!anySuspended); }
public MainPage() { this.InitializeComponent(); IReadOnlyList <ProcessDiagnosticInfo> processes = ProcessDiagnosticInfo.GetForProcesses(); if (processes != null) { foreach (ProcessDiagnosticInfo process in processes) { string exeName = process.ExecutableFileName; string pid = process.ProcessId.ToString(); systemProcesses.Add(new Process { Name = exeName, ProcessID = pid }); Debug.WriteLine(exeName + " " + pid); } } }
/// <summary> /// 获取所有进程(接口实现) : 包括Win32 与 UWP /// </summary> /// <returns>ObservableCollection<Process></returns> public ObservableCollection <Process> GetProcessNow() { ObservableCollection <Process> processes = new ObservableCollection <Process>(); //取出所有进程 IReadOnlyList <ProcessDiagnosticInfo> details = ProcessDiagnosticInfo.GetForProcesses(); foreach (ProcessDiagnosticInfo detail in details) { if (detail.Parent != null) { if ((!detail.ExecutableFileName.Equals("winlogon.exe")) && (!detail.ExecutableFileName.Equals("svchost.exe")) && (!detail.Parent.ExecutableFileName.Equals("wininit.exe"))) { var temp2 = new Process(detail.ExecutableFileName, "2333", 3); processes.Add(temp2); } } } return(processes); }
public MemoryMonitor(bool monitorPagedMemory, bool monitorWorkingSet, bool monitorVirtualMemory, int monitorPeriodInMilliseconds = 500) { if (!monitorPagedMemory && !monitorWorkingSet && !monitorVirtualMemory) { throw new ArgumentException("At least one flag has to be true."); } this.monitorPagedMemory = monitorPagedMemory; this.monitorWorkingSet = monitorWorkingSet; this.monitorVirtualMemory = monitorVirtualMemory; this.monitorPeriodInMilliseconds = monitorPeriodInMilliseconds; #if NETFX_CORE CurrentProcess = ProcessDiagnosticInfo.GetForCurrentProcess().MemoryUsage; #else CurrentProcess = Process.GetCurrentProcess(); #endif timer = new Timer(DoMonitor, null, Timeout.Infinite, MonitorPeriodInMilliseconds); }
/// <summary> /// When used in .NET Core not supported monitoring of privileged time. /// </summary> /// <param name="monitorPrivilegedTime">If truth be monitored the privileged time. Not supported for .Net core.</param> /// <param name="monitorProcessorTime">If truth be monitored the processor time.</param> /// <param name="monitorUserTime">If truth be monitored the user time.</param> /// <param name="monitorPeriodInMilliseconds">The time interval between invocations of refresh, in milliseconds. Specify Timeout.Infinite to disable periodic signaling.</param> public CPUMonitor(bool monitorPrivilegedTime, bool monitorProcessorTime, bool monitorUserTime, int monitorPeriodInMilliseconds = 500) { if (!monitorPrivilegedTime && !monitorProcessorTime && !monitorUserTime) { throw new ArgumentException("At least one flag has to be true."); } this.monitorPrivilegedTime = monitorPrivilegedTime; this.monitorProcessorTime = monitorProcessorTime; this.monitorUserTime = monitorUserTime; this.monitorPeriodInMilliseconds = monitorPeriodInMilliseconds; #if NETFX_CORE if (monitorPrivilegedTime) { throw new NotSupportedException("Not support in .Net Core."); } CurrentProcess = ProcessDiagnosticInfo.GetForCurrentProcess().CpuUsage; #else string processName = Process.GetCurrentProcess().ProcessName; if (monitorPrivilegedTime) { privilegedTimeCounter = new PerformanceCounter("Process", "% Privileged Time", processName); } if (monitorProcessorTime) { processorTimeCounter = new PerformanceCounter("Process", "% Processor Time", processName); } if (monitorUserTime) { userTimeCounter = new PerformanceCounter("Process", "% User Time", processName); } #endif timer = new Timer(DoMonitor, null, Timeout.Infinite, MonitorPeriodInMilliseconds); }
public async void Run(IBackgroundTaskInstance taskInstance) { lock ( ActiveTask ) { uint PID = ProcessDiagnosticInfo.GetForCurrentProcess().ProcessId; if (!string.IsNullOrEmpty(ActiveTask)) { Logger.Log(ID, "Another Task is already running: " + ActiveTask + " | " + PID, LogType.INFO); taskInstance.GetDeferral().Complete(); return; } ActiveTask = string.Format("{0}: {1}", taskInstance.Task.Name, PID); } Deferral = taskInstance.GetDeferral(); // Associate a cancellation handler with the background task. taskInstance.Canceled += new BackgroundTaskCanceledEventHandler(OnCanceled); try { Retrying = (taskInstance.Task.Name == TASK_RETRY); await Init(); using (CanvasDevice = Image.CreateCanvasDevice()) { await UpdateSpiders(); } } finally { ActiveTask = ""; Deferral.Complete(); } }
int IPlatform.GetCurrentProcessId() => (int)ProcessDiagnosticInfo.GetForCurrentProcess().ProcessId;
private async void Timer_Tick(object sender, object e) { Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder; try { var s = ""; Windows.Storage.StorageFile sampleFile = await storageFolder.GetFileAsync("procs.txt"); list.Items.Clear(); foreach (var i in (await Windows.Storage.FileIO.ReadTextAsync(sampleFile)).Split('\n')) { if (i.IndexOf('~') != -1) { if (i.Split('~')[0] == "default" && s == "") { s = i.Split('~')[1]; } else { foreach (ProcessDiagnosticInfo ii in ProcessDiagnosticInfo.GetForProcesses()) { if (i.Split('~')[0] == ii.ExecutableFileName) { s = i.Split('~')[1]; } } } Grid g = new Grid() { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch }; ListViewItem lvi = new ListViewItem() { Content = g, HorizontalAlignment = HorizontalAlignment.Stretch, HorizontalContentAlignment = HorizontalAlignment.Stretch }; g.Children.Add(new TextBlock() { Text = i.Split('~')[0], HorizontalAlignment = HorizontalAlignment.Left }); g.Children.Add(new TextBlock() { Text = i.Split('~')[1], HorizontalAlignment = HorizontalAlignment.Right }); list.Items.Add(lvi); } } if (s != singlton.status) { singlton.status = s; } answTextBlock.Text = s; //await Windows.Storage.FileIO.WriteTextAsync(sampleFile, "Test~System\nexplorer.exe~играет в проводник windows"); } catch (FileNotFoundException ex) { Windows.Storage.StorageFile sampleFile = await storageFolder.CreateFileAsync("procs.txt", Windows.Storage.CreationCollisionOption.ReplaceExisting); answTextBlock.Text = ex.Message; await Windows.Storage.FileIO.WriteTextAsync(sampleFile, "default~ "); } catch (Exception ex) { answTextBlock.Text = ex.Message; } }