Skip to content

[llvm-profdata] Disable -all-functions by default #138105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

omern1
Copy link
Member

@omern1 omern1 commented May 1, 2025

This patch disables the -all-functions path in llvm-profdata's show subcommand by default. Users now have to pass -all-functions if they want llvm-profdata to dump all functions. This makes for a better interactive usage experience as it doesn't flood stdout when looking at very large profiles.

This patch disables the -all-functions path in `llvm-profdata`'s `show`
subcommand by default. Users now have to pass -all-functions if they
want `llvm-profdata` to dump all functions. This makes for a better
interactive usage experience as it doesn't flood stdout when looking at
very large profiles.
@llvmbot llvmbot added the PGO Profile Guided Optimizations label May 1, 2025
@llvmbot
Copy link
Member

llvmbot commented May 1, 2025

@llvm/pr-subscribers-pgo

Author: Nabeel Omer (omern1)

Changes

This patch disables the -all-functions path in llvm-profdata's show subcommand by default. Users now have to pass -all-functions if they want llvm-profdata to dump all functions. This makes for a better interactive usage experience as it doesn't flood stdout when looking at very large profiles.


Full diff: https://github.com/llvm/llvm-project/pull/138105.diff

10 Files Affected:

  • (modified) llvm/test/tools/llvm-profdata/forward-compatible.test (+2-2)
  • (modified) llvm/test/tools/llvm-profdata/gcc-gcov-sample-profile.test (+3-3)
  • (modified) llvm/test/tools/llvm-profdata/inline-samples.test (+1-1)
  • (modified) llvm/test/tools/llvm-profdata/overflow-sample.test (+2-2)
  • (modified) llvm/test/tools/llvm-profdata/profile-symbol-list-compress.test (+1-1)
  • (modified) llvm/test/tools/llvm-profdata/profile-symbol-list.test (+1-1)
  • (modified) llvm/test/tools/llvm-profdata/sample-fs.test (+11-11)
  • (modified) llvm/test/tools/llvm-profdata/sample-profile-basic.test (+4-4)
  • (modified) llvm/test/tools/llvm-profdata/sample-profile-json.test (+2-2)
  • (modified) llvm/tools/llvm-profdata/llvm-profdata.cpp (+1-1)
diff --git a/llvm/test/tools/llvm-profdata/forward-compatible.test b/llvm/test/tools/llvm-profdata/forward-compatible.test
index 51a7336bb4056..fa51d16353408 100644
--- a/llvm/test/tools/llvm-profdata/forward-compatible.test
+++ b/llvm/test/tools/llvm-profdata/forward-compatible.test
@@ -1,6 +1,6 @@
 REQUIRES: zlib
-RUN: llvm-profdata show -sample %S/Inputs/unknown.section.extbin.profdata | FileCheck %s
-RUN: llvm-profdata show -sample %S/Inputs/unknown.section.compressed.extbin.profdata | FileCheck %s
+RUN: llvm-profdata show -sample -all-functions %S/Inputs/unknown.section.extbin.profdata | FileCheck %s
+RUN: llvm-profdata show -sample -all-functions %S/Inputs/unknown.section.compressed.extbin.profdata | FileCheck %s
 RUN: llvm-profdata show -sample -show-sec-info-only %S/Inputs/unknown.section.extbin.profdata | FileCheck %s -check-prefix=HDR
 RUN: llvm-profdata show -sample -show-sec-info-only %S/Inputs/unknown.section.compressed.extbin.profdata | FileCheck %s -check-prefix=HDR-COMPRESS
 
diff --git a/llvm/test/tools/llvm-profdata/gcc-gcov-sample-profile.test b/llvm/test/tools/llvm-profdata/gcc-gcov-sample-profile.test
index 5f6c2a221eb27..07f5cf619370a 100644
--- a/llvm/test/tools/llvm-profdata/gcc-gcov-sample-profile.test
+++ b/llvm/test/tools/llvm-profdata/gcc-gcov-sample-profile.test
@@ -5,7 +5,7 @@ Tests for sample profiles encoded in GCC's gcov format.
 
 1- Show all functions. This profile has a single main() function with several
    inlined callees.
-RUN: llvm-profdata show --sample %p/Inputs/gcc-sample-profile.gcov | FileCheck %s --check-prefix=SHOW1
+RUN: llvm-profdata show --sample -all-functions %p/Inputs/gcc-sample-profile.gcov | FileCheck %s --check-prefix=SHOW1
 SHOW1: Function: main: 364084, 0, 6 sampled lines
 SHOW1: 2.3: inlined callee: _Z3fool: 243786, 0, 3 sampled lines
 SHOW1:   1.3: inlined callee: _Z3bari: 0, 0, 2 sampled lines
