This is an automated email from the ASF dual-hosted git repository.

gmurthy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git


The following commit(s) were added to refs/heads/main by this push:
     new 492cbfe  DISPATCH-1958: Removed the QD_MEMORY_STATS option. Added code 
to qdstat to prevent qdstat -m failure when talking to older routers with 
memory stats turned off
492cbfe is described below

commit 492cbfe59d73ca31435a0d7dc780529160d9d35c
Author: Ganesh Murthy <[email protected]>
AuthorDate: Tue Nov 2 11:27:22 2021 -0400

    DISPATCH-1958: Removed the QD_MEMORY_STATS option. Added code to qdstat to 
prevent qdstat -m failure when talking to older routers with memory stats 
turned off
---
 CMakeLists.txt               |  2 --
 README.adoc                  |  3 ---
 src/alloc_pool.c             | 23 +----------------------
 src/config.h.in              |  1 -
 tests/system_tests_qdstat.py |  6 ------
 tools/qdstat                 |  9 ++++++++-
 6 files changed, 9 insertions(+), 35 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index cdf8679..e76b7e7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -77,8 +77,6 @@ message(STATUS "Build type is 
\"${CMAKE_BUILD_TYPE}\"${has_debug_symbols}")
 # This is commonly needed so define it before we include anything else.
 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
 
-option(QD_MEMORY_STATS "Track memory pool usage statistics" ON)
-
 if(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
     option(QD_ENABLE_ASSERTIONS "Enable assertions" ON)
 else()
diff --git a/README.adoc b/README.adoc
index 22cc1a4..2e8e8f4 100644
--- a/README.adoc
+++ b/README.adoc
@@ -308,9 +308,6 @@ Other options include `Debug` (disables optimizations) and 
`Coverage`.
 |`-DQD_ENABLE_ASSERTIONS=`
 |Seting this to `ON` enables asserts irrespective of `CMAKE_BUILD_TYPE`.
 
-|`-DQD_MEMORY_STATS=`
-|Dispatch will track memory pool usage statistics if this is enabled.
-
 |`-DCONSOLE_INSTALL=`
 |Web console will not be built if this is set to `OFF`.
 
diff --git a/src/alloc_pool.c b/src/alloc_pool.c
index f6e21d9..4548a2e 100644
--- a/src/alloc_pool.c
+++ b/src/alloc_pool.c
@@ -88,7 +88,6 @@ DEQ_DECLARE(qd_alloc_type_t, qd_alloc_type_list_t);
 // -DQD_MEMORY_DEBUG=1 from RuntimeChecks.cmake and .travis.yml when doing
 // RUNTIME=asan testing
 //
-#if QD_MEMORY_STATS
 static const char *leaking_types[] = {
     "qd_hash_handle_t",       // DISPATCH-1696
 
@@ -114,7 +113,6 @@ static const char *leaking_types[] = {
     "qdr_delivery_ref_t", // DISPATCH-1702
 
     0};
-#endif
 
 //128 has been chosen because many CPUs arch use an
 //adjacent line prefetching optimization that load
@@ -290,10 +288,8 @@ static void qd_alloc_init(qd_alloc_type_desc_t *desc)
         init_stack(&desc->global_pool->free_list);
         desc->lock = sys_mutex();
         DEQ_INIT(desc->tpool_list);
-#if QD_MEMORY_STATS
         desc->stats = NEW(qd_alloc_stats_t);
         ZERO(desc->stats);
-#endif
 
         qd_alloc_type_t *type_item = NEW(qd_alloc_type_t);
         DEQ_ITEM_INIT(type_item);
@@ -306,6 +302,7 @@ static void qd_alloc_init(qd_alloc_type_desc_t *desc)
 
         desc->header  = PATTERN_FRONT;
         desc->trailer = PATTERN_BACK;
+
         qd_entity_cache_add(QD_ALLOCATOR_TYPE, type_item);
     }
 
@@ -375,10 +372,8 @@ void *qd_alloc(qd_alloc_type_desc_t *desc, qd_alloc_pool_t 
**tpool)
         const int moved = unordered_move_stack(&desc->global_pool->free_list, 
&pool->free_list,
                                                
desc->config->transfer_batch_size);
         assert(moved == desc->config->transfer_batch_size);
-#if QD_MEMORY_STATS
         desc->stats->batches_rebalanced_to_threads++;
         desc->stats->held_by_threads += moved;
-#endif
     } else {
         //
         // Allocate a full batch from the heap and put it on the thread list.
@@ -405,10 +400,8 @@ void *qd_alloc(qd_alloc_type_desc_t *desc, qd_alloc_pool_t 
**tpool)
             }
             item->sequence = 0;
             ASAN_POISON_MEMORY_REGION(&item[1], desc->total_size);
