object-introspection/test/integration/templates.toml
Jake Hillion 71e734b120 tbv2: calculate total memory footprint
Add the option to calculate total size (inclusive size) by wrapping the
existing iterator. This change provides a new iterator, `SizedIterator`, which
wraps an existing iterator and adds a new field `size` to the output element.

This is achieved with a two pass algorithm on the existing iterator:
1. Gather metadata for each element. This includes the total size up until that
   element and the range of elements that should be included in the size.
2. Return the result from the underlying iterator with the additional
   field.

This algorithm is `O(N)` time on the number of elements in the iterator and
`O(N)` time, storing 16 bytes per element. This isn't super expensive but is a
lot more than the current algorithm which requires close to constant space.
Because of this I've implemented it as a wrapper on the iterator rather than on
by default, though it is now on in every one of our integration test cases.

Test plan:
- Added to the integration tests for full coverage.
2024-01-04 09:21:35 +00:00

103 lines
2.7 KiB
TOML

includes = ["vector"]
definitions = '''
template <typename T>
class TemplatedClass1 {
T val;
};
template <typename T, typename S>
class TemplatedClass2 {
TemplatedClass1<T> tc1;
S val2;
};
struct Foo {
int a;
int b;
};
template <int N>
struct TemplatedClassVal {
int arr[N];
};
'''
[cases]
[cases.int]
oil_skip = "primitives are named differently in treebuilderv2" # https://github.com/facebookexperimental/object-introspection/issues/286
param_types = ["const TemplatedClass1<int>&"]
setup = "return {};"
expect_json = '''[{
"typeName":"ns_templates::TemplatedClass1<int>",
"staticSize":4,
"dynamicSize":0,
"members":[{
"typeName":"int32_t"
}]}]'''
[cases.vector]
param_types = ["const TemplatedClass1<std::vector<int>>&"]
setup = "return {};"
expect_json = '''[{
"typeName":"ns_templates::TemplatedClass1<std::vector<int, std::allocator<int> > >",
"staticSize":24,
"dynamicSize":0,
"members":[{
"typeName":"std::vector<int32_t, std::allocator<int32_t>>",
"staticSize":24,
"dynamicSize":0,
"length":0,
"capacity":0,
"elementStaticSize":4
}]}]'''
expect_json_v2 = '''[{
"typeName":"ns_templates::TemplatedClass1<std::vector<int, std::allocator<int> > >",
"staticSize":24,
"exclusiveSize":0,
"size":24,
"members":[{
"typeName":"std::vector<int32_t, std::allocator<int32_t>>",
"staticSize":24,
"exclusiveSize":24,
"size":24,
"length":0,
"capacity":0
}]}]'''
[cases.two]
oil_skip = "OIL returns better primitive names"
param_types = ["const TemplatedClass2<Foo, int>&"]
setup = "return {};"
expect_json = '''[{
"typeName":"ns_templates::TemplatedClass2<ns_templates::Foo, int>",
"staticSize":12,
"dynamicSize":0,
"members":[
{"typeName":"ns_templates::TemplatedClass1<ns_templates::Foo>", "staticSize":8, "dynamicSize":0},
{"typeName":"int32_t", "staticSize":4, "dynamicSize":0}
]}]'''
[cases.value]
param_types = ["const TemplatedClassVal<3>&"]
setup = "return {};"
expect_json = '''[{
"typeName":"ns_templates::TemplatedClassVal<3>",
"staticSize":12,
"dynamicSize":0,
"members":[{
"staticSize":12,
"dynamicSize":0,
"length":3,
"capacity":3,
"elementStaticSize":4
}]}]'''
expect_json_v2 = '''[{
"typeName":"ns_templates::TemplatedClassVal<3>",
"staticSize":12,
"exclusiveSize":0,
"size":12,
"members":[{
"staticSize":12,
"exclusiveSize":0,
"size":12,
"length":3,
"capacity":3
}]}]'''