Skip to content

handle missing libgdiplus#592

Merged
adamsitnik merged 2 commits intodotnet:masterfrom
adamsitnik:missinglibgdiplus
Jun 27, 2019
Merged

handle missing libgdiplus#592
adamsitnik merged 2 commits intodotnet:masterfrom
adamsitnik:missinglibgdiplus

Conversation

@adamsitnik
Copy link
Copy Markdown
Member

As of today, when we try to run the benchmarks on a Linux machine without libgdiplus installed the benchmark app crashes and does not run any benchmark.

An example from #517 :

$/usr/share/dotnet/dotnet run -f netcoreapp3.0 -c Release -- --filter '*'
Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'System.Drawing.Tests.Perf_Image_Load' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Gdip' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'libgdiplus': The specified module could not be found.
   at System.Runtime.InteropServices.FunctionWrapper`1.get_Delegate()
   at System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr& token, StartupInput& input, StartupOutput& output)
   at System.Drawing.SafeNativeMethods.Gdip..cctor()
   --- End of inner exception stack trace ---
   at System.Drawing.SafeNativeMethods.Gdip.GdipCreateBitmapFromScan0(Int32 width, Int32 height, Int32 stride, Int32 format, HandleRef scan0, IntPtr& bitmap)
   at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
   at System.Drawing.Tests.Perf_Image_Load.ImageTestData.CreateTestImage(ImageFormat format) in /home/asoldatov/performance/src/benchmarks/micro/corefx/System.Drawing/Perf_Image_Load.cs:line 76
   at System.Drawing.Tests.Perf_Image_Load.ImageTestData..ctor(ImageFormat format) in /home/asoldatov/performance/src/benchmarks/micro/corefx/System.Drawing/Perf_Image_Load.cs:line 60
   at System.Drawing.Tests.Perf_Image_Load..cctor() in /home/asoldatov/performance/src/benchmarks/micro/corefx/System.Drawing/Perf_Image_Load.cs:line 17
   --- End of inner exception stack trace ---
   at System.Drawing.Tests.Perf_Image_Load.ImageFormats() in /home/asoldatov/performance/src/benchmarks/micro/corefx/System.Drawing/Perf_Image_Load.cs:line 24
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at BenchmarkDotNet.Running.BenchmarkConverter.GetValidValuesForParamsSource(Type parentType, String sourceName)
   at BenchmarkDotNet.Running.BenchmarkConverter.GetArgumentsDefinitions(MethodInfo benchmark, Type target)+MoveNext()
   at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at BenchmarkDotNet.Running.BenchmarkConverter.MethodsToBenchmarksWithFullConfig(Type containingType, MethodInfo[] benchmarkMethods, ImmutableConfig immutableConfig)
   at BenchmarkDotNet.Running.BenchmarkConverter.TypeToBenchmarks(Type type, IConfig config)
   at BenchmarkDotNet.Running.TypeFilter.<>c__DisplayClass1_0.<Filter>b__0(Type type)
   at System.Linq.Enumerable.SelectListIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.ToArray()
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at BenchmarkDotNet.Running.TypeFilter.Filter(IConfig effectiveConfig, IEnumerable`1 types)
   at BenchmarkDotNet.Running.BenchmarkSwitcher.RunWithDirtyAssemblyResolveHelper(String[] args, IConfig config)
   at BenchmarkDotNet.Running.BenchmarkSwitcher.Run(String[] args, IConfig config)
   at MicroBenchmarks.Program.Main(String[] args) in /home/asoldatov/performance/src/benchmarks/micro/Program.cs:line 35

My proposal is to handle the exception, print a red warning with explanation (and a solution) and let the other benchmarks run.

@adamsitnik adamsitnik requested review from billwert and jorive June 27, 2019 06:01
@billwert
Copy link
Copy Markdown
Contributor

let the other benchmarks run.

I suspect this is likely to cause people to miss / ignore it. Why not just fail the run and let them fix it? I think the major value is to point out how to fix the problem trivially.

catch (Exception) when (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("libgdiplus is missing, you can install it by running 'apt-get install libgdiplus'");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it worth it to call out sudo here?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think so, the user might be already sudo or have permissions.

@jorive
Copy link
Copy Markdown

jorive commented Jun 27, 2019

I agree with Bill here. It's better to fail and let people fix it. A warning will be easily ignored.

@adamsitnik
Copy link
Copy Markdown
Member Author

I have pushed a change, now the exception is re-thrown.

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 this pull request may close these issues.

3 participants