Skip to content

Commit

Permalink
refactor jsapi - logbypass
Browse files Browse the repository at this point in the history
  • Loading branch information
hyj1991 committed Oct 27, 2022
1 parent 767d8ce commit df9b7f2
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 13 deletions.
1 change: 1 addition & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"src/jsapi/export_logger.cc",
"src/jsapi/export_hooks.cc",
"src/jsapi/export_http.cc",
"src/jsapi/export_thread_logbypass.cc",
],
"include_dirs": [
'src',
Expand Down
17 changes: 17 additions & 0 deletions src/jsapi/export_thread_logbypass.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "include/export_thread_logbypass.h"

#include "environment_data.h"
#include "logbypass/log.h"

namespace xprofiler {
using Nan::FunctionCallbackInfo;
using Nan::True;
using v8::Value;

void RunLogBypass(const FunctionCallbackInfo<Value>& info) {
EnvironmentData* env_data = EnvironmentData::GetCurrent(info);
StartLogThread(env_data);
info.GetReturnValue().Set(True());
}

} // namespace xprofiler
10 changes: 10 additions & 0 deletions src/jsapi/include/export_thread_logbypass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef XPROFILER_SRC_JSAPI_THREAD_LOGBYPASS_H
#define XPROFILER_SRC_JSAPI_THREAD_LOGBYPASS_H

#include "nan.h"

namespace xprofiler {
void RunLogBypass(const Nan::FunctionCallbackInfo<v8::Value>& info);
}

#endif /* XPROFILER_SRC_JSAPI_THREAD_LOGBYPASS_H */
11 changes: 1 addition & 10 deletions src/logbypass/log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@
#include "gc.h"
#include "heap.h"
#include "http.h"
#include "library/utils.h"
#include "libuv.h"
#include "logger.h"
#include "process_data.h"
#include "uv.h"

namespace xprofiler {
using Nan::False;
using Nan::FunctionCallbackInfo;
using Nan::ThrowTypeError;
using Nan::True;
using v8::Value;

void LogByPass::ThreadEntry(uv_loop_t* loop) {
CHECK_EQ(0, uv_timer_init(loop, &cpu_interval_));
Expand Down Expand Up @@ -101,8 +95,7 @@ void LogByPass::Write(EnvironmentData* env_data, bool log_format_alinode) {
WriteHttpStatus(env_data, log_format_alinode, GetPatchHttpTimeout());
}

void RunLogBypass(const FunctionCallbackInfo<Value>& info) {
EnvironmentData* env_data = EnvironmentData::GetCurrent(info);
void StartLogThread(EnvironmentData* env_data) {
ThreadId thread_id = env_data->thread_id();
// init gc hooks
InitGcStatusHooks(env_data);
Expand All @@ -116,8 +109,6 @@ void RunLogBypass(const FunctionCallbackInfo<Value>& info) {
data->log_by_pass->StartIfNeeded();
InfoT("init", thread_id, "logbypass: log thread created.");
}

info.GetReturnValue().Set(True());
}

} // namespace xprofiler
3 changes: 1 addition & 2 deletions src/logbypass/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class LogByPass final : public XpfThread {
bool next_log_ = false;
};

// javascript-accessible
void RunLogBypass(const Nan::FunctionCallbackInfo<v8::Value>& info);
void StartLogThread(EnvironmentData* env_data);
} // namespace xprofiler

#endif /* XPROFILER_SRC_LOGBYPASS_LOG_H */
2 changes: 1 addition & 1 deletion src/xprofiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include "jsapi/include/export_hooks.h"
#include "jsapi/include/export_http.h"
#include "jsapi/include/export_logger.h"
#include "jsapi/include/export_thread_logbypass.h"
#include "library/common.h"
#include "logbypass/log.h"
#include "nan.h"
#include "platform/platform.h"
#include "process_data.h"
Expand Down

0 comments on commit df9b7f2

Please sign in to comment.