Wed Oct 22 17:45:48 CEST 2008 Paolo Molaro <lupus@ximian.com>
authorPaolo Molaro <lupus@oddwiz.org>
Wed, 22 Oct 2008 15:51:45 +0000 (15:51 -0000)
committerPaolo Molaro <lupus@oddwiz.org>
Wed, 22 Oct 2008 15:51:45 +0000 (15:51 -0000)
* mono-perfcounters.c, icall-def.h, environment.c, environment.h:
use the code in mono-proclib.h to get processor information.

svn path=/trunk/mono/; revision=116753

mono/metadata/ChangeLog
mono/metadata/environment.c
mono/metadata/environment.h
mono/metadata/icall-def.h
mono/metadata/icall.c
mono/metadata/mono-perfcounters.c

index f1bc211a46574875d12c2a6fcb6e92784d3064f6..16c0daf5c6ee7270c5f801ea1a3ee8e67e55e9c8 100644 (file)
@@ -1,3 +1,9 @@
+
+Wed Oct 22 17:45:48 CEST 2008 Paolo Molaro <lupus@ximian.com>
+
+       * mono-perfcounters.c, icall-def.h, environment.c, environment.h:
+       use the code in mono-proclib.h to get processor information.
+
 2008-10-22 Gonzalo Paniagua Javier <gonzalo@novell.com>
 
        * appdomain.c: fixed the logic that determines whether assemblies in a
index e3f971dca45926fa294031c4eb2d9ca9ea8a820c..9b5392f814876ae97e7d9c2480d7221928efec02 100644 (file)
@@ -65,9 +65,3 @@ ves_icall_System_Environment_GetOSVersionString (void)
        return mono_string_new (mono_domain_get (), "0.0.0.0");
 }
 
-gint32 ves_icall_System_Environment_get_ProcessorCount(void)
-{
-       SYSTEM_INFO sys_info;
-       GetSystemInfo(&sys_info);
-       return sys_info.dwNumberOfProcessors;
-}
index 1b2abad1aed5ab07650fb3338e6e08a1f5b013fc..4493a7db7ba3d5737a8b13a4528b9b404ef31137 100644 (file)
@@ -17,8 +17,6 @@ extern void mono_environment_exitcode_set (gint32 value);
 
 extern MonoString* ves_icall_System_Environment_GetOSVersionString (void);
 
-extern gint32 ves_icall_System_Environment_get_ProcessorCount(void);
-
 G_END_DECLS
 
 #endif /* _MONO_METADATA_ENVIRONMENT_H_ */
index c032d93beae3becaf790ddef034aed443983498f..1a89ff25a9aeab4960e238bbc38b26c05a6106f6 100644 (file)
@@ -239,7 +239,7 @@ ICALL(ENV_10, "get_HasShutdownStarted", ves_icall_System_Environment_get_HasShut
 ICALL(ENV_11, "get_MachineName", ves_icall_System_Environment_get_MachineName)
 ICALL(ENV_12, "get_NewLine", ves_icall_System_Environment_get_NewLine)
 ICALL(ENV_13, "get_Platform", ves_icall_System_Environment_get_Platform)
-ICALL(ENV_14, "get_ProcessorCount", ves_icall_System_Environment_get_ProcessorCount)
+ICALL(ENV_14, "get_ProcessorCount", mono_cpu_count)
 ICALL(ENV_15, "get_TickCount", mono_msec_ticks)
 ICALL(ENV_16, "get_UserName", ves_icall_System_Environment_get_UserName)
 ICALL(ENV_17, "internalGetEnvironmentVariable", ves_icall_System_Environment_GetEnvironmentVariable)
index 063553f8c6455eb93dbd2589b6c2bbd1c82e5167..9bf5d3f2fd134edb6f8d0146310357362533ae8e 100644 (file)
@@ -67,6 +67,7 @@
 #include <mono/utils/strtod.h>
 #include <mono/utils/monobitset.h>
 #include <mono/utils/mono-time.h>
+#include <mono/utils/mono-proclib.h>
 
 #if defined (PLATFORM_WIN32)
 #include <windows.h>
index c53166a07df46be1393f837f5e2609ca84cd389e..44b8563b0069cce7d32c30f25f9c49a433734c17 100644 (file)
@@ -563,50 +563,10 @@ id_from_string (MonoString *instance, gboolean is_process)
        return id;
 }
 
