Skip to content
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

built-in accurate and cross platform Memory Diagnoser #284

Merged
merged 14 commits into from
Nov 25, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
don't try to use AppDomain's Monitoring in Mono since it's not implem…
…ented there
  • Loading branch information
adamsitnik committed Nov 3, 2016
commit 4cabc202bcb5f76a2e417d6b20aedf5c23e12e3a
4 changes: 4 additions & 0 deletions src/BenchmarkDotNet.Core/Diagnosers/MemoryDiagnoser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using BenchmarkDotNet.Running;
using System.Linq;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Portability;

namespace BenchmarkDotNet.Diagnosers
{
Expand Down Expand Up @@ -55,6 +56,9 @@ public AllocationColumn(Dictionary<Benchmark, GcStats> results)
public string GetValue(Summary summary, Benchmark benchmark)
{
#if !CORE
if (RuntimeInformation.IsMono())
return "?";

if (results.ContainsKey(benchmark))
{
var result = results[benchmark];
Expand Down
4 changes: 4 additions & 0 deletions src/BenchmarkDotNet.Core/Engines/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using BenchmarkDotNet.Characteristics;
using BenchmarkDotNet.Horology;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Portability;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
using JetBrains.Annotations;
Expand Down Expand Up @@ -172,6 +173,9 @@ private void EnableMonitoring()
if(!IsDiagnoserAttached) // it could affect the results, we do this in separate, diagnostics-only run
return;
#if CLASSIC
if(RuntimeInformation.IsMono()) // Monitoring is not available in Mono, see http://stackoverflow.com/questions/40234948/how-to-get-the-number-of-allocated-bytes-in-mono
return;

AppDomain.MonitoringIsEnabled = true;
#endif
}
Expand Down
3 changes: 2 additions & 1 deletion src/BenchmarkDotNet.Core/Engines/GcStats.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using BenchmarkDotNet.Portability;

namespace BenchmarkDotNet.Engines
{
Expand Down Expand Up @@ -79,7 +80,7 @@ private static long GetAllocatedBytes(bool isDiagnosticsEnabled)
#if NETCOREAPP11 // when MS releases new version of .NET Runtime to nuget.org
return GC.GetAllocatedBytesForCurrentThread(); // https://github.com/dotnet/corefx/pull/12489
#elif CLASSIC
if (!isDiagnosticsEnabled)
if (!isDiagnosticsEnabled || RuntimeInformation.IsMono()) // Monitoring is not available in Mono, see http://stackoverflow.com/questions/40234948/how-to-get-the-number-of-allocated-bytes-
return 0;

// "This instance Int64 property returns the number of bytes that have been allocated by a specific
Expand Down
4 changes: 3 additions & 1 deletion src/BenchmarkDotNet.Core/Portability/RuntimeInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace BenchmarkDotNet.Portability
{
public class RuntimeInformation
{
private static readonly bool isMono = Type.GetType("Mono.Runtime") != null; // it allocates a lot of memory, we need to check it once in order to keep Enging non-allocating!

private const string Debug = "DEBUG";
private const string Release = "RELEASE";
internal const string Unknown = "?";
Expand All @@ -39,7 +41,7 @@ internal static bool IsWindows()
#endif
}

private static bool IsMono() => Type.GetType("Mono.Runtime") != null;
internal static bool IsMono() => isMono;

internal static string GetOsVersion()
{
Expand Down