* src/vm/vm.c (XXusage): Removed -verbose:memory.
authortwisti <none@none>
Wed, 20 Jun 2007 17:54:36 +0000 (17:54 +0000)
committertwisti <none@none>
Wed, 20 Jun 2007 17:54:36 +0000 (17:54 +0000)
(vm_create): Likewise.

* src/mm/memory.c (memory_thread): Rewritten to use new variables.

* src/vmcore/options.c (errno.h): Added.
(stdint.h): Likewise
(stdio.h): Likewise.
(stdlib.h): Likewise.
(opt_verbosememory): Removed.
(opt_ProfileGCMemoryUsage): Added.
(opt_ProfileMemoryUsage): Likewise.
(opt_ProfileMemoryUsageGNUPlot): Likewise.
(options_XX): Likewise.
(options_xx): Implemented.

* src/vmcore/options.h (stdint.h): Added.
(option_t): Likewise.
(opt_ProfileGCMemoryUsage): Likewise.
(opt_ProfileMemoryUsage): Likewise.
(opt_ProfileMemoryUsageGNUPlot): Likewise.
(options_xx): Changed signature.

* src/vmcore/statistics.c (statistics_print_gc_memory_usage):
Rewritten to use new variables and GNU Plot output.

* configure.ac (AC_CHECK_FUNCS): Added atoi, atol, strchr, strncmp.

configure.ac
src/mm/memory.c
src/vm/vm.c
src/vmcore/options.c
src/vmcore/options.h
src/vmcore/statistics.c

index a725e4f62eff63f8146915eedb2bc883b644daa2..34ea651648e340cfc219c7e4a89d72a214909c57 100644 (file)
@@ -22,7 +22,7 @@ dnl along with this program; if not, write to the Free Software
 dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 dnl 02110-1301, USA.
 dnl 
-dnl $Id: configure.ac 8056 2007-06-10 14:49:57Z michi $
+dnl $Id: configure.ac 8112 2007-06-20 17:54:36Z twisti $
 
 dnl Process this file with autoconf to produce a configure script.
 
@@ -253,6 +253,8 @@ AC_FUNC_MEMCMP
 AC_FUNC_MMAP
 
 dnl keep them alpha-sorted!
+AC_CHECK_FUNCS([atoi])
+AC_CHECK_FUNCS([atol])
 AC_CHECK_FUNCS([calloc])
 AC_CHECK_FUNCS([confstr])
 AC_CHECK_FUNCS([free])
@@ -271,8 +273,10 @@ AC_CHECK_FUNCS([mprotect])
 AC_CHECK_FUNCS([open])
 AC_CHECK_FUNCS([scandir])
 AC_CHECK_FUNCS([select])
+AC_CHECK_FUNCS([strchr])
 AC_CHECK_FUNCS([strdup])
 AC_CHECK_FUNCS([strerror])
+AC_CHECK_FUNCS([strncmp])
 AC_CHECK_FUNCS([strstr])
 AC_CHECK_FUNCS([time])
 
index 1b8839fb7a59b87cd348a0c939751ca6f8c51c7d..6039e2abf8e45d3f28d5798882b0574c25b9b1af 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: memory.c 7902 2007-05-11 22:33:15Z twisti $
+   $Id: memory.c 8112 2007-06-20 17:54:36Z twisti $
 
 */
 
@@ -372,23 +372,38 @@ void mem_free(void *m, s4 size)
 #if defined(ENABLE_THREADS) && !defined(NDEBUG)
 static void memory_thread(void)
 {
+       int32_t seconds;
+
+       /* If both arguments are specified, use the value of
+          ProfileMemoryUsage. */
+
+       if (opt_ProfileGCMemoryUsage)
+               seconds = opt_ProfileGCMemoryUsage;
+
+       if (opt_ProfileMemoryUsage)
+               seconds = opt_ProfileMemoryUsage;
+
        while (true) {
-               /* sleep thread for 2 seconds */
+               /* sleep thread */
 
-               threads_sleep(2 * 1000, 0);
+               threads_sleep(seconds * 1000, 0);
 
 # if defined(ENABLE_STATISTICS)
-               /* print current date and time */
+               /* Print current date and time (only when we print to the
+                  stdout). */
 
-               statistics_print_date();
+               if (!opt_ProfileMemoryUsageGNUPlot)
+                       statistics_print_date();
 
                /* print memory usage */
 
-               statistics_print_memory_usage();
+               if (opt_ProfileMemoryUsage)
+                       statistics_print_memory_usage();
 
                /* print GC memory usage */
 
-               statistics_print_gc_memory_usage();
+               if (opt_ProfileGCMemoryUsage)
+                       statistics_print_gc_memory_usage();
 # endif
        }
 }
index 4675dec1a002b193df6144c13acb00ad5ef10487..878fe35335578f56d804e7e0093b093d3e6144b8 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: vm.c 8108 2007-06-20 12:05:26Z ajordan $
+   $Id: vm.c 8112 2007-06-20 17:54:36Z twisti $
 
 */
 
