Add dump_at_max mode.

This allows to get a dump at the maximum observed value, rather than
at the time the dump is requested.

Test: profile system_server, get pprof 3f13aabe9d21eb2e1a28d281b2e9e6be.

Change-Id: Iff3075ed49bfbf992ac4e6f511100e1a7a67363c
Bug: 120177095
diff --git a/tools/heap_profile b/tools/heap_profile
index 5d76a4e..09a6911 100755
--- a/tools/heap_profile
+++ b/tools/heap_profile
@@ -153,6 +153,9 @@
   parser.add_argument("--idle-allocations", help="Keep track of how many "
                       "bytes were unused since the last dump, per "
                       "callstack", action="store_true")
+  parser.add_argument("--dump-at-max", help="Dump the maximum memory usage"
+                      "rather than at the time of the dump.",
+                      action="store_true")
   parser.add_argument("--simpleperf", action="store_true",
                       help="Get simpleperf profile of heapprofd. This is "
                       "only for heapprofd development.")
@@ -192,6 +195,8 @@
     target_cfg += "no_startup: true\n"
   if args.no_running:
     target_cfg += "no_running: true\n"
+  if args.dump_at_max:
+    target_cfg += "dump_at_max: true\n"
   if args.pid:
     for pid in args.pid.split(','):
       try: