]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: Add "bluestore compression stats"
authorAdam Kupczyk <akupczyk@ibm.com>
Thu, 13 Jun 2024 17:34:57 +0000 (17:34 +0000)
committerAdam Kupczyk <akupczyk@ibm.com>
Thu, 24 Apr 2025 06:47:18 +0000 (06:47 +0000)
Add new admin socket command to inspect Estimator stats per collection.

Signed-off-by: Adam Kupczyk <akupczyk@ibm.com>
src/os/bluestore/BlueAdmin.cc
src/os/bluestore/Compression.cc
src/os/bluestore/Compression.h

index e765c8d907d37e6ba2ca21e4c3eab41c760fc62c..310a2036347e61c5412a1d01740fb81d5f97c50d 100644 (file)
@@ -2,6 +2,7 @@
 // vim: ts=8 sw=2 smarttab
 
 #include "BlueAdmin.h"
+#include "Compression.h"
 #include "common/pretty_binary.h"
 #include "common/debug.h"
 #include <asm-generic/errno-base.h>
@@ -42,6 +43,12 @@ BlueStore::SocketHook::SocketHook(BlueStore& store)
       this,
       "print object internals");
     ceph_assert(r == 0);
+    r = admin_socket->register_command(
+      "bluestore compression stats "
+      "name=collection,type=CephString,req=false",
+      this,
+      "print compression stats, per collection");
+    ceph_assert(r == 0);
   }
 }
 
@@ -142,6 +149,34 @@ int BlueStore::SocketHook::call(
     }
     r = -ENOENT;
     ss << "No collection that can hold such object" << std::endl;
+  } else if (command == "bluestore compression stats") {
+    std::vector<CollectionRef> copied;
+    {
+      std::shared_lock l(store.coll_lock);
+      copied.reserve(store.coll_map.size());
+      for (const auto& c : store.coll_map) {
+        copied.push_back(c.second);
+      }
+    }
+    std::string coll;
+    cmd_getval(cmdmap, "collection", coll);
+    f->open_array_section("compression");
+    for (const auto& c : copied) {
+      std::shared_lock l(c->lock);
+      if ((coll.empty() && bool(c->estimator))
+        || coll == c->get_cid().c_str()) {
+        f->open_object_section("collection");
+        f->dump_string("cid", c->get_cid().c_str());
+        f->open_object_section("estimator");
+        if (c->estimator) {
+          c->estimator->dump(f);
+        }
+        f->close_section();
+        f->close_section();
+      }
+    }
+    f->close_section();
+    return 0;
   } else {
     ss << "Invalid command" << std::endl;
     r = -ENOSYS;
index 6c31699d4e4270c3b7afc76ba76fe3056368f8fd..41684cb630d34490730f79dd93479614e36734f1 100644 (file)
@@ -223,6 +223,12 @@ void Estimator::finish()
   cleanup();
 }
 
+void Estimator::dump(Formatter *f) const {
+  f->dump_float("expected_compression_now", expected_compression_factor);
+  f->dump_float("expected_recompression_error", expected_recompression_error);
+  f->dump_float("expected_pad_expansion", expected_pad_expansion);
+}
+
 Estimator* BlueStore::create_estimator()
 {
   return new Estimator(this);
index d266e1d2e79da725c05a21ad1723e4191a74aa78..ed78150019141a787f8ea1cd086b6c17a8b7da31 100644 (file)
@@ -51,7 +51,7 @@ public:
     Writer::blob_vec& bd);
 
   void finish();
-
+  void dump(Formatter *f) const;
 private:
   BlueStore* bluestore;
   double expected_compression_factor = 0.5;