]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/osd: specialize fmt::formatter<> for OpSequencer 41814/head
authorKefu Chai <kchai@redhat.com>
Fri, 11 Jun 2021 06:18:22 +0000 (14:18 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 11 Jun 2021 06:19:14 +0000 (14:19 +0800)
so we can print it like fmt::format("{}", sequencer)

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crimson/osd/osd_operation_sequencer.h

index 78bf82f6fd8d265d9353031708e88f17c95ff861..a83b9d1ccc80267380362630984f968c9c63f2ca 100644 (file)
@@ -4,6 +4,7 @@
 #pragma once
 
 #include <map>
+#include <fmt/format.h>
 #include <seastar/core/condition-variable.hh>
 #include "crimson/common/operation.h"
 #include "osd/osd_types.h"
@@ -103,8 +104,11 @@ private:
   // the id of last op which is completed
   uint64_t last_completed = 0;
   seastar::condition_variable unblocked;
+
+  friend fmt::formatter<OpSequencer>;
 };
 
+
 class OpSequencers {
 public:
   OpSequencer& get(const spg_t& pgid) {
@@ -118,3 +122,20 @@ private:
   std::map<spg_t, OpSequencer> pg_ops;
 };
 } // namespace crimson::osd
+
+template <>
+struct fmt::formatter<crimson::osd::OpSequencer> {
+  // ignore the format string
+  constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
+
+  template <typename FormatContext>
+  auto format(const crimson::osd::OpSequencer& sequencer,
+              FormatContext& ctx)
+  {
+    return fmt::format_to(ctx.out(),
+                          "(last_completed={},last_unblocked={},last_issued={})",
+                          sequencer.last_completed,
+                          sequencer.last_unblocked,
+                          sequencer.last_issued);
+  }
+};