Пример #1
0
        private void drawCPUGraph()
        {
            Graphics g = Graphics.FromImage(cpuGraph);

            g.SmoothingMode = SmoothingMode.AntiAlias;

            int fw = cpuGraph.Width;
            int fh = cpuGraph.Height;
            int m  = fh / 10;

            g.FillRectangle(new SolidBrush(Color.White), 0, 0, fw, fh);
            Pen pen = new Pen(Color.FromArgb(220, 220, 220), 1F);

            for (int y = 0; y < fh; y += m)
            {
                g.DrawLine(pen, 0, y, fw, y);
            }
            g.DrawLine(Pens.Gray, 0, fh / 2, fw, fh / 2);

            int count = cpuStats.Count;

            if (count >= 2)
            {
                int     bw        = (fw + (60 - 1)) / 60;
                Point[] userGraph = new Point[count + 2];
                Point[] sysGraph  = new Point[count + 2];

                userGraph[count + 0].X = fw - (count - 1) * bw;
                userGraph[count + 0].Y = fh - 0;
                userGraph[count + 1].X = fw - 0 * bw;
                userGraph[count + 1].Y = fh - 0;

                sysGraph[count + 0].X = fw - (count - 1) * bw;
                sysGraph[count + 0].Y = fh - 0;
                sysGraph[count + 1].X = fw - 0 * bw;
                sysGraph[count + 1].Y = fh - 0;

                for (int i = 0; i < count; i++)
                {
                    CPUUsage usage = cpuStats[i];
                    userGraph[i].X = sysGraph[i].X = fw - i * bw;
                    userGraph[i].Y = fh - usage.Active;
                    sysGraph[i].Y  = fh - usage.System;
                }

                g.FillPolygon(new SolidBrush(Color.FromArgb(50, 0, 0, 255)), userGraph);
                g.DrawPolygon(new Pen(Color.FromArgb(0, 0, 255), 1F), userGraph);
                g.FillPolygon(new SolidBrush(Color.FromArgb(50, 255, 0, 0)), sysGraph);
            }

            if (cpuStats.Count > 0)
            {
                CPUUsage u = cpuStats[0];
                lblCPUUser.Text   = u.User.ToString("##0\\%");
                lblCPUSystem.Text = u.System.ToString("##0\\%");
                lblCPUIdle.Text   = u.Idle.ToString("##0\\%");
            }

            g.Dispose();
        }
Пример #2
0
        public static ProcessMetric FromObject(object obj)
        {
            if (obj == null)
            {
                return(null);
            }
            JsonObject json = new JsonObject(obj);

            return(new ProcessMetric()
            {
                pid = json.Int32("pid"),
                type = json.String("type"),
                memory = MemoryInfo.FromObject(json["memory"]),
                cpu = CPUUsage.FromObject(json["cpu"])
            });
        }
Пример #3
0
        public double InitiliazeCPUNETCORE()
        {
            if (_cpuUsage == null)
            {
#if NETCORE
                if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux))
                {
                    _cpuUsage = new NetCoreCPUUsage();
                }
                else
                {
                    _cpuUsage = new CPUUsage();
                }
#endif
            }
            return(0.0);
        }
Пример #4
0
        public int GetPercentageCPUUsage()
        {
            lock (_syncLockCPUUsage)
            {
                if (_cpuUsage == null)
                {
                    _cpuUsage = new CPUUsage();
                }

                try
                {
                    return(_cpuUsage.GetUsage());
                }
                catch (System.Exception)
                {
                    return(-3);
                }
            }
        }
Пример #5
0
        public void CountProcessorUsage(object sender, EventArgs e)
        {
            cpuStats.Update();
            CPUUsage cpuUsage = cpuStats.Latest;

            memStats.Update();
            MemoryUsage memUsage = memStats.Latest;

            pageio_count += memUsage.Pageout * (memUsage.Pagein + 1);
            //if (pageio_count > 0) pageio_count += memUsage.Pagein;
            pageio_count -= pageio_count / 50 + 1;
            if (pageio_count < 0)
            {
                pageio_count = 0;
            }

            int pattern = cpuUsage.Active / 10;

            pattern += memUsage.Pageout / 15;
            pattern += memUsage.Pagein / 30;
            if (pattern > 10)
            {
                pattern = 10;
            }

            FaceDef.PatternSuite suite = FaceDef.PatternSuite.Normal;

            UInt64 avilable = (UInt64)memStats.TotalVisibleMemorySize * 1024 - memUsage.Used;

            if (pageio_count > 100)
            {
                suite = FaceDef.PatternSuite.MemoryInsufficient;
            }
            else if (avilable < 0)
            {
                suite = FaceDef.PatternSuite.MemoryDecline;
            }

            int markers = FaceDef.MarkerNone;

            if (memUsage.Pagein > 0)
            {
                markers += FaceDef.MarkerPageIn;
            }
            if (memUsage.Pageout > 0)
            {
                markers += FaceDef.MarkerPageOut;
            }

            if (patternWindow != null)
            {
                patternWindow.UpdatePattern(suite, pattern, markers);
            }

            if (statusWindow != null)
            {
                statusWindow.UpdateGraph();
            }

            if (optimusMini.IsAlive && curFaceDef != null)
            {
                Bitmap   image = new Bitmap(96, 96);
                Graphics g     = Graphics.FromImage(image);
                g.FillRectangle(new SolidBrush(Color.White), 0, 0, image.Width, image.Height);
                curFaceDef.DrawPatternImage(g, suite, pattern, markers, 96F / 128F);
                g.Dispose();

                optimusMini.ShowPicture(1, image);
            }
        }