diff --git a/deps/oblib/src/lib/utility/ob_print_utils.h b/deps/oblib/src/lib/utility/ob_print_utils.h index 239b0609c..8117a169a 100644 --- a/deps/oblib/src/lib/utility/ob_print_utils.h +++ b/deps/oblib/src/lib/utility/ob_print_utils.h @@ -147,11 +147,11 @@ public: class CStringBufMgr { public: - static const int BUF_SIZE = 8 * 1024; - static const int MIN_REST_SIZE = 1024; + static const int BUF_SIZE = 32 * 1024; + static const int MIN_SIZE = 12 * 1024; struct BufNode { - char buf_[BUF_SIZE]; + char buf_[MIN_SIZE]; int64_t level_; struct BufNode *next_; }; @@ -169,17 +169,19 @@ public: } void inc_level() { level_++; } void dec_level() { level_--; } - int64_t get_pos() { return pos_; } - void set_pos(int64_t pos) + void update_position(int64_t pos) { if (0 == level_) { - if (MIN_REST_SIZE > BUF_SIZE - pos) { + pos_ += pos; + if (MIN_SIZE > BUF_SIZE - pos_) { pos_ = 0; - } else { - pos_ = pos; } } } + int64_t get_buffer_len() + { + return 0 == level_ ? (BUF_SIZE - pos_) : MIN_SIZE; + } char *acquire() { char *buffer = NULL; @@ -235,15 +237,14 @@ const char *to_cstring(const T &obj, const bool verbose) if (OB_ISNULL(buffer)) { LIB_LOG_RET(ERROR, OB_ALLOCATE_MEMORY_FAILED, "buffer is NULL"); } else { - int64_t pos = mgr.get_pos(); - const int64_t buf_len = CStringBufMgr::BUF_SIZE - pos; + const int64_t buf_len = mgr.get_buffer_len(); str_len = obj.to_string(buffer, buf_len -1, verbose); if (str_len >= 0 && str_len < buf_len) { buffer[str_len] = '\0'; } else { buffer[0] = '\0'; } - mgr.set_pos(pos + str_len + 1); + mgr.update_position(str_len + 1); } mgr.try_clear_list(); mgr.dec_level(); @@ -261,15 +262,14 @@ const char *to_cstring(const T &obj, FalseType) if (OB_ISNULL(buffer)) { LIB_LOG_RET(ERROR, OB_ALLOCATE_MEMORY_FAILED, "buffer is NULL"); } else { - int64_t pos = mgr.get_pos(); - const int64_t buf_len = CStringBufMgr::BUF_SIZE - pos; + const int64_t buf_len = mgr.get_buffer_len(); str_len = to_string(obj, buffer, buf_len -1); if (str_len >= 0 && str_len < buf_len) { buffer[str_len] = '\0'; } else { buffer[0] = '\0'; } - mgr.set_pos(pos + str_len + 1); + mgr.update_position(str_len + 1); } mgr.try_clear_list(); mgr.dec_level(); diff --git a/deps/oblib/unittest/lib/utility/test_print_utils.cpp b/deps/oblib/unittest/lib/utility/test_print_utils.cpp index ebbce9f27..f5d4823cc 100644 --- a/deps/oblib/unittest/lib/utility/test_print_utils.cpp +++ b/deps/oblib/unittest/lib/utility/test_print_utils.cpp @@ -108,18 +108,12 @@ TEST(print_utility, to_cstring) to_cstring(*tuples[0]), to_cstring(*tuples[1]), to_cstring(*tuples[2])); _OB_LOG(INFO, "print tuple string, {%s}, {%s}, {%s}, {%s}, {%s}, {%s}, {%s}", to_cstring(*tuples[3]), to_cstring(*tuples[4]), to_cstring(*tuples[5]), to_cstring(*tuples[6]), to_cstring(*tuples[7]), to_cstring(*tuples[8]), to_cstring(*tuples[9])); - for (int i = 0; i < 10; ++i) { - int64_t pos = CStringBufMgr::get_thread_local_instance().get_pos(); - _OB_LOG(INFO, "print tuple string, pos = %ld\n", pos); - to_cstring(*tuples[0]); - } // the performance of to_cstring when observer reach memory limit EventItem item; item.trigger_freq_ = 1; item.error_code_ = OB_ALLOCATE_MEMORY_FAILED; ::oceanbase::common::EventTable::instance().set_event(EventTable::EN_4, item); - int64_t pos = CStringBufMgr::get_thread_local_instance().get_pos(); - _OB_LOG(INFO, "print tuple string, {%s}, pos = %ld\n", to_cstring(*tuples[0]), pos); + _OB_LOG(INFO, "print tuple string, {%s}\n", to_cstring(*tuples[0])); } int main(int argc, char **argv) diff --git a/src/sql/engine/expr/ob_expr.h b/src/sql/engine/expr/ob_expr.h index 46bc84116..3b4b6b84f 100644 --- a/src/sql/engine/expr/ob_expr.h +++ b/src/sql/engine/expr/ob_expr.h @@ -1120,8 +1120,7 @@ inline const char *get_vectorized_row_str(ObEvalCtx &eval_ctx, if (OB_ISNULL(buffer)) { LIB_LOG_RET(ERROR, OB_ALLOCATE_MEMORY_FAILED, "buffer is NULL"); } else { - int64_t pos = mgr.get_pos(); - const int64_t buf_len = CStringBufMgr::BUF_SIZE - pos; + const int64_t buf_len = mgr.get_buffer_len(); databuff_printf(buffer, buf_len, str_len, "vectorized_rows(%ld)=", index); str_len += to_string(ROWEXPR2STR(eval_ctx, exprs), buffer + str_len, buf_len - str_len - 1); if (str_len >= 0 && str_len < buf_len) { @@ -1129,6 +1128,7 @@ inline const char *get_vectorized_row_str(ObEvalCtx &eval_ctx, } else { buffer[0] = '\0'; } + mgr.update_position(str_len + 1); } mgr.try_clear_list(); mgr.dec_level();