-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
207 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
// 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. | ||
|
||
#pragma once | ||
|
||
#include <bvar/bvar.h> | ||
#include <stdint.h> | ||
|
||
namespace doris { | ||
|
||
inline bvar::Adder<int64_t> g_total_rowset_meta_mem_size("doris_total_rowset_meta_mem_size"); | ||
inline bvar::Adder<int64_t> g_total_rowset_meta_num("doris_total_rowset_meta_num"); | ||
|
||
inline bvar::Adder<int64_t> g_total_tablet_meta_mem_size("doris_total_tablet_meta_mem_size"); | ||
inline bvar::Adder<int64_t> g_total_tablet_meta_num("doris_total_tablet_meta_num"); | ||
|
||
inline bvar::Adder<int64_t> g_total_tablet_column_mem_size("doris_total_tablet_column_mem_size"); | ||
inline bvar::Adder<int64_t> g_total_tablet_column_num("doris_total_tablet_column_num"); | ||
|
||
inline bvar::Adder<int64_t> g_total_tablet_index_mem_size("doris_total_tablet_index_mem_size"); | ||
inline bvar::Adder<int64_t> g_total_tablet_index_num("doris_total_tablet_index_num"); | ||
|
||
inline bvar::Adder<int64_t> g_total_tablet_schema_mem_size("doris_total_tablet_schema_mem_size"); | ||
inline bvar::Adder<int64_t> g_total_tablet_schema_num("doris_total_tablet_schema_num"); | ||
|
||
inline bvar::Adder<int64_t> g_total_segment_mem_size("doris_total_segment_mem_size"); | ||
inline bvar::Adder<int64_t> g_total_segment_num("doris_total_segment_num"); | ||
|
||
inline bvar::Adder<int64_t> g_total_column_reader_mem_size("doris_total_column_reader_mem_size"); | ||
inline bvar::Adder<int64_t> g_total_column_reader_num("doris_total_column_reader_num"); | ||
|
||
class RowsetMeta; | ||
class TabletMeta; | ||
class TabletColumn; | ||
class TabletIndex; | ||
class TabletSchema; | ||
|
||
namespace segment_v2 { | ||
class Segment; | ||
class ColumnReader; | ||
}; // namespace segment_v2 | ||
|
||
/* | ||
When a derived Class extends MetadataAdder, then the Class's number and fixed length field's memory can be counted automatically. | ||
But if the Class has variable length field, then you should overwrite get_metadata_size and call update_metadata_size when the Class's memory changes. | ||
There are some special situations that need to be noted: | ||
1. when the derived Class override copy constructor, you'd better update memory size(call update_metadata_size) if derived class's | ||
memory changed in its copy constructor or you not call MetadataAdder's copy constructor. | ||
2. when the derived Class override operator=, you'd better update memory size(call update_metadata_size) if the derived Class has variable length field; | ||
Anyway, you should update mem size whenever derived Class's memory changes. | ||
*/ | ||
|
||
template <typename T> | ||
class MetadataAdder { | ||
private: | ||
int64_t _current_meta_size {0}; | ||
|
||
void add_mem_size(int64_t val); | ||
|
||
void add_num(int64_t val); | ||
|
||
protected: | ||
virtual ~MetadataAdder(); | ||
|
||
virtual int64_t get_metadata_size() { return sizeof(T); } | ||
|
||
MetadataAdder(const MetadataAdder& other); | ||
|
||
void update_metadata_size(); | ||
|
||
public: | ||
MetadataAdder(); | ||
}; | ||
|
||
template <typename T> | ||
MetadataAdder<T>::MetadataAdder(const MetadataAdder<T>& other) { | ||
this->_current_meta_size = other._current_meta_size; | ||
add_num(1); | ||
add_mem_size(this->_current_meta_size); | ||
} | ||
|
||
template <typename T> | ||
MetadataAdder<T>::MetadataAdder() { | ||
this->_current_meta_size = sizeof(T); | ||
add_mem_size(this->_current_meta_size); | ||
add_num(1); | ||
} | ||
|
||
template <typename T> | ||
MetadataAdder<T>::~MetadataAdder() { | ||
add_mem_size(-_current_meta_size); | ||
add_num(-1); | ||
} | ||
|
||
template <typename T> | ||
void MetadataAdder<T>::update_metadata_size() { | ||
int64_t old_size = _current_meta_size; | ||
_current_meta_size = get_metadata_size(); | ||
int64_t size_diff = _current_meta_size - old_size; | ||
|
||
add_mem_size(size_diff); | ||
} | ||
|
||
template <typename T> | ||
void MetadataAdder<T>::add_mem_size(int64_t val) { | ||
if (val == 0) { | ||
return; | ||
} | ||
if constexpr (std::is_same_v<T, RowsetMeta>) { | ||
g_total_rowset_meta_mem_size << val; | ||
} else if constexpr (std::is_same_v<T, TabletMeta>) { | ||
g_total_tablet_meta_mem_size << val; | ||
} else if constexpr (std::is_same_v<T, TabletColumn>) { | ||
g_total_tablet_column_mem_size << val; | ||
} else if constexpr (std::is_same_v<T, TabletIndex>) { | ||
g_total_tablet_index_mem_size << val; | ||
} else if constexpr (std::is_same_v<T, TabletSchema>) { | ||
g_total_tablet_schema_mem_size << val; | ||
} else if constexpr (std::is_same_v<T, segment_v2::Segment>) { | ||
g_total_segment_mem_size << val; | ||
} else if constexpr (std::is_same_v<T, segment_v2::ColumnReader>) { | ||
g_total_column_reader_mem_size << val; | ||
} | ||
} | ||
|
||
template <typename T> | ||
void MetadataAdder<T>::add_num(int64_t val) { | ||
if (val == 0) { | ||
return; | ||
} | ||
if constexpr (std::is_same_v<T, RowsetMeta>) { | ||
g_total_rowset_meta_num << val; | ||
} else if constexpr (std::is_same_v<T, TabletMeta>) { | ||
g_total_tablet_meta_num << val; | ||
} else if constexpr (std::is_same_v<T, TabletColumn>) { | ||
g_total_tablet_column_num << val; | ||
} else if constexpr (std::is_same_v<T, TabletIndex>) { | ||
g_total_tablet_index_num << val; | ||
} else if constexpr (std::is_same_v<T, TabletSchema>) { | ||
g_total_tablet_schema_num << val; | ||
} else if constexpr (std::is_same_v<T, segment_v2::Segment>) { | ||
g_total_segment_num << val; | ||
} else if constexpr (std::is_same_v<T, segment_v2::ColumnReader>) { | ||
g_total_column_reader_num << val; | ||
} | ||
} | ||
|
||
}; // namespace doris |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.