[llvm] [memprof] Add YAML read/write support to llvm-profdata (PR #118915)

Snehasish Kumar via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 6 12:33:56 PST 2024


================
@@ -3242,18 +3270,42 @@ static int showSampleProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
 static int showMemProfProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
   if (SFormat == ShowFormat::Json)
     exitWithError("JSON output is not supported for MemProf");
-  auto ReaderOr = llvm::memprof::RawMemProfReader::create(
-      Filename, ProfiledBinary, /*KeepNames=*/true);
-  if (Error E = ReaderOr.takeError())
-    // Since the error can be related to the profile or the binary we do not
-    // pass whence. Instead additional context is provided where necessary in
-    // the error message.
-    exitWithError(std::move(E), /*Whence*/ "");
-
-  std::unique_ptr<llvm::memprof::RawMemProfReader> Reader(
-      ReaderOr.get().release());
-
-  Reader->printYAML(OS);
+
+  // Load the file to check the magic bytes.
+  llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> BufferOrError =
+      llvm::MemoryBuffer::getFile(Filename);
+  if (auto EC = BufferOrError.getError())
+    exitWithError("Error opening profile file '" + Filename + "'");
+  auto Buffer = std::move(BufferOrError.get());
----------------
snehasish wrote:

Can this be replaced by using the Path version of the hasFormat check below?

https://github.com/llvm/llvm-project/pull/118915


More information about the llvm-commits mailing list