yiguolei commented on code in PR #41429:
URL: https://github.com/apache/doris/pull/41429#discussion_r1796682723


##########
be/src/olap/metadata_adder.h:
##########
@@ -0,0 +1,225 @@
+// 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_rowset_meta_mem_bytes("doris_rowset_meta_mem_bytes");
+inline bvar::Adder<int64_t> g_rowset_meta_num("doris_rowset_meta_num");
+
+inline bvar::Adder<int64_t> 
g_tablet_meta_mem_bytes("doris_tablet_meta_mem_bytes");
+inline bvar::Adder<int64_t> g_tablet_meta_num("doris_tablet_meta_num");
+
+inline bvar::Adder<int64_t> 
g_tablet_column_mem_bytes("doris_tablet_column_mem_bytes");
+inline bvar::Adder<int64_t> g_tablet_column_num("doris_tablet_column_num");
+
+inline bvar::Adder<int64_t> 
g_tablet_index_mem_bytes("doris_tablet_index_mem_bytes");
+inline bvar::Adder<int64_t> g_tablet_index_num("doris_tablet_index_num");
+
+inline bvar::Adder<int64_t> 
g_tablet_schema_mem_bytes("doris_tablet_schema_mem_bytes");
+inline bvar::Adder<int64_t> g_tablet_schema_num("doris_tablet_schema_num");
+
+inline bvar::Adder<int64_t> g_segment_mem_bytes("doris_segment_mem_bytes");
+inline bvar::Adder<int64_t> g_segment_num("doris_segment_num");
+
+inline bvar::Adder<int64_t> 
g_column_reader_mem_bytes("doris_column_reader_mem_bytes");
+inline bvar::Adder<int64_t> g_column_reader_num("doris_column_reader_num");
+
+inline bvar::Adder<int64_t> 
g_bitmap_index_reader_mem_bytes("doris_bitmap_index_reader_mem_bytes");
+inline bvar::Adder<int64_t> 
g_bitmap_index_reader_num("doris_bitmap_index_reader_num");
+
+inline bvar::Adder<int64_t> g_bloom_filter_index_reader_mem_bytes(
+        "doris_bloom_filter_index_reader_mem_bytes");
+inline bvar::Adder<int64_t> 
g_bloom_filter_index_reader_num("doris_bloom_filter_index_reader_num");
+
+inline bvar::Adder<int64_t> 
g_index_page_reader_mem_bytes("doris_index_page_reader_mem_bytes");
+inline bvar::Adder<int64_t> 
g_index_page_reader_num("doris_index_page_reader_num");
+
+inline bvar::Adder<int64_t> g_indexed_column_reader_mem_bytes(
+        "doris_indexed_column_reader_mem_bytes");
+inline bvar::Adder<int64_t> 
g_indexed_column_reader_num("doris_indexed_column_reader_num");
+
+inline bvar::Adder<int64_t> g_inverted_index_reader_mem_bytes(
+        "doris_inverted_index_reader_mem_bytes");
+inline bvar::Adder<int64_t> 
g_inverted_index_reader_num("doris_inverted_index_reader_num");
+
+inline bvar::Adder<int64_t> g_ordinal_index_reader_mem_bytes(
+        "doris_ordinal_index_reader_mem_bytes");
+inline bvar::Adder<int64_t> 
g_ordinal_index_reader_num("doris_ordinal_index_reader_num");
+
+inline bvar::Adder<int64_t> g_zone_map_index_reader_mem_bytes(
+        "doris_zone_map_index_reader_mem_bytes");
+inline bvar::Adder<int64_t> 
g_zone_map_index_reader_num("doris_zone_map_index_reader_num");
+
+class RowsetMeta;
+class TabletMeta;
+class TabletColumn;
+class TabletIndex;
+class TabletSchema;
+
+namespace segment_v2 {
+class Segment;
+class ColumnReader;
+class BitmapIndexReader;
+class BloomFilterIndexReader;
+class IndexPageReader;
+class IndexedColumnReader;
+class InvertedIndexReader;
+class OrdinalIndexReader;
+class ZoneMapIndexReader;
+}; // 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);

Review Comment:
   move this method before virtual ~MetadataAdder();



-- 
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