Example #1
0
        private void SurveyThreads(ref TimelineData timelineData)
        {
            List<int> listCurrentThread = new List<int>();

            foreach (ProcessThread processThread in Process.GetCurrentProcess().Threads)
            {
                if(!_listThreadToIgnore.Contains(processThread.Id))
                    listCurrentThread.Add(processThread.Id);
            }

            timelineData.CountThreads = (byte)listCurrentThread.Count;
            timelineData.CountNewThreads = (byte)listCurrentThread.Count(t => !_listPreviousThread.Contains(t));
            timelineData.CountDeadThreads = (byte)_listPreviousThread.Count(t => !listCurrentThread.Contains(t));

            _listPreviousThread = listCurrentThread;
        }
Example #2
0
        public void RefreshGraph()
        {
            try
            {
                DateTime currentRefresh = DateTime.Now;

                gImg.Clear(Color.Gray);

                TimelineData prevTimeLineData = new TimelineData();

                //--- Calcul les valeurs hautes
                maxCpuValue = (int)monitor.ListTimeLineData.Max(t => t.CPU);
                maxRamValue = (int)monitor.ListTimeLineData.Max(t => t.RAM);
                maxCountTotalThreads = (int)monitor.ListTimeLineData.Max(t => t.CountThreads);
                maxCountNewThreads = (int)monitor.ListTimeLineData.Max(t => t.CountNewThreads);
                maxCountDeadThreads = (int)monitor.ListTimeLineData.Max(t => t.CountDeadThreads);
                maxCountThreads = Math.Max(Math.Max(maxCountTotalThreads, maxCountNewThreads), maxCountDeadThreads);
                //---

                foreach (TimelineData timelineData in monitor.ListTimeLineData)
                {
                    //--- Courbe de la charge CPU
                    if (chkCPU.Checked)
                    {
                        gImg.DrawLine(penCPU,
                            ConvertPointToGraph((int)prevTimeLineData.Time, (int)prevTimeLineData.CPU, 100),
                            ConvertPointToGraph((int)timelineData.Time, (int)timelineData.CPU, 100));
                    }
                    //---

                    //--- Courbe de la charge RAM
                    if (chkRAM.Checked)
                    {
                        gImg.DrawLine(penRAM,
                        ConvertPointToGraph((int)prevTimeLineData.Time, (int)prevTimeLineData.RAM, maxRamValue),
                        ConvertPointToGraph((int)timelineData.Time, (int)timelineData.RAM, maxRamValue));
                    }
                    //---

                    //=== Courbe des threads
                    //---> Nouveaux
                    if (chkThreadNew.Checked)
                    {
                        gImg.DrawLine(penThreadNew,
                            ConvertPointToGraph((int)prevTimeLineData.Time, (int)prevTimeLineData.CountNewThreads, maxCountThreads),
                            ConvertPointToGraph((int)timelineData.Time, (int)timelineData.CountNewThreads, maxCountThreads));
                    }

                    //---> Morts
                    if (chkThreadDead.Checked)
                    {
                        gImg.DrawLine(penThreadDead,
                            ConvertPointToGraph((int)prevTimeLineData.Time, (int)prevTimeLineData.CountDeadThreads, maxCountThreads),
                            ConvertPointToGraph((int)timelineData.Time, (int)timelineData.CountDeadThreads, maxCountThreads));
                    }

                    //---> Total
                    if (chkThreadTotal.Checked)
                    {
                        gImg.DrawLine(penThreadTotal,
                            ConvertPointToGraph((int)prevTimeLineData.Time, (int)prevTimeLineData.CountThreads, maxCountThreads),
                            ConvertPointToGraph((int)timelineData.Time, (int)timelineData.CountThreads, maxCountThreads));
                    }
                    //===

                    prevTimeLineData = timelineData;
                }

                //---> Rafraichissement des labels toutes les 5 secondes
                //     Ces labels sont Thread Safe
                if (currentRefresh.Subtract(_lastRefreshLabel).TotalMilliseconds > 1000)
                {
                    _lastRefreshLabel = currentRefresh;
                    lblCPU.SetText(String.Format("Max: {0}%\r\nCur:  {1}%", maxCpuValue, prevTimeLineData.CPU));
                    lblRAM.SetText(String.Format("Max: {0}\r\nCur:  {1}", FormatRAMValue(maxRamValue), FormatRAMValue(prevTimeLineData.RAM)));
                    lblTotalThread.SetText(String.Format("Max: {0}\r\nCur:  {1}", maxCountThreads, prevTimeLineData.CountThreads));
                    lblNewThread.SetText(String.Format("Max: {0}\r\nCur:  {1}", maxCountNewThreads, prevTimeLineData.CountNewThreads));
                    lblDeadThread.SetText(String.Format("Max: {0}\r\nCur:  {1}", maxCountDeadThreads, prevTimeLineData.CountDeadThreads));
                }

                g.DrawImage(img, 0, 0);
            }
            catch
            {
            }
        }
Example #3
0
        private void LoopMonitoring()
        {
            while (!_cancelMonitoring)
            {
                _lastRefresh = DateTime.Now.TimeOfDay;

                //---
                TimelineData timelineData = new TimelineData();

                timelineData.Time = DateTime.Now.TimeOfDay.Subtract(_firstRefresh).TotalMilliseconds / _refreshRate;
                timelineData.CPU = SurveyCPU();
                timelineData.RAM = SurveyRAM();
                SurveyThreads(ref timelineData);

                ListTimeLineData.Add(timelineData);
                //---

                _ucMonitoring.RefreshGraph();

                Thread.Sleep(_refreshRate);
            }
        }