From: Radoslaw Zarzynski Date: Thu, 28 Jul 2016 16:17:38 +0000 (+0200) Subject: rgw: implement RGWStreamIOAccountingEngine. X-Git-Tag: v11.1.0~454^2~53 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ba0050865a98ae14ee1e6a71568337836edf3116;p=ceph.git rgw: implement RGWStreamIOAccountingEngine. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/rgw/rgw_client_io_decoimpl.h b/src/rgw/rgw_client_io_decoimpl.h index f727033f0478..c5e07b1230e2 100644 --- a/src/rgw/rgw_client_io_decoimpl.h +++ b/src/rgw/rgw_client_io_decoimpl.h @@ -86,4 +86,83 @@ public: } }; + +template +class RGWStreamIOAccountingEngine : public RGWDecoratedStreamIO, + 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::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::write_data(buf, len); + if (enabled) { + total_sent += sent; + } + return sent; + } + +public: + template + RGWStreamIOAccountingEngine(U&& decoratee) + : RGWDecoratedStreamIO(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::send_status(status, status_name); + if (enabled) { + total_sent += sent; + } + return sent; + } + + int send_100_continue() override { + const auto sent = RGWDecoratedStreamIO::send_100_continue(); + if (enabled) { + total_sent += sent; + } + return sent; + } + + int send_content_length(const uint64_t len) override { + const auto sent = RGWDecoratedStreamIO::send_content_length(len); + if (enabled) { + total_sent += sent; + } + return sent; + } + + int complete_header() override { + const auto sent = RGWDecoratedStreamIO::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 */