summaryrefslogtreecommitdiff
path: root/absl/container/sample_element_size_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'absl/container/sample_element_size_test.cc')
-rw-r--r--absl/container/sample_element_size_test.cc31
1 files changed, 20 insertions, 11 deletions
diff --git a/absl/container/sample_element_size_test.cc b/absl/container/sample_element_size_test.cc
index b23626b4..22470b49 100644
--- a/absl/container/sample_element_size_test.cc
+++ b/absl/container/sample_element_size_test.cc
@@ -12,6 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#include <cstddef>
+#include <unordered_set>
+#include <utility>
+#include <vector>
+
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/container/flat_hash_map.h"
@@ -38,15 +43,16 @@ void TestInlineElementSize(
// set cannot be flat_hash_set, however, since that would introduce a mutex
// deadlock.
std::unordered_set<const HashtablezInfo*>& preexisting_info, // NOLINT
- std::vector<Table>& tables, const typename Table::value_type& elt,
+ std::vector<Table>& tables,
+ const std::vector<typename Table::value_type>& values,
size_t expected_element_size) {
for (int i = 0; i < 10; ++i) {
// We create a new table and must store it somewhere so that when we store
// a pointer to the resulting `HashtablezInfo` into `preexisting_info`
// that we aren't storing a dangling pointer.
tables.emplace_back();
- // We must insert an element to get a hashtablez to instantiate.
- tables.back().insert(elt);
+ // We must insert elements to get a hashtablez to instantiate.
+ tables.back().insert(values.begin(), values.end());
}
size_t new_count = 0;
sampler.Iterate([&](const HashtablezInfo& info) {
@@ -82,6 +88,9 @@ TEST(FlatHashMap, SampleElementSize) {
std::vector<flat_hash_set<bigstruct>> flat_set_tables;
std::vector<node_hash_map<int, bigstruct>> node_map_tables;
std::vector<node_hash_set<bigstruct>> node_set_tables;
+ std::vector<bigstruct> set_values = {bigstruct{{0}}, bigstruct{{1}}};
+ std::vector<std::pair<const int, bigstruct>> map_values = {{0, bigstruct{}},
+ {1, bigstruct{}}};
// It takes thousands of new tables after changing the sampling parameters
// before you actually get some instrumentation. And if you must actually
@@ -97,14 +106,14 @@ TEST(FlatHashMap, SampleElementSize) {
std::unordered_set<const HashtablezInfo*> preexisting_info; // NOLINT
sampler.Iterate(
[&](const HashtablezInfo& info) { preexisting_info.insert(&info); });
- TestInlineElementSize(sampler, preexisting_info, flat_map_tables,
- {0, bigstruct{}}, sizeof(int) + sizeof(bigstruct));
- TestInlineElementSize(sampler, preexisting_info, node_map_tables,
- {0, bigstruct{}}, sizeof(void*));
- TestInlineElementSize(sampler, preexisting_info, flat_set_tables, //
- bigstruct{}, sizeof(bigstruct));
- TestInlineElementSize(sampler, preexisting_info, node_set_tables, //
- bigstruct{}, sizeof(void*));
+ TestInlineElementSize(sampler, preexisting_info, flat_map_tables, map_values,
+ sizeof(int) + sizeof(bigstruct));
+ TestInlineElementSize(sampler, preexisting_info, node_map_tables, map_values,
+ sizeof(void*));
+ TestInlineElementSize(sampler, preexisting_info, flat_set_tables, set_values,
+ sizeof(bigstruct));
+ TestInlineElementSize(sampler, preexisting_info, node_set_tables, set_values,
+ sizeof(void*));
#endif
}