Skip to content

Commit 3092142

Browse files
author
Paulo Janotti
committed
Fix perf impact and multi process against single corelib
1 parent c3fe0c6 commit 3092142

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/coverlet.core/Instrumentation/ModuleTrackerTemplate.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@ public static void RecordHit(int hitLocationIndex)
4848
if (t_isTracking)
4949
return;
5050

51-
t_isTracking = true;
52-
5351
if (t_threadHits == null)
5452
{
53+
t_isTracking = true;
5554
lock (_threads)
5655
{
5756
if (t_threadHits == null)
@@ -60,10 +59,10 @@ public static void RecordHit(int hitLocationIndex)
6059
_threads.Add(t_threadHits);
6160
}
6261
}
62+
t_isTracking = false;
6363
}
6464

6565
++t_threadHits[hitLocationIndex];
66-
t_isTracking = false;
6766
}
6867

6968
public static void UnloadModule(object sender, EventArgs e)
@@ -136,6 +135,10 @@ public static void UnloadModule(object sender, EventArgs e)
136135
// Prevent any double counting scenario, i.e.: UnloadModule called twice (not sure if this can happen in practice ...)
137136
// Only an issue if DomainUnload and ProcessExit can both happens, perhaps can be removed...
138137
Array.Clear(HitsArray, 0, HitsArray.Length);
138+
139+
// On purpose this is not under a try-finally: it is better to have an exception if there was any error writing the hits file
140+
// this case is relevant when instrumenting corelib since multiple processes can be running against the same instrumented dll.
141+
mutex.ReleaseMutex();
139142
}
140143
}
141144
}

test/coverlet.core.tests/Instrumentation/InstrumenterTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class InstrumenterTests
1212
[Fact(Skip = "To be used only validating System.Private.CoreLib instrumentation")]
1313
public void TestCoreLibInstrumentation()
1414
{
15+
// Attention: to run this test adjust the paths and copy the IL only version of corelib
1516
const string OriginalFilesDir = @"c:\s\tmp\Coverlet-CoreLib\Original\";
1617
const string TestFilesDir = @"c:\s\tmp\Coverlet-CoreLib\Test\";
1718

0 commit comments

Comments
 (0)