From 29521c3a77e0c44318da8901594dd0f9e96e2299 Mon Sep 17 00:00:00 2001 From: Braden Ganetsky Date: Sat, 11 May 2024 11:28:06 -0500 Subject: [PATCH 1/8] Create natvis file and update CMakeLists.txt --- CMakeLists.txt | 9 +++++++++ extra/boost_unordered.natvis | 10 ++++++++++ 2 files changed, 19 insertions(+) create mode 100644 extra/boost_unordered.natvis diff --git a/CMakeLists.txt b/CMakeLists.txt index b8f2a176..9bcd6769 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,15 @@ target_link_libraries(boost_unordered Boost::throw_exception ) +if(CMAKE_VERSION VERSION_GREATER 3.18 AND CMAKE_GENERATOR MATCHES "Visual Studio") + + file(GLOB_RECURSE boost_unordered_IDEFILES CONFIGURE_DEPENDS include/*.hpp) + source_group(TREE ${PROJECT_SOURCE_DIR}/include FILES ${boost_unordered_IDEFILES} PREFIX "Header Files") + list(APPEND boost_unordered_IDEFILES extra/boost_unordered.natvis) + target_sources(boost_unordered PRIVATE ${boost_unordered_IDEFILES}) + +endif() + target_compile_features(boost_unordered INTERFACE cxx_std_11) if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt") diff --git a/extra/boost_unordered.natvis b/extra/boost_unordered.natvis new file mode 100644 index 00000000..befb2355 --- /dev/null +++ b/extra/boost_unordered.natvis @@ -0,0 +1,10 @@ + + + + + + From 485101db9ba384430db49f44f11d639e088388f2 Mon Sep 17 00:00:00 2001 From: Braden Ganetsky Date: Fri, 31 May 2024 23:51:30 -0500 Subject: [PATCH 2/8] Write natvis for fca containers --- extra/boost_unordered.natvis | 88 ++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/extra/boost_unordered.natvis b/extra/boost_unordered.natvis index befb2355..344ab554 100644 --- a/extra/boost_unordered.natvis +++ b/extra/boost_unordered.natvis @@ -7,4 +7,92 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + + + + + + + + + + + + + + + + hash(active_idx()) + key_eq(active_idx()) + hash(spare_idx()) + key_eq(spare_idx()) + + + + + + + + + + + + current_bucket = &buckets[bucket_index] + node = current_bucket->next + + node->buf.t_ + node = node->next + + ++bucket_index + + + + + + + + + + + + + + current_bucket = &buckets[bucket_index] + node = current_bucket->next + + node->buf.t_ + node = node->next + + ++bucket_index + + + + + + + + + + {{ size={table_.size_} }} + + table_.buckets_.size_ + table_.mlf_ + *reinterpret_cast<table::functions*>(&table_) + *reinterpret_cast<table::bucket_array_type::node_allocator_type*>(&table_.buckets_) + table_.buckets_ + + + + + + {{ size={table_.size_} }} + + table_.buckets_.size_ + table_.mlf_ + *reinterpret_cast<table::functions*>(&table_) + *reinterpret_cast<table::bucket_array_type::node_allocator_type*>(&table_.buckets_) + table_.buckets_,view(MapHelper) + + + From 27ead86b360068c6473d9ee520c9c80983a2a477 Mon Sep 17 00:00:00 2001 From: Braden Ganetsky Date: Fri, 31 May 2024 23:51:31 -0500 Subject: [PATCH 3/8] Write natvis for fca iterators --- extra/boost_unordered.natvis | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/extra/boost_unordered.natvis b/extra/boost_unordered.natvis index 344ab554..308e2565 100644 --- a/extra/boost_unordered.natvis +++ b/extra/boost_unordered.natvis @@ -95,4 +95,16 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + + + + + + {p->buf.t_} + {{ end iterator }} + + p->buf.t_ + + + From 763a8629284bb4f3e9809640874ebac078cbe7ed Mon Sep 17 00:00:00 2001 From: Braden Ganetsky Date: Fri, 31 May 2024 23:51:31 -0500 Subject: [PATCH 4/8] Write natvis for foa and cfoa helpers --- extra/boost_unordered.natvis | 52 ++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/extra/boost_unordered.natvis b/extra/boost_unordered.natvis index 308e2565..02b85421 100644 --- a/extra/boost_unordered.natvis +++ b/extra/boost_unordered.natvis @@ -107,4 +107,56 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + + + + {*p} + + *p + + + + + + ({p->first}, {p->second}) + + p->first + p->second + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 0a66c687fdad0d214f29570672986c2fa6654cc7 Mon Sep 17 00:00:00 2001 From: Braden Ganetsky Date: Sat, 1 Jun 2024 09:26:37 -0500 Subject: [PATCH 5/8] Write natvis for foa and cfoa containers --- extra/boost_unordered.natvis | 142 ++++++++++++++++++++ include/boost/unordered/detail/foa/core.hpp | 6 + 2 files changed, 148 insertions(+) diff --git a/extra/boost_unordered.natvis b/extra/boost_unordered.natvis index 02b85421..b00f49bb 100644 --- a/extra/boost_unordered.natvis +++ b/extra/boost_unordered.natvis @@ -159,4 +159,146 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + *p_ + + first_time = false + + n0 = reinterpret_cast<uintptr_t>(pc_) % sizeof(group_type) + pc_ -= (ptrdiff_t)n0 + + mask = (reinterpret_cast<group_type*>(pc_)->match_occupied() >> (n0+1)) << (n0+1) + + pc_ += sizeof(group_type) + p_ += group_type::N + mask = reinterpret_cast<group_type*>(pc_)->match_occupied() + + + n = countr_zero(mask) + + p_ = nullptr + + + pc_ += (ptrdiff_t)n + p_ -= (ptrdiff_t)n0 + p_ += (ptrdiff_t)n + + + + + + + + + + + + + + + + + + + + + + + *p_ + + first_time = false + + n0 = reinterpret_cast<uintptr_t>(pc_) % sizeof(group_type) + pc_ -= (ptrdiff_t)n0 + + mask = (reinterpret_cast<group_type*>(pc_)->match_occupied() >> (n0+1)) << (n0+1) + + pc_ += sizeof(group_type) + p_ += group_type::N + mask = reinterpret_cast<group_type*>(pc_)->match_occupied() + + + n = countr_zero(mask) + + p_ = nullptr + + + pc_ += (ptrdiff_t)n + p_ -= (ptrdiff_t)n0 + p_ += (ptrdiff_t)n + + + + + + + + + + + + + + {{ size={table_.size_ctrl.size} }} + + *reinterpret_cast<hasher*>(static_cast<table_type::super::base1*>(&table_)) + *reinterpret_cast<key_equal*>(static_cast<table_type::super::base2*>(&table_)) + *reinterpret_cast<allocator_type*>(static_cast<table_type::super::base3*>(&table_)) + table_ + + + + + + + {{ size={table_.size_ctrl.size} }} + + *reinterpret_cast<hasher*>(static_cast<table_type::super::base1*>(&table_)) + *reinterpret_cast<key_equal*>(static_cast<table_type::super::base2*>(&table_)) + *reinterpret_cast<allocator_type*>(static_cast<table_type::super::base3*>(&table_)) + table_,view(MapHelper) + + + diff --git a/include/boost/unordered/detail/foa/core.hpp b/include/boost/unordered/detail/foa/core.hpp index db73a866..513b433d 100644 --- a/include/boost/unordered/detail/foa/core.hpp +++ b/include/boost/unordered/detail/foa/core.hpp @@ -1413,6 +1413,12 @@ __declspec(empty_bases) /* activate EBO with multiple inheritance */ table_core:empty_value,empty_value,empty_value { +private: + // These `baseN` aliases are for debugger visualizations, like natvis + using base1=empty_value; + using base2=empty_value; + using base3=empty_value; + public: using type_policy=TypePolicy; using group_type=Group; From 901f0a29b8d55b713c9b55105018e64d9ce64df6 Mon Sep 17 00:00:00 2001 From: Braden Ganetsky Date: Fri, 31 May 2024 23:51:32 -0500 Subject: [PATCH 6/8] Write natvis for foa iterators --- extra/boost_unordered.natvis | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/extra/boost_unordered.natvis b/extra/boost_unordered.natvis index b00f49bb..e0f5bc46 100644 --- a/extra/boost_unordered.natvis +++ b/extra/boost_unordered.natvis @@ -301,4 +301,15 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + + + + + {*p_} + {{ end iterator }} + + *p_ + + + From 317d4aa06023c4ecb4b8ba27c6601ab727bb73d5 Mon Sep 17 00:00:00 2001 From: Braden Ganetsky Date: Fri, 31 May 2024 23:51:33 -0500 Subject: [PATCH 7/8] Write release notes and documentation for natvis --- doc/unordered.adoc | 1 + doc/unordered/changes.adoc | 1 + doc/unordered/debuggability.adoc | 16 ++++++++++++++++ 3 files changed, 18 insertions(+) create mode 100644 doc/unordered/debuggability.adoc diff --git a/doc/unordered.adoc b/doc/unordered.adoc index 1febb283..8f339623 100644 --- a/doc/unordered.adoc +++ b/doc/unordered.adoc @@ -18,6 +18,7 @@ include::unordered/concurrent.adoc[] include::unordered/hash_quality.adoc[] include::unordered/compliance.adoc[] include::unordered/structures.adoc[] +include::unordered/debuggability.adoc[] include::unordered/benchmarks.adoc[] include::unordered/rationale.adoc[] include::unordered/ref.adoc[] diff --git a/doc/unordered/changes.adoc b/doc/unordered/changes.adoc index 56a2dd4c..ffdaf242 100644 --- a/doc/unordered/changes.adoc +++ b/doc/unordered/changes.adoc @@ -11,6 +11,7 @@ * Added container `pmr` aliases when header `` is available. The alias `boost::unordered::pmr::[container]` refers to `boost::unordered::[container]` with a `std::pmr::polymorphic_allocator` allocator type. * Equipped open-addressing and concurrent containers to internally calculate and provide statistical metrics affected by the quality of the hash function. This functionality is enabled by the global macro `BOOST_UNORDERED_ENABLE_STATS`. * Avalanching hash functions must now be marked via an `is_avalanching` typedef with an embedded `value` constant set to `true` (typically, defining `is_avalanching` as `std::true_type`). `using is_avalanching = void` is deprecated but allowed for backwards compatibility. +* Added Visual Studio Natvis framework custom visualizations for containers and iterators. This works for all containers with an allocator using raw pointers. In this release, containers and iterators are not supported if their allocator uses fancy pointers. This may be addressed in later releases. == Release 1.85.0 diff --git a/doc/unordered/debuggability.adoc b/doc/unordered/debuggability.adoc new file mode 100644 index 00000000..cd40e498 --- /dev/null +++ b/doc/unordered/debuggability.adoc @@ -0,0 +1,16 @@ +[#debuggability] +:idprefix: debuggability_ + += Debuggability + +== Visual Studio Natvis + +All containers and iterators have custom visualizations in the Natvis framework, as long as their allocator uses regular raw pointers. Any container or iterator with an allocator using fancy pointers does not have a custom visualization right now. + +The visualizations mirror those for the standard unordered containers. A container has a maximum of 100 elements displayed at once. Each set element has its item name listed as `[i]`, where `i` is the index in the display, starting at `0`. Each map element has its item name listed as `[\{key-display}]` by default. For example, if the first element is the pair `("abc", 1)`, the item name will be `["abc"]`. This behaviour can be overridden by using the view "ShowElementsByIndex", which switches the map display behaviour to name the elements by index. This same view name is used in the standard unordered containers. + +By default, the closed-addressing containers will show the `[hash_function]` and `[key_eq]`, the `[spare_hash_function]` and `[spare_key_eq]` if applicable, the `[allocator]`, and the elements. Using the view "detailed" adds the `[bucket_count]` and `[max_load_factor]`. Conversely, using the view "simple" shows only the elements, with no other items present. + +By default, the open-addressing containers will show the `[hash_function]`, `[key_eq]`, `[allocator]`, and the elements. Using the view "simple" shows only the elements, with no other items present. Both the SIMD and the non-SIMD implementations are viewable through the Natvis framework. + +Iterators are displayed similarly to their standard counterparts. An iterator is displayed as though it were the element that it points to. An end iterator is simply displayed as `\{ end iterator }`. From 39d86cb896cb4bb5e6a9edfe2a2ac83ca829cd60 Mon Sep 17 00:00:00 2001 From: Braden Ganetsky Date: Sun, 2 Jun 2024 11:27:15 -0500 Subject: [PATCH 8/8] Display foa stats in natvis if applicable --- extra/boost_unordered.natvis | 69 ++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/extra/boost_unordered.natvis b/extra/boost_unordered.natvis index e0f5bc46..d4dbc186 100644 --- a/extra/boost_unordered.natvis +++ b/extra/boost_unordered.natvis @@ -8,7 +8,7 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - + @@ -20,7 +20,7 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - + hash(active_idx()) key_eq(active_idx()) @@ -159,6 +159,69 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + + + + stats + + insertion + successful_lookup + unsuccessful_lookup + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {{ count = {n} }} + + n + + {{ average = {average(0)} }} + + average(0) + variance(0) + deviation(0) + + + + {{ average = {average(1)} }} + + average(1) + variance(1) + deviation(1) + + + + + @@ -189,6 +252,7 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + cstats @@ -233,6 +297,7 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + cstats