You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by se...@apache.org on 2022/12/26 01:56:58 UTC

[incubator-brpc] branch master updated: optimize mbvar doc (#2058)

This is an automated email from the ASF dual-hosted git repository.

serverglen 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 3b9fe0a2 optimize mbvar doc (#2058)
3b9fe0a2 is described below

commit 3b9fe0a28577be9b29682e39772b40bedb4604d3
Author: caidj <31...@users.noreply.github.com>
AuthorDate: Mon Dec 26 09:56:48 2022 +0800

    optimize mbvar doc (#2058)
    
    * optimize mbvar doc
    
    * optimize doc
---
 docs/cn/mbvar_c++.md | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)

diff --git a/docs/cn/mbvar_c++.md b/docs/cn/mbvar_c++.md
index c68f95d7..4abe2f6b 100644
--- a/docs/cn/mbvar_c++.md
+++ b/docs/cn/mbvar_c++.md
@@ -24,6 +24,8 @@
     - [bvar::IntRecorder](#bvarintrecorder)
     - [bvar::LatencyRecorder](#bvarlatencyrecorder)
     - [bvar::Status](#bvarstatus)
+    - [bvar::WindowEx](#bvarwindowex)
+    - [bvar::PerSecondEx](#bvarpersecondex)
 
 # mbvar Introduction
 
@@ -38,7 +40,9 @@ mbvar中有两个类,分别是MVariable和MultiDimension,MVariable是多维
 | bvar::Miner<T> | 求最小值,默认std::numeric_limits<T>::max(),varname << N相当于varname = min(varname, N)。 |
 | bvar::IntRecorder | 求自使用以来的平均值。注意这里的定语不是“一段时间内”。一般要通过Window衍生出时间窗口内的平均值。 |
 | bvar::LatencyRecorder | 专用于记录延时和qps的变量。输入延时,平均延时/最大延时/qps/总次数 都有了。 |
-| bvar::Status<T> | 记录和显示一个值,拥有额外的set_value函数 |
+| bvar::Status<T> | 记录和显示一个值,拥有额外的set_value函数。 |
+| bvar::WindowEx<R, T> | 获得之前一段时间内的统计值。WindowEx是独立存在的,不依赖其他的计数器,需要给它发送数据。 |
+| bvar::PerSecondEx<T> | 获得之前一段时间内平均每秒的统计值。PerSecondEx是独立存在的,不依赖其他的计数器,需要给它发送数据。 |
 
 例子:
 ```c++
@@ -772,3 +776,49 @@ void request_cost(const std::list<std::string>& request_labels) {
 } // namespace bar
 } // namespace foo
 ```
+
+### bvar::WindowEx
+获得之前一段时间内的统计值。
+```c++
+#include <bvar/bvar.h>
+#include <bvar/window.h>
+#include <bvar/multi_dimension.h>
+
+namespace foo {
+namespace bar {
+// 定义一个全局的多维度mbvar变量
+bvar::MultiDimension<bvar::WindowEx<bvar::Adder<int>, 60>> sum_minute("sum_minute", {"idc", "method", "status"});
+
+void Record(const std::list<std::string>& request_labels, int num) {
+    // 获取request对应的单维度mbvar指针,假设request_labels = {"tc", "get", "200"}
+    bvar::WindowEx<bvar::Adder<int>, 60>* status = sum_minute.get_stats(request_labels);
+    // status只能在sum_minute生命周期内访问,否则行为未定义,可能会出core
+    *status << num;
+}
+
+} // namespace bar
+} // namespace foo
+```
+
+### bvar::PerSecondEx
+获得之前一段时间内平均每秒的统计值。
+```c++
+#include <bvar/bvar.h>
+#include <bvar/window.h>
+#include <bvar/multi_dimension.h>
+
+namespace foo {
+namespace bar {
+// 定义一个全局的多维度mbvar变量
+bvar::MultiDimension<bvar::PerSecondEx<bvar::Adder<int>>> sum_per_second("sum_per_second", {"idc", "method", "status"});
+
+void Record(const std::list<std::string>& request_labels, int num) {
+    // 获取request对应的单维度mbvar指针,假设request_labels = {"tc", "get", "200"}
+    bvar::PerSecondEx<bvar::Adder<int>>* status = sum_per_second.get_stats(request_labels);
+    // status只能在sum_per_second生命周期内访问,否则行为未定义,可能会出core
+    *status << num;
+}
+
+} // namespace bar
+} // namespace foo
+```


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org