Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/mcs
diff options
context:
space:
mode:
authorjaykrell <jay.krell@cornell.edu>2018-01-23 01:40:33 +0300
committerLudovic Henry <luhenry@microsoft.com>2018-01-23 01:40:33 +0300
commitda444c9d514d0918193d78cd83d7ee586836ce6a (patch)
tree28e9c6c54ca209c6d0aad852bb34472a14f6dcb4 /mcs
parent3363ec9cc4160bba07339d5c5337011a793652bd (diff)
[perfcounters] Move machine handling from native to managed. (#6543)
* Move machine handling of performance counters from native to managed -- just slightly less native code therefore. * PR feedback: Rename ValidMachine to IsValidMachine. Use string::operator== instead of .Length/[]. Change InstanceExistsInternal to return bool/MonoBoolean directly instead of int. Remove question mark on FIXME comment for more reliable grep. Remove redundant zeroing of a pointer.
Diffstat (limited to 'mcs')
-rw-r--r--mcs/class/System/System.Diagnostics/PerformanceCounter.cs11
-rw-r--r--mcs/class/System/System.Diagnostics/PerformanceCounterCategory.cs53
2 files changed, 44 insertions, 20 deletions
diff --git a/mcs/class/System/System.Diagnostics/PerformanceCounter.cs b/mcs/class/System/System.Diagnostics/PerformanceCounter.cs
index 4261b3bc491..2c3305159d0 100644
--- a/mcs/class/System/System.Diagnostics/PerformanceCounter.cs
+++ b/mcs/class/System/System.Diagnostics/PerformanceCounter.cs
@@ -127,7 +127,7 @@ namespace System.Diagnostics {
[MethodImplAttribute (MethodImplOptions.InternalCall)]
static extern IntPtr GetImpl (string category, string counter,
- string instance, string machine, out PerformanceCounterType ctype, out bool custom);
+ string instance, out PerformanceCounterType ctype, out bool custom);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
static extern bool GetSample (IntPtr impl, bool only_value, out CounterSample sample);
@@ -138,6 +138,11 @@ namespace System.Diagnostics {
[MethodImplAttribute (MethodImplOptions.InternalCall)]
static extern void FreeData (IntPtr impl);
+ static bool IsValidMachine (string machine)
+ { // no support for counters on other machines
+ return machine == ".";
+ }
+
/* the perf counter has changed, ensure it's valid and setup it to
* be able to collect/update data
*/
@@ -146,7 +151,9 @@ namespace System.Diagnostics {
// need to free the previous info
if (impl != IntPtr.Zero)
Close ();
- impl = GetImpl (categoryName, counterName, instanceName, machineName, out type, out is_custom);
+
+ if (IsValidMachine (machineName))
+ impl = GetImpl (categoryName, counterName, instanceName, out type, out is_custom);
// system counters are always readonly
if (!is_custom)
readOnly = true;
diff --git a/mcs/class/System/System.Diagnostics/PerformanceCounterCategory.cs b/mcs/class/System/System.Diagnostics/PerformanceCounterCategory.cs
index 3f8a88f1147..84e8c1b91c4 100644
--- a/mcs/class/System/System.Diagnostics/PerformanceCounterCategory.cs
+++ b/mcs/class/System/System.Diagnostics/PerformanceCounterCategory.cs
@@ -44,27 +44,27 @@ namespace System.Diagnostics
static extern bool CategoryDelete (string name);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern string CategoryHelpInternal (string category, string machine);
+ static extern string CategoryHelpInternal (string category);
/* this icall allows a null counter and it will just search for the category */
[MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern bool CounterCategoryExists (string counter, string category, string machine);
+ static extern bool CounterCategoryExists (string counter, string category);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
static extern bool Create (string categoryName, string categoryHelp,
PerformanceCounterCategoryType categoryType, CounterCreationData[] items);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern int InstanceExistsInternal (string instance, string category, string machine);
+ static extern bool InstanceExistsInternal (string instance, string category);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern string[] GetCategoryNames (string machine);
+ static extern string[] GetCategoryNames ();
[MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern string[] GetCounterNames (string category, string machine);
+ static extern string[] GetCounterNames (string category);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern string[] GetInstanceNames (string category, string machine);
+ static extern string[] GetInstanceNames (string category);
static void CheckCategory (string categoryName) {
if (categoryName == null)
@@ -95,10 +95,17 @@ namespace System.Diagnostics
this.machineName = machineName;
}
+ static bool IsValidMachine (string machine)
+ { // no support for counters on other machines
+ return machine == ".";
+ }
+
// may throw InvalidOperationException, Win32Exception
public string CategoryHelp {
get {
- string res = CategoryHelpInternal (categoryName, machineName);
+ string res = null;
+ if (IsValidMachine (machineName))
+ res = CategoryHelpInternal (categoryName);
if (res != null)
return res;
throw new InvalidOperationException ();
@@ -154,7 +161,8 @@ namespace System.Diagnostics
CheckCategory (categoryName);
if (machineName == null)
throw new ArgumentNullException ("machineName");
- return CounterCategoryExists (counterName, categoryName, machineName);
+ return IsValidMachine (machineName)
+ && CounterCategoryExists (counterName, categoryName);
}
[Obsolete ("Use another overload that uses PerformanceCounterCategoryType instead")]
@@ -227,7 +235,8 @@ namespace System.Diagnostics
public static bool Exists (string categoryName, string machineName)
{
CheckCategory (categoryName);
- return CounterCategoryExists (null, categoryName, machineName);
+ return IsValidMachine (machineName) &&
+ CounterCategoryExists (null, categoryName);
}
public static PerformanceCounterCategory[] GetCategories ()
@@ -239,7 +248,11 @@ namespace System.Diagnostics
{
if (machineName == null)
throw new ArgumentNullException ("machineName");
- string[] catnames = GetCategoryNames (machineName);
+
+ if (!IsValidMachine (machineName))
+ return Array.Empty<PerformanceCounterCategory>();
+
+ string[] catnames = GetCategoryNames ();
PerformanceCounterCategory[] cats = new PerformanceCounterCategory [catnames.Length];
for (int i = 0; i < catnames.Length; ++i)
cats [i] = new PerformanceCounterCategory (catnames [i], machineName);
@@ -253,7 +266,9 @@ namespace System.Diagnostics
public PerformanceCounter[] GetCounters (string instanceName)
{
- string[] countnames = GetCounterNames (categoryName, machineName);
+ if (!IsValidMachine (machineName))
+ return Array.Empty<PerformanceCounter>();
+ string[] countnames = GetCounterNames (categoryName);
PerformanceCounter[] counters = new PerformanceCounter [countnames.Length];
for (int i = 0; i < countnames.Length; ++i) {
counters [i] = new PerformanceCounter (categoryName, countnames [i], instanceName, machineName);
@@ -263,7 +278,9 @@ namespace System.Diagnostics
public string[] GetInstanceNames ()
{
- return GetInstanceNames (categoryName, machineName);
+ if (!IsValidMachine (machineName))
+ return Array.Empty<string>();
+ return GetInstanceNames (categoryName);
}
public bool InstanceExists (string instanceName)
@@ -283,12 +300,12 @@ namespace System.Diagnostics
CheckCategory (categoryName);
if (machineName == null)
throw new ArgumentNullException ("machineName");
- int val = InstanceExistsInternal (instanceName, categoryName, machineName);
- if (val == 0)
- return false;
- if (val == 1)
- return true;
- throw new InvalidOperationException ();
+
+ //?FIXME: machine appears to be wrong
+ //if (!IsValidMachine (machineName))
+ //return false;
+
+ return InstanceExistsInternal (instanceName, categoryName);
}
[MonoTODO]