Skip to content
This repository was archived by the owner on Nov 15, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions main/OpenCover.Console/OpenCover.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
<None Include="app.config">
<SubType>Designer</SubType>
</None>
<None Include="OpenCover.Console.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions main/OpenCover.Console/OpenCover.Console.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[.NET Framework Debugging Control]
GenerateTrackingInfo=1
AllowOptimize=0
4 changes: 2 additions & 2 deletions main/OpenCover.Framework/Manager/MemoryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void Dispose()
s.Release(1);
s.Dispose();
});
//ProfilerHasResults.Do(e => e.Dispose());
ProfilerHasResults.Do(e => e.Dispose());
ResultsHaveBeenReceived.Do(e => e.Dispose());
StreamAccessorResults.Do(r => r.Dispose());
_mmfResults.Do(r => r.Dispose());
Expand Down Expand Up @@ -252,7 +252,7 @@ public void Dispose()
s.Release(1);
s.Dispose();
});
//ProfilerRequestsInformation.Do(e => e.Dispose());
ProfilerRequestsInformation.Do(e => e.Dispose());
InformationReadyForProfiler.Do(e => e.Dispose());
InformationReadByProfiler.Do(e => e.Dispose());
StreamAccessorComms.Do(r => r.Dispose());
Expand Down
82 changes: 43 additions & 39 deletions main/OpenCover.Framework/Manager/ProfilerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ProfilerManager : IProfilerManager

private static readonly ILog DebugLogger = LogManager.GetLogger("DebugLogger");

class ThreadTermination
private class ThreadTermination
{
public ThreadTermination()
{
Expand Down Expand Up @@ -85,7 +85,8 @@ public void RunProcess(Action<Action<StringDictionary>> process, string[] servic
_memoryManager.Initialise(@namespace, key, servicePrincipal);
_messageQueue = new ConcurrentQueue<byte[]>();

using (_mcb = new MemoryManager.ManagedCommunicationBlock(@namespace, key, MaxMsgSize, -1, servicePrincipal))
using (_mcb = new MemoryManager.ManagedCommunicationBlock(@namespace, key, MaxMsgSize, -1, servicePrincipal)
)
using (var processMgmt = new AutoResetEvent(false))
using (var queueMgmt = new AutoResetEvent(false))
using (var environmentKeyRead = new AutoResetEvent(false))
Expand Down Expand Up @@ -242,7 +243,8 @@ private void ProcessMessages(WaitHandle[] handles)
ConsumeException(() =>
{
g.Select(h => h.CancelThreadEvent).ToList().ForEach(h => h.Set());
WaitHandle.WaitAll(g.Select(h => h.ThreadFinishedEvent).ToArray<WaitHandle>(), new TimeSpan(0, 0, 20));
WaitHandle.WaitAll(g.Select(h => h.ThreadFinishedEvent).ToArray<WaitHandle>(),
new TimeSpan(0, 0, 20));
});
})).ToArray();

Expand Down Expand Up @@ -289,51 +291,53 @@ private WaitCallback ProcessBlock(ManagedBufferBlock block,
{
return state =>
{
var processEvents = new WaitHandle[]
{
block.CommunicationBlock.ProfilerRequestsInformation,
block.MemoryBlock.ProfilerHasResults,
threadTermination.CancelThreadEvent
};
threadActivatedEvent.Set();

try
{
while (block.Active)
var processEvents = new WaitHandle[]
{
switch (WaitHandle.WaitAny(processEvents))
block.CommunicationBlock.ProfilerRequestsInformation,
block.MemoryBlock.ProfilerHasResults,
threadTermination.CancelThreadEvent
};
threadActivatedEvent.Set();

try
{
while (block.Active)
{
case 0:
_communicationManager.HandleCommunicationBlock(block.CommunicationBlock, b => { });
break;
case 1:
var data = _communicationManager.HandleMemoryBlock(block.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
switch (WaitHandle.WaitAny(processEvents))
{
case 0:
_communicationManager.HandleCommunicationBlock(block.CommunicationBlock, b => { });
break;
case 1:
var data = _communicationManager.HandleMemoryBlock(block.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)
{
ThreadHelper.YieldOrSleep(100);
} while (_messageQueue.Count > 200);
}
break;
case 2:
return;
do
{
ThreadHelper.YieldOrSleep(100);
} while (_messageQueue.Count > 200);
}
break;
case 2:
return;
}
}
_memoryManager.RemoveDeactivatedBlocks();
}
finally
{
threadTermination.ThreadFinishedEvent.Set();
}
_memoryManager.RemoveDeactivatedBlocks();
}
finally
catch (ObjectDisposedException)
{
// we can now dispose these events as we no longer need them
block.CommunicationBlock.ProfilerRequestsInformation.Dispose();
block.MemoryBlock.ProfilerHasResults.Dispose();

threadTermination.ThreadFinishedEvent.Set();

/* an attempt to close thread has probably happened and the events disposed */
}
};
}
Expand Down
6 changes: 5 additions & 1 deletion main/cmdline/pedigree.cmd
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
OpenCover.Console.exe -register:user -enableperformancecounters -target:dogfood.cmd -filter:+[OpenCover*]* -output:pedigree_results.xml
@echo off
pushd %cd%
cd %~dp0
OpenCover.Console.exe -register:user -enableperformancecounters -target:dogfood.cmd -filter:+[OpenCover*]* -output:pedigree_results.xml
popd