예제 #1
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (CpuLoad != 0)
            {
                hash ^= CpuLoad.GetHashCode();
            }
            if (GpuLoad != 0)
            {
                hash ^= GpuLoad.GetHashCode();
            }
            if (Fps != 0)
            {
                hash ^= Fps.GetHashCode();
            }
            if (CpuTemp != 0)
            {
                hash ^= CpuTemp.GetHashCode();
            }
            if (GpuTemp != 0)
            {
                hash ^= GpuTemp.GetHashCode();
            }
            if (CpuFreq != 0)
            {
                hash ^= CpuFreq.GetHashCode();
            }
            if (GpuFreq != 0)
            {
                hash ^= GpuFreq.GetHashCode();
            }
            return(hash);
        }
예제 #2
0
        public override string Handle(IDictionary <string, string> arguments)
        {
            var cpu  = new CpuLoad();
            var disk = new DiskActivity();

            var returnString = JsonConvert.SerializeObject(new { Type = "SystemInfo", Data = new { Cpu = cpu.Count(), Disk = disk.Count() } });

            return(returnString);
        }
예제 #3
0
        public void Start()
        {
            _clients = new List <TcpClient>();

            _webSocket = new WebSocketServer(5050);
            _webSocket.ClientDisconnected += _webSocket_ClientDisconnected;
            _webSocket.NewMessage         += _webSocket_NewMessage;

            _webSocket.Start();

            _cpuLoad         = new CpuLoad();
            _cpuLoad.Update += _cpuLoad_Update;

            _ramUsage         = new RamUsage();
            _ramUsage.Update += _ramUsage_Update;

            _diskActivity         = new DiskActivity();
            _diskActivity.Update += _diskActivity_Update;

            _httpServer = new CCHttpServer();
        }
예제 #4
0
        public LoadWindow(LoadCheckType checkType, string additionalInformation)
        {
            InitializeComponent();
            this.checkType = checkType;

            switch (this.checkType)
            {
            case LoadCheckType.Cpu:
                this.Title   = Wsapm.Resources.Wsapm.LoadWinodw_TitleCpu;
                this.cpuLoad = new CpuLoad();
                break;

            case LoadCheckType.NetworkTotal:
            case LoadCheckType.NetworkReceived:
            case LoadCheckType.NetworkSent:
                this.Title       = Wsapm.Resources.Wsapm.LoadWinodw_TitleNetwork;
                this.networkLoad = new NetworkLoad(additionalInformation);
                break;

            default:
                break;
            }
        }
예제 #5
0
        /// <summary>
        /// This method is called on a background thread to sample the Cpu usage and try to control it
        /// </summary>
        /// <param name="state">Dummy object used by the WaitCallback delegate</param>
        private static void ControlUsage(object state)
        {
            ///Save the original affinity
            ProcessPriorityClass originalPriority = _currentProcess.PriorityClass;
            IntPtr originalAffinity = _currentProcess.ProcessorAffinity;

            ProcessThread thisW32Thread = null;
            int           threadID      = GetCurrentWin32ThreadId();
            int           allCpuMask    = Convert.ToInt32(Math.Pow(2, ProcessorCount) - 1);

            for (int i = 0; i < _currentProcess.Threads.Count; i++)
            {
                ProcessThread pt = _currentProcess.Threads[i];
                if (pt.Id == threadID)
                {
                    thisW32Thread     = pt;
                    pt.IdealProcessor = (int)allCpuMask;
                    pt.PriorityLevel  = ThreadPriorityLevel.Highest;
                    break;
                }
            }

            using (PerformanceCounter cpuUsageCounter = new PerformanceCounter("Process", "% Processor Time", string.Format("{0}_{1}", _currentProcess.ProcessName, _currentProcess.Id)))
                using (CpuLoad cpuLoad = new CpuLoad())
                {
                    while (_isStarted)
                    {
                        ///Sample the usage
                        float cpuUsage = cpuUsageCounter.NextValue() / ProcessorCount;
                        //Usage is higher, let's reduce
                        if (cpuUsage > _upperLimit)
                        {
                            //It is higher than 10%
                            if (cpuUsage > _upperLimit + 10)
                            {
                                //let's reduce the Cpu/Core/Thread count if possible
                                if (!cpuLoad.ReduceProcessor())
                                {
                                    //Could not reduce the Cpu/Core/Thread for the process, let's change process priority
                                    if (!ChangePriority(false))
                                    {
                                        //Already a low priority process, let's put on the loaded Cpu/Core
                                        if (cpuLoad.Reduce())
                                        {
                                            _currentProcess.ProcessorAffinity = new IntPtr(cpuLoad.Mask);
                                        }
                                    }
                                }
                                else
                                {
                                    _currentProcess.ProcessorAffinity = new IntPtr(cpuLoad.Mask);
                                }
                                Console.WriteLine("< 10 No. of CPU {0}, Mask {1} Priority Process {2} Thread {3}", cpuLoad.ProcessorInUse, cpuLoad.Mask, _currentProcess.BasePriority, thisW32Thread.CurrentPriority);
                            }
                            //Cpu usage is not more than 10%, let's change process priority
                            else if (!ChangePriority(false))
                            {
                                //Already a low priority process, let's put on the loaded Cpu/Core
                                if (cpuLoad.Reduce())
                                {
                                    _currentProcess.ProcessorAffinity = new IntPtr(cpuLoad.Mask);
                                }
                            }
                        }
                        else if (cpuUsage < _lowerLimit)
                        {
                            if (cpuUsage < _lowerLimit - 10)
                            {
                                if (!cpuLoad.IncreaseProcessor())
                                {
                                    if (!ChangePriority(true))
                                    {
                                        if (cpuLoad.Increase())
                                        {
                                            _currentProcess.ProcessorAffinity = new IntPtr(cpuLoad.Mask);
                                        }
                                    }
                                }
                                else
                                {
                                    _currentProcess.ProcessorAffinity = new IntPtr(cpuLoad.Mask);
                                }
                            }
                            else if (!ChangePriority(true))
                            {
                                if (cpuLoad.Increase())
                                {
                                    _currentProcess.ProcessorAffinity = new IntPtr(cpuLoad.Mask);
                                }
                            }
                        }
                        Thread.Sleep(_samplingInterval);
                    }
                }

            _currentProcess.ProcessorAffinity = originalAffinity;
            _currentProcess.PriorityClass     = originalPriority;
        }