]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: implement RGWStreamIOAccountingEngine.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Thu, 28 Jul 2016 16:17:38 +0000 (18:17 +0200)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Fri, 21 Oct 2016 20:57:18 +0000 (22:57 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/rgw/rgw_client_io_decoimpl.h

index f727033f04781a69ef9398146c051a387b94bd5a..c5e07b1230e2db28d3107873714c70d596ac8991 100644 (file)
@@ -86,4 +86,83 @@ public:
   }
 };
 
+
+template <typename T>
+class RGWStreamIOAccountingEngine : public RGWDecoratedStreamIO<T>,
+                                    public RGWClientIOAccounter {
+  bool enabled;
+  uint64_t total_sent;
+  uint64_t total_received;
+
+protected:
+  int read_data(char* const buf, const int max) override {
+    const auto received = RGWDecoratedStreamIO<T>::read_data(buf, max);
+    if (enabled) {
+      total_received += received;
+    }
+    return received;
+  }
+
+  int write_data(const char* const buf, const int len) override {
+    const auto sent = RGWDecoratedStreamIO<T>::write_data(buf, len);
+    if (enabled) {
+      total_sent += sent;
+    }
+    return sent;
+  }
+
+public:
+  template <typename U>
+  RGWStreamIOAccountingEngine(U&& decoratee)
+    : RGWDecoratedStreamIO<T>(std::move(decoratee)),
+      enabled(false),
+      total_sent(0),
+      total_received(0) {
+  }
+
+  int send_status(const int status, const char* const status_name) override {
+    const auto sent = RGWDecoratedStreamIO<T>::send_status(status, status_name);
+    if (enabled) {
+      total_sent += sent;
+    }
+    return sent;
+  }
+
+  int send_100_continue() override {
+    const auto sent = RGWDecoratedStreamIO<T>::send_100_continue();
+    if (enabled) {
+      total_sent += sent;
+    }
+    return sent;
+  }
+
+  int send_content_length(const uint64_t len) override {
+    const auto sent = RGWDecoratedStreamIO<T>::send_content_length(len);
+    if (enabled) {
+      total_sent += sent;
+    }
+    return sent;
+  }
+
+  int complete_header() override {
+    const auto sent = RGWDecoratedStreamIO<T>::complete_header();
+    if (enabled) {
+      total_sent += sent;
+    }
+    return sent;
+  }
+
+  uint64_t get_bytes_sent() const override {
+    return total_sent;
+  }
+
+  uint64_t get_bytes_received() const override {
+    return total_received;
+  }
+
+  void set_account(bool enabled) override {
+    this->enabled = enabled;
+  }
+};
+
 #endif /* CEPH_RGW_CLIENT_IO_DECOIMPL_H */