Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

2010-04-16 Marek Habersack <mhabersack@novell.com>

    	* configure.in: added a check for sysconf(3)

    2010-04-16  Marek Habersack  <mhabersack@novell.com>

    	* mono-perfcounters.c: added code for the "Mono
    	Memory/Total Physical Memory" performance counter.

    	* mono-perfcounters-def.h: added definition of the "Mono
    	Memory/Total Physical Memory" performance counter.

svn path=/trunk/mono/; revision=155566
  • Loading branch information...
commit 67cfed8f271dc55d4bdae3a9f56de859f7e821d7 1 parent 08cef12
@grendello grendello authored
View
4 ChangeLog
@@ -1,3 +1,7 @@
+2010-04-16 Marek Habersack <mhabersack@novell.com>
+
+ * configure.in: added a check for sysconf(3)
+
2010-04-14 Miguel de Icaza <miguel@novell.com>
* configure.in: turn the AC_MSG_ERROR into a AC_MSG_WARN since in
View
1  configure.in
@@ -1010,6 +1010,7 @@ if test x$target_win32 = xno; then
AC_CHECK_FUNCS(getpriority)
AC_CHECK_FUNCS(setpriority)
AC_CHECK_FUNCS(dl_iterate_phdr)
+ AC_CHECK_FUNCS(sysconf)
AC_CHECK_FUNCS(sched_setaffinity)
View
8 mono/metadata/ChangeLog
@@ -1,3 +1,11 @@
+2010-04-16 Marek Habersack <mhabersack@novell.com>
+
+ * mono-perfcounters.c: added code for the "Mono
+ Memory/Total Physical Memory" performance counter.
+
+ * mono-perfcounters-def.h: added definition of the "Mono
+ Memory/Total Physical Memory" performance counter.
+
2010-04-15 Rodrigo Kumpera <rkumpera@novell.com>
* class.c (mono_class_get_method_by_index): Return NULL
View
1  mono/metadata/mono-perfcounters-def.h
@@ -27,6 +27,7 @@ PERFCTR_COUNTER(PROC_PBYTES, "Private Bytes", "", NumberOfItems64, unused)
/* sample runtime counter */
PERFCTR_CAT(MONO_MEM, "Mono Memory", "", SingleInstance, Mono, MEM_NUM_OBJECTS)
PERFCTR_COUNTER(MEM_NUM_OBJECTS, "Allocated Objects", "", NumberOfItems64, unused)
+PERFCTR_COUNTER(MEM_PHYS_TOTAL, "Total Physical Memory", "Physical memory installed in the machine, in bytes", NumberOfItems64, unused)
PERFCTR_CAT(ASPNET, "ASP.NET", "", MultiInstance, Mono, ASPNET_REQ_Q)
PERFCTR_COUNTER(ASPNET_REQ_Q, "Requests Queued", "", NumberOfItems64, aspnet_requests_queued)
View
69 mono/metadata/mono-perfcounters.c
@@ -12,9 +12,21 @@
#include <time.h>
#include <string.h>
#include <stdlib.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#if defined (__OpenBSD)
+#include <sys/param.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
+#if defined (__NetBSD__) || defined (__APPLE__)
+#include <sys/sysctl.h>
+#endif
#include "metadata/mono-perfcounters.h"
#include "metadata/appdomain.h"
#include "metadata/object-internals.h"
@@ -380,6 +392,60 @@ predef_cleanup (ImplVtable *vtable)
perfctr_unlock ();
}
+static guint64
+mono_determine_physical_ram_size (void)
+{
+#if defined (TARGET_WIN32)
+ MEMORYSTATUSEX memstat;
+
+ memstat.dwLength = sizeof (memstat);
+ GlobalMemoryStatusEx (&memstat);
+ return (guint64)memstat.ullTotalPhys;
+#elif defined (__NetBSD__) || defined (__APPLE__)
+#ifdef __NetBSD__
+ unsigned long value;
+#else
+ guint64 value;
+#endif
+ int mib[2] = {
+ CTL_HW,
+#ifdef __NetBSD__
+ HW_PHYSMEM
+#else
+ HW_MEMSIZE
+#endif
+ };
+ size_t size_sys = sizeof (value);
+
+ sysctl (mib, 2, &value, &size_sys, NULL, 0);
+ if (value == 0)
+ return 134217728;
+
+ return (guint64)value;
+#elif defined (HAVE_SYSCONF)
+ guint64 page_size = 0, num_pages = 0;
+
+ /* sysconf works on most *NIX operating systems, if your system doesn't have it or if it
+ * reports invalid values, please add your OS specific code below. */
+#ifdef _SC_PAGESIZE
+ page_size = (guint64)sysconf (_SC_PAGESIZE);
+#endif
+
+#ifdef _SC_PHYS_PAGES
+ num_pages = (guint64)sysconf (_SC_PHYS_PAGES);
+#endif
+
+ if (!page_size || !num_pages) {
+ g_warning ("Your operating system's sysconf (3) function doesn't correctly report physical memory size!");
+ return 134217728;
+ }
+
+ return page_size * num_pages;
+#else
+ return 134217728;
+#endif
+}
+
void
mono_perfcounters_init (void)
{
@@ -829,6 +895,9 @@ mono_mem_counter (ImplVtable *vtable, MonoBoolean only_value, MonoCounterSample
case COUNTER_MEM_NUM_OBJECTS:
sample->rawValue = mono_stats.new_object_count;
return TRUE;
+ case COUNTER_MEM_PHYS_TOTAL:
+ sample->rawValue = mono_determine_physical_ram_size ();;
+ return TRUE;
}
return FALSE;
}
Please sign in to comment.
Something went wrong with that request. Please try again.