@@ -14,8 +14,8 @@ SHOW1:   1.8: inlined callee: _Z3bari: 0, 0, 2 sampled lines
 
 2- Convert the profile to text encoding and check that they are both
    identical.
-RUN: llvm-profdata merge --sample %p/Inputs/gcc-sample-profile.gcov --text -o - | llvm-profdata show --sample - -o %t-text
-RUN: llvm-profdata show --sample %p/Inputs/gcc-sample-profile.gcov -o %t-gcov
+RUN: llvm-profdata merge --sample %p/Inputs/gcc-sample-profile.gcov --text -o - | llvm-profdata show --sample -all-functions - -o %t-text
+RUN: llvm-profdata show --sample -all-functions %p/Inputs/gcc-sample-profile.gcov -o %t-gcov
 RUN: diff %t-text %t-gcov
 
 4- Merge the gcov and text encodings of the profile and check that the
diff --git a/llvm/test/tools/llvm-profdata/inline-samples.test b/llvm/test/tools/llvm-profdata/inline-samples.test
index d97d82ea644b7..d656000250b7a 100644
--- a/llvm/test/tools/llvm-profdata/inline-samples.test
+++ b/llvm/test/tools/llvm-profdata/inline-samples.test
@@ -6,7 +6,7 @@ RUN: llvm-profdata merge --sample %p/Inputs/inline-samples.afdo -o %t.profbin
 
 2- Show all functions. This profile has a single main() function with several
    inlined callees.
-RUN: llvm-profdata show --sample %t.profbin | FileCheck %s --check-prefix=SHOW1
+RUN: llvm-profdata show --sample -all-functions %t.profbin | FileCheck %s --check-prefix=SHOW1
 SHOW1: Function: main: 366846, 0, 6 sampled lines
 SHOW1: 2.3: inlined callee: _Z3fool: 246044, 0, 3 sampled lines
 SHOW1:   1.3: inlined callee: _Z3bari: 0, 0, 2 sampled lines
diff --git a/llvm/test/tools/llvm-profdata/overflow-sample.test b/llvm/test/tools/llvm-profdata/overflow-sample.test
index 83adf6d63b549..651614448c130 100644
--- a/llvm/test/tools/llvm-profdata/overflow-sample.test
+++ b/llvm/test/tools/llvm-profdata/overflow-sample.test
@@ -2,7 +2,7 @@ Tests for overflow when merging sampled profiles.
 
 1- Merge profile having maximum counts with itself and verify overflow detected
 RUN: llvm-profdata merge -sample %p/Inputs/overflow-sample.proftext %p/Inputs/overflow-sample.proftext -o %t.out 2>&1 | FileCheck %s -check-prefix=MERGE_OVERFLOW
-RUN: llvm-profdata show -sample %t.out | FileCheck %s --check-prefix=SHOW_OVERFLOW
+RUN: llvm-profdata show -sample -all-functions %t.out | FileCheck %s --check-prefix=SHOW_OVERFLOW
 MERGE_OVERFLOW: {{.*}}: main: Counter overflow
 SHOW_OVERFLOW-DAG: Function: main: 2000, 0, 2 sampled lines
 SHOW_OVERFLOW-DAG: Samples collected in the function's body {
@@ -23,7 +23,7 @@ SHOW_OVERFLOW-DAG: No inlined callsites in this function
 
 2- Merge profile having maximum counts by itself and verify no overflow
 RUN: llvm-profdata merge -sample %p/Inputs/overflow-sample.proftext -o %t.out 2>&1 | FileCheck %s -allow-empty -check-prefix=MERGE_NO_OVERFLOW
-RUN: llvm-profdata show -sample %t.out | FileCheck %s --check-prefix=SHOW_NO_OVERFLOW
+RUN: llvm-profdata show -sample -all-functions %t.out | FileCheck %s --check-prefix=SHOW_NO_OVERFLOW
 MERGE_NO_OVERFLOW-NOT: {{.*}}: main: Counter overflow
 SHOW_NO_OVERFLOW-DAG: Function: main: 1000, 0, 2 sampled lines
 SHOW_NO_OVERFLOW-DAG: Samples collected in the function's body {
