]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
dout: DoutPrefixProvider operates directly on stream 21608/head
authorCasey Bodley <cbodley@redhat.com>
Mon, 23 Apr 2018 20:03:59 +0000 (16:03 -0400)
committerCasey Bodley <cbodley@redhat.com>
Mon, 23 Apr 2018 22:08:25 +0000 (18:08 -0400)
removes the need for stringstream in more complicated prefixes

Signed-off-by: Casey Bodley <cbodley@redhat.com>
14 files changed:
src/common/dout.h
src/osd/ECBackend.cc
src/osd/PG.cc
src/osd/PG.h
src/osd/PGBackend.cc
src/osd/PGBackend.h
src/osd/PGLog.cc
src/osd/PGLog.h
src/osd/PrimaryLogPG.cc
src/osd/PrimaryLogPG.h
src/osd/ReplicatedBackend.cc
src/osd/Watch.cc
src/osd/Watch.h
src/test/osd/test_ec_transaction.cc

index 69b85c94788355a3792bc4ee744d91413545d7c7..df5cd83bf55f91d6781aae42dea0e96e3dfe9afd 100644 (file)
@@ -37,7 +37,7 @@ inline std::ostream& operator<<(std::ostream& out, _bad_endl_use_dendl_t) {
 
 class DoutPrefixProvider {
 public:
-  virtual string gen_prefix() const = 0;
+  virtual std::ostream& gen_prefix(std::ostream& out) const = 0;
   virtual CephContext *get_cct() const = 0;
   virtual unsigned get_subsys() const = 0;
   virtual ~DoutPrefixProvider() {}
@@ -99,7 +99,7 @@ struct is_dynamic<dynamic_marker_t<T>> : public std::true_type {};
 #define ldpp_dout(dpp, v)                                              \
   if (dpp)                                                             \
     dout_impl(dpp->get_cct(), ceph::dout::need_dynamic(dpp->get_subsys()), v)                          \
-    (*_dout << dpp->gen_prefix())
+    dpp->gen_prefix(*_dout)
 
 #define lgeneric_subdout(cct, sub, v) dout_impl(cct, ceph_subsys_##sub, v) *_dout
 #define lgeneric_dout(cct, v) dout_impl(cct, ceph_subsys_, v) *_dout
index 90924ca522083699db39108a467b0bfb8e4d7cb6..3ae93eebf05d29bce1a42d9450b73c3664bf5674 100644 (file)
@@ -32,7 +32,7 @@
 #undef dout_prefix
 #define dout_prefix _prefix(_dout, this)
 static ostream& _prefix(std::ostream *_dout, ECBackend *pgb) {
-  return *_dout << pgb->get_parent()->gen_dbg_prefix();
+  return pgb->get_parent()->gen_dbg_prefix(*_dout);
 }
 
 struct ECRecoveryHandle : public PGBackend::RecoveryHandle {
index 76d6d41d9b8211d66b63069ec54b7ae737c1aaf5..e4c168fbb238a45f1b7fdf6ea7c6e02e18ddfd4d 100644 (file)
@@ -87,7 +87,7 @@ const string fastinfo_key("_fastinfo");
 template <class T>
 static ostream& _prefix(std::ostream *_dout, T *t)
 {
-  return *_dout << t->gen_prefix();
+  return t->gen_prefix(*_dout);
 }
 
 void PGStateHistory::enter(PG* pg, const utime_t entime, const char* state)
@@ -383,9 +383,8 @@ void PG::lock(bool no_lockdep) const
   dout(30) << "lock" << dendl;
 }
 
-std::string PG::gen_prefix() const
+std::ostream& PG::gen_prefix(std::ostream& out) const
 {
-  stringstream out;
   OSDMapRef mapref = osdmap_ref;
   if (_lock.is_locked_by_me()) {
     out << "osd." << osd->whoami
@@ -396,7 +395,7 @@ std::string PG::gen_prefix() const
        << " pg_epoch: " << (mapref ? mapref->get_epoch():0)
        << " pg[" << info.pgid << "(unlocked)] ";
   }
-  return out.str();
+  return out;
 }
   
 /********* PG **********/
@@ -6558,7 +6557,7 @@ void PG::_delete_some(ObjectStore::Transaction *t)
 
 /*------------ Recovery State Machine----------------*/
 #undef dout_prefix
-#define dout_prefix (*_dout << context< RecoveryMachine >().pg->gen_prefix() \
+#define dout_prefix (context< RecoveryMachine >().pg->gen_prefix(*_dout) \
                     << "state<" << get_state_name() << ">: ")
 
 /*------Crashed-------*/
@@ -9159,7 +9158,7 @@ void PG::RecoveryState::WaitUpThru::exit()
 
 /*----RecoveryState::RecoveryMachine Methods-----*/
 #undef dout_prefix
-#define dout_prefix *_dout << pg->gen_prefix()
+#define dout_prefix pg->gen_prefix(*_dout)
 
 void PG::RecoveryState::RecoveryMachine::log_enter(const char *state_name)
 {
@@ -9182,7 +9181,7 @@ void PG::RecoveryState::RecoveryMachine::log_exit(const char *state_name, utime_
 
 /*---------------------------------------------------*/
 #undef dout_prefix
-#define dout_prefix (*_dout << (debug_pg ? debug_pg->gen_prefix() : string()) << " PriorSet: ")
+#define dout_prefix ((debug_pg ? debug_pg->gen_prefix(*_dout) : *_dout) << " PriorSet: ")
 
 void PG::RecoveryState::start_handle(RecoveryCtx *new_ctx) {
   assert(!rctx);
index 5b9af60fab6db99d250375f235e31b2e8c19a0cf..0711bb27e29b3bbf3d4c63603b0e45a14f73a605 100644 (file)
@@ -259,7 +259,7 @@ public:
   class RecoveryCtx;
 
   // -- methods --
-  std::string gen_prefix() const override;
+  std::ostream& gen_prefix(std::ostream& out) const override;
   CephContext *get_cct() const override {
     return cct;
   }
@@ -703,7 +703,9 @@ protected:
       is_readable.reset(_is_readable);
       is_recoverable.reset(_is_recoverable);
     }
-    string gen_prefix() const { return pg->gen_prefix(); }
+    std::ostream& gen_prefix(std::ostream& out) const {
+      return pg->gen_prefix(out);
+    }
     bool needs_recovery(
       const hobject_t &hoid,
       eversion_t *v = 0) const {
index 0823ac0528cc45445ee7ded34a9d10e27048979c..6cdbac4001f63e48141b46e124ea74b2fb602c8f 100644 (file)
@@ -36,7 +36,7 @@
 #undef dout_prefix
 #define dout_prefix _prefix(_dout, this)
 static ostream& _prefix(std::ostream *_dout, PGBackend *pgb) {
-  return *_dout << pgb->get_parent()->gen_dbg_prefix();
+  return pgb->get_parent()->gen_dbg_prefix(*_dout);
 }
 
 void PGBackend::recover_delete_object(const hobject_t &oid, eversion_t v,
index 55f7f1d909d6f08812439dd98f826957fe505a8a..51c35a81180273c864117d1c65ec39d3adfd9b55 100644 (file)
@@ -162,7 +162,7 @@ typedef ceph::shared_ptr<const OSDMap> OSDMapRef;
      virtual const set<pg_shard_t> &get_acting_shards() const = 0;
      virtual const set<pg_shard_t> &get_backfill_shards() const = 0;
 
-     virtual std::string gen_dbg_prefix() const = 0;
+     virtual std::ostream& gen_dbg_prefix(std::ostream& out) const = 0;
 
      virtual const map<hobject_t, set<pg_shard_t>> &get_missing_loc_shards()
        const = 0;
@@ -310,8 +310,8 @@ typedef ceph::shared_ptr<const OSDMap> OSDMapRef;
    OSDMapRef get_osdmap() const { return get_parent()->pgb_get_osdmap(); }
    const pg_info_t &get_info() { return get_parent()->get_info(); }
 
-   std::string gen_prefix() const {
-     return parent->gen_dbg_prefix();
+   std::ostream& gen_prefix(std::ostream& out) const {
+     return parent->gen_dbg_prefix(out);
    }
 
    /**
index 4445a9cf1a479790e80992979c6bfae4643b9184..2090d4ef7dc9655245375cd406d6974fa8ad4be1 100644 (file)
@@ -26,7 +26,7 @@
 
 static ostream& _prefix(std::ostream *_dout, const PGLog *pglog)
 {
-  return *_dout << pglog->gen_prefix();
+  return pglog->gen_prefix(*_dout);
 }
 
 //////////////////// PGLog::IndexedLog ////////////////////
index e3035bc0d75aeaf52c927cda75ea634a76f587e3..1215d5301087ca8e8f608b1b6a54d1138af4c46b 100644 (file)
@@ -34,8 +34,8 @@ constexpr auto PGLOG_INDEXED_ALL              = PGLOG_INDEXED_OBJECTS
 class CephContext;
 
 struct PGLog : DoutPrefixProvider {
-  string gen_prefix() const override {
-    return "";
+  std::ostream& gen_prefix(std::ostream& out) const override {
+    return out;
   }
   unsigned get_subsys() const override {
     return static_cast<unsigned>(ceph_subsys_osd);
index a5c260740f8e609d2887661c8991b4d8943470e7..c8b9dc6ad6fdc062d0bac669495cbd461c7b98d5 100644 (file)
@@ -65,7 +65,7 @@
 #define dout_prefix _prefix(_dout, this)
 template <typename T>
 static ostream& _prefix(std::ostream *_dout, T *pg) {
-  return *_dout << pg->gen_prefix();
+  return pg->gen_prefix(*_dout);
 }
 
 
@@ -14987,7 +14987,7 @@ int PrimaryLogPG::rep_repair_primary_object(const hobject_t& soid, OpRequestRef
 
 /*---SnapTrimmer Logging---*/
 #undef dout_prefix
-#define dout_prefix *_dout << pg->gen_prefix() 
+#define dout_prefix pg->gen_prefix(*_dout)
 
 void PrimaryLogPG::SnapTrimmer::log_enter(const char *state_name)
 {
@@ -15001,7 +15001,7 @@ void PrimaryLogPG::SnapTrimmer::log_exit(const char *state_name, utime_t enter_t
 
 /*---SnapTrimmer states---*/
 #undef dout_prefix
-#define dout_prefix (*_dout << context< SnapTrimmer >().pg->gen_prefix() \
+#define dout_prefix (context< SnapTrimmer >().pg->gen_prefix(*_dout) \
                     << "SnapTrimmer state<" << get_state_name() << ">: ")
 
 /* NotTrimming */
index 48dbd070a921c68f4729164c7da257eb74510b75..aa0a57e5356fa54a2493f84c6d36bddda2cc8aea 100644 (file)
@@ -339,8 +339,10 @@ public:
     return backfill_targets;
   }
 
-  std::string gen_dbg_prefix() const override { return gen_prefix(); }
-  
+  std::ostream& gen_dbg_prefix(std::ostream& out) const override {
+    return gen_prefix(out);
+  }
+
   const map<hobject_t, set<pg_shard_t>>
     &get_missing_loc_shards() const override {
     return missing_loc.get_missing_locs();
index 18a0369831885a4cc528ba9c222fe62c0c995b97..d6d1f731053a0ea0584b356c1deab6f60db31f9e 100644 (file)
@@ -28,7 +28,7 @@
 #undef dout_prefix
 #define dout_prefix _prefix(_dout, this)
 static ostream& _prefix(std::ostream *_dout, ReplicatedBackend *pgb) {
-  return *_dout << pgb->get_parent()->gen_dbg_prefix();
+  return pgb->get_parent()->gen_dbg_prefix(*_dout);
 }
 
 namespace {
index 3d6985567e06a3b8d2ee9f34381bb87922e2f500..ef91e9e427bb0f7ca20ba9d790c946327730e4d1 100644 (file)
@@ -25,7 +25,7 @@ struct CancelableContext : public Context {
 static ostream& _prefix(
   std::ostream* _dout,
   Notify *notify) {
-  return *_dout << notify->gen_dbg_prefix();
+  return notify->gen_dbg_prefix(*_dout);
 }
 
 Notify::Notify(
@@ -229,7 +229,7 @@ void Notify::init()
 static ostream& _prefix(
   std::ostream* _dout,
   Watch *watch) {
-  return *_dout << watch->gen_dbg_prefix();
+  return watch->gen_dbg_prefix(*_dout);
 }
 
 class HandleWatchTimeout : public CancelableContext {
@@ -278,11 +278,9 @@ public:
 #undef dout_prefix
 #define dout_prefix _prefix(_dout, this)
 
-string Watch::gen_dbg_prefix() {
-  stringstream ss;
-  ss << pg->gen_prefix() << " -- Watch(" 
-     << make_pair(cookie, entity) << ") ";
-  return ss.str();
+std::ostream& Watch::gen_dbg_prefix(std::ostream& out) {
+  return pg->gen_prefix(out) << " -- Watch("
+      << make_pair(cookie, entity) << ") ";
 }
 
 Watch::Watch(
index f41475c42cbd51432358bd6a1fa8f0d31429fcc2..ebcb7059f00511d3a83886052fd0ce0c93c2be12 100644 (file)
@@ -99,12 +99,10 @@ class Notify {
   void unregister_cb();
 public:
 
-  string gen_dbg_prefix() {
-    stringstream ss;
-    ss << "Notify(" << make_pair(cookie, notify_id) << " "
-       << " watchers=" << watchers.size()
-       << ") ";
-    return ss.str();
+  std::ostream& gen_dbg_prefix(std::ostream& out) {
+    return out << "Notify(" << make_pair(cookie, notify_id) << " "
+        << " watchers=" << watchers.size()
+        << ") ";
   }
   void set_self(NotifyRef _self) {
     self = _self;
@@ -210,7 +208,7 @@ public:
     return entity.num();
   }
 
-  string gen_dbg_prefix();
+  std::ostream& gen_dbg_prefix(std::ostream& out);
   static WatchRef makeWatchRef(
     PrimaryLogPG *pg, OSDService *osd,
     ceph::shared_ptr<ObjectContext> obc, uint32_t timeout, uint64_t cookie, entity_name_t entity, const entity_addr_t &addr);
index 1ef2d5d832c136292988b46a67ecd785de3ded5c..98669667a777266a4f4120dfd79e4a0563ac0895 100644 (file)
@@ -19,7 +19,7 @@
 #include "test/unit.cc"
 
 struct mydpp : public DoutPrefixProvider {
-  string gen_prefix() const override { return "foo"; }
+  std::ostream& gen_prefix(std::ostream& out) const override { return out << "foo"; }
   CephContext *get_cct() const override { return g_ceph_context; }
   unsigned get_subsys() const override { return ceph_subsys_osd; }
 } dpp;