@@ -530,7 +530,7 @@ static void XXusage(void)
 {
        puts("    -v                       write state-information");
 #if !defined(NDEBUG)
-       puts("    -verbose[:call|exception|jit|memory|threads]");
+       puts("    -verbose[:call|exception|jit|threads]");
        puts("                             enable specific verbose output");
        puts("    -debug-color             colored output for ANSI terms");
 #endif
@@ -1158,15 +1158,6 @@ bool vm_create(JavaVMInitArgs *vm_args)
                                initverbose = true;
                                compileverbose = true;
                        }
-                       else if (strcmp("memory", opt_arg) == 0) {
-                               opt_verbosememory = true;
-
-# if defined(ENABLE_STATISTICS)
-                               /* we also need statistics */
-
-                               opt_stat = true;
-# endif
-                       }
                        else if (strcmp("threads", opt_arg) == 0) {
                                opt_verbosethreads = true;
                        }
@@ -1700,7 +1691,7 @@ bool vm_create(JavaVMInitArgs *vm_args)
 # if !defined(NDEBUG)
        /* start the memory profiling thread */
 
-       if (opt_verbosememory)
+       if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
                if (!memory_start_thread())
                        vm_abort("vm_create: memory_start_thread failed");
 # endif
index e1be3c69f25ced4be1d158267df03408e2c08028..d68c46503d087a6e8d316b569932aa122dc62f28 100644 (file)
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: options.c 8062 2007-06-11 08:12:14Z twisti $
+   $Id: options.c 8112 2007-06-20 17:54:36Z twisti $
 
 */
 
 
 #include "config.h"
 
+#include <errno.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
 #if defined(HAVE_STRING_H)
 # include <string.h>
 #endif
 
 #include <limits.h>
 
-#include "vm/types.h"
-
 #include "mm/memory.h"
+
 #include "native/jni.h"
+
+#include "vm/vm.h"
+
 #include "vmcore/options.h"
 
 
@@ -78,7 +85,6 @@ bool opt_verbosegc        = false;
 bool opt_verbosejni       = false;
 bool opt_verbosecall      = false;      /* trace all method invocation        */
 bool opt_verboseexception = false;
-bool opt_verbosememory    = false;
 bool opt_verbosethreads   = false;
 
 bool showmethods = false;
@@ -169,6 +175,30 @@ const char *opt_filter_verbosecall_exclude = 0;
 const char *opt_filter_show_method = 0;
 #endif
 
+
+/* -XX options ****************************************************************/
+
+/* NOTE: For better readability keep these alpha-sorted. */
+
+int32_t  opt_ProfileGCMemoryUsage      = 0;
+int32_t  opt_ProfileMemoryUsage        = 0;
+FILE    *opt_ProfileMemoryUsageGNUPlot = NULL;
+
+
+enum {
+       OPT_ProfileGCMemoryUsage,
+       OPT_ProfileMemoryUsage,
+       OPT_ProfileMemoryUsageGNUPlot
+};
+
+
+option_t options_XX[] = {
+       { "ProfileGCMemoryUsage",      OPT_ProfileGCMemoryUsage,      "" },
+       { "ProfileMemoryUsage",        OPT_ProfileMemoryUsage,        "" },
+       { "ProfileMemoryUsageGNUPlot", OPT_ProfileMemoryUsageGNUPlot, "" },
+};
+
+
 /* options_get *****************************************************************
 
    DOCUMENT ME!!!
@@ -257,9 +287,84 @@ s4 options_get(opt_struct *opts, JavaVMInitArgs *vm_args)
 
 *******************************************************************************/
 
-void options_xx(char *opt_arg)
+void options_xx(const char *name)
 {
-       log_println("opt_arg: %s", opt_arg);
+       char    *end;
+       int32_t  length;
+       char    *value;
+       int32_t  option;
+       char    *filename;
+       FILE    *file;
+       int32_t  i;
+
+       log_println("name: %s", name);
+
+       /* Search for a ':' in the option name and get the option name
+          length and the value of the option. */
+
+       end = strchr(name, ':');
+
+       if (end == NULL) {
+               length = strlen(name);
+               value  = NULL;
+       }
+       else {
+               length = end - name;
+               value  = end + 1;
+       }
+
+       /* search the option in the option array */
+
+       option = OPT_ERROR;
+
+       for (i = 0; options_XX[i].name != NULL; i++) {
+               if (strncmp(options_XX[i].name, name, length) == 0) {
+                       option = options_XX[i].option;
+                       break;
+               }
+       }
+
+       /* process the option */
+
+       switch (option) {
+       case OPT_ProfileGCMemoryUsage:
+               if (value == NULL)
+                       opt_ProfileGCMemoryUsage = 5;
+               else
+                       opt_ProfileGCMemoryUsage = atoi(value);
+               break;
+
+       case OPT_ProfileMemoryUsage:
+               if (value == NULL)
+                       opt_ProfileMemoryUsage = 5;
+               else
+                       opt_ProfileMemoryUsage = atoi(value);
+
+# if defined(ENABLE_STATISTICS)
+               /* we also need statistics */
+
+               opt_stat = true;
+# endif
+               break;
+
+       case OPT_ProfileMemoryUsageGNUPlot:
+               if (value == NULL)
+                       filename = "profile.dat";
+               else
+                       filename = value;
+
+               file = fopen(filename, "w");
+
+               if (file == NULL)
+                       vm_abort("options_xx: fopen failed: %s", strerror(errno));
+
+               opt_ProfileMemoryUsageGNUPlot = file;
+               break;
+
+       default:
+               printf("Unknown option: -XX:%s\n", name);
+               break;
+       }
 }
 
 