diff --git a/llvm/test/tools/llvm-profdata/profile-symbol-list-compress.test b/llvm/test/tools/llvm-profdata/profile-symbol-list-compress.test
index b445695c8e8e4..d4fe867983489 100644
--- a/llvm/test/tools/llvm-profdata/profile-symbol-list-compress.test
+++ b/llvm/test/tools/llvm-profdata/profile-symbol-list-compress.test
@@ -2,5 +2,5 @@ REQUIRES: zlib
 ; RUN: llvm-profdata merge -sample -extbinary -compress-all-sections -prof-sym-list=%S/Inputs/profile-symbol-list-1.text %S/Inputs/sample-profile.proftext -o %t.1.output
 ; RUN: llvm-profdata merge -sample -extbinary -compress-all-sections -prof-sym-list=%S/Inputs/profile-symbol-list-2.text %S/Inputs/sample-profile.proftext -o %t.2.output
 ; RUN: llvm-profdata merge -sample -extbinary -compress-all-sections %t.1.output %t.2.output -o %t.3.output
-; RUN: llvm-profdata show -sample -show-prof-sym-list %t.3.output > %t.4.output
+; RUN: llvm-profdata show -all-functions -sample -show-prof-sym-list %t.3.output > %t.4.output
 ; RUN: diff -b %S/Inputs/profile-symbol-list.expected %t.4.output
diff --git a/llvm/test/tools/llvm-profdata/profile-symbol-list.test b/llvm/test/tools/llvm-profdata/profile-symbol-list.test
index 39dcd11ec1db7..e070fcd3a64c8 100644
--- a/llvm/test/tools/llvm-profdata/profile-symbol-list.test
+++ b/llvm/test/tools/llvm-profdata/profile-symbol-list.test
@@ -1,7 +1,7 @@
 ; RUN: llvm-profdata merge -sample -extbinary -prof-sym-list=%S/Inputs/profile-symbol-list-1.text %S/Inputs/sample-profile.proftext -o %t.1.output
 ; RUN: llvm-profdata merge -sample -extbinary -prof-sym-list=%S/Inputs/profile-symbol-list-2.text %S/Inputs/sample-profile.proftext -o %t.2.output
 ; RUN: llvm-profdata merge -sample -extbinary %t.1.output %t.2.output -o %t.3.output
-; RUN: llvm-profdata show -sample -show-prof-sym-list %t.3.output > %t.4.output
+; RUN: llvm-profdata show -sample -all-functions -show-prof-sym-list %t.3.output > %t.4.output
 ; RUN: diff -b %S/Inputs/profile-symbol-list.expected %t.4.output
 ; RUN: llvm-profdata merge -sample -extbinary --drop-profile-symbol-list %t.1.output %t.2.output -o %t.5.output
 ; RUN: llvm-profdata show -sample -show-sec-info-only %t.5.output  | FileCheck %s -check-prefix=NOSYMLIST
diff --git a/llvm/test/tools/llvm-profdata/sample-fs.test b/llvm/test/tools/llvm-profdata/sample-fs.test
index d3d038b17ab70..1404f5433bf76 100644
--- a/llvm/test/tools/llvm-profdata/sample-fs.test
+++ b/llvm/test/tools/llvm-profdata/sample-fs.test
@@ -1,8 +1,8 @@
 Basic tests for sample profiles using fs discriminators.
 
 1- Show command and keep all the discrimiantor bits
-RUN: llvm-profdata show --sample %p/Inputs/sample-fs.proftext -profile-isfs | FileCheck %s --check-prefix=SHOW1
-RUN: llvm-profdata show --sample %p/Inputs/sample-fs.proftext -profile-isfs -fs-discriminator-pass=PassLast | FileCheck %s --check-prefix=SHOW1
+RUN: llvm-profdata show --sample -all-functions %p/Inputs/sample-fs.proftext -profile-isfs | FileCheck %s --check-prefix=SHOW1
+RUN: llvm-profdata show --sample -all-functions %p/Inputs/sample-fs.proftext -profile-isfs -fs-discriminator-pass=PassLast | FileCheck %s --check-prefix=SHOW1
 SHOW1: Function: main: 6436, 0, 6 sampled lines
 SHOW1: Samples collected in the function's body {
 SHOW1:   4: 534
@@ -14,7 +14,7 @@ SHOW1:   5.738209025: 2150
 SHOW1: }
 
 2- Show command and keep only the base discriminator bits
