Fix BufferSlice size statistics.

GitOrigin-RevId: 2dcfeb4981435b93106df5817c849df8a94ba14f
This commit is contained in:
levlam 2020-08-05 03:21:10 +03:00
parent 8ac59dc77d
commit 4455b66e8b
2 changed files with 13 additions and 2 deletions

View File

@ -147,10 +147,10 @@ class BufferSlice {
debug_untrack();
}
void debug_track() {
void debug_track() const {
BufferAllocator::track_buffer_slice(static_cast<int64>(size()));
}
void debug_untrack() {
void debug_untrack() const {
BufferAllocator::track_buffer_slice(-static_cast<int64>(size()));
}
@ -214,6 +214,7 @@ class BufferSlice {
BufferSlice from_slice(Slice slice) const {
auto res = BufferSlice(BufferAllocator::create_reader(buffer_));
res.debug_untrack();
res.begin_ = static_cast<size_t>(slice.ubegin() - buffer_->data_);
res.end_ = static_cast<size_t>(slice.uend() - buffer_->data_);
res.debug_track();

View File

@ -134,6 +134,16 @@ TEST(Http, reader) {
SET_VERBOSITY_LEVEL(VERBOSITY_NAME(ERROR));
auto start_mem = BufferAllocator::get_buffer_mem();
auto start_size = BufferAllocator::get_buffer_slice_size();
{
BufferSlice a("test test");
BufferSlice b = std::move(a);
a = std::move(b);
BufferSlice c = a.from_slice(a);
CHECK(c.size() == a.size());
}
clear_thread_locals();
ASSERT_EQ(start_mem, BufferAllocator::get_buffer_mem());
ASSERT_EQ(start_size, BufferAllocator::get_buffer_slice_size());
for (int i = 0; i < 20; i++) {
td::ChainBufferWriter input_writer;
auto input = input_writer.extract_reader();