-#if QD_MEMORY_STATS
             desc->stats->held_by_threads++;
             desc->stats->total_alloc_from_heap++;
-#endif
         }
     }
     sys_mutex_unlock(desc->lock);
@@ -490,10 +483,8 @@ void qd_dealloc(qd_alloc_type_desc_t *desc, 
qd_alloc_pool_t **tpool, char *p)
     const int moved = unordered_move_stack(&pool->free_list, 
&desc->global_pool->free_list,
                                            desc->config->transfer_batch_size);
     assert(moved == desc->config->transfer_batch_size);
-#if QD_MEMORY_STATS
     desc->stats->batches_rebalanced_to_global++;
     desc->stats->held_by_threads -= moved;
-#endif
     //
     // If there's a global_free_list size limit, remove items until the limit 
is
     // not exceeded.
@@ -502,9 +493,7 @@ void qd_dealloc(qd_alloc_type_desc_t *desc, qd_alloc_pool_t 
**tpool, char *p)
         while (DEQ_SIZE(desc->global_pool->free_list) > 
desc->config->global_free_list_max) {
             item = pop_stack(&desc->global_pool->free_list);
             free(item);
-#if QD_MEMORY_STATS
             desc->stats->total_free_to_heap++;
-#endif
         }
     }
 
@@ -576,9 +565,7 @@ void qd_alloc_finalize(void)
         item = pop_stack(&desc->global_pool->free_list);
         while (item) {
             free(item);
-#if QD_MEMORY_STATS
             desc->stats->total_free_to_heap++;
-#endif
             item = pop_stack(&desc->global_pool->free_list);
         }
         free_stack_chunks(&desc->global_pool->free_list);
@@ -594,9 +581,7 @@ void qd_alloc_finalize(void)
             item = pop_stack(&tpool->free_list);
             while (item) {
                 free(item);
-#if QD_MEMORY_STATS
                 desc->stats->total_free_to_heap++;
-#endif
                 item = pop_stack(&tpool->free_list);
             }
             DEQ_REMOVE_HEAD(desc->tpool_list);
@@ -608,7 +593,6 @@ void qd_alloc_finalize(void)
         //
         // Check the stats for lost items
         //
-#if QD_MEMORY_STATS
         if (dump_file && desc->stats->total_free_to_heap < 
desc->stats->total_alloc_from_heap) {
             bool suppressed = false;
             for (int i = 0; leaking_types[i]; ++i) {
@@ -653,14 +637,11 @@ void qd_alloc_finalize(void)
             }
 #endif
         }
-#endif
 
         //
         // Reclaim the descriptor components
         //
-#if QD_MEMORY_STATS
         free(desc->stats);
-#endif
         sys_mutex_free(desc->lock);
         desc->lock = 0;
         desc->trailer = 0;
