public Form1(int iTimeout) { InitializeComponent(); mainPanel = new Panel(); mainPanel.Dock = DockStyle.Fill; mainPanel.AutoScroll = true; this.tabControl1.TabPages[0].Controls.Add(mainPanel); panels = new memorybar2[33]; //we have slots 1 to 32 plus one total bar //VMhelper vmh = new VMhelper(); //vmh.test(); //vmh.ShowMemory(); VMusage.CeGetProcVMusage vmInfo = new CeGetProcVMusage(); vmInfos = vmInfo._procVMinfo; createPanels(); foreach (VMusage.procVMinfo vm in vmInfos) { textBox1.Text += vm.ToString()+"\r\n"; updateBar((int)vm.slot, vm.name, (int)vm.memusage); } //memorystatus.MemoryInfo.GlobalMemoryStatus(ref memInfoStatus); //updateBar(0, "total " + memInfoStatus.dwAvailVirtual / 1000000, (int)(memInfoStatus.dwTotalVirtual)); updateTotalMemBar(); //start the background tasks vmiThread = new vmInfoThread(); vmiThread._iTimeOut = iTimeout*1000; vmiThread.updateEvent += new vmInfoThread.updateEventHandler(vmiThread_updateEvent); }
public Form1(int iTimeout) { InitializeComponent(); mainPanel = new Panel(); mainPanel.Dock = DockStyle.Fill; mainPanel.AutoScroll = true; this.tabControl1.TabPages[0].Controls.Add(mainPanel); panels = new memorybar2[33]; //we have slots 1 to 32 plus one total bar //VMhelper vmh = new VMhelper(); //vmh.test(); //vmh.ShowMemory(); VMusage.CeGetProcVMusage vmInfo = new CeGetProcVMusage(); vmInfos = vmInfo._procVMinfo; createPanels(); foreach (VMusage.procVMinfo vm in vmInfos) { textBox1.Text += vm.ToString() + "\r\n"; updateBar((int)vm.slot, vm.name, (int)vm.memusage); } //memorystatus.MemoryInfo.GlobalMemoryStatus(ref memInfoStatus); //updateBar(0, "total " + memInfoStatus.dwAvailVirtual / 1000000, (int)(memInfoStatus.dwTotalVirtual)); updateTotalMemBar(); //start the background tasks vmiThread = new vmInfoThread(); vmiThread._iTimeOut = iTimeout * 1000; vmiThread.updateEvent += new vmInfoThread.updateEventHandler(vmiThread_updateEvent); }
/// <summary> /// build thread and process list periodically and fire update event and enqueue results for the socket thread /// </summary> void usageThread() { try { int interval = 3000; //rebuild a new mem usage info VMusage.CeGetProcVMusage vmInfo = new CeGetProcVMusage(); while (!bStopMainThread) { eventEnableCapture.WaitOne(); List <VMusage.procVMinfo> myList = vmInfo._procVMinfo; //get a list of processes and the VM usage StringBuilder sbLogInfo = new StringBuilder(); //needed to merge infos for log System.Threading.Thread.Sleep(interval); uint _totalMemUse = 0; long lTimeStamp = DateTime.Now.ToFileTimeUtc(); //send all data in one block List <byte> buffer = new List <byte>(); buffer.AddRange(ByteHelper.LargePacketBytes); foreach (VMusage.procVMinfo pvmi in myList) { pvmi.Time = lTimeStamp; buffer.AddRange(pvmi.toByte()); _totalMemUse += pvmi.memusage; if (!pvmi.name.StartsWith("Slot", StringComparison.InvariantCultureIgnoreCase)) { //_fileLogger.addLog(pvmi.ToString()); //adds one row for each VM info sbLogInfo.Append(pvmi.name + "\t" + pvmi.memusage.ToString() + "\t"); } } procStatsQueueBytes.Enqueue(buffer.ToArray()); /* * //enqueue item by item * foreach(VMusage.procVMinfo pvmi in myList){ * pvmi.Time = lTimeStamp; * procStatsQueueBytes.Enqueue(pvmi.toByte()); * _totalMemUse += pvmi.memusage; * } */ onUpdateHandler(new procVMinfoEventArgs(myList, _totalMemUse)); //send MemoryStatusInfo memorystatus.MemoryInfo.MEMORYSTATUS mstat = new memorystatus.MemoryInfo.MEMORYSTATUS(); if (memorystatus.MemoryInfo.GetMemoryStatus(ref mstat)) { MemoryInfoHelper memoryInfoStat = new MemoryInfoHelper(mstat); System.Diagnostics.Debug.WriteLine(memoryInfoStat.ToString()); //send header procStatsQueueBytes.Enqueue(ByteHelper.meminfostatusBytes); //send data procStatsQueueBytes.Enqueue(memoryInfoStat.toByte()); //log global memstatus sbLogInfo.Append( "total\t" + memoryInfoStat.totalPhysical.ToString() + "\tfree\t" + memoryInfoStat.availPhysical.ToString() + "\tvtotal\t" + memoryInfoStat.totalVirtual.ToString() + "tvfree\t" + memoryInfoStat.availVirtual.ToString() + "\tload\t" + memoryInfoStat.memoryLoad + "\t"); } //write a log line _fileLogger.addLog(sbLogInfo.ToString() + "\r\n"); procStatsQueueBytes.Enqueue(ByteHelper.endOfTransferBytes); ((AutoResetEvent)eventEnableSend).Set(); }//while true } catch (ThreadAbortException ex) { System.Diagnostics.Debug.WriteLine("ThreadAbortException: usageThread(): " + ex.Message); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception: usageThread(): " + ex.Message); } System.Diagnostics.Debug.WriteLine("Thread ENDED"); }
/// <summary> /// build thread and process list periodically and fire update event and enqueue results for the socket thread /// </summary> void usageThread() { try { int interval = 3000; //rebuild a new mem usage info VMusage.CeGetProcVMusage vmInfo = new CeGetProcVMusage(); while (!bStopMainThread) { eventEnableCapture.WaitOne(); List<VMusage.procVMinfo> myList = vmInfo._procVMinfo; //get a list of processes and the VM usage StringBuilder sbLogInfo = new StringBuilder(); //needed to merge infos for log System.Threading.Thread.Sleep(interval); uint _totalMemUse = 0; long lTimeStamp = DateTime.Now.ToFileTimeUtc(); //send all data in one block List<byte> buffer = new List<byte>(); buffer.AddRange(ByteHelper.LargePacketBytes); foreach (VMusage.procVMinfo pvmi in myList) { pvmi.Time = lTimeStamp; buffer.AddRange(pvmi.toByte()); _totalMemUse += pvmi.memusage; if (!pvmi.name.StartsWith("Slot", StringComparison.InvariantCultureIgnoreCase)) { //_fileLogger.addLog(pvmi.ToString()); //adds one row for each VM info sbLogInfo.Append(pvmi.name + "\t" + pvmi.memusage.ToString() + "\t"); } } procStatsQueueBytes.Enqueue(buffer.ToArray()); /* //enqueue item by item foreach(VMusage.procVMinfo pvmi in myList){ pvmi.Time = lTimeStamp; procStatsQueueBytes.Enqueue(pvmi.toByte()); _totalMemUse += pvmi.memusage; } */ onUpdateHandler(new procVMinfoEventArgs(myList, _totalMemUse)); //send MemoryStatusInfo memorystatus.MemoryInfo.MEMORYSTATUS mstat = new memorystatus.MemoryInfo.MEMORYSTATUS(); if (memorystatus.MemoryInfo.GetMemoryStatus(ref mstat)) { MemoryInfoHelper memoryInfoStat= new MemoryInfoHelper(mstat); System.Diagnostics.Debug.WriteLine(memoryInfoStat.ToString()); //send header procStatsQueueBytes.Enqueue(ByteHelper.meminfostatusBytes); //send data procStatsQueueBytes.Enqueue(memoryInfoStat.toByte()); //log global memstatus sbLogInfo.Append( "total\t" + memoryInfoStat.totalPhysical.ToString() + "\tfree\t" + memoryInfoStat.availPhysical.ToString() + "\tvtotal\t" + memoryInfoStat.totalVirtual.ToString() + "tvfree\t" + memoryInfoStat.availVirtual.ToString() + "\tload\t" + memoryInfoStat.memoryLoad + "\t"); } //write a log line _fileLogger.addLog(sbLogInfo.ToString()+"\r\n"); procStatsQueueBytes.Enqueue(ByteHelper.endOfTransferBytes); ((AutoResetEvent)eventEnableSend).Set(); }//while true } catch (ThreadAbortException ex) { System.Diagnostics.Debug.WriteLine("ThreadAbortException: usageThread(): " + ex.Message); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception: usageThread(): " + ex.Message); } System.Diagnostics.Debug.WriteLine("Thread ENDED"); }