/// <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 }
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); }
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); }
public void LogMessage(string message) { var processId = ProcessDiagnosticInfo.GetForCurrentProcess().ProcessId; singleInstance.logger.Information(processId + " " + message); Debug.WriteLine("Message " + message); }
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 }
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 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); }))); }
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;
public MainPage() { this.InitializeComponent(); ResourceLoader rl = ResourceLoader.GetForCurrentView(); PrintInfoOperatingSystem printInfoOS = new PrintInfoOperatingSystem(rl); PrintInfoHardware printInfoHw = new PrintInfoHardware(rl); PrintInfoScreen printInfoScreen = new PrintInfoScreen(rl); PrintInfoNetwork printInfoNetwork = new PrintInfoNetwork(rl); // Infos système d'exploitation InfoPlatform.Text = printInfoOS.PrintOperatingSystem(); InfoPlatform.Text += Environment.NewLine + printInfoOS.PrintOperatingSystemVersion(); InfoPlatform.Text += Environment.NewLine + printInfoOS.PrintOperatingSystemArchitecture(); InfoPlatform.Text += Environment.NewLine + printInfoOS.PrintIfOperatingSystemIs64Bit(); InfoPlatform.Text += Environment.NewLine + printInfoOS.PrintDeviceFamily(); InfoPlatform.Text += Environment.NewLine; // Infos hardware InfoPlatform.Text += Environment.NewLine + printInfoHw.PrintMachineName(); InfoPlatform.Text += Environment.NewLine + printInfoHw.PrintDeviceManufacturer(); InfoPlatform.Text += Environment.NewLine + printInfoHw.PrintDeviceModel(); InfoPlatform.Text += Environment.NewLine + printInfoHw.PrintProcessorArchitecture(); InfoPlatform.Text += Environment.NewLine + printInfoHw.PrintIf64BitProcessor(); InfoPlatform.Text += Environment.NewLine + printInfoHw.PrintProcessorCount(); InfoPlatform.Text += Environment.NewLine + printInfoHw.PrintAvailableMemory(); InfoPlatform.Text += Environment.NewLine + printInfoHw.PrintMemoryPageSize(); InfoPlatform.Text += Environment.NewLine + printInfoHw.PrintPhysicalMemoryMapped(); InfoPlatform.Text += Environment.NewLine + "."; // Diagnostique du processus InfoPlatform.Text += Environment.NewLine + rl.GetString("ResourcesUsage/Text") + ProcessDiagnosticInfo.GetForCurrentProcess().CpuUsage.GetReport().KernelTime + " (KernelTime)"; InfoPlatform.Text += Environment.NewLine + rl.GetString("ResourcesUsage/Text") + ProcessDiagnosticInfo.GetForCurrentProcess().MemoryUsage.GetReport().VirtualMemorySizeInBytes / (2 ^ 30) + " GB (VirtualMemorySizeInBytes)"; InfoPlatform.Text += Environment.NewLine + rl.GetString("ResourcesUsage/Text") + ProcessDiagnosticInfo.GetForCurrentProcess().DiskUsage.GetReport().BytesReadCount + " (BytesReadCount)"; // Récupération des informations sur l'écran InfoScreen.Text = printInfoScreen.PrintScreenSize(); InfoScreen.Text += Environment.NewLine + printInfoScreen.PrintRawDpi(); InfoScreen.Text += Environment.NewLine + printInfoScreen.PrintScaleFactor(); InfoScreen.Text += Environment.NewLine + printInfoScreen.PrintResolutionScale(); InfoScreen.Text += Environment.NewLine + printInfoScreen.PrintDisplayNativeOrientation(); InfoScreen.Text += Environment.NewLine + printInfoScreen.PrintDisplayCurrentOrientation(); // Connexion réseau/Internet InfoNetwork.Text = printInfoNetwork.PrintIfNetworkAvailable(); InfoNetwork.Text += Environment.NewLine + printInfoNetwork.PrintNetworkConnectivityLevel(); InfoNetwork.Text += Environment.NewLine + printInfoNetwork.PrintNetworkCostType(); // Autres infos TimeSpan timeSpendSinceStart = getTimeSpendSinceStart(); // Jours, heures, minutes, secondes, millisecondes DateTime startDate = DateTime.Now - timeSpendSinceStart; // Année, mois, jours, heures, minutes, secondes, millisecondes InfoOthers.Text = rl.GetString("Others_SystemStartDate/Text") + startDate + Environment.NewLine + rl.GetString("Others_TimeElapsedSinceSystemStart/Text") + timeSpendSinceStart.ToString() + Environment.NewLine + rl.GetString("Others_TimeElapsedSinceAppStart/Text") + SystemInformation.AppUptime; }
// public static List<Tuple<double, double, int>> HeightmapValues = new List<Tuple<double, double, int>>(); public static void Draw(CanvasAnimatedDrawEventArgs args) { Strings.Clear(); try { Strings.Add("Type: " + Mouse.TileTypeString); } catch (Exception e) { } Strings.Add("Max delta X: " + MaxDeltaX.ToString("F")); Strings.Add("Max delta Y: " + MaxDeltaY.ToString("F")); Strings.Add("Mouse: " + Mouse.CoordinatesString); Strings.Add("Mouse (chunk): " + Mouse.ChunkString); Strings.Add("Mouse (tile): " + Mouse.TileString); Strings.Add("Mouse (absolute tile): " + Mouse.AbsoluteTileString); Strings.Add("Mouse left: " + (Mouse.LeftButtonDown ? "DOWN" : "UP")); Strings.Add("Mouse right: " + (Mouse.RightButtonDown ? "DOWN" : "UP")); Strings.Add("Draw: " + LastDrawTime.ToString() + "ms"); Strings.Add("Draw mouse: " + LastDrawMouseTime.ToString() + "ms"); Strings.Add("Draw debug: " + LastDrawDebugTime.ToString() + "ms"); Strings.Add("Draw map: " + LastDrawMapTime.ToString() + "ms"); Strings.Add("Update: " + LastUpdateTime.ToString() + "ms"); Strings.Add("Debug update: " + LastDebugUpdateTime.ToString() + "ms"); Strings.Add("Full loop: " + LastFullLoopTime.ToString() + "ms"); Strings.Add("Full loop (max): " + MaxFullLoopTime.ToString() + "ms"); Strings.Add("Total frames: " + TotalFrames.ToString()); Strings.Add("Slow frames: " + SlowFrames.ToString()); Strings.Add("Camera offset: " + Camera.CoordinatesString()); Strings.Add("Camera offset (chunk): " + Camera.ChunkPositionString()); Strings.Add("Camera offset (tile): " + Camera.ChunkTilePositionString()); Strings.Add("Draw mode: " + Debug.DrawMode.ToString()); if (Map.DebugChunkCount > 0) { Strings.Add("Chunk count: " + TotalChunkCount.ToString()); Strings.Add("Chunks on screen: " + OnScreenChunkCount.ToString()); lock (DebugCollectionsLock) { Strings.Add("Average chunk load time: " + ChunkLoadTimes.Average().ToString("F") + "ms"); Strings.Add("Last chunk load time: " + ChunkLoadTimes.Last().ToString() + "ms"); Strings.Add("Average heightmap load time: " + HeightMapTimes.Average().ToString("F") + "ms"); Strings.Add("Last heightmap load time: " + HeightMapTimes.Last().ToString("F") + "ms"); } } ProcessMemoryUsageReport report = ProcessDiagnosticInfo.GetForCurrentProcess().MemoryUsage.GetReport(); Strings.Add("Working set: " + (report.WorkingSetSizeInBytes / 1000000).ToString() + "MB"); if (ChunkSizeMB != null) { Strings.Add(ChunkSizeMB); } //args.DrawingSession.DrawText("Folder: " + Windows.Storage.ApplicationData.Current.LocalFolder.Path, new Vector2(10, 10), Colors.White); int x = 1500; int y = 20; int width = 410; int height = (Strings.Count + 1) * 20; Color backgroundColor = Colors.CornflowerBlue; Color borderColor = Colors.White; args.DrawingSession.FillRectangle(new Windows.Foundation.Rect(x - 5, y - 5, width, height), backgroundColor); args.DrawingSession.DrawRoundedRectangle(new Windows.Foundation.Rect(x - 5, y - 5, width, height), 3, 3, borderColor); foreach (string str in Strings) { args.DrawingSession.DrawText(str, new Vector2(x, y), Colors.White); y += 20; } if (TimedStrings.Count > 0) { y += 50; height = (TimedStrings.Count + 1) * 20; args.DrawingSession.FillRectangle(new Windows.Foundation.Rect(x - 5, y - 5, width, height), backgroundColor); args.DrawingSession.DrawRoundedRectangle(new Windows.Foundation.Rect(x - 5, y - 5, width, height), 3, 3, borderColor); lock (Debug.DebugCollectionsLock) { foreach (TimedString str in TimedStrings) { str.Draw(args, new Vector2(x, y)); y += 20; } } } }