[PATCH] D125255: [llvm-profgen] Support a threshold to control hiding warning summaries

Lei Wang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 9 12:02:56 PDT 2022


wlei created this revision.
Herald added subscribers: hoy, wenlei.
Herald added a project: All.
wlei requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125255

Files:
  llvm/tools/llvm-profgen/ErrorHandling.h
  llvm/tools/llvm-profgen/PerfReader.cpp


Index: llvm/tools/llvm-profgen/PerfReader.cpp
===================================================================
--- llvm/tools/llvm-profgen/PerfReader.cpp
+++ llvm/tools/llvm-profgen/PerfReader.cpp
@@ -43,6 +43,12 @@
                                   cl::ZeroOrMore,
                                   cl::desc("Show detailed warning message."));
 
+cl::opt<int> WarningSummaryThres(
+    "warning-summary-threshold", llvm::cl::init(5),
+    llvm::cl::desc("Print out the warning summary only if it reaches to the "
+                   "threshold(in percentage), default value is 5%."),
+    llvm::cl::Optional);
+
 extern cl::opt<std::string> PerfTraceFilename;
 extern cl::opt<bool> ShowDisassemblyOnly;
 extern cl::opt<bool> ShowSourceLocations;
Index: llvm/tools/llvm-profgen/ErrorHandling.h
===================================================================
--- llvm/tools/llvm-profgen/ErrorHandling.h
+++ llvm/tools/llvm-profgen/ErrorHandling.h
@@ -10,6 +10,7 @@
 #define LLVM_TOOLS_LLVM_PROFGEN_ERRORHANDLING_H
 
 #include "llvm/ADT/Twine.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorOr.h"
@@ -18,6 +19,8 @@
 
 using namespace llvm;
 
+extern cl::opt<int> WarningSummaryThres;
+
 [[noreturn]] inline void exitWithError(const Twine &Message,
                                        StringRef Whence = StringRef(),
                                        StringRef Hint = StringRef()) {
@@ -49,8 +52,13 @@
 inline void emitWarningSummary(uint64_t Num, uint64_t Total, StringRef Msg) {
   if (!Total || !Num)
     return;
-  WithColor::warning() << format("%.2f", static_cast<double>(Num) * 100 / Total)
-                       << "%(" << Num << "/" << Total << ") " << Msg << "\n";
+
+  double P = static_cast<double>(Num) * 100 / Total;
+  if (P < WarningSummaryThres)
+    return;
+
+  WithColor::warning() << format("%.2f", P) << "%(" << Num << "/" << Total
+                       << ") " << Msg << "\n";
 }
 
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125255.428150.patch
Type: text/x-patch
Size: 2022 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220509/9d9e01f5/attachment.bin>


More information about the llvm-commits mailing list