@@ -694,13 +675,11 @@ qd_error_t qd_entity_refresh_allocator(qd_entity_t* 
entity, void *impl) {
         qd_entity_set_long(entity, "transferBatchSize", 
alloc_type->desc->config->transfer_batch_size) == 0 &&
         qd_entity_set_long(entity, "localFreeListMax", 
alloc_type->desc->config->local_free_list_max) == 0 &&
         qd_entity_set_long(entity, "globalFreeListMax", 
alloc_type->desc->config->global_free_list_max) == 0
-#if QD_MEMORY_STATS
         && qd_entity_set_long(entity, "totalAllocFromHeap", 
alloc_type->desc->stats->total_alloc_from_heap) == 0 &&
         qd_entity_set_long(entity, "totalFreeToHeap", 
alloc_type->desc->stats->total_free_to_heap) == 0 &&
         qd_entity_set_long(entity, "heldByThreads", 
alloc_type->desc->stats->held_by_threads) == 0 &&
         qd_entity_set_long(entity, "batchesRebalancedToThreads", 
alloc_type->desc->stats->batches_rebalanced_to_threads) == 0 &&
         qd_entity_set_long(entity, "batchesRebalancedToGlobal", 
alloc_type->desc->stats->batches_rebalanced_to_global) == 0
-#endif
         )
         return QD_ERROR_NONE;
     return qd_error_code();
diff --git a/src/config.h.in b/src/config.h.in
index d162224..2183054 100644
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -21,6 +21,5 @@
 
 #define QPID_DISPATCH_VERSION "${QPID_DISPATCH_VERSION}"
 #define QPID_CONSOLE_STAND_ALONE_INSTALL_DIR 
"${CONSOLE_STAND_ALONE_INSTALL_DIR}"
-#cmakedefine01 QD_MEMORY_STATS
 #cmakedefine01 QD_HAVE_GETRLIMIT
 #endif // __src_config_h_in__
diff --git a/tests/system_tests_qdstat.py b/tests/system_tests_qdstat.py
index 87eef85..37170b8 100644
--- a/tests/system_tests_qdstat.py
+++ b/tests/system_tests_qdstat.py
@@ -243,9 +243,6 @@ class QdstatTest(QdstatTestBase):
 
     def test_memory(self):
         out = self.run_qdstat(['--memory'])
-        if out.strip() == "No memory statistics available":
-            # router built w/o memory pools enabled]
-            return self.skipTest("Router's memory pools disabled")
         self.assertIn("QDR.A", out)
         self.assertIn("UTC", out)
         regexp = r'qdr_address_t\s+[0-9]+'
@@ -253,9 +250,6 @@ class QdstatTest(QdstatTestBase):
 
     def test_memory_csv(self):
         out = self.run_qdstat(['--memory', '--csv'])
-        if out.strip() == "No memory statistics available":
-            # router built w/o memory pools enabled]
-            return self.skipTest("Router's memory pools disabled")
         self.assertIn("QDR.A", out)
         self.assertIn("UTC", out)
         regexp = r'qdr_address_t","[0-9]+'
diff --git a/tools/qdstat b/tools/qdstat
index ebddb49..9e87355 100755
--- a/tools/qdstat
+++ b/tools/qdstat
@@ -731,7 +731,12 @@ class BusManager(object):
             self.display_datetime_router_id()
 
         pooled_total = 0
+        memory_stats_enabled = True
         for t in objects:
+            # t.totalAllocFromHeap is None *only* if memory stats is disabled.
+            if t.totalAllocFromHeap is None:
+                memory_stats_enabled = False
+                break
             row = []
             row.append(self._identity_clean(t.identity))
             row.append(PlainNum(t.typeSize))
@@ -743,10 +748,12 @@ class BusManager(object):
             row.append(PlainNum(t.batchesRebalancedToGlobal))
             rows.append(row)
             pooled_total += (t.typeSize * t.totalAllocFromHeap)
-        if not rows:
+
+        if not rows or not memory_stats_enabled:
             # router built w/o memory pools:
             print("No memory statistics available")
             return
+
         title = "Memory Pools"
         sorter = Sorter(heads, rows, 'type', 0, True)
         dispRows = sorter.getSorted()

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to