Renaming --mem-stats-at-exit option to --mem-stats; adding --mem-stats-separate option for dumping memory statistics and resetting memory usage peak values after parse.
JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
This commit is contained in:
+26
-6
@@ -27,6 +27,8 @@
|
||||
#include "ecma-objects-general.h"
|
||||
#include "jerry.h"
|
||||
#include "jrt.h"
|
||||
#include "mem-heap.h"
|
||||
#include "mem-poolman.h"
|
||||
#include "parser.h"
|
||||
#include "serializer.h"
|
||||
#include "vm.h"
|
||||
@@ -901,14 +903,24 @@ jerry_api_eval (const char *source_p, /**< source code */
|
||||
void
|
||||
jerry_init (jerry_flag_t flags) /**< combination of Jerry flags */
|
||||
{
|
||||
jerry_flags = flags;
|
||||
|
||||
#ifndef MEM_STATS
|
||||
if (flags & (JERRY_FLAG_MEM_STATS_AT_EXIT | JERRY_FLAG_MEM_STATS_PER_OPCODE))
|
||||
if (flags & (JERRY_FLAG_MEM_STATS))
|
||||
{
|
||||
#ifndef MEM_STATS
|
||||
flags &= ~(JERRY_FLAG_MEM_STATS
|
||||
| JERRY_FLAG_MEM_STATS_PER_OPCODE
|
||||
| JERRY_FLAG_MEM_STATS_SEPARATE);
|
||||
|
||||
printf ("Ignoring memory statistics option because of '!MEM_STATS' build configuration.\n");
|
||||
}
|
||||
#endif /* !MEM_STATS */
|
||||
}
|
||||
else if (flags & (JERRY_FLAG_MEM_STATS_PER_OPCODE | JERRY_FLAG_MEM_STATS_SEPARATE))
|
||||
{
|
||||
flags &= ~(JERRY_FLAG_MEM_STATS_PER_OPCODE | JERRY_FLAG_MEM_STATS_SEPARATE);
|
||||
|
||||
printf ("Ignoring detailed memory statistics options because memory statistics dump mode is not enabled.\n");
|
||||
}
|
||||
|
||||
jerry_flags = flags;
|
||||
|
||||
mem_init ();
|
||||
serializer_init ();
|
||||
@@ -921,7 +933,7 @@ jerry_init (jerry_flag_t flags) /**< combination of Jerry flags */
|
||||
void
|
||||
jerry_cleanup (void)
|
||||
{
|
||||
bool is_show_mem_stats = ((jerry_flags & JERRY_FLAG_MEM_STATS_AT_EXIT) != 0);
|
||||
bool is_show_mem_stats = ((jerry_flags & JERRY_FLAG_MEM_STATS) != 0);
|
||||
|
||||
ecma_finalize ();
|
||||
serializer_free ();
|
||||
@@ -966,6 +978,14 @@ jerry_parse (const char* source_p, /**< script source */
|
||||
serializer_print_opcodes ();
|
||||
parser_free ();
|
||||
|
||||
#ifdef MEM_STATS
|
||||
if (jerry_flags & JERRY_FLAG_MEM_STATS_SEPARATE)
|
||||
{
|
||||
mem_stats_print ();
|
||||
mem_stats_reset_peak ();
|
||||
}
|
||||
#endif /* MEM_STATS */
|
||||
|
||||
bool is_show_mem_stats_per_opcode = ((jerry_flags & JERRY_FLAG_MEM_STATS_PER_OPCODE) != 0);
|
||||
|
||||
init_int (opcodes, is_show_mem_stats_per_opcode);
|
||||
|
||||
+8
-7
@@ -31,13 +31,14 @@
|
||||
*/
|
||||
typedef uint32_t jerry_flag_t;
|
||||
|
||||
#define JERRY_FLAG_EMPTY (0) /**< empty flag set */
|
||||
#define JERRY_FLAG_SHOW_OPCODES (1 << 0) /**< dump opcodes to stdout after parse */
|
||||
#define JERRY_FLAG_MEM_STATS_AT_EXIT (1 << 1) /**< dump per-opcode memory statistics during execution
|
||||
* (in the mode full GC is performed after each opcode handler) */
|
||||
#define JERRY_FLAG_MEM_STATS_PER_OPCODE (1 << 2) /**< dump peak memory statistics before exit */
|
||||
#define JERRY_FLAG_PARSE_ONLY (1 << 3) /**< parse only, prevents script execution (only for testing)
|
||||
* FIXME: Remove. */
|
||||
#define JERRY_FLAG_EMPTY (0u) /**< empty flag set */
|
||||
#define JERRY_FLAG_SHOW_OPCODES (1u << 0) /**< dump opcodes to stdout after parse */
|
||||
#define JERRY_FLAG_MEM_STATS (1u << 1) /**< dump memory statistics */
|
||||
#define JERRY_FLAG_MEM_STATS_PER_OPCODE (1u << 2) /**< dump per-opcode memory statistics during execution
|
||||
* (in the mode full GC is performed after each opcode handler) */
|
||||
#define JERRY_FLAG_MEM_STATS_SEPARATE (1u << 3) /**< dump memory statistics and reset peak values after parse */
|
||||
#define JERRY_FLAG_PARSE_ONLY (1u << 4) /**< parse only, prevents script execution (only for testing)
|
||||
* FIXME: Remove. */
|
||||
|
||||
/**
|
||||
* Error codes
|
||||
|
||||
@@ -185,3 +185,41 @@ mem_is_heap_pointer (void *pointer) /**< pointer */
|
||||
return (uint8_pointer >= mem_heap_area && uint8_pointer <= (mem_heap_area + MEM_HEAP_AREA_SIZE));
|
||||
} /* mem_is_heap_pointer */
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
#ifdef MEM_STATS
|
||||
/**
|
||||
* Reset peak values in memory usage statistics
|
||||
*/
|
||||
void
|
||||
mem_stats_reset_peak (void)
|
||||
{
|
||||
mem_heap_stats_reset_peak ();
|
||||
mem_pools_stats_reset_peak ();
|
||||
} /* mem_stats_reset_peak */
|
||||
|
||||
/**
|
||||
* Print memory usage statistics
|
||||
*/
|
||||
void
|
||||
mem_stats_print (void)
|
||||
{
|
||||
mem_heap_print (false, false, true);
|
||||
|
||||
mem_pools_stats_t stats;
|
||||
mem_pools_get_stats (&stats);
|
||||
|
||||
printf ("Pools stats:\n");
|
||||
printf (" Chunk size: %zu\n"
|
||||
" Pools: %zu\n"
|
||||
" Allocated chunks: %zu\n"
|
||||
" Free chunks: %zu\n"
|
||||
" Peak pools: %zu\n"
|
||||
" Peak allocated chunks: %zu\n\n",
|
||||
MEM_POOL_CHUNK_SIZE,
|
||||
stats.pools_count,
|
||||
stats.allocated_chunks,
|
||||
stats.free_chunks,
|
||||
stats.peak_pools_count,
|
||||
stats.peak_allocated_chunks);
|
||||
} /* mem_stats_print */
|
||||
#endif /* MEM_STATS */
|
||||
|
||||
@@ -93,6 +93,11 @@ extern void mem_unregister_a_try_give_memory_back_callback (mem_try_give_memory_
|
||||
extern bool mem_is_heap_pointer (void *pointer);
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
#ifdef MEM_STATS
|
||||
extern void mem_stats_reset_peak (void);
|
||||
extern void mem_stats_print (void);
|
||||
#endif /* MEM_STATS */
|
||||
|
||||
#endif /* !JERRY_MEM_ALLOCATOR_H */
|
||||
|
||||
/**
|
||||
|
||||
+6
-2
@@ -139,14 +139,18 @@ main (int argc,
|
||||
printf ("Branch name:\t%s\n", jerry_branch_name);
|
||||
printf ("\n");
|
||||
}
|
||||
else if (!strcmp ("--mem-stats-at-exit", argv[i]))
|
||||
else if (!strcmp ("--mem-stats", argv[i]))
|
||||
{
|
||||
flags |= JERRY_FLAG_MEM_STATS_AT_EXIT;
|
||||
flags |= JERRY_FLAG_MEM_STATS;
|
||||
}
|
||||
else if (!strcmp ("--mem-stats-per-opcode", argv[i]))
|
||||
{
|
||||
flags |= JERRY_FLAG_MEM_STATS_PER_OPCODE;
|
||||
}
|
||||
else if (!strcmp ("--mem-stats-separate", argv[i]))
|
||||
{
|
||||
flags |= JERRY_FLAG_MEM_STATS_SEPARATE;
|
||||
}
|
||||
else if (!strcmp ("--parse-only", argv[i]))
|
||||
{
|
||||
flags |= JERRY_FLAG_PARSE_ONLY;
|
||||
|
||||
+6
-2
@@ -146,14 +146,18 @@ int jerry_main (int argc, char *argv[])
|
||||
printf ("Commit hash:\t%s\n", jerry_commit_hash);
|
||||
printf ("Branch name:\t%s\n", jerry_branch_name);
|
||||
}
|
||||
else if (!strcmp ("--mem-stats-at-exit", argv[i]))
|
||||
else if (!strcmp ("--mem-stats", argv[i]))
|
||||
{
|
||||
flags |= JERRY_FLAG_MEM_STATS_AT_EXIT;
|
||||
flags |= JERRY_FLAG_MEM_STATS;
|
||||
}
|
||||
else if (!strcmp ("--mem-stats-per-opcode", argv[i]))
|
||||
{
|
||||
flags |= JERRY_FLAG_MEM_STATS_PER_OPCODE;
|
||||
}
|
||||
else if (!strcmp ("--mem-stats-separate", argv[i]))
|
||||
{
|
||||
flags |= JERRY_FLAG_MEM_STATS_SEPARATE;
|
||||
}
|
||||
else if (!strcmp ("--parse-only", argv[i]))
|
||||
{
|
||||
flags |= JERRY_FLAG_PARSE_ONLY;
|
||||
|
||||
Reference in New Issue
Block a user