gavinchou commented on code in PR #47563:
URL: https://github.com/apache/doris/pull/47563#discussion_r1958306375


##########
be/src/io/tools/file_cache_microbench.cpp:
##########
@@ -0,0 +1,1222 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <brpc/controller.h>
+#include <brpc/http_status_code.h>
+#include <brpc/server.h>
+#include <brpc/uri.h>
+#include <bvar/bvar.h>
+#include <glog/logging.h>
+
+#include <atomic>
+#include <chrono>
+#include <condition_variable>
+#include <filesystem> // 添加这个头文件
+#include <future>
+#include <iomanip>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <mutex>
+#include <queue>
+#include <string>
+#include <thread>
+#include <unordered_set>
+#include <vector>
+#include <cstdlib>
+
+#include "build/proto/microbench.pb.h"
+#include "common/config.h"
+#include "common/status.h"
+#include "gflags/gflags.h"
+#include "io/cache/cached_remote_file_reader.h"
+#include "io/file_factory.h"
+#include "io/fs/s3_file_system.h"
+#include "io/fs/s3_file_writer.h"
+#include "rapidjson/document.h"
+#include "rapidjson/stringbuffer.h"
+#include "rapidjson/writer.h"
+#include "runtime/exec_env.h"
+#include "util/bvar_helper.h"
+#include "util/defer_op.h"
+#include "util/stopwatch.hpp"
+
+bvar::LatencyRecorder write_latency("file_cache_microbench_append");
+bvar::LatencyRecorder read_latency("file_cache_microbench_read_at");
+
+// 添加gflags定义
+DEFINE_int32(port, 8888, "Http Port of this server");
+
+// 添加一个数据生成器类
+class DataGenerator {
+public:
+    DataGenerator(size_t total_size, size_t buffer_size = 1024 * 1024) // 
默认1MB缓冲区
+            : _total_size(total_size), _generated_size(0), 
_buffer_size(buffer_size) {
+        _buffer.resize(_buffer_size, 'x');
+    }
+
+    // 生成特定大小的数据,作为静态函数
+    static std::string generate_fixed_size_data(size_t size) {
+        return std::string(size, 'x'); // 生成指定大小的 'x' 字符串
+    }
+
+    // 获取下一块数据
+    doris::Slice next_chunk() {
+        if (_generated_size >= _total_size) {
+            return doris::Slice(); // 返回空slice表示结束
+        }
+
+        size_t remaining = _total_size - _generated_size;
+        size_t chunk_size = std::min(remaining, _buffer_size);
+        _generated_size += chunk_size;
+
+        return doris::Slice(_buffer.data(), chunk_size);
+    }
+
+    // 重置生成器
+    void reset() { _generated_size = 0; }
+
+    // 检查是否还有更多数据
+    bool has_more() const { return _generated_size < _total_size; }
+
+    // 获取总大小
+    size_t total_size() const { return _total_size; }
+
+private:
+    const size_t _total_size;
+    size_t _generated_size;
+    const size_t _buffer_size;
+    std::string _buffer;
+};
+
+// IOPS 统计器
+class IopsStats {

Review Comment:
   use bvar



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to