summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStephen Toub <stoub@microsoft.com>2019-05-22 00:27:00 -0400
committerJan Kotas <jkotas@microsoft.com>2019-05-21 21:26:59 -0700
commit29810a78e5b93d8da9fb921d096226d249fc75a5 (patch)
treeb2bbebd9396bb48402f72e8f194423c20f91bfb4 /src
parentfcada94108a025da328ef91a80399c498ccf1677 (diff)
downloadcoreclr-29810a78e5b93d8da9fb921d096226d249fc75a5.tar.gz
coreclr-29810a78e5b93d8da9fb921d096226d249fc75a5.tar.bz2
coreclr-29810a78e5b93d8da9fb921d096226d249fc75a5.zip
Implement AppDomain.Monitoring*MemorySize (#24610)
* Implement AppDomain.MonitoringTotalAllocatedMemorySize * Change precise:true back to precise:false in GetTotalAllocatedBytes
Diffstat (limited to 'src')
-rw-r--r--src/System.Private.CoreLib/Resources/Strings.resx3
-rw-r--r--src/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetCpuUtilization.cs6
-rw-r--r--src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems2
-rw-r--r--src/System.Private.CoreLib/shared/System/AppDomain.Unix.cs26
-rw-r--r--src/System.Private.CoreLib/shared/System/AppDomain.Windows.cs14
-rw-r--r--src/System.Private.CoreLib/shared/System/AppDomain.cs20
6 files changed, 56 insertions, 15 deletions
diff --git a/src/System.Private.CoreLib/Resources/Strings.resx b/src/System.Private.CoreLib/Resources/Strings.resx
index 1b6c83c237..48cbbcffc8 100644
--- a/src/System.Private.CoreLib/Resources/Strings.resx
+++ b/src/System.Private.CoreLib/Resources/Strings.resx
@@ -3220,9 +3220,6 @@
<data name="PlatformNotSupported_CAS" xml:space="preserve">
<value>Code Access Security is not supported on this platform.</value>
</data>
- <data name="PlatformNotSupported_AppDomain_ResMon" xml:space="preserve">
- <value>AppDomain resource monitoring is not supported on this platform.</value>
- </data>
<data name="PlatformNotSupported_Principal" xml:space="preserve">
<value>Windows Principal functionality is not supported on this platform.</value>
</data>
diff --git a/src/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetCpuUtilization.cs b/src/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetCpuUtilization.cs
index 35e77c4541..a630a3e82c 100644
--- a/src/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetCpuUtilization.cs
+++ b/src/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetCpuUtilization.cs
@@ -13,9 +13,9 @@ internal static partial class Interop
[StructLayout(LayoutKind.Sequential)]
internal struct ProcessCpuInformation
{
- ulong lastRecordedCurrentTime;
- ulong lastRecordedKernelTime;
- ulong lastRecordedUserTime;
+ internal ulong lastRecordedCurrentTime;
+ internal ulong lastRecordedKernelTime;
+ internal ulong lastRecordedUserTime;
}
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetCpuUtilization")]
diff --git a/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems b/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems
index 35b10dbdc2..cb5180f823 100644
--- a/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems
+++ b/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems
@@ -1091,6 +1091,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Internal\IO\File.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeFileHandle.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeFindHandle.Windows.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\AppDomain.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Buffer.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\DateTime.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.Windows.cs" />
@@ -1253,6 +1254,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.Write.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Internal\IO\File.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeFileHandle.Unix.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\AppDomain.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Buffer.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\DateTime.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\DebugProvider.Unix.cs" />
diff --git a/src/System.Private.CoreLib/shared/System/AppDomain.Unix.cs b/src/System.Private.CoreLib/shared/System/AppDomain.Unix.cs
new file mode 100644
index 0000000000..3c1ef889f9
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/AppDomain.Unix.cs
@@ -0,0 +1,26 @@
+// 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.
+
+namespace System
+{
+ public sealed partial class AppDomain
+ {
+ public TimeSpan MonitoringTotalProcessorTime
+ {
+ get
+ {
+ Interop.Sys.ProcessCpuInformation cpuInfo = default;
+ Interop.Sys.GetCpuUtilization(ref cpuInfo);
+
+ ulong userTime100Nanoseconds = cpuInfo.lastRecordedUserTime / 100; // nanoseconds to 100-nanoseconds
+ if (userTime100Nanoseconds > long.MaxValue)
+ {
+ userTime100Nanoseconds = long.MaxValue;
+ }
+
+ return new TimeSpan((long)userTime100Nanoseconds);
+ }
+ }
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/AppDomain.Windows.cs b/src/System.Private.CoreLib/shared/System/AppDomain.Windows.cs
new file mode 100644
index 0000000000..07633273e2
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/AppDomain.Windows.cs
@@ -0,0 +1,14 @@
+// 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.
+
+namespace System
+{
+ public sealed partial class AppDomain
+ {
+ public TimeSpan MonitoringTotalProcessorTime =>
+ Interop.Kernel32.GetProcessTimes(Interop.Kernel32.GetCurrentProcess(), out _, out _, out _, out long userTime100Nanoseconds) ?
+ new TimeSpan(userTime100Nanoseconds) :
+ TimeSpan.Zero;
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/AppDomain.cs b/src/System.Private.CoreLib/shared/System/AppDomain.cs
index 34e26efc56..9c5a02c505 100644
--- a/src/System.Private.CoreLib/shared/System/AppDomain.cs
+++ b/src/System.Private.CoreLib/shared/System/AppDomain.cs
@@ -184,26 +184,28 @@ namespace System
public static bool MonitoringIsEnabled
{
- get { return false; }
+ get { return true; }
set
{
if (!value)
{
throw new ArgumentException(SR.Arg_MustBeTrue);
}
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_AppDomain_ResMon);
}
}
- public long MonitoringSurvivedMemorySize { get { throw CreateResMonNotAvailException(); } }
+ public long MonitoringSurvivedMemorySize => MonitoringSurvivedProcessMemorySize;
- public static long MonitoringSurvivedProcessMemorySize { get { throw CreateResMonNotAvailException(); } }
-
- public long MonitoringTotalAllocatedMemorySize { get { throw CreateResMonNotAvailException(); } }
-
- public TimeSpan MonitoringTotalProcessorTime { get { throw CreateResMonNotAvailException(); } }
+ public static long MonitoringSurvivedProcessMemorySize
+ {
+ get
+ {
+ GCMemoryInfo mi = GC.GetGCMemoryInfo();
+ return mi.HeapSizeBytes - mi.FragmentedBytes;
+ }
+ }
- private static Exception CreateResMonNotAvailException() => new InvalidOperationException(SR.PlatformNotSupported_AppDomain_ResMon);
+ public long MonitoringTotalAllocatedMemorySize => GC.GetTotalAllocatedBytes(precise: false);
[ObsoleteAttribute("AppDomain.GetCurrentThreadId has been deprecated because it does not provide a stable Id when managed threads are running on fibers (aka lightweight threads). To get a stable identifier for a managed thread, use the ManagedThreadId property on Thread. https://go.microsoft.com/fwlink/?linkid=14202", false)]
public static int GetCurrentThreadId() => Environment.CurrentManagedThreadId;