提交 27669eda authored 作者: Andrey Volk's avatar Andrey Volk

FS-11194: [mod_v8] Implement JavaScript Process Status with Heap statistics.

上级 fc139b70
...@@ -63,6 +63,8 @@ public: ...@@ -63,6 +63,8 @@ public:
JS_FUNCTION_DEF_STATIC(FetchURL); JS_FUNCTION_DEF_STATIC(FetchURL);
JS_FUNCTION_DEF_STATIC(FetchURLHash); JS_FUNCTION_DEF_STATIC(FetchURLHash);
JS_FUNCTION_DEF_STATIC(FetchURLFile); JS_FUNCTION_DEF_STATIC(FetchURLFile);
JS_FUNCTION_DEF_STATIC(Version);
JS_FUNCTION_DEF_STATIC(Id);
}; };
#endif /* FS_GLOBAL_H */ #endif /* FS_GLOBAL_H */
......
...@@ -332,7 +332,6 @@ public: ...@@ -332,7 +332,6 @@ public:
static void Dispose(); /* Deinitialize the V8 engine */ static void Dispose(); /* Deinitialize the V8 engine */
static void Include(const v8::FunctionCallbackInfo<v8::Value>& args); /* Adds functionality to include another JavaScript from the running script */ static void Include(const v8::FunctionCallbackInfo<v8::Value>& args); /* Adds functionality to include another JavaScript from the running script */
static void Version(const v8::FunctionCallbackInfo<v8::Value>& args); /* Internal Version function accessable from JS - used to get the current V( version */
static const std::string GetExceptionInfo(v8::Isolate* isolate, v8::TryCatch* try_catch); /* Get the exception information from a V8 TryCatch instance */ static const std::string GetExceptionInfo(v8::Isolate* isolate, v8::TryCatch* try_catch); /* Get the exception information from a V8 TryCatch instance */
const std::vector<const js_class_definition_t *>& GetExtenderClasses() const;/* Returns the list of class definitions */ const std::vector<const js_class_definition_t *>& GetExtenderClasses() const;/* Returns the list of class definitions */
...@@ -355,7 +354,7 @@ public: ...@@ -355,7 +354,7 @@ public:
int GetForcedTerminationLineNumber(void); int GetForcedTerminationLineNumber(void);
/* Method to force termination of a script */ /* Method to force termination of a script */
static void ExitScript(v8::Isolate *isolate, const char *msg); static void ExitScript(v8::Isolate *isolate, const char *msg, bool jskill = false);
/* Get the filename and line number of the current JS stack */ /* Get the filename and line number of the current JS stack */
static char *GetStackInfo(v8::Isolate *isolate, int *lineNumber); static char *GetStackInfo(v8::Isolate *isolate, int *lineNumber);
......
...@@ -83,6 +83,19 @@ typedef struct { ...@@ -83,6 +83,19 @@ typedef struct {
} }
v8_event_t; v8_event_t;
#define ISOLATE_DATA_OBJECT 0
#define ISOLATE_DATA_DEBUG 1
#define ISOLATE_DATA_PRIVATE 2
/* Isolate Private Data */
typedef struct {
std::string str_task_id; /* JavaScript task id */
std::string input_code; /* Path to JavaScript source */
switch_time_t start_time; /* Script start_time */
v8::HeapStatistics stats;
} js_isolate_private_data_t;
SWITCH_END_EXTERN_C SWITCH_END_EXTERN_C
void v8_add_event_handler(void *event_handler); void v8_add_event_handler(void *event_handler);
......
...@@ -748,6 +748,19 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FileDelete) ...@@ -748,6 +748,19 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FileDelete)
info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments")); info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments"));
} }
/* Internal Version function accessable from JS - used to get the current V8 version */
JS_GLOBAL_FUNCTION_IMPL_STATIC(Version)
{
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), V8::GetVersion()));
}
/* TaskId assigned to the script - used to manage the task */
JS_GLOBAL_FUNCTION_IMPL_STATIC(Id)
{
js_isolate_private_data_t *private_data = (js_isolate_private_data_t*)info.GetIsolate()->GetData(ISOLATE_DATA_PRIVATE);
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), private_data->str_task_id.c_str()));
}
static const js_function_t fs_proc[] = { static const js_function_t fs_proc[] = {
{"console_log", FSGlobal::Log}, // Deprecated {"console_log", FSGlobal::Log}, // Deprecated
{"consoleLog", FSGlobal::Log}, {"consoleLog", FSGlobal::Log},
...@@ -770,6 +783,8 @@ static const js_function_t fs_proc[] = { ...@@ -770,6 +783,8 @@ static const js_function_t fs_proc[] = {
{"fetchUrl", FSGlobal::FetchURL}, {"fetchUrl", FSGlobal::FetchURL},
{"fetchUrlHash", FSGlobal::FetchURLHash}, {"fetchUrlHash", FSGlobal::FetchURLHash},
{"fetchUrlFile", FSGlobal::FetchURLFile}, {"fetchUrlFile", FSGlobal::FetchURLFile},
{"id", FSGlobal::Id },
{"version", FSGlobal::Version},
{0} {0}
}; };
......
...@@ -264,11 +264,6 @@ void JSMain::Log(const v8::FunctionCallbackInfo<Value>& args) ...@@ -264,11 +264,6 @@ void JSMain::Log(const v8::FunctionCallbackInfo<Value>& args)
args.GetReturnValue().Set(Undefined(args.GetIsolate())); args.GetReturnValue().Set(Undefined(args.GetIsolate()));
} }
void JSMain::Version(const v8::FunctionCallbackInfo<Value>& args)
{
args.GetReturnValue().Set(String::NewFromUtf8(args.GetIsolate(), V8::GetVersion()));
}
const string JSMain::ExecuteScript(const string& filename, bool *resultIsError) const string JSMain::ExecuteScript(const string& filename, bool *resultIsError)
{ {
// Get the file and load into a string. // Get the file and load into a string.
...@@ -553,7 +548,7 @@ int JSMain::GetForcedTerminationLineNumber(void) ...@@ -553,7 +548,7 @@ int JSMain::GetForcedTerminationLineNumber(void)
return forcedTerminationLineNumber; return forcedTerminationLineNumber;
} }
void JSMain::ExitScript(Isolate *isolate, const char *msg) void JSMain::ExitScript(Isolate *isolate, const char *msg, bool jskill)
{ {
if (!isolate) { if (!isolate) {
return; return;
...@@ -580,7 +575,10 @@ void JSMain::ExitScript(Isolate *isolate, const char *msg) ...@@ -580,7 +575,10 @@ void JSMain::ExitScript(Isolate *isolate, const char *msg)
js_strdup(js->forcedTerminationMessage, msg); js_strdup(js->forcedTerminationMessage, msg);
} }
js->forcedTerminationScriptFile = GetStackInfo(isolate, &js->forcedTerminationLineNumber); /* When forcefully killed, don't call GetStackInfo() because isolate is locked by another thread */
if (!jskill) {
js->forcedTerminationScriptFile = GetStackInfo(isolate, &js->forcedTerminationLineNumber);
}
} }
isolate->TerminateExecution(); isolate->TerminateExecution();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论