Skip to content

Support for SingleFile && SelfContained apps #1685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
am11 opened this issue Apr 4, 2021 · 0 comments · Fixed by #1686
Closed

Support for SingleFile && SelfContained apps #1685

am11 opened this issue Apr 4, 2021 · 0 comments · Fixed by #1686
Milestone

Comments

@am11
Copy link
Member

am11 commented Apr 4, 2021

Currently, it seems like the true single file deployment (supported in .NET 5 onwards) is not working properly with BenchmarkDotNet.

Repro

# on Unbuntu 20.04 with latest .NET 5.0 (5.0.4) in PATH
$ dotnet new console -n MyBenchmarkApp
$ cd MyBenchMarkApp
$ dotnet add package BenchmarkDotNet

# write some InProcess benchmarks
$ cat > Program.cs <<EOF
using System;
using System.Threading;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

[InProcess]
public class Program
{
    [Benchmark]
    public void Slow() => Thread.Sleep(100);

    [Benchmark]
    public void Fast() => Thread.Sleep(25);

    static void Main() => BenchmarkRunner.Run<Program>();
}
EOF

# deploy as a singlefile ELF executable (to a dir called ./publish)
$ dotnet publish -c Release -r linux-x64 --self-contained true -p:PublishSingleFile=true -o publish

# first test the (shared) executable which gets generated as part of the build under `./bin`
$ bin/Release/net5.0/linux-x64/MyBenchmarkApp
# ✅ works!
# and size of this shared executable
$ du -h bin/Release/net5.0/linux-x64/MyBenchmarkApp
11M     bin/Release/net5.0/linux-x64/MyBenchmarkApp

# then try the published app
$ publish/MyBenchmarkApp
# 🛑 fails!
// Validating benchmarks:
// ***** BenchmarkRunner: Start   *****
// ***** Found 2 benchmark(s) in total *****
// ***** Building 1 exe(s) in Parallel: Start   *****
Failed to generate partition: System.ArgumentNullException: Value cannot be null. (Parameter 'path1')
   at System.IO.Path.Combine(String path1, String path2)
   at BenchmarkDotNet.Toolchains.InProcess.Emit.InProcessEmitGenerator.GetArtifactsPaths(BuildPartition buildPartition, String rootArtifactsFolderPath)
   at BenchmarkDotNet.Toolchains.InProcess.Emit.InProcessEmitGenerator.GenerateProject(BuildPartition buildPartition, ILogger logger, String rootArtifactsFolderPath)
// ***** Done, took 00:00:00 (0.11 sec)   *****
// Found 2 benchmarks:
//   Program.Slow: InProcess(Toolchain=InProcessEmitToolchain)
//   Program.Fast: InProcess(Toolchain=InProcessEmitToolchain)

// Build Error: Exception!
Message: Object reference not set to an instance of an object.,
Stack trace:
   at BenchmarkDotNet.Toolchains.Results.BuildResult.Failure(GenerateResult generateResult, Exception exception)
   at BenchmarkDotNet.Running.BenchmarkRunnerClean.Build(BuildPartition buildPartition, String rootArtifactsFolderPath, ILogger buildLogger)

// Build Error: Exception!
Message: Object reference not set to an instance of an object.,
Stack trace:
   at BenchmarkDotNet.Toolchains.Results.BuildResult.Failure(GenerateResult generateResult, Exception exception)
   at BenchmarkDotNet.Running.BenchmarkRunnerClean.Build(BuildPartition buildPartition, String rootArtifactsFolderPath, ILogger buildLogger)

// ***** BenchmarkRunner: Finish  *****
...

# and size of this single executable
$ du -h publish/MyBenchmarkApp
77M     publish/MyBenchmarkApp

another strange thing is the ./publish directory has more files than expected (in case of a console app without BenchmarkDotNet reference):

$ ls -R publish
publish:
amd64  MyBenchmarkApp MyBenchmarkApp.pdb  x86

publish/amd64: // is it necessary on Linux?
KernelTraceControl.dll  msdia140.dll

publish/x86: // is it necessary on Linux?
KernelTraceControl.Win61.dll  KernelTraceControl.dll  msdia140.dll
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants