]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: Add memprofrate value to GODEBUG
authorLynn Boger <laboger@linux.vnet.ibm.com>
Wed, 28 Jan 2015 18:28:59 +0000 (12:28 -0600)
committerIan Lance Taylor <iant@golang.org>
Tue, 3 Feb 2015 00:28:27 +0000 (00:28 +0000)
Add memprofrate as a value recognized in GODEBUG.  The
value provided is used as the new setting for
runtime.MemProfileRate, allowing the user to
adjust memory profiling.

Change-Id: If129a247683263b11e2dd42473cf9b31280543d5
Reviewed-on: https://go-review.googlesource.com/3450
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/runtime/extern.go
src/runtime/runtime1.go

index 58acbb378808968df596fc71ffd6e9643cdfe790..7141cd8a7a13d77d84f7fe3ab6c6582f06ef3b93 100644 (file)
@@ -45,6 +45,10 @@ a comma-separated list of name=val pairs. Supported names are:
        This should only be used as a temporary workaround to diagnose buggy code.
        The real fix is to not store integers in pointer-typed locations.
 
+       memprofrate: setting memprofrate=X will update the value of runtime.MemProfileRate.
+       When set to 0 memory profiling is disabled.  Refer to the description of
+       MemProfileRate for the default value.
+
        scheddetail: setting schedtrace=X and scheddetail=1 causes the scheduler to emit
        detailed multiline info every X milliseconds, describing state of the scheduler,
        processors, threads and goroutines.
index 5dcc83d2e5f42b682bfba596ec4648c0491df21c..337a44f553866cbb4e299ca6bf680c8348fa1811 100644 (file)
@@ -308,7 +308,10 @@ type dbgVar struct {
 
 // TODO(rsc): Make GC respect debug.invalidptr.
 
-// Holds variables parsed from GODEBUG env var.
+// Holds variables parsed from GODEBUG env var,
+// except for "memprofrate" since there is an
+// existing int var for that value, which may
+// already have an initial value.
 var debug struct {
        allocfreetrace int32
        efence         int32
@@ -352,9 +355,17 @@ func parsedebugvars() {
                        continue
                }
                key, value := field[:i], field[i+1:]
-               for _, v := range dbgvars {
-                       if v.name == key {
-                               *v.value = int32(atoi(value))
+
+               // Update MemProfileRate directly here since it
+               // int, not int32, and should only be updated
+               // if specified in GODEBUG.
+               if key == "memprofrate" {
+                       MemProfileRate = atoi(value)
+               } else {
+                       for _, v := range dbgvars {
+                               if v.name == key {
+                                       *v.value = int32(atoi(value))
+                               }
                        }
                }
        }