]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Bug 387080 - Add --peak-only option to ms_print
authorJulien Floyd <jgfloyd229@gmail.com>
Mon, 25 May 2026 15:34:19 +0000 (17:34 +0200)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Wed, 27 May 2026 18:29:02 +0000 (20:29 +0200)
Original patch submitted by "Vadim Zeitlin <vz-kde@zeitlins.org>"

This is based on the original patch that added the --only-peak option to ms_print.

Most of my changes targeted the documentation and test.

NEWS
massif/docs/ms-manual.xml
massif/ms_print.in
massif/tests/Makefile.am
massif/tests/peak_only.post.exp [new file with mode: 0644]
massif/tests/peak_only.stderr.exp [new file with mode: 0644]
massif/tests/peak_only.vgtest [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 6daae9ff1c163efce428fd76c398903738f48668..34f222e2841ee250cbec24f3fe35a60403f7b3f4 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -25,7 +25,8 @@ are not entered into bugzilla tend to get forgotten about or ignored.
 
 271615  Unhandled instruction "popcnt" on x86
 295974  Add SSE4.1 PEXTRD instruction for x86 32 bit
-391311  [Patch] Fix arm64 valgrind tests compilation with clang
+387080  Add --peak-only option to ms_print
+391311  Fix arm64 valgrind tests compilation with clang
 519223  Recognize ioctl(UFFDIO_*) operations
 519539  Darwin shm_open mode is optional and depends on oflag
 519574  valgrind 3.27 "--fair-sched=yes" does not work
index 22941fa522b52d824bc736c508e400d747041ea2..0b4a81d82dc60ce011c1151dfbae7e1559caef11 100644 (file)
@@ -279,6 +279,13 @@ consumption was greatest.  The peak snapshot is represented in the graph by
 a bar consisting of '#' characters.  The text at the bottom shows
 that snapshot 14 was the peak.</para>
 
+<para> The option <option>--peak-only</option> limits the output to just the
+peak memory consumption figure and omits the full snapshot graph and
+associated output. This is primarily intended for use in automated
+environments such as CI pipelines, where the peak value is captured by a
+script for comparison against a threshold. The number of bytes printed
+does not use thousands separators to make parsing easier.</para>
+
 <para>Massif's determination of when the peak occurred can be wrong, for
 two reasons.</para>
 
@@ -837,6 +844,16 @@ various places online.
     </listitem>
   </varlistentry>
 
+  <varlistentry id="opt.peak-only" xreflabel="--peak-only">
+   <term>
+     <option><![CDATA[--peak-only]]></option>
+   </term>
+   <listitem>
+     <para>Print only the peak memory usage figure in bytes, omitting
+     the snapshot graph and all other output.</para>
+   </listitem>
+</varlistentry>
+
   <varlistentry id="opt.time-unit" xreflabel="--time-unit">
     <term>
       <option><![CDATA[--time-unit=<i|ms|B> [default: i] ]]></option>
index ecd9f383ee28361325e9582452e61076169942cc..d97b8788cf42d17021ac3cdf9b6dd5b9314adc81 100644 (file)
@@ -38,6 +38,9 @@ my $cmd;
 # Time unit used in profile.
 my $time_unit;
 
+# Indicates whether only peak memory usage should be given.
+my $peak_only = 0;
+
 # Threshold dictating what percentage an entry must represent for us to
 # bother showing it.
 my $threshold = 1.0;
@@ -70,6 +73,7 @@ usage: ms_print [options] massif-out-file
   options for the user, with defaults in [ ], are:
     -h --help             show this message
     --version             show version
+    --peak-only           show only the peak memory usage [no]
     --threshold=<m.n>     significance threshold, in percent [$threshold]
     --x=<4..1000>         graph width, in columns [72]
     --y=<4..1000>         graph height, in rows [20]
@@ -113,6 +117,9 @@ sub process_cmd_line()
             if ($arg =~ /^--version$/) {
                 die("ms_print-$version\n");
 
+            # --peak-only
+            } elsif ($arg eq '--peak-only') {
+                $peak_only = 1;
             # --threshold=X (tolerates a trailing '%')
             } elsif ($arg =~ /^--threshold=([\d\.]+)%?$/) {
                 $threshold = $1;
@@ -466,6 +473,12 @@ sub read_input_file()
     close(INPUTFILE);
     close(TMPFILE);
 
+    if ($peak_only) {
+        print "Peak memory usage: $peak_mem_total_szB bytes\n";
+        unlink($tmp_file);
+        return;
+    }
+
     #-------------------------------------------------------------------------
     # Print header.
     #-------------------------------------------------------------------------
index 776c6c6f60827e96f0a9e510a11ebb9e5502df74..3027bc307f975a290680602223831d68586d86fa 100644 (file)
@@ -36,6 +36,7 @@ EXTRA_DIST = \
        overloaded-new.stderr.exp overloaded-new.vgtest \
        pages_as_heap.stderr.exp pages_as_heap.vgtest \
        peak.post.exp peak.stderr.exp peak.vgtest \
+       peak_only.post.exp peak_only.stderr.exp peak_only.vgtest \
        peak2.post.exp peak2.stderr.exp peak2.vgtest \
        realloc.post.exp realloc.stderr.exp realloc.vgtest \
        thresholds_0_0.post.exp \
diff --git a/massif/tests/peak_only.post.exp b/massif/tests/peak_only.post.exp
new file mode 100644 (file)
index 0000000..ec6293e
--- /dev/null
@@ -0,0 +1 @@
+Peak memory usage: 34704 bytes
diff --git a/massif/tests/peak_only.stderr.exp b/massif/tests/peak_only.stderr.exp
new file mode 100644 (file)
index 0000000..139597f
--- /dev/null
@@ -0,0 +1,2 @@
+
+
diff --git a/massif/tests/peak_only.vgtest b/massif/tests/peak_only.vgtest
new file mode 100644 (file)
index 0000000..89ac06c
--- /dev/null
@@ -0,0 +1,16 @@
+prog: peak
+vgopts: --stacks=no --time-unit=B --peak-inaccuracy=0 --heap-admin=128 --massif-out-file=massif.out
+vgopts: --ignore-fn=__part_load_locale --ignore-fn=__time_load_locale --ignore-fn=dwarf2_unwind_dyld_add_image_hook --ignore-fn=get_or_create_key_element
+# Darwin ignore functions, for macOS 10.13
+vgopts: --alloc-fn=_xpc_malloc --ignore-fn=_xpc_dictionary_insert --ignore-fn=map_images_nolock --ignore-fn="allocBuckets(void*, unsigned int)" --ignore-fn="realizeClass(objc_class*)" --ignore-fn=_NXHashRehashToCapacity --ignore-fn=NXCreateHashTableFromZone --ignore-fn=NXCreateMapTableFromZone --ignore-fn=NXHashInsert --ignore-fn=add_class_to_loadable_list --ignore-fn=class_createInstance --ignore-fn=xpc_string_create --alloc-fn=strdup --alloc-fn=_xpc_calloc --ignore-fn=xpc_array_create
+# Darwin ignore functions, for macOS 10.14
+vgopts: --ignore-fn="_NXMapRehash(_NXMapTable*)" --ignore-fn=arc4_init --ignore-fn="realizeClassWithoutSwift(objc_class*)" --ignore-fn="objc_class::setHasCustomRR(bool)" --ignore-fn=_objc_flush_caches --ignore-fn="remapClass(objc_class*)" --ignore-fn="isEqualPrototype(void const*, void const*, void const*)" --ignore-fn="TimeLogger::log(char const*)" --ignore-fn="freeBuckets(NXHashTable*, int)" --ignore-fn=NXHashGet --ignore-fn=call_load_methods --ignore-fn=objc_msgLookup
+# Darwin ignore functions, for macOS 10.15
+vgopts: --ignore-fn=_objc_init --ignore-fn="objc::DenseMap<char const*, objc::detail::DenseSetEmpty, objc::DenseMapValueInfo<objc::detail::DenseSetEmpty>, objc::DenseMapInfo<char const*>, objc::detail::DenseSetPair<char const*> >::grow(unsigned int)" --ignore-fn="realizeClassWithoutSwift(objc_class*, objc_class*)" --ignore-fn="schedule_class_load(objc_class*)" --ignore-fn="objc::SafeRanges::add(unsigned long, unsigned long)" --ignore-fn="getProtocol(char const*)" --ignore-fn="class_setWeakIvarLayout" --ignore-fn="NXMapRemove" --ignore-fn="int sliceRequiresGC<Arch32>(Arch32::mh_t, FileSlice)" --ignore-fn="_mapStrIsEqual(_NXMapTable*, void const*, void const*)" --ignore-fn="_NXMapMember(_NXMapTable*, void const*, void**)" --ignore-fn=NXMapInsert --ignore-fn="objc::DenseMap<objc_class*, objc_class*, objc::DenseMapValueInfo<objc_class*>, objc::DenseMapInfo<objc_class*>, objc::detail::DenseMapPair<objc_class*, objc_class*> >::grow(unsigned int)" --ignore-fn="object_setClass" --ignore-fn="objc_msgSend_stret" --ignore-fn="protocols()" --ignore-fn="copySwiftV1MangledName(char const*, bool)" --ignore-fn="_getObjc2ProtocolList(header_info const*, unsigned long*)"
+# Darwin ignore functions, for macOS 12
+vgopts: --ignore-fn=_xpc_alloc
+# Darwin ignore functions, for macOS 13
+vgopts: --ignore-fn=_xpc_strdup --ignore-fn=_vasprintf --ignore-fn="_fetchInitializingClassList(bool)" --ignore-fn="cache_t::allocateBuckets(unsigned int)"
+post: perl ../../massif/ms_print --peak-only massif.out
+#| ../../tests/filter_addresses | ./filter_ignore_fn
+cleanup: rm massif.out