public byte[] HandleMemoryBlock(IManagedMemoryBlock mmb) { var data = new byte[mmb.BufferSize]; mmb.ProfilerHasResults.Reset(); mmb.StreamAccessorResults.Seek(0, SeekOrigin.Begin); mmb.StreamAccessorResults.Read(data, 0, mmb.BufferSize); mmb.ResultsHaveBeenReceived.Set(); return data; }
public byte[] HandleMemoryBlock(IManagedMemoryBlock mmb) { var data = new byte[mmb.BufferSize]; mmb.ProfilerHasResults.Reset(); mmb.StreamAccessorResults.Seek(0, SeekOrigin.Begin); mmb.StreamAccessorResults.Read(data, 0, mmb.BufferSize); mmb.ResultsHaveBeenReceived.Set(); return(data); }
/// <summary> /// process a results block from the profiler /// </summary> /// <param name="mmb"></param> public byte[] HandleMemoryBlock(IManagedMemoryBlock mmb) { mmb.ProfilerHasResults.Reset(); do { mmb.StreamAccessorResults.Seek(0, SeekOrigin.Begin); } while (mmb.StreamAccessorResults.Read(mmb.Buffer, 0, mmb.BufferSize) != mmb.BufferSize); var nCount = (int)BitConverter.ToUInt32(mmb.Buffer, 0); var dataSize = (nCount + 1)*sizeof (UInt32); var newData = new byte[dataSize]; Buffer.BlockCopy(mmb.Buffer, 0, newData, 0, dataSize); mmb.ResultsHaveBeenReceived.Set(); return newData; }
/// <summary> /// process a results block from the profiler /// </summary> /// <param name="mmb"></param> public byte[] HandleMemoryBlock(IManagedMemoryBlock mmb) { mmb.ProfilerHasResults.Reset(); do { mmb.StreamAccessorResults.Seek(0, SeekOrigin.Begin); } while (mmb.StreamAccessorResults.Read(mmb.Buffer, 0, mmb.BufferSize) != mmb.BufferSize); var nCount = (int)BitConverter.ToUInt32(mmb.Buffer, 0); var dataSize = (nCount + 1) * sizeof(UInt32); var newData = new byte[dataSize]; Buffer.BlockCopy(mmb.Buffer, 0, newData, 0, dataSize); mmb.ResultsHaveBeenReceived.Set(); return(newData); }
private Tuple <ManualResetEvent, ManualResetEvent> StartProcessingThread(IManagedCommunicationBlock communicationBlock, IManagedMemoryBlock memoryBlock) { var threadActivated = new AutoResetEvent(false); var terminateThread = new ManualResetEvent(false); var threadTerminated = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem((state) => { var processEvents = new WaitHandle[] { communicationBlock.ProfilerRequestsInformation, memoryBlock.ProfilerHasResults, terminateThread, }; threadActivated.Set(); while (true) { switch (WaitHandle.WaitAny(processEvents)) { case 0: _communicationManager.HandleCommunicationBlock(communicationBlock, (cB, mB) => { }); break; case 1: { var data = _communicationManager.HandleMemoryBlock(memoryBlock); _messageQueue.Enqueue(data); } break; case 2: threadTerminated.Set(); return; } } }); threadActivated.WaitOne(); return(new Tuple <ManualResetEvent, ManualResetEvent>(terminateThread, threadTerminated)); }
private Tuple<EventWaitHandle, EventWaitHandle> StartProcessingThread(IManagedCommunicationBlock communicationBlock, IManagedMemoryBlock memoryBlock) { var terminateThread = new ManualResetEvent(false); var threadTerminated = new ManualResetEvent(false); using (var threadActivated = new AutoResetEvent(false)) { ThreadPool.QueueUserWorkItem(ProcessBlock(communicationBlock, memoryBlock, terminateThread, threadActivated, threadTerminated)); threadActivated.WaitOne(); } return new Tuple<EventWaitHandle, EventWaitHandle>(terminateThread, threadTerminated); }
private WaitCallback ProcessBlock(IManagedCommunicationBlock communicationBlock, IManagedMemoryBlock memoryBlock, WaitHandle terminateThread, EventWaitHandle threadActivated, EventWaitHandle threadTerminated) { return state => { var processEvents = new [] { communicationBlock.ProfilerRequestsInformation, memoryBlock.ProfilerHasResults, terminateThread }; threadActivated.Set(); while(true) { switch (WaitHandle.WaitAny(processEvents)) { case 0: _communicationManager.HandleCommunicationBlock(communicationBlock, (cB, mB) => { }); break; case 1: var data = _communicationManager.HandleMemoryBlock(memoryBlock); // don't let the queue get too big as using too much memory causes // problems i.e. the target process closes down but the host takes // ages to shutdown; this is a compromise. _messageQueue.Enqueue(data); if (_messageQueue.Count > 400) { do { Thread.Yield(); } while (_messageQueue.Count > 200); } break; case 2: threadTerminated.Set(); return; } } }; }
private void StartProcessingThread(IManagedCommunicationBlock communicationBlock, IManagedMemoryBlock memoryBlock) { var threadActivated = new AutoResetEvent(false); ThreadPool.QueueUserWorkItem((state) => { var processEvents = new WaitHandle[] { communicationBlock.ProfilerRequestsInformation, memoryBlock.ProfilerHasResults }; threadActivated.Set(); do { switch (WaitHandle.WaitAny(processEvents, new TimeSpan(0, 0, 1))) { case WaitHandle.WaitTimeout: break; case 0: _communicationManager.HandleCommunicationBlock(communicationBlock, (cB, mB) => { }); break; case 1: { var data = _communicationManager.HandleMemoryBlock(memoryBlock); _messageQueue.Enqueue(data); } break; } } while (_continueWait); }); threadActivated.WaitOne(); }
private WaitCallback ProcessBlock(IManagedCommunicationBlock communicationBlock, IManagedMemoryBlock memoryBlock, WaitHandle terminateThread, EventWaitHandle threadActivated, EventWaitHandle threadTerminated) { return(state => { var processEvents = new [] { communicationBlock.ProfilerRequestsInformation, memoryBlock.ProfilerHasResults, terminateThread }; threadActivated.Set(); while (true) { switch (WaitHandle.WaitAny(processEvents)) { case 0: _communicationManager.HandleCommunicationBlock(communicationBlock, (cB, mB) => { }); break; case 1: var data = _communicationManager.HandleMemoryBlock(memoryBlock); // don't let the queue get too big as using too much memory causes // problems i.e. the target process closes down but the host takes // ages to shutdown; this is a compromise. _messageQueue.Enqueue(data); if (_messageQueue.Count > 400) { do { Thread.Yield(); } while (_messageQueue.Count > 200); } break; case 2: threadTerminated.Set(); return; } } }); }
private Tuple <EventWaitHandle, EventWaitHandle> StartProcessingThread(IManagedCommunicationBlock communicationBlock, IManagedMemoryBlock memoryBlock) { var terminateThread = new ManualResetEvent(false); var threadTerminated = new ManualResetEvent(false); using (var threadActivated = new AutoResetEvent(false)) { ThreadPool.QueueUserWorkItem(ProcessBlock(communicationBlock, memoryBlock, terminateThread, threadActivated, threadTerminated)); threadActivated.WaitOne(); } return(new Tuple <EventWaitHandle, EventWaitHandle>(terminateThread, threadTerminated)); }
private Tuple<ManualResetEvent, ManualResetEvent> StartProcessingThread(IManagedCommunicationBlock communicationBlock, IManagedMemoryBlock memoryBlock) { var threadActivated = new AutoResetEvent(false); var terminateThread = new ManualResetEvent(false); var threadTerminated = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem((state) => { var processEvents = new WaitHandle[] { communicationBlock.ProfilerRequestsInformation, memoryBlock.ProfilerHasResults, terminateThread, }; threadActivated.Set(); while(true) { switch (WaitHandle.WaitAny(processEvents)) { case 0: _communicationManager.HandleCommunicationBlock(communicationBlock, (cB, mB) => { }); break; case 1: { var data = _communicationManager.HandleMemoryBlock(memoryBlock); _messageQueue.Enqueue(data); } break; case 2: threadTerminated.Set(); return; } } }); threadActivated.WaitOne(); return new Tuple<ManualResetEvent, ManualResetEvent>(terminateThread, threadTerminated); }
private WaitCallback ProcessBlock(IManagedCommunicationBlock communicationBlock, IManagedMemoryBlock memoryBlock, WaitHandle terminateThread, EventWaitHandle threadActivated, EventWaitHandle threadTerminated) { return(state => { var processEvents = new WaitHandle[] { communicationBlock.ProfilerRequestsInformation, memoryBlock.ProfilerHasResults, terminateThread }; threadActivated.Set(); while (true) { switch (WaitHandle.WaitAny(processEvents)) { case 0: _communicationManager.HandleCommunicationBlock(communicationBlock, (cB, mB) => { }); break; case 1: var data = _communicationManager.HandleMemoryBlock(memoryBlock); _messageQueue.Enqueue(data); break; case 2: threadTerminated.Set(); return; } } }); }