-static void
-get_cpu_times (int cpu_id, gint64 *user, gint64 *systemt, gint64 *irq, gint64 *sirq, gint64 *idle)
-{
-       SYSTEM_INFO info;
-       char buf [256];
-       char *s;
-       int hz = 100;
-       long long unsigned int user_ticks, nice_ticks, system_ticks, idle_ticks, iowait_ticks, irq_ticks, sirq_ticks;
-       FILE *f = fopen ("/proc/stat", "r");
-       if (!f)
-               return;
-       GetSystemInfo (&info);
-       hz *= info.dwNumberOfProcessors;
-       while ((s = fgets (buf, sizeof (buf), f))) {
-               char *data = NULL;
-               if (cpu_id < 0 && strncmp (s, "cpu", 3) == 0 && g_ascii_isspace (s [3])) {
-                       data = s + 4;
-               } else if (cpu_id >= 0 && strncmp (s, "cpu", 3) == 0 && strtol (s + 3, &data, 10) == cpu_id) {
-                       if (data == s + 3)
-                               continue;
-                       data++;
-               } else {
-                       continue;
-               }
-               sscanf (data, "%Lu %Lu %Lu %Lu %Lu %Lu %Lu", &user_ticks, &nice_ticks, &system_ticks, &idle_ticks, &iowait_ticks, &irq_ticks, &sirq_ticks);
-       }
-       fclose (f);
-
-       if (user)
-               *user = (user_ticks + nice_ticks) * 10000000 / hz;
-       if (systemt)
-               *systemt = (system_ticks) * 10000000 / hz;
-       if (irq)
-               *irq = (irq_ticks) * 10000000 / hz;
-       if (sirq)
-               *sirq = (sirq_ticks) * 10000000 / hz;
-       if (idle)
-               *idle = (idle_ticks) * 10000000 / hz;
-}
-
 static MonoBoolean
 get_cpu_counter (ImplVtable *vtable, MonoBoolean only_value, MonoCounterSample *sample)
 {
-       gint64 value = 0;
+       MonoProcessError error;
        int id = GPOINTER_TO_INT (vtable->arg);
        int pid = id >> 5;
        id &= 0x1f;
@@ -617,24 +577,19 @@ get_cpu_counter (ImplVtable *vtable, MonoBoolean only_value, MonoCounterSample *
        sample->counterType = predef_counters [predef_categories [CATEGORY_CPU].first_counter + id].type;
        switch (id) {
        case COUNTER_CPU_USER_TIME:
-               get_cpu_times (pid, &value, NULL, NULL, NULL, NULL);
-               sample->rawValue = value;
+               sample->rawValue = mono_cpu_get_data (pid, MONO_CPU_USER_TIME, &error);
                return TRUE;
        case COUNTER_CPU_PRIV_TIME:
-               get_cpu_times (pid, NULL, &value, NULL, NULL, NULL);
-               sample->rawValue = value;
+               sample->rawValue = mono_cpu_get_data (pid, MONO_CPU_PRIV_TIME, &error);
                return TRUE;
        case COUNTER_CPU_INTR_TIME:
-               get_cpu_times (pid, NULL, NULL, &value, NULL, NULL);
-               sample->rawValue = value;
+               sample->rawValue = mono_cpu_get_data (pid, MONO_CPU_INTR_TIME, &error);
                return TRUE;
        case COUNTER_CPU_DCP_TIME:
-               get_cpu_times (pid, NULL, NULL, NULL, &value, NULL);
-               sample->rawValue = value;
+               sample->rawValue = mono_cpu_get_data (pid, MONO_CPU_DCP_TIME, &error);
                return TRUE;
        case COUNTER_CPU_PROC_TIME:
-               get_cpu_times (pid, NULL, NULL, NULL, NULL, &value);
-               sample->rawValue = value;
+               sample->rawValue = mono_cpu_get_data (pid, MONO_CPU_IDLE_TIME, &error);
                return TRUE;
        }
        return FALSE;
@@ -1244,14 +1199,13 @@ static MonoArray*
 get_cpu_instances (void)
 {
        void **buf = NULL;
-       int i;
+       int i, count;
        MonoArray *array;
-       SYSTEM_INFO info;
-       GetSystemInfo (&info);
-       buf = g_new (void*, info.dwNumberOfProcessors);
-       for (i = 0; i < info.dwNumberOfProcessors; ++i)
+       count = mono_cpu_count ();
+       buf = g_new (void*, count);
+       for (i = 0; i < count; ++i)
                buf [i] = GINT_TO_POINTER (i);
-       array = get_string_array (buf, info.dwNumberOfProcessors, FALSE);
+       array = get_string_array (buf, count, FALSE);
        g_free (buf);
        return array;
 }