}
        obj.Flagstr("cpuprofile", "file: write cpu profile to file", &cpuprofile)
        obj.Flagstr("memprofile", "file: write memory profile to file", &memprofile)
+       obj.Flagint64("memprofilerate", "set runtime.MemProfileRate", &memprofilerate)
        obj.Flagparse(usage)
 
        if flag_dynlink {
 
 import (
        "cmd/internal/obj"
        "os"
+       "runtime"
        "runtime/pprof"
        "strconv"
        "strings"
        return s
 }
 
-// simulation of int(*s++) in C
-func intstarstringplusplus(s string) (int, string) {
-       if s == "" {
-               return 0, ""
-       }
-       return int(s[0]), s[1:]
-}
-
 // strings.Compare, introduced in Go 1.5.
 func stringsCompare(a, b string) int {
        if a == b {
        os.Exit(code)
 }
 
-var cpuprofile string
-var memprofile string
+var (
+       cpuprofile     string
+       memprofile     string
+       memprofilerate int64
+)
 
 func startProfile() {
        if cpuprofile != "" {
                AtExit(pprof.StopCPUProfile)
        }
        if memprofile != "" {
+               if memprofilerate != 0 {
+                       runtime.MemProfileRate = int(memprofilerate)
+               }
                f, err := os.Create(memprofile)
                if err != nil {
                        Fatal("%v", err)
                }
                AtExit(func() {
+                       runtime.GC() // profile all outstanding allocations
                        if err := pprof.WriteHeapProfile(f); err != nil {
                                Fatal("%v", err)
                        }
 
        }
        obj.Flagstr("cpuprofile", "file: write cpu profile to file", &cpuprofile)
        obj.Flagstr("memprofile", "file: write memory profile to file", &memprofile)
+       obj.Flagint64("memprofilerate", "set runtime.MemProfileRate", &memprofilerate)
        obj.Flagparse(usage)
        startProfile()
        Ctxt.Bso = &Bso
 
        "io"
        "log"
        "os"
+       "runtime"
        "runtime/pprof"
        "strings"
        "time"
        os.Exit(code)
 }
 
-var cpuprofile string
-var memprofile string
+var (
+       cpuprofile     string
+       memprofile     string
+       memprofilerate int64
+)
 
 func startProfile() {
        if cpuprofile != "" {
                AtExit(pprof.StopCPUProfile)
        }
        if memprofile != "" {
+               if memprofilerate != 0 {
+                       runtime.MemProfileRate = int(memprofilerate)
+               }
                f, err := os.Create(memprofile)
                if err != nil {
                        log.Fatalf("%v", err)
                }
                AtExit(func() {
+                       runtime.GC() // profile all outstanding allocations
                        if err := pprof.WriteHeapProfile(f); err != nil {
                                log.Fatalf("%v", err)
                        }