index f8c2a94c5037cbe7ee75c715d618c30e7195dcca..558b26d69d032161b713ec3701dd140af3c0e9f0 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: options.h 8062 2007-06-11 08:12:14Z twisti $
+   $Id: options.h 8112 2007-06-20 17:54:36Z twisti $
 
 */
 
@@ -32,6 +32,9 @@
 
 
 #include "config.h"
+
+#include <stdint.h>
+
 #include "vm/types.h"
 
 #include "native/jni.h"
@@ -57,6 +60,15 @@ struct opt_struct {
 };
 
 
+typedef struct option_t option_t;
+
+struct option_t {
+       char    *name;
+       int32_t  option;
+       char    *doc;
+};
+
+
 /* global variables ***********************************************************/
 
 extern s4    opt_index;
@@ -87,7 +99,6 @@ extern bool opt_verbosegc;
 extern bool opt_verbosejni;
 extern bool opt_verbosecall;
 extern bool opt_verboseexception;
-extern bool opt_verbosememory;
 extern bool opt_verbosethreads;
 
 extern bool showmethods;
@@ -178,10 +189,20 @@ extern const char *opt_filter_verbosecall_exclude;
 extern const char *opt_filter_show_method;
 #endif
 
+
+/* -XX options ****************************************************************/
+
+/* NOTE: For better readability keep these alpha-sorted. */
+
+extern int32_t  opt_ProfileGCMemoryUsage;
+extern int32_t  opt_ProfileMemoryUsage;
+extern FILE    *opt_ProfileMemoryUsageGNUPlot;
+
+
 /* function prototypes ********************************************************/
 
 s4   options_get(opt_struct *opts, JavaVMInitArgs *vm_args);
-void options_xx(char *opt_arg);
+void options_xx(const char *name);
 
 #endif /* _OPTIONS_H */
 
index 595000a79402358e545653663b0351212398cd96..096e49ca173ea6e6fa7776b5b5252fc8d7049ef6 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: statistics.c 8094 2007-06-16 01:15:41Z ajordan $
+   $Id: statistics.c 8112 2007-06-20 17:54:36Z twisti $
 
 */
 
@@ -736,14 +736,38 @@ void statistics_print_memory_usage(void)
 
 void statistics_print_gc_memory_usage(void)
 {
-       log_println("GC memory usage -------------------");
-       log_println("");
-       log_println("max. heap size: %10lld", gc_get_max_heap_size());
-       log_println("");
-       log_println("heap size:      %10lld", gc_get_heap_size());
-       log_println("free:           %10lld", gc_get_free_bytes());
-       log_println("used:           %10lld", gc_get_total_bytes());
-       log_println("");
+       static int64_t count = 0;
+       int64_t max;
+       int64_t size;
+       int64_t free;
+       int64_t used;
+       int64_t total;
+
+       count++;
+
+       max   = gc_get_max_heap_size();
+       size  = gc_get_heap_size();
+       free  = gc_get_free_bytes();
+       used  = size - free;
+       total = gc_get_total_bytes();
+
+       if (opt_ProfileMemoryUsageGNUPlot) {
+               if (count == 1)
+                       fprintf(opt_ProfileMemoryUsageGNUPlot, "plot \"profile.dat\" using 1:2 with lines title \"max. Java heap size\", \"profile.dat\" using 1:3 with lines title \"Java heap size\", \"profile.dat\" using 1:4 with lines title \"used\", \"profile.dat\" using 1:5 with lines title \"free\"\n");
+
+               fprintf(opt_ProfileMemoryUsageGNUPlot, "%lld %lld% lld %lld %lld\n", count, max, size, used, free);
+       }
+       else {
+               log_println("GC memory usage -------------------");
+               log_println("");
+               log_println("max. Java heap size: %10lld", max);
+               log_println("");
+               log_println("Java heap size:      %10lld", size);
+               log_println("used:                %10lld", used);
+               log_println("free:                %10lld", free);
+               log_println("totally used:        %10lld", total);
+               log_println("");
+       }
 }