-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
219 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) Toni Solarin-Sodara | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.IO; | ||
using BenchmarkDotNet.Attributes; | ||
using Coverlet.Core; | ||
using Coverlet.Core.Abstractions; | ||
using Coverlet.Core.Helpers; | ||
using Coverlet.Core.Symbols; | ||
using Moq; | ||
|
||
namespace coverlet.core.benchmark.tests | ||
{ | ||
[MemoryDiagnoser] | ||
public class CoverageBenchmarks | ||
{ | ||
private Coverage _coverage; | ||
private readonly Mock<ILogger> _mockLogger = new(); | ||
private DirectoryInfo _directory; | ||
|
||
[GlobalSetup(Target = nameof(GetCoverageBenchmark))] | ||
public void GetCoverageBenchmarkSetup() | ||
{ | ||
string module = GetType().Assembly.Location; | ||
string pdb = Path.Combine(Path.GetDirectoryName(module), Path.GetFileNameWithoutExtension(module) + ".pdb"); | ||
|
||
_directory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString())); | ||
|
||
File.Copy(module, Path.Combine(_directory.FullName, Path.GetFileName(module)), true); | ||
File.Copy(pdb, Path.Combine(_directory.FullName, Path.GetFileName(pdb)), true); | ||
|
||
// TODO: Find a way to mimick hits | ||
var instrumentationHelper = | ||
new InstrumentationHelper(new ProcessExitHandler(), new RetryHelper(), new FileSystem(), new Mock<ILogger>().Object, | ||
new SourceRootTranslator(module, new Mock<ILogger>().Object, new FileSystem(), new AssemblyAdapter())); | ||
|
||
var parameters = new CoverageParameters | ||
{ | ||
IncludeFilters = new string[] { "[coverlet.tests.projectsample.excludedbyattribute*]*" }, | ||
IncludeDirectories = Array.Empty<string>(), | ||
ExcludeFilters = Array.Empty<string>(), | ||
ExcludedSourceFiles = Array.Empty<string>(), | ||
ExcludeAttributes = Array.Empty<string>(), | ||
IncludeTestAssembly = false, | ||
SingleHit = false, | ||
MergeWith = string.Empty, | ||
UseSourceLink = false | ||
}; | ||
|
||
_coverage = new Coverage(Path.Combine(_directory.FullName, Path.GetFileName(module)), parameters, _mockLogger.Object, instrumentationHelper, new FileSystem(), new SourceRootTranslator(_mockLogger.Object, new FileSystem()), new CecilSymbolHelper()); | ||
_coverage.PrepareModules(); | ||
|
||
} | ||
|
||
[GlobalCleanup] | ||
public void IterationCleanup() | ||
{ | ||
_directory.Delete(true); | ||
} | ||
|
||
[Benchmark] | ||
public void GetCoverageBenchmark() | ||
{ | ||
CoverageResult result = _coverage.GetCoverageResult(); | ||
} | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
test/coverlet.core.benchmark.tests/InstrumenterBenchmarks.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using Coverlet.Core.Abstractions; | ||
using Coverlet.Core.Helpers; | ||
using Coverlet.Core.Symbols; | ||
|
||
using BenchmarkDotNet.Attributes; | ||
using Coverlet.Core.Instrumentation; | ||
using Coverlet.Core; | ||
using System.IO; | ||
using Moq; | ||
|
||
namespace coverlet.core.benchmark.tests | ||
{ | ||
[MemoryDiagnoser] | ||
public class InstrumenterBenchmarks | ||
{ | ||
Mock<ILogger> _mockLogger; | ||
Mock<FileSystem> _partialMockFileSystem; | ||
readonly string[] _files = new[] | ||
{ | ||
"System.Private.CoreLib.dll", | ||
"System.Private.CoreLib.pdb" | ||
}; | ||
Instrumenter _instrumenter; | ||
DirectoryInfo _directory; | ||
SourceRootTranslator _sourceRootTranslator; | ||
CoverageParameters _parameters; | ||
InstrumentationHelper _instrumentationHelper; | ||
|
||
//[GlobalSetup(Target = nameof(InstrumenterBenchmarks))] | ||
//public void InstrumenterBenchmarkSetup() | ||
//{ | ||
|
||
//} | ||
|
||
[GlobalCleanup] | ||
public void IterationCleanup() | ||
{ | ||
_directory.Delete(true); | ||
} | ||
|
||
[Benchmark] | ||
public void InstrumenterBenchmark() | ||
{ | ||
_mockLogger = new Mock<ILogger>(); | ||
_directory = Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), nameof(InstrumenterBenchmark))); | ||
|
||
foreach (string file in _files) | ||
{ | ||
File.Copy(Path.Combine(Directory.GetCurrentDirectory(), "TestAssets", file), Path.Combine(_directory.FullName, file), overwrite: true); | ||
} | ||
|
||
_partialMockFileSystem = new Mock<FileSystem>(); | ||
_partialMockFileSystem.CallBase = true; | ||
_partialMockFileSystem.Setup(fs => fs.OpenRead(It.IsAny<string>())).Returns((string path) => | ||
{ | ||
if (Path.GetFileName(path.Replace(@"\", @"/")) == _files[1]) | ||
{ | ||
return File.OpenRead(Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), "TestAssets"), _files[1])); | ||
} | ||
else | ||
{ | ||
return File.OpenRead(path); | ||
} | ||
}); | ||
_partialMockFileSystem.Setup(fs => fs.Exists(It.IsAny<string>())).Returns((string path) => | ||
{ | ||
if (Path.GetFileName(path.Replace(@"\", @"/")) == _files[1]) | ||
{ | ||
return File.Exists(Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), "TestAssets"), _files[1])); | ||
} | ||
else | ||
{ | ||
if (path.Contains(@":\git\runtime")) | ||
{ | ||
return true; | ||
} | ||
else | ||
{ | ||
return File.Exists(path); | ||
} | ||
} | ||
}); | ||
_sourceRootTranslator = new SourceRootTranslator(_mockLogger.Object, new FileSystem()); | ||
_parameters = new CoverageParameters(); | ||
_instrumentationHelper = | ||
new InstrumentationHelper(new ProcessExitHandler(), new RetryHelper(), _partialMockFileSystem.Object, _mockLogger.Object, _sourceRootTranslator); | ||
_instrumenter = new Instrumenter(Path.Combine(_directory.FullName, _files[0]), "_coverlet_instrumented", _parameters, _mockLogger.Object, _instrumentationHelper, _partialMockFileSystem.Object, _sourceRootTranslator, new CecilSymbolHelper()); | ||
|
||
// implement your benchmark here | ||
InstrumenterResult result = _instrumenter.Instrument(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+3.16 MB
test/coverlet.core.benchmark.tests/TestAssets/System.Private.CoreLib.dll
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
using BenchmarkDotNet.Configs; | ||
//using BenchmarkDotNet.Environments; | ||
using BenchmarkDotNet.Jobs; | ||
using BenchmarkDotNet.Running; | ||
using BenchmarkDotNet.Toolchains.InProcess.NoEmit; | ||
|
||
namespace coverlet.msbuild.benchmark.tests | ||
{ | ||
public class Program | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
var config = DefaultConfig.Instance | ||
.AddJob(Job.MediumRun | ||
.WithLaunchCount(1) | ||
.WithToolchain(InProcessNoEmitToolchain.Instance | ||
) | ||
); | ||
var summary = BenchmarkRunner.Run<MSBuildTaskBenchmarks>(config, args); | ||
var config = DefaultConfig.Instance | ||
.WithOptions(ConfigOptions.JoinSummary) | ||
.AddJob(Job | ||
.ShortRun | ||
.WithLaunchCount(1) | ||
.WithToolchain(InProcessNoEmitToolchain.Instance)); | ||
var summary = BenchmarkRunner.Run(new[]{ | ||
BenchmarkConverter.TypeToBenchmarks( typeof(CoverageResultTaskBenchmarks), config), | ||
//BenchmarkConverter.TypeToBenchmarks( typeof(InstrumentationTaskBenchmarks), config) | ||
}); | ||
|
||
// Use this to select benchmarks from the console: | ||
//var summaries = BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, config); | ||
} | ||
// Use this to select benchmarks from the console: | ||
//var summaries = BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, config); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters