Exemple #1
0
            public static PerfomanceInfoData GetPerformanceInfo()
            {
                PerfomanceInfoData          data     = new PerfomanceInfoData();
                PsApiPerformanceInformation perfInfo = new PsApiPerformanceInformation();

                if (GetPerformanceInfo(out perfInfo, Marshal.SizeOf(perfInfo)))
                {
                    /// data in pages
                    data.CommitTotalPages = perfInfo.CommitTotal.ToInt64();
                    data.CommitLimitPages = perfInfo.CommitLimit.ToInt64();
                    data.CommitPeakPages  = perfInfo.CommitPeak.ToInt64();

                    /// data in bytes
                    Int64 pageSize = perfInfo.PageSize.ToInt64();
                    data.PhysicalTotalBytes     = perfInfo.PhysicalTotal.ToInt64() * pageSize;
                    data.PhysicalAvailableBytes = perfInfo.PhysicalAvailable.ToInt64() * pageSize;
                    data.SystemCacheBytes       = perfInfo.SystemCache.ToInt64() * pageSize;
                    data.KernelTotalBytes       = perfInfo.KernelTotal.ToInt64() * pageSize;
                    data.KernelPagedBytes       = perfInfo.KernelPaged.ToInt64() * pageSize;
                    data.KernelNonPagedBytes    = perfInfo.KernelNonPaged.ToInt64() * pageSize;
                    data.PageSizeBytes          = pageSize;

                    /// counters
                    data.HandlesCount = perfInfo.HandlesCount;
                    data.ProcessCount = perfInfo.ProcessCount;
                    data.ThreadCount  = perfInfo.ThreadCount;
                }
                return(data);
            }
Exemple #2
0
        public RAMUsageBar(dynamic settings)
        {
            if (settings["color"] != null)
            {
                this.MainColor = (string)settings["color"];
            }
            if (settings["background-color"] != null)
            {
                this.BackgroudColor = (string)settings["background-color"];
            }
            if (settings["width"] != null)
            {
                this.Width = (int)settings["width"];
            }
            if (settings["height"] != null)
            {
                this.Height = (int)settings["height"];
            }
            if (settings["radius"] != null)
            {
                this.Radius = (int)settings["radius"];
            }
            this.grid = new Grid();
            Rectangle rect = new Rectangle();

            rect.Fill    = new SolidColorBrush((Color)ColorConverter.ConvertFromString(this.BackgroudColor.ToUpper()));
            rect.RadiusX = Radius;
            rect.RadiusY = Radius;
            this.grid.Children.Add(rect);
            this.grid.Width  = this.Width;
            this.grid.Margin = new Thickness(0, (18 - this.Height) / 2, 0, (18 - this.Height) / 2);
            this.innerRect   = new Rectangle();
            this.innerRect.HorizontalAlignment = HorizontalAlignment.Left;
            if (!this.MainColor.Equals("from-percentage"))
            {
                innerRect.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(this.MainColor.ToUpper()));
            }
            this.innerRect.RadiusX = Radius;
            this.innerRect.RadiusY = Radius;
            this.innerRect.Width   = 0;
            this.grid.Children.Add(this.innerRect);

            this.timer          = new Timer();
            this.timer.Interval = 1000;
            this.timer.Elapsed += delegate {
                PerfomanceInfoData data = PsApiWrapper.GetPerformanceInfo();
                Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate
                {
                    double percentage = ((double)1 - ((double)data.PhysicalAvailableBytes / (double)data.PhysicalTotalBytes));
                    if (this.MainColor.Equals("from-percentage"))
                    {
                        this.innerRect.Fill = new SolidColorBrush(this.PercentColor(100 - percentage * 100));
                    }
                    this.innerRect.Width = percentage * (double)this.Width;
                }));
            };
            this.timer.Start();
        }
Exemple #3
0
        /// <summary>
        /// Get physical memory information
        /// </summary>
        private void GetMemoryInformaton()
        {
            this.performanceInfoData = PsApiWrapper.GetPerformanceInfo();

            var AvailableGb = this.performanceInfoData.PhysicalAvailableBytes.ToPrettySize(1);
            var UsedGb      = (this.performanceInfoData.PhysicalTotalBytes - this.performanceInfoData.PhysicalAvailableBytes).ToPrettySize(1);

            this.UsedPhysicalMemoryInPercent = (double)(this.performanceInfoData.PhysicalTotalBytes - this.performanceInfoData.PhysicalAvailableBytes) / this.performanceInfoData.PhysicalTotalBytes * 100;
            this.FreePhysicalMemoryInPercent = (double)100 - this.UsedPhysicalMemoryInPercent;

            this.OnPropertyChanged(() => this.UsedPhysicalMemory);
            this.OnPropertyChanged(() => this.FreePhysicalMemory);
        }
Exemple #4
0
        public RAMUsageText(dynamic settings)
        {
            if (settings["color"] != null)
            {
                this.MainColor = (string)settings["color"];
            }
            this.textBlock            = new TextBlock();
            this.textBlock.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(this.MainColor));

            this.timer          = new Timer();
            this.timer.Interval = 1000;
            this.timer.Elapsed += delegate {
                PerfomanceInfoData data = PsApiWrapper.GetPerformanceInfo();
                Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate
                {
                    this.textBlock.Text = $"{Math.Round(((double)1 - ((double)data.PhysicalAvailableBytes / (double)data.PhysicalTotalBytes)) * 100)} %";
                }));
            };
            this.timer.Start();
        }
        /// <summary>
        /// Get physical memory information
        /// </summary>
        private void GetPhysicalMemoryInformation()
        {
            this.performanceInfoData = PsApiWrapper.GetPerformanceInfo();

            var AvailableGb = this.performanceInfoData.PhysicalAvailableBytes.ToPrettySize(1);
            var UsedGb      = (this.performanceInfoData.PhysicalTotalBytes - this.performanceInfoData.PhysicalAvailableBytes).ToPrettySize(1);

            this.UsedPhysicalMemoryInPercent = (double)(this.performanceInfoData.PhysicalTotalBytes - this.performanceInfoData.PhysicalAvailableBytes) / this.performanceInfoData.PhysicalTotalBytes * 100;
            this.UsedPhysicalMemory          = (this.performanceInfoData.PhysicalTotalBytes - this.performanceInfoData.PhysicalAvailableBytes).ToPrettySize(1);
            this.FreePhysicalMemoryInPercent = (double)100 - this.UsedPhysicalMemoryInPercent;
            this.FreePhysicalMemory          = this.performanceInfoData.PhysicalAvailableBytes.ToPrettySize(1);

            if (this.CurrentRAMWorkloadSeries != null && this.CurrentRAMWorkloadSeries.Count == 0)
            {
                this.CurrentRAMWorkloadSeries.Add(new ChartDataPoint()
                {
                    Name = "Used Physical Memory", Value = this.UsedPhysicalMemoryInPercent
                });
            }
            else
            {
                this.CurrentRAMWorkloadSeries.FirstOrDefault().Value = this.UsedPhysicalMemoryInPercent;
            }
        }