Add API for get the memory stats (#1923)
JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
This commit is contained in:
committed by
Zoltan Herczeg
parent
8b5fe254d9
commit
c242248b47
@@ -33,6 +33,7 @@
|
||||
#include "ecma-promise-object.h"
|
||||
#include "jcontext.h"
|
||||
#include "jerryscript.h"
|
||||
#include "jmem.h"
|
||||
#include "js-parser.h"
|
||||
#include "re-compiler.h"
|
||||
|
||||
@@ -254,6 +255,39 @@ jerry_gc (void)
|
||||
ecma_gc_run (JMEM_FREE_UNUSED_MEMORY_SEVERITY_LOW);
|
||||
} /* jerry_gc */
|
||||
|
||||
/**
|
||||
* Get heap memory stats.
|
||||
*
|
||||
* @return true - get the heap stats successful
|
||||
* false - otherwise. Usually it is because the MEM_STATS feature is not enabled.
|
||||
*/
|
||||
bool
|
||||
jerry_get_memory_stats (jerry_heap_stats_t *out_stats_p) /**< [out] heap memory stats */
|
||||
{
|
||||
#ifdef JMEM_STATS
|
||||
if (out_stats_p == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
jmem_heap_stats_t jmem_heap_stats = {0};
|
||||
jmem_heap_get_stats (&jmem_heap_stats);
|
||||
|
||||
*out_stats_p = (jerry_heap_stats_t)
|
||||
{
|
||||
.version = 1,
|
||||
.size = jmem_heap_stats.size,
|
||||
.allocated_bytes = jmem_heap_stats.allocated_bytes,
|
||||
.peak_allocated_bytes = jmem_heap_stats.peak_allocated_bytes
|
||||
};
|
||||
|
||||
return true;
|
||||
#else
|
||||
JERRY_UNUSED (out_stats_p);
|
||||
return false;
|
||||
#endif
|
||||
} /* jerry_get_memory_stats */
|
||||
|
||||
/**
|
||||
* Simple Jerry runner
|
||||
*
|
||||
|
||||
@@ -158,6 +158,19 @@ typedef struct
|
||||
jerry_value_t setter;
|
||||
} jerry_property_descriptor_t;
|
||||
|
||||
/**
|
||||
* Description of JerryScript heap memory stats.
|
||||
* It is for memory profiling.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
size_t version; /**< the version of the stats struct */
|
||||
size_t size; /**< heap total size */
|
||||
size_t allocated_bytes; /**< currently allocated bytes */
|
||||
size_t peak_allocated_bytes; /**< peak allocated bytes */
|
||||
size_t reserved[4]; /**< padding for future extensions */
|
||||
} jerry_heap_stats_t;
|
||||
|
||||
/**
|
||||
* Type of an external function handler.
|
||||
*/
|
||||
@@ -235,6 +248,8 @@ void jerry_get_memory_limits (size_t *out_data_bss_brk_limit_p, size_t *out_stac
|
||||
void jerry_gc (void);
|
||||
void *jerry_get_context_data (const jerry_context_data_manager_t *manager_p);
|
||||
|
||||
bool jerry_get_memory_stats (jerry_heap_stats_t *out_stats_p);
|
||||
|
||||
/**
|
||||
* Parser and executor functions.
|
||||
*/
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
*/
|
||||
|
||||
#ifdef JMEM_STATS
|
||||
void jmem_heap_get_stats (jmem_heap_stats_t *);
|
||||
void jmem_heap_stats_reset_peak (void);
|
||||
void jmem_heap_stats_print (void);
|
||||
#endif /* JMEM_STATS */
|
||||
|
||||
@@ -161,6 +161,7 @@ void jmem_stats_free_object_bytes (size_t string_size);
|
||||
void jmem_stats_allocate_property_bytes (size_t property_size);
|
||||
void jmem_stats_free_property_bytes (size_t property_size);
|
||||
|
||||
void jmem_heap_get_stats (jmem_heap_stats_t *);
|
||||
#endif /* JMEM_STATS */
|
||||
|
||||
jmem_cpointer_t jmem_compress_pointer (const void *pointer_p) __attr_pure___;
|
||||
|
||||
Reference in New Issue
Block a user