[REEF-1817] Port PerformanceCounters to a CoreCLR-Compliant System
This addressed the issue by
* Using performance counters only in the 4.5.1 build
* Leaving DotNet Core performance monitoring unsupported for now
JIRA:
[REEF-1817](https://issues.apache.org/jira/browse/REEF-1817)
Pull request:
This closes #1335
diff --git a/lang/cs/Org.Apache.REEF.Common/Runtime/MachineStatus.cs b/lang/cs/Org.Apache.REEF.Common/Runtime/MachineStatus.cs
index c6ee2b6..6c78477 100644
--- a/lang/cs/Org.Apache.REEF.Common/Runtime/MachineStatus.cs
+++ b/lang/cs/Org.Apache.REEF.Common/Runtime/MachineStatus.cs
@@ -24,6 +24,10 @@
{
public class MachineStatus
{
+#if DOTNET_BUILD
+ private const string NotSupportedValue = "<UNSUPPORTED>";
+ private const string NotSupportedMessage = "Machine Status is not supported on this OS";
+#else
private static readonly PerformanceCounter CpuCounter;
private static readonly PerformanceCounter RamCounter;
@@ -60,12 +64,17 @@
InstanceName = processName
};
}
+#endif
public static string CurrentNodeCpuUsage
{
get
{
+#if DOTNET_BUILD
+ return NotSupportedValue + "%";
+#else
return CpuCounter.NextValue() + "%";
+#endif
}
}
@@ -73,7 +82,11 @@
{
get
{
- return RamCounter.NextValue() + "MB";
+#if DOTNET_BUILD
+ return NotSupportedValue + "MB";
+#else
+ return RamCounter.NextValue() + "MB";
+#endif
}
}
@@ -81,7 +94,11 @@
{
get
{
+#if DOTNET_BUILD
+ return NotSupportedValue + "MB";
+#else
return ((float)Process.WorkingSet64 / 1000000.0).ToString(CultureInfo.InvariantCulture) + "MB";
+#endif
}
}
@@ -89,7 +106,11 @@
{
get
{
+#if DOTNET_BUILD
+ return NotSupportedValue + "MB";
+#else
return ((float)Process.PeakWorkingSet64 / 1000000.0).ToString(CultureInfo.InvariantCulture) + "MB";
+#endif
}
}
@@ -98,12 +119,19 @@
{
get
{
+#if DOTNET_BUILD
+ return NotSupportedValue + "MB";
+#else
return ((float)ProcessCpuCounter.RawValue / 1000000.0) + "%";
+#endif
}
}
public override string ToString()
{
+#if DOTNET_BUILD
+ return NotSupportedMessage;
+#else
string info = "No machine status information retrieved. Could be due to lack of admin right to get the info.";
if (_checkStatus)
{
@@ -131,6 +159,7 @@
}
return info;
+#endif
}
}
}