summaryrefslogtreecommitdiffstats
path: root/src/H5MM.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@koziol.gov>2020-03-10 23:37:55 (GMT)
committerQuincey Koziol <koziol@koziol.gov>2020-03-10 23:37:55 (GMT)
commit04b8cc82a858aeb8a0beb3738984240b528952dc (patch)
tree708c35662a0be75429403326035b767693640437 /src/H5MM.c
parent9abbdeaa66c70a00b6a7bedee9c76d2493a8e947 (diff)
downloadhdf5-04b8cc82a858aeb8a0beb3738984240b528952dc.zip
hdf5-04b8cc82a858aeb8a0beb3738984240b528952dc.tar.gz
hdf5-04b8cc82a858aeb8a0beb3738984240b528952dc.tar.bz2
Add routines to query the library's free list sizes and allocation stats.
Diffstat (limited to 'src/H5MM.c')
-rw-r--r--src/H5MM.c74
1 files changed, 71 insertions, 3 deletions
diff --git a/src/H5MM.c b/src/H5MM.c
index 94bd542..4fbecd4 100644
--- a/src/H5MM.c
+++ b/src/H5MM.c
@@ -108,8 +108,8 @@ static H5MM_block_t H5MM_block_head_s;
/* Statistics about block allocations */
static unsigned long long H5MM_total_alloc_bytes_s = 0;
-static unsigned long long H5MM_curr_alloc_bytes_s = 0;
-static unsigned long long H5MM_peak_alloc_bytes_s = 0;
+static size_t H5MM_curr_alloc_bytes_s = 0;
+static size_t H5MM_peak_alloc_bytes_s = 0;
static size_t H5MM_max_block_size_s = 0;
static size_t H5MM_total_alloc_blocks_count_s = 0;
static size_t H5MM_curr_alloc_blocks_count_s = 0;
@@ -235,7 +235,7 @@ H5MM_final_sanity_check(void)
HDassert(H5MM_block_head_s.prev == &H5MM_block_head_s);
#ifdef H5MM_PRINT_MEMORY_STATS
HDfprintf(stderr, "%s: H5MM_total_alloc_bytes_s = %llu\n", __func__, H5MM_total_alloc_bytes_s);
- HDfprintf(stderr, "%s: H5MM_peak_alloc_bytes_s = %llu\n", __func__, H5MM_peak_alloc_bytes_s);
+ HDfprintf(stderr, "%s: H5MM_peak_alloc_bytes_s = %zu\n", __func__, H5MM_peak_alloc_bytes_s);
HDfprintf(stderr, "%s: H5MM_max_block_size_s = %zu\n", __func__, H5MM_max_block_size_s);
HDfprintf(stderr, "%s: H5MM_total_alloc_blocks_count_s = %zu\n", __func__, H5MM_total_alloc_blocks_count_s);
HDfprintf(stderr, "%s: H5MM_peak_alloc_blocks_count_s = %zu\n", __func__, H5MM_peak_alloc_blocks_count_s);
@@ -625,3 +625,71 @@ H5MM_memcpy(void *dest, const void *src, size_t n)
} /* end H5MM_memcpy() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5MM_get_alloc_stats
+ *
+ * Purpose: Gets the memory allocation statistics for the library, if the
+ * H5_MEMORY_ALLOC_SANITY_CHECK macro is defined. If the macro is not
+ * defined, zeros are returned. These statistics are global for the
+ * entire library.
+ *
+ * Parameters:
+ * unsigned long long *total_alloc_bytes; OUT: Running count of total # of bytes allocated
+ * size_t *curr_alloc_bytes; OUT: Current # of bytes allocated
+ * size_t *peak_alloc_bytes; OUT: Peak # of bytes allocated
+ * size_t *max_block_size; OUT: Largest block allocated
+ * size_t *total_alloc_blocks_count; OUT: Running count of total # of blocks allocated
+ * size_t *curr_alloc_blocks_count; OUT: Current # of blocks allocated
+ * size_t *peak_alloc_blocks_count; OUT: Peak # of blocks allocated
+ *
+ * Return: Success: non-negative
+ * Failure: negative
+ *
+ * Programmer: Quincey Koziol
+ * Saturday, March 7, 2020
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5MM_get_alloc_stats(unsigned long long *total_alloc_bytes, size_t *curr_alloc_bytes,
+ size_t *peak_alloc_bytes, size_t *max_block_size, size_t *total_alloc_blocks_count,
+ size_t *curr_alloc_blocks_count, size_t *peak_alloc_blocks_count)
+{
+ FUNC_ENTER_NOAPI_NOERR
+
+#if defined H5_MEMORY_ALLOC_SANITY_CHECK
+ if(total_alloc_bytes)
+ *total_alloc_bytes = H5MM_total_alloc_bytes_s;
+ if(curr_alloc_bytes)
+ *curr_alloc_bytes = H5MM_curr_alloc_bytes_s;
+ if(peak_alloc_bytes)
+ *peak_alloc_bytes = H5MM_peak_alloc_bytes_s;
+ if(max_block_size)
+ *max_block_size = H5MM_max_block_size_s;
+ if(total_alloc_blocks_count)
+ *total_alloc_blocks_count = H5MM_total_alloc_blocks_count_s;
+ if(curr_alloc_blocks_count)
+ *curr_alloc_blocks_count = H5MM_curr_alloc_blocks_count_s;
+ if(peak_alloc_blocks_count)
+ *peak_alloc_blocks_count = H5MM_peak_alloc_blocks_count_s;
+#else /* H5_MEMORY_ALLOC_SANITY_CHECK */
+ if(total_alloc_bytes)
+ *total_alloc_bytes = 0;
+ if(curr_alloc_bytes)
+ *curr_alloc_bytes = 0;
+ if(peak_alloc_bytes)
+ *peak_alloc_bytes = 0;
+ if(max_block_size)
+ *max_block_size = 0;
+ if(total_alloc_blocks_count)
+ *total_alloc_blocks_count = 0;
+ if(curr_alloc_blocks_count)
+ *curr_alloc_blocks_count = 0;
+ if(peak_alloc_blocks_count)
+ *peak_alloc_blocks_count = 0;
+#endif /* H5_MEMORY_ALLOC_SANITY_CHECK */
+
+ FUNC_LEAVE_NOAPI(SUCCEED)
+} /* end H5get_alloc_stats() */
+