-RUN: llvm-profdata show --sample %p/Inputs/sample-fs.proftext -profile-isfs -fs-discriminator-pass=Base | FileCheck %s --check-prefix=SHOW2
+RUN: llvm-profdata show --sample -all-functions %p/Inputs/sample-fs.proftext -profile-isfs -fs-discriminator-pass=Base | FileCheck %s --check-prefix=SHOW2
 SHOW2: Function: main: 6436, 0, 4 sampled lines
 SHOW2: Samples collected in the function's body {
 SHOW2:   4: 534
@@ -24,7 +24,7 @@ SHOW2:   5.1: 3225
 SHOW2: }
 
 3- Show command and keep only the base discriminator bits and first pass of FS discriminator
-RUN: llvm-profdata show --sample %p/Inputs/sample-fs.proftext -profile-isfs -fs-discriminator-pass=Pass1 | FileCheck %s --check-prefix=SHOW3
+RUN: llvm-profdata show --sample -all-functions %p/Inputs/sample-fs.proftext -profile-isfs -fs-discriminator-pass=Pass1 | FileCheck %s --check-prefix=SHOW3
 Function: main: 6436, 0, 6 sampled lines
 SHOW3: Samples collected in the function's body {
 SHOW3:   4: 534
@@ -36,20 +36,20 @@ SHOW3:   5.11521: 2150
 SHOW3: }
 
 4- Merge command and keep all the discrimiantor bits
-RUN: llvm-profdata merge --sample %p/Inputs/sample-fs.proftext -profile-isfs -fs-discriminator-pass=PassLast --binary -o - | llvm-profdata show --sample - -o %t1-binary_1
-RUN: llvm-profdata merge --sample %p/Inputs/sample-fs.proftext -profile-isfs --binary -o - | llvm-profdata show --sample - -o %t1-binary_2
-RUN: llvm-profdata show --sample %p/Inputs/sample-fs.proftext -profile-isfs -o %t1-text
+RUN: llvm-profdata merge --sample %p/Inputs/sample-fs.proftext -profile-isfs -fs-discriminator-pass=PassLast --binary -o - | llvm-profdata show --sample -all-functions - -o %t1-binary_1
+RUN: llvm-profdata merge --sample %p/Inputs/sample-fs.proftext -profile-isfs --binary -o - | llvm-profdata show --sample -all-functions - -o %t1-binary_2
+RUN: llvm-profdata show --sample -all-functions %p/Inputs/sample-fs.proftext -profile-isfs -o %t1-text
 RUN: diff %t1-binary_1 %t1-text
 RUN: diff %t1-binary_2 %t1-text
 
 2- Merge command and keep only the base discriminator bits
-RUN: llvm-profdata merge --sample %p/Inputs/sample-fs.proftext -profile-isfs -fs-discriminator-pass=Base --binary -o - | llvm-profdata show --sample - -o %t2-binary
-RUN: llvm-profdata show --sample %p/Inputs/sample-fs.proftext -profile-isfs -fs-discriminator-pass=Base -o %t2-text
+RUN: llvm-profdata merge --sample %p/Inputs/sample-fs.proftext -profile-isfs -fs-discriminator-pass=Base --binary -o - | llvm-profdata show --sample -all-functions - -o %t2-binary
+RUN: llvm-profdata show --sample -all-functions %p/Inputs/sample-fs.proftext -profile-isfs -fs-discriminator-pass=Base -o %t2-text
 RUN: diff %t2-binary %t2-text
 
 3- Merge command and keep only the base discriminator bits and first pass of FS discriminator
-RUN: llvm-profdata merge --sample %p/Inputs/sample-fs.proftext -profile-isfs -fs-discriminator-pass=Pass1 --binary -o - | llvm-profdata show --sample - -o %t3-binary
-RUN: llvm-profdata show --sample %p/Inputs/sample-fs.proftext -profile-isfs -fs-discriminator-pass=Pass1 -o %t3-text
+RUN: llvm-profdata merge --sample %p/Inputs/sample-fs.proftext -profile-isfs -fs-discriminator-pass=Pass1 --binary -o - | llvm-profdata show --sample -all-functions - -o %t3-binary
+RUN: llvm-profdata show --sample -all-functions %p/Inputs/sample-fs.proftext -profile-isfs -fs-discriminator-pass=Pass1 -o %t3-text
 RUN: diff %t3-binary %t3-text
 
 4- ProfileIsFS is set properly in extbinary format from the internal option
diff --git a/llvm/test/tools/llvm-profdata/sample-profile-basic.test b/llvm/test/tools/llvm-profdata/sample-profile-basic.test
index 0b0d37aac36cf..ab63ef090987d 100644
--- a/llvm/test/tools/llvm-profdata/sample-profile-basic.test
+++ b/llvm/test/tools/llvm-profdata/sample-profile-basic.test
@@ -1,7 +1,7 @@
 Basic tests for sample profiles.
 
 1- Show all functions
