You've already forked linux-packaging-mono
Imported Upstream version 5.16.0.100
Former-commit-id: 38faa55fb9669e35e7d8448b15c25dc447f25767
This commit is contained in:
parent
0a9828183b
commit
7d7f676260
@@ -2,14 +2,26 @@ thisdir = class/Mono.Profiler.Log
|
||||
include ../../build/rules.make
|
||||
|
||||
LIBRARY = Mono.Profiler.Log.dll
|
||||
LIBRARY_SNK = ../mono.snk
|
||||
|
||||
LIB_REFS = System System.Core
|
||||
KEYFILE = $(LIBRARY_SNK)
|
||||
LIB_MCS_FLAGS = /unsafe /publicsign /nowarn:0618
|
||||
|
||||
LIBRARY_WARN_AS_ERROR = yes
|
||||
|
||||
NO_TEST = yes
|
||||
KEYFILE = $(LIBRARY_SNK)
|
||||
|
||||
LIB_REFS = System System.Core
|
||||
LIB_MCS_FLAGS = /unsafe /publicsign /nowarn:0618
|
||||
|
||||
XTEST_LIB_REFS = System System.Core Facades/System.Threading.Tasks
|
||||
|
||||
xunit-test-local: log-profiler-test.exe
|
||||
|
||||
log-profiler-test.exe: Test/log-profiler-test.cs
|
||||
$(CSCOMPILE) $(PLATFORM_DEBUG_FLAGS) /unsafe $(if $(MCS_MODE),,/warnaserror) /r:$(build_libdir)/mscorlib.dll /r:$(build_lib) /out:$@ $<
|
||||
|
||||
EXTRA_DISTFILES = \
|
||||
Test/log-profiler-test.cs
|
||||
|
||||
CLEAN_FILES = \
|
||||
log-profiler-test.exe \
|
||||
log-profiler-test.exe.mdb \
|
||||
log-profiler-test.pdb
|
||||
|
||||
include ../../build/library.make
|
||||
|
||||
@@ -124,12 +124,14 @@ namespace Mono.Profiler.Log {
|
||||
// mono/metadata/profiler.h : MonoProfilerCodeBufferType
|
||||
public enum LogJitHelper {
|
||||
Method = 0,
|
||||
[Obsolete ("This value is no longer produced.")]
|
||||
MethodTrampoline = 1,
|
||||
UnboxTrampoline = 2,
|
||||
ImtTrampoline = 3,
|
||||
GenericsTrampoline = 4,
|
||||
SpecificTrampoline = 5,
|
||||
Helper = 6,
|
||||
[Obsolete ("This value is no longer produced.")]
|
||||
Monitor = 7,
|
||||
DelegateInvoke = 8,
|
||||
ExceptionHandling = 9,
|
||||
|
||||
@@ -276,7 +276,7 @@ namespace Mono.Profiler.Log {
|
||||
|
||||
public struct HeapRoot {
|
||||
|
||||
public long AddressPointer { get; internal set; }
|
||||
public long SlotPointer { get; internal set; }
|
||||
|
||||
public long ObjectPointer { get; internal set; }
|
||||
|
||||
|
||||
@@ -443,7 +443,7 @@ namespace Mono.Profiler.Log {
|
||||
|
||||
for (var i = 0; i < list.Length; i++) {
|
||||
list [i] = new HeapRootsEvent.HeapRoot {
|
||||
AddressPointer = StreamHeader.FormatVersion >= 15 ? ReadPointer () : 0,
|
||||
SlotPointer = StreamHeader.FormatVersion >= 15 ? ReadPointer () : 0,
|
||||
ObjectPointer = ReadObject (),
|
||||
Attributes = StreamHeader.FormatVersion < 15 ?
|
||||
(StreamHeader.FormatVersion == 13 ?
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Mono.Profiler.Log {
|
||||
|
||||
const int MinVersion = 13;
|
||||
|
||||
const int MaxVersion = 16;
|
||||
const int MaxVersion = 17;
|
||||
|
||||
const int Id = 0x4d505a01;
|
||||
|
||||
|
||||
325
mcs/class/Mono.Profiler.Log/Test/log-profiler-test.cs
Normal file
325
mcs/class/Mono.Profiler.Log/Test/log-profiler-test.cs
Normal file
@@ -0,0 +1,325 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using Mono.Profiler.Log;
|
||||
|
||||
namespace Mono.Profiling.Tests {
|
||||
|
||||
static class Program {
|
||||
|
||||
static int Main (string[] args)
|
||||
{
|
||||
if (args.Length != 1) {
|
||||
Console.WriteLine ("Usage: log-profiler-test <test name>");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!_tests.TryGetValue (args [0], out var test)) {
|
||||
Console.WriteLine ("Unknown test name: '{0}'", args [0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
test.Run ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static readonly IReadOnlyDictionary<string, ProfilerTest> _tests = new Dictionary<string, ProfilerTest> {
|
||||
["do-nothing"] = new DoNothingTest (),
|
||||
["busy-work"] = new BusyWorkTest (),
|
||||
["idle-sleep"] = new IdleSleepTest (),
|
||||
["simple-allocation"] = new SimpleAllocationTest (),
|
||||
["wasteful-allocation"] = new WastefulAllocationTest (),
|
||||
["runtime-api"] = new RuntimeApiTest (),
|
||||
["exception-clause"] = new ExceptionClauseTest (),
|
||||
["monitor-lock"] = new MonitorLockTest (),
|
||||
["backtrace"] = new BacktraceTest (),
|
||||
["gc-handle"] = new GCHandleTest (),
|
||||
["finalization"] = new FinalizationTest (),
|
||||
["pinvoke"] = new PInvokeTest (),
|
||||
};
|
||||
}
|
||||
|
||||
abstract class ProfilerTest {
|
||||
|
||||
public abstract void Run ();
|
||||
}
|
||||
|
||||
sealed class DoNothingTest : ProfilerTest {
|
||||
|
||||
public override void Run ()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
sealed class BusyWorkTest : ProfilerTest {
|
||||
|
||||
int _value;
|
||||
|
||||
public override void Run ()
|
||||
{
|
||||
var threads = new Thread [4];
|
||||
|
||||
for (var i = 0; i < threads.Length; i++) {
|
||||
threads [i] = new Thread (Work) {
|
||||
Name = "BusyWork" + i,
|
||||
};
|
||||
}
|
||||
|
||||
foreach (var thread in threads)
|
||||
thread.Start ();
|
||||
|
||||
foreach (var thread in threads)
|
||||
thread.Join ();
|
||||
}
|
||||
|
||||
void Work ()
|
||||
{
|
||||
for (var i = 0; i < 500000000; i++)
|
||||
_value /= (i + 100) * 1000;
|
||||
}
|
||||
}
|
||||
|
||||
sealed class IdleSleepTest : ProfilerTest {
|
||||
|
||||
public override void Run ()
|
||||
{
|
||||
var threads = new Thread [4];
|
||||
|
||||
for (var i = 0; i < threads.Length; i++) {
|
||||
threads [i] = new Thread (Sleep) {
|
||||
Name = "IdleSleep" + i,
|
||||
};
|
||||
}
|
||||
|
||||
foreach (var thread in threads)
|
||||
thread.Start ();
|
||||
|
||||
foreach (var thread in threads)
|
||||
thread.Join ();
|
||||
}
|
||||
|
||||
static void Sleep ()
|
||||
{
|
||||
Thread.Sleep (5000);
|
||||
}
|
||||
}
|
||||
|
||||
sealed class SimpleAllocationTest : ProfilerTest {
|
||||
|
||||
readonly (object, int[], Exception)[] _objects = new (object, int[], Exception) [10000];
|
||||
|
||||
public override void Run ()
|
||||
{
|
||||
for (var i = 0; i < _objects.Length; i++)
|
||||
_objects [i] = (new object (), new int [i], new Exception ());
|
||||
}
|
||||
}
|
||||
|
||||
sealed class WastefulAllocationTest : ProfilerTest {
|
||||
|
||||
public override void Run ()
|
||||
{
|
||||
for (var i = 0; i < 100000; i++) {
|
||||
var dummy = new int [i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed class RuntimeApiTest : ProfilerTest {
|
||||
|
||||
readonly object[] _array = new object [1000];
|
||||
|
||||
public override void Run ()
|
||||
{
|
||||
if (!LogProfiler.IsAttached)
|
||||
throw new Exception ("Where's the log profiler?");
|
||||
|
||||
for (var i = 0; i < _array.Length; i++)
|
||||
_array [i] = new object ();
|
||||
|
||||
LogProfiler.TriggerHeapshot ();
|
||||
|
||||
Thread.Sleep (5000);
|
||||
}
|
||||
}
|
||||
|
||||
sealed class ExceptionClauseTest : ProfilerTest {
|
||||
|
||||
sealed class CustomException : Exception {
|
||||
}
|
||||
|
||||
public override void Run ()
|
||||
{
|
||||
var ex = new CustomException ();
|
||||
|
||||
try {
|
||||
throw ex;
|
||||
} catch (Exception e) when (e is CustomException) {
|
||||
}
|
||||
|
||||
try {
|
||||
throw ex;
|
||||
} catch (Exception) {
|
||||
} finally {
|
||||
Dummy ();
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl (MethodImplOptions.NoInlining)]
|
||||
static void Dummy ()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
sealed class MonitorLockTest : ProfilerTest {
|
||||
|
||||
readonly object _lock = new object ();
|
||||
|
||||
public override void Run ()
|
||||
{
|
||||
var thread = new Thread (TryLock) {
|
||||
Name = "MonitorLock1",
|
||||
};
|
||||
|
||||
Monitor.Enter (_lock);
|
||||
thread.Start ();
|
||||
Thread.Sleep (10000);
|
||||
Monitor.Exit (_lock);
|
||||
thread.Join ();
|
||||
|
||||
thread = new Thread (Lock) {
|
||||
Name = "MonitorLock2",
|
||||
};
|
||||
|
||||
thread.Start ();
|
||||
Lock ();
|
||||
thread.Join ();
|
||||
}
|
||||
|
||||
void TryLock ()
|
||||
{
|
||||
while (!Monitor.TryEnter (_lock, 1));
|
||||
|
||||
Monitor.Exit (_lock);
|
||||
}
|
||||
|
||||
void Lock ()
|
||||
{
|
||||
for (var i = 0; i < 1000000; i++) {
|
||||
lock (_lock) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed class BacktraceTest : ProfilerTest {
|
||||
|
||||
sealed class CustomException : Exception {
|
||||
}
|
||||
|
||||
public override void Run ()
|
||||
{
|
||||
try {
|
||||
One ();
|
||||
} catch (CustomException) {
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl (MethodImplOptions.NoInlining)]
|
||||
static void One ()
|
||||
{
|
||||
Two ();
|
||||
}
|
||||
|
||||
[MethodImpl (MethodImplOptions.NoInlining)]
|
||||
static void Two ()
|
||||
{
|
||||
Three ();
|
||||
}
|
||||
|
||||
[MethodImpl (MethodImplOptions.NoInlining)]
|
||||
static void Three ()
|
||||
{
|
||||
Four ();
|
||||
}
|
||||
|
||||
[MethodImpl (MethodImplOptions.NoInlining)]
|
||||
static void Four ()
|
||||
{
|
||||
throw new CustomException ();
|
||||
}
|
||||
}
|
||||
|
||||
sealed class GCHandleTest : ProfilerTest {
|
||||
|
||||
sealed class NormalClass {
|
||||
}
|
||||
|
||||
sealed class PinnedClass {
|
||||
}
|
||||
|
||||
sealed class WeakClass {
|
||||
}
|
||||
|
||||
sealed class WeakTrackResurrectionClass {
|
||||
}
|
||||
|
||||
public override void Run ()
|
||||
{
|
||||
var normal = GCHandle.Alloc (new NormalClass (), GCHandleType.Normal);
|
||||
normal.Free ();
|
||||
|
||||
var pinned = GCHandle.Alloc (new PinnedClass (), GCHandleType.Pinned);
|
||||
pinned.Free ();
|
||||
|
||||
var weak = GCHandle.Alloc (new WeakClass (), GCHandleType.Weak);
|
||||
weak.Free ();
|
||||
|
||||
var weakTrack = GCHandle.Alloc (new WeakTrackResurrectionClass (), GCHandleType.WeakTrackResurrection);
|
||||
weakTrack.Free ();
|
||||
}
|
||||
}
|
||||
|
||||
sealed class FinalizationTest : ProfilerTest {
|
||||
|
||||
sealed class FinalizableClass {
|
||||
|
||||
static int _finalized;
|
||||
|
||||
~FinalizableClass ()
|
||||
{
|
||||
_finalized++;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Run ()
|
||||
{
|
||||
for (var i = 0; i < 10000; i++) {
|
||||
new FinalizableClass ();
|
||||
|
||||
if (i % 1000 == 0) {
|
||||
GC.Collect ();
|
||||
GC.WaitForPendingFinalizers ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed class PInvokeTest : ProfilerTest {
|
||||
|
||||
[DllImport ("libc", EntryPoint = "uname")]
|
||||
static extern int KernelName (IntPtr buf);
|
||||
|
||||
public override void Run ()
|
||||
{
|
||||
for (var i = 0; i < 10000000; i++)
|
||||
KernelName (IntPtr.Zero);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user