Skip to content

Commit 7b5baca

Browse files
ttreyerJakeHillion
authored andcommitted
Fix exclusive_size for F14FastMap
1 parent 9ce7bd5 commit 7b5baca

File tree

2 files changed

+46
-17
lines changed

2 files changed

+46
-17
lines changed

test/integration/folly_f14_fast_map.toml

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ definitions = '''
88
folly::F14FastMap<int, int> m1;
99
folly::F14FastMap<int, Bar> m2;
1010
folly::F14FastMap<int, int> m3;
11-
folly::F14FastMap<int, int> m4;
11+
folly::F14FastMap<int, long> m4;
1212
};
1313
'''
1414

@@ -42,7 +42,7 @@ definitions = '''
4242
'''
4343
expect_json = '''[{
4444
"staticSize":96,
45-
"dynamicSize":304,
45+
"dynamicSize":368,
4646
"members":[
4747
{"name":"m1", "staticSize":24, "dynamicSize":48, "length":3, "capacity":3, "elementStaticSize":8},
4848
{
@@ -65,14 +65,31 @@ definitions = '''
6565
{"staticSize":8, "members":[{"name":"a"}, {"name": "b"}]}
6666
]},
6767
{"name":"m3", "staticSize":24, "dynamicSize":80, "length":7, "capacity":7, "elementStaticSize":8},
68-
{"name":"m4", "staticSize":24, "dynamicSize":96, "length":9, "capacity":9, "elementStaticSize":8}
68+
{"name":"m4", "staticSize":24, "dynamicSize":160, "length":9, "capacity":9, "elementStaticSize":12}
6969
]}]'''
7070
expect_json_v2 = '''[{
7171
"staticSize":96,
7272
"exclusiveSize": 0,
7373
"members":[
74-
{"name":"m1", "staticSize":24, "exclusiveSize": 24, "length": 3, "capacity": 3},
75-
{"name":"m2", "staticSize":24, "exclusiveSize": 24, "length": 5, "capacity": 5},
76-
{"name":"m3", "staticSize":24, "exclusiveSize": 24, "length": 7, "capacity": 7},
77-
{"name":"m4", "staticSize":24, "exclusiveSize": 24, "length": 9, "capacity": 9}
78-
]}]'''
74+
{"name":"m1", "staticSize":24, "exclusiveSize": 48, "length": 3, "capacity": 3},
75+
{"name":"m2", "staticSize":24, "exclusiveSize": 44, "length": 5, "capacity": 5},
76+
{"name":"m3", "staticSize":24, "exclusiveSize": 48, "length": 7, "capacity": 7},
77+
{
78+
"name":"m4",
79+
"staticSize":24,
80+
"exclusiveSize": 40,
81+
"length": 9,
82+
"capacity": 9,
83+
"members":[
84+
{"staticSize":16, "exclusiveSize": 4},
85+
{"staticSize":16, "exclusiveSize": 4},
86+
{"staticSize":16, "exclusiveSize": 4},
87+
{"staticSize":16, "exclusiveSize": 4},
88+
{"staticSize":16, "exclusiveSize": 4},
89+
{"staticSize":16, "exclusiveSize": 4},
90+
{"staticSize":16, "exclusiveSize": 4},
91+
{"staticSize":16, "exclusiveSize": 4},
92+
{"staticSize":16, "exclusiveSize": 4}
93+
]
94+
}]
95+
}]'''

types/f14_fast_map.toml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,9 @@ struct TypeHandler<DB, %1%<T0, T1, T2, T3, T4>> {
7171
"""
7272

7373
traversal_func = """
74-
// TODO: This implementation enables the traversal of the container,
75-
// but doesn't report the memory footprint accurately.
76-
// Revisit this implementation and fix memory footprint reporting.
7774
auto tail = returnArg
78-
.write((uintptr_t)&container)
75+
.write((uintptr_t)container.getAllocatedMemorySize())
76+
.write((uintptr_t)container.bucket_count())
7977
.write(container.size());
8078
8179
for (auto &&entry: container) {
@@ -94,26 +92,40 @@ return tail.finish();
9492
type = "types::st::VarInt<DB>"
9593
func = "el.pointer = std::get<ParsedData::VarInt>(d.val).value;"
9694

95+
[[codegen.processor]]
96+
type = "types::st::VarInt<DB>"
97+
func = """
98+
el.container_stats.emplace(result::Element::ContainerStats {
99+
.capacity = std::get<ParsedData::VarInt>(d.val).value,
100+
});
101+
"""
102+
97103
[[codegen.processor]]
98104
type = """
99105
types::st::List<DB, types::st::Pair<DB,
100106
typename TypeHandler<DB, T0>::type,
101107
typename TypeHandler<DB, T1>::type>>
102108
"""
103109
func = """
110+
static constexpr size_t element_size = sizeof(typename container_type::value_type);
111+
112+
auto allocationSize = el.pointer.value();
113+
el.pointer.reset();
114+
104115
auto list = std::get<ParsedData::List>(d.val);
105-
el.container_stats.emplace(result::Element::ContainerStats {
106-
.capacity = list.length,
107-
.length = list.length,
108-
});
116+
el.container_stats->length = list.length;
117+
118+
el.exclusive_size += allocationSize - list.length * element_size;
109119
110120
static constexpr std::array<inst::Field, 2> element_fields{
111121
make_field<DB, T0>("key"),
112122
make_field<DB, T1>("value"),
113123
};
114124
115125
static constexpr inst::Field element{
116-
0, 0, "[]",
126+
element_size,
127+
element_size - sizeof(T0) - sizeof(T1),
128+
"[]",
117129
std::array<std::string_view, 0>{},
118130
element_fields,
119131
std::array<inst::ProcessorInst, 0>{},

0 commit comments

Comments
 (0)