diff --git a/src/jsvm.h b/src/jsvm.h index 2b52563b63407fbdd0f6253a16c216ac819798f4..7041bc57ce3b7b32635991ce8715ce39a471631d 100644 --- a/src/jsvm.h +++ b/src/jsvm.h @@ -208,6 +208,17 @@ JSVM_EXTERN JSVM_Status OH_JSVM_OpenEnvScope(JSVM_Env env, JSVM_EXTERN JSVM_Status OH_JSVM_CloseEnvScope(JSVM_Env env, JSVM_EnvScope scope); +/** + * @brief This function retrieves the VM instance of the given environment. + * + * @param env: The environment that the JSVM-API call is invoked under. + * @param result: The VM instance of the environment. + * @return Returns JSVM_ok if the API succeeded. + * @since 11 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_GetVM(JSVM_Env env, + JSVM_VM* result); + /** * @brief This function compiles a string of JavaScript code and returns the compiled script. * @@ -2148,6 +2159,82 @@ JSVM_EXTERN JSVM_Status OH_JSVM_CreateSnapshot(JSVM_VM vm, const char** blobData, size_t* blobSize); +/** + * @brief This function returns a set of statistics data of the heap of the VM. + * @param vm: The VM whose heap statistics are returned. + * @param result: The heap statistics data. + * @return Returns JSVM_ok if the API succeeded. + * @since 11 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_GetHeapStatistics(JSVM_VM vm, + JSVM_HeapStatistics* result); + +/** + * @brief This function creates and starts a CPU profiler. + * @param vm: The VM to start CPU profiler for. + * @param result: The pointer to the CPU profiler. + * @return Returns JSVM_ok if the API succeeded. + * @since 11 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_StartCPUProfiler(JSVM_VM vm, + JSVM_CPUProfiler* result); + +/** + * @brief This function stops the CPU profiler and output to the stream. + * @param vm: THe VM to start CPU profiler for. + * @param profiler: The CPU profiler to stop. + * @param stream: The output stream callback for receiving the data. + * @param stream_data: Optional data to be passed to the stream callback. + * @return Returns JSVM_ok if the API succeeded. + * @since 11 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_StopCPUProfiler(JSVM_VM vm, + JSVM_CPUProfiler profiler, + JSVM_OutputStream stream, + void* stream_data); +/** + * @brief This funciton takes the current heap snapshot and output to the stream. + * @param vm: The VM whose heap snapshot is taken. + * @param stream: The output stream callback for receiving the data. + * @param stream_data: Optional data to be passed to the stream callback. + * @return Returns JSVM_ok if the API succeeded. + * @since 11 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_TakeHeapSnapshot(JSVM_VM vm, + JSVM_OutputStream stream, + void* stream_data); + +/** + * @brief This functiong activates insepctor on host and port. + * @param env: The environment that the API is invoked under. + * @param host: The host to listen to for inspector connections. + * @param port: The port to listen to for inspector connections. + * @return Returns JSVM_ok if the API succeeded. + * @since 11 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_OpenInspector(JSVM_Env env, + const char* host, + uint16_t port); + +/** + * @brief This function attempts to close all remaining inspector connections. + * @param env: The environment that the API is invoked under. + * @return Returns JSVM_ok if the API succeeded. + * @since 11 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_CloseInspector(JSVM_Env env); + +/** + * @brief This function will block until a client (existing or connected later) + * has sent Runtime.runIfWaitingForDebugger command. + * @param env: The environment that the API is invoked under. + * @param break_next_line: Whether break on the next line of JavaScript code. + * @return Returns JSVM_ok if the API succeeded. + * @since 11 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_WaitForDebugger(JSVM_Env env, + bool break_next_line); + EXTERN_C_END /** @} */ diff --git a/src/jsvm_types.h b/src/jsvm_types.h index c778282bcacd741da23640b8c1a8cc4602ee3de8..ffe6f91029eba451a838028acdc4904701e6b7fa 100644 --- a/src/jsvm_types.h +++ b/src/jsvm_types.h @@ -92,6 +92,13 @@ typedef struct JSVM_Script__* JSVM_Script; */ typedef struct JSVM_Env__* JSVM_Env; +/** + * @brief To represent a JavaScript profiler. + * + * @since 11 + */ +typedef struct JSVM_CPUProfiler__* JSVM_CPUProfiler; + /** * @brief To represent a JavaScript VM environment. * @@ -162,6 +169,15 @@ typedef void(JSVM_CDECL* JSVM_Finalize)(JSVM_Env env, void* finalizeData, void* finalizeHint); +/** + * @brief Function pointer type for callback of ASCII output stream. + * + * @since 11 + */ +typedef bool(JSVM_CDECL* JSVM_OutputStream)(const char* data, + int size, + void* stream_data); + /** * @brief JSVM_PropertyAttributes are flag used to control the behavior of properties set on a js object. * @@ -356,6 +372,40 @@ typedef enum { JSVM_MEMORY_PRESSURE_LEVEL_CRITICAL, } JSVM_MemoryPressureLevel; +/** + * @brief Heap statisics. + * + * @since 11 + */ +typedef struct { + /** the size of the total heap. */ + size_t total_heap_size; + /** the executable size of the total heap. */ + size_t total_heap_size_executable; + /** the physical size of the total heap. */ + size_t total_physical_size; + /** the available size of the total heap. */ + size_t total_available_size; + /** used size of the heap. */ + size_t used_heap_size; + /** heap size limit. */ + size_t heap_size_limit; + /** memory requested by the heap. */ + size_t malloced_memory; + /** heap-requested external memory. */ + size_t external_memory; + /** peak memory requested by the heap. */ + size_t peak_malloced_memory; + /** the number of native contexts. */ + size_t number_of_native_contexts; + /** the number of detached contexts. */ + size_t number_of_detached_contexts; + /** the size of the total global handles. */ + size_t total_global_handles_size; + /** the size of the used global handles. */ + size_t used_global_handles_size; +} JSVM_HeapStatistics; + /** * @brief Init the JavaScript VM with init option. *