This is an automated email from the ASF dual-hosted git repository. jamesge pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-brpc.git
The following commit(s) were added to refs/heads/master by this push: new e2c9d6a bvar::Status on integrals supports historical series e2c9d6a is described below commit e2c9d6a7802dfc9fad944ef3972ca282f680b8d4 Author: gejun <ge...@bilibili.com> AuthorDate: Mon Jun 10 12:39:07 2019 +0800 bvar::Status on integrals supports historical series --- src/bvar/passive_status.h | 5 ++-- src/bvar/status.h | 60 +++++++++++++++++++++++++++++++++++++++++++---- src/bvar/window.h | 5 ++-- 3 files changed, 59 insertions(+), 11 deletions(-) diff --git a/src/bvar/passive_status.h b/src/bvar/passive_status.h index 8ada60b..9f5a3be 100644 --- a/src/bvar/passive_status.h +++ b/src/bvar/passive_status.h @@ -149,7 +149,7 @@ public: detail::AddTo<Tp> op() const { return detail::AddTo<Tp>(); } detail::MinusFrom<Tp> inv_op() const { return detail::MinusFrom<Tp>(); } - int describe_series(std::ostream& os, const SeriesOptions& options) const { + int describe_series(std::ostream& os, const SeriesOptions& options) const override { if (_series_sampler == NULL) { return 1; } @@ -165,10 +165,9 @@ public: } protected: - // @Variable int expose_impl(const butil::StringPiece& prefix, const butil::StringPiece& name, - DisplayFilter display_filter) { + DisplayFilter display_filter) override { const int rc = Variable::expose_impl(prefix, name, display_filter); if (ADDITIVE && rc == 0 && diff --git a/src/bvar/status.h b/src/bvar/status.h index 48c0ae1..568fa87 100644 --- a/src/bvar/status.h +++ b/src/bvar/status.h @@ -86,16 +86,41 @@ template <typename T> class Status<T, typename butil::enable_if<detail::is_atomical<T>::value>::type> : public Variable { public: - Status() {} - Status(const T& value) : _value(value) { } - Status(const butil::StringPiece& name, const T& value) : _value(value) { + struct PlaceHolderOp { + void operator()(T&, const T&) const {} + }; + class SeriesSampler : public detail::Sampler { + public: + typedef typename butil::conditional< + true, detail::AddTo<T>, PlaceHolderOp>::type Op; + explicit SeriesSampler(Status* owner) + : _owner(owner), _series(Op()) {} + void take_sample() { _series.append(_owner->get_value()); } + void describe(std::ostream& os) { _series.describe(os, NULL); } + private: + Status* _owner; + detail::Series<T, Op> _series; + }; + +public: + Status() : _series_sampler(NULL) {} + Status(const T& value) : _value(value), _series_sampler(NULL) { } + Status(const butil::StringPiece& name, const T& value) + : _value(value), _series_sampler(NULL) { this->expose(name); } Status(const butil::StringPiece& prefix, - const butil::StringPiece& name, const T& value) : _value(value) { + const butil::StringPiece& name, const T& value) + : _value(value), _series_sampler(NULL) { this->expose_as(prefix, name); } - ~Status() { hide(); } + ~Status() { + hide(); + if (_series_sampler) { + _series_sampler->destroy(); + _series_sampler = NULL; + } + } // Implement Variable::describe() and Variable::get_value(). void describe(std::ostream& os, bool /*quote_string*/) const { @@ -116,8 +141,33 @@ public: _value.store(value, butil::memory_order_relaxed); } + int describe_series(std::ostream& os, const SeriesOptions& options) const override { + if (_series_sampler == NULL) { + return 1; + } + if (!options.test_only) { + _series_sampler->describe(os); + } + return 0; + } + +protected: + int expose_impl(const butil::StringPiece& prefix, + const butil::StringPiece& name, + DisplayFilter display_filter) override { + const int rc = Variable::expose_impl(prefix, name, display_filter); + if (rc == 0 && + _series_sampler == NULL && + FLAGS_save_series) { + _series_sampler = new SeriesSampler(this); + _series_sampler->schedule(); + } + return rc; + } + private: butil::atomic<T> _value; + SeriesSampler* _series_sampler; }; // Specialize for std::string, adding a printf-style set_value(). diff --git a/src/bvar/window.h b/src/bvar/window.h index 984f5c6..f67a8e9 100644 --- a/src/bvar/window.h +++ b/src/bvar/window.h @@ -123,7 +123,7 @@ public: time_t window_size() const { return _window_size; } - int describe_series(std::ostream& os, const SeriesOptions& options) const { + int describe_series(std::ostream& os, const SeriesOptions& options) const override { if (_series_sampler == NULL) { return 1; } @@ -140,10 +140,9 @@ public: } protected: - // @Variable int expose_impl(const butil::StringPiece& prefix, const butil::StringPiece& name, - DisplayFilter display_filter) { + DisplayFilter display_filter) override { const int rc = Variable::expose_impl(prefix, name, display_filter); if (rc == 0 && _series_sampler == NULL && --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For additional commands, e-mail: dev-h...@brpc.apache.org