-RUN: llvm-profdata show --sample %p/Inputs/sample-profile.proftext | FileCheck %s --check-prefix=SHOW1
+RUN: llvm-profdata show --sample -all-functions %p/Inputs/sample-profile.proftext | FileCheck %s --check-prefix=SHOW1
 SHOW1-DAG: Function: main: 184019, 0, 7 sampled lines
 SHOW1-DAG: 9: 2064, calls: _Z3bari:1471 _Z3fooi:631
 SHOW1-DAG: Function: _Z3fooi: 7711, 610, 1 sampled lines
@@ -17,8 +17,8 @@ SHOW2-NOT: Function: _Z3fooi: 7711, 610, 1 sampled lines
 
 3- Convert the profile to binary encoding and check that they are both
    identical.
-RUN: llvm-profdata merge --sample %p/Inputs/sample-profile.proftext --binary -o - | llvm-profdata show --sample - -o %t-binary
-RUN: llvm-profdata show --sample %p/Inputs/sample-profile.proftext -o %t-text
+RUN: llvm-profdata merge --sample %p/Inputs/sample-profile.proftext --binary -o - | llvm-profdata show --sample -all-functions - -o %t-binary
+RUN: llvm-profdata show --sample -all-functions %p/Inputs/sample-profile.proftext -o %t-text
 RUN: diff %t-binary %t-text
 
 4- Merge the binary and text encodings of the profile and check that the
@@ -31,5 +31,5 @@ MERGE1: _Z3bari:40602:2874
 MERGE1: _Z3fooi:15422:1220
 
 5- Detect invalid text encoding (e.g. instrumentation profile text format).
-RUN: not llvm-profdata show --sample %p/Inputs/foo3bar3-1.proftext 2>&1 | FileCheck %s --check-prefix=BADTEXT
+RUN: not llvm-profdata show --sample -all-functions %p/Inputs/foo3bar3-1.proftext 2>&1 | FileCheck %s --check-prefix=BADTEXT
 BADTEXT: error: {{.+}}: Unrecognized sample profile encoding format
diff --git a/llvm/test/tools/llvm-profdata/sample-profile-json.test b/llvm/test/tools/llvm-profdata/sample-profile-json.test
index 9e96693faace6..052a990a2acd5 100644
--- a/llvm/test/tools/llvm-profdata/sample-profile-json.test
+++ b/llvm/test/tools/llvm-profdata/sample-profile-json.test
@@ -1,5 +1,5 @@
-RUN: llvm-profdata show --sample --json %p/Inputs/sample-profile.proftext | FileCheck %s --check-prefix=JSON
-RUN: llvm-profdata show --sample --show-format=json %p/Inputs/sample-profile.proftext | FileCheck %s --check-prefix=JSON
+RUN: llvm-profdata show --sample -all-functions --json %p/Inputs/sample-profile.proftext | FileCheck %s --check-prefix=JSON
+RUN: llvm-profdata show --sample -all-functions --show-format=json %p/Inputs/sample-profile.proftext | FileCheck %s --check-prefix=JSON
 JSON:      [
 JSON-NEXT:   {
 JSON-NEXT:     "name": "main",
diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp
index 9a5d3f91d6256..e20bae850ea57 100644
--- a/llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -3242,7 +3242,7 @@ static int showSampleProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
   if (std::error_code EC = Reader->read())
     exitWithErrorCode(EC, Filename);
 
-  if (ShowAllFunctions || FuncNameFilter.empty()) {
+  if (ShowAllFunctions) {
     if (SFormat == ShowFormat::Json)
       Reader->dumpJson(OS);
     else

@teresajohnson teresajohnson requested a review from xur-llvm May 1, 2025 14:16
@teresajohnson
Copy link
Contributor

Adding an FDO developer for thoughts. It looks like -all-functions is already disabled by default, the issue is that it is essentially ignored if the -function= function filter option is not specified. I'm not sure if it has always been that way, but I think the code change makes sense (and I think line 3018 should probably be changed similarly?). That being said, if the default has always been to show all functions, it might make sense to make this code change but also flip the -all-functions default to true to maintain the status quo (but then the code change here fixes the issue where -all-functions=false would do nothing without -function= ). I would like @xur-llvm 's opinion on this though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PGO Profile Guided Optimizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants