Skip to content

Commit d87a5dc

Browse files
daeyeonhs0225
authored andcommitted
chore: improve development logs
Signed-off-by: Daeyeon Jeong <[email protected]>
1 parent 68bb4fa commit d87a5dc

File tree

12 files changed

+58
-11
lines changed

12 files changed

+58
-11
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
11
'use strict';
22

3+
// @lwnode
4+
process._rawDebug('js:run_main_module');
5+
36
const {
47
prepareMainThreadExecution
58
} = require('internal/bootstrap/pre_execution');
69

10+
process._rawDebug('js:prepareMainThreadExecution');
11+
712
prepareMainThreadExecution(true);
813

14+
process._rawDebug('js:markBootstrapComplete');
15+
916
markBootstrapComplete();
1017

18+
process._rawDebug('+js:runMain');
19+
1120
// Note: this loads the module through the ESM loader if the module is
1221
// determined to be an ES module. This hangs from the CJS module loader
1322
// because we currently allow monkey-patching of the module loaders
1423
// in the preloaded scripts through require('module').
1524
// runMain here might be monkey-patched by users in --require.
1625
// XXX: the monkey-patchability here should probably be deprecated.
1726
require('internal/modules/cjs/loader').Module.runMain(process.argv[1]);
27+
28+
process._rawDebug('-js:runMain');
29+
30+
let list = process.lwnode.getModuleList();
31+
process._rawDebug(list, list.length);

deps/node/lib/internal/modules/cjs/helpers.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ function loadNativeModule(filename, request) {
3232
const mod = NativeModule.map.get(filename);
3333
if (mod) {
3434
debug('load native module %s', request);
35+
// @lwnode
36+
process._rawDebug('=js:load native module', request);
3537
mod.compileForPublicLoader();
3638
return mod;
3739
}

deps/node/lib/internal/modules/cjs/loader.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,8 +1065,11 @@ Module.prototype._compile = function(content, filename) {
10651065
result = inspectorWrapper(compiledWrapper, thisValue, exports,
10661066
require, module, filename, dirname);
10671067
} else {
1068+
// @lwnode
1069+
process._rawDebug('+js:compiledWrapper.call', filename);
10681070
result = compiledWrapper.call(thisValue, exports, require, module,
10691071
filename, dirname);
1072+
process._rawDebug('-js:compiledWrapper.call', filename);
10701073
}
10711074
hasLoadedAnyUserCJSModule = true;
10721075
if (requireDepth === 0) statCache = null;

deps/node/lib/internal/process/execution.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ function createOnGlobalUncaughtException() {
148148
}
149149
} catch {} // Ignore the exception. Diagnostic reporting is unavailable.
150150
}
151-
151+
// @lwnode
152+
process._rawDebug('js:uncaughtException or unhandledRejection detected.');
153+
if (process.lwnode.hasSystemInfo('tizen')) {
154+
console.warn(`Warning: It is not safe to resume normal operation after 'uncaughtException' or 'unhandledRejection'. (https://nodejs.org/api/process.html#warning-using-uncaughtexception-correctly)`);
155+
}
152156
const type = fromPromise ? 'unhandledRejection' : 'uncaughtException';
153157
process.emit('uncaughtExceptionMonitor', er, type);
154158
if (exceptionHandlerState.captureFn !== null) {

deps/node/src/lwnode/lwnode-public.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Runtime::~Runtime() {
145145

146146
int Runtime::Start(int argc, char** argv, std::promise<void>&& promise) {
147147
LWNODE_PERF_LOG("[Runtime::Start]");
148-
LWNODE_DEV_LOG("[Runtime] version:", LWNODE_VERSION_TAG);
148+
LWNODE_DEV_LOG("[Runtime] version: %s", LWNODE_VERSION_TAG);
149149
#if defined(NDEBUG)
150150
LWNODE_DEV_LOG("[Runtime] release mode");
151151
#else

deps/node/src/node_main_lw_runner-inl.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,11 @@ class LWNodeMainRunner {
121121
Isolate::Scope isolate_scope(isolate_);
122122
HandleScope handle_scope(isolate_);
123123

124+
LWNODE_DEV_LOG("[LWNodeMainRunner::Run] create main environment");
124125
int exit_code = 0;
125126
DeleteFnPtr<Environment, FreeEnvironment> env_ =
126127
nodeMainInstance.CreateMainEnvironment(&exit_code);
127-
LWNODE_DEV_LOG("[LWNodeMainRunner::Run] create main environment");
128+
LWNODE_DEV_LOG("[LWNodeMainRunner::Run] /create main environment");
128129

129130
CHECK_NOT_NULL(env_);
130131

@@ -148,16 +149,20 @@ class LWNodeMainRunner {
148149
}
149150

150151
if (exit_code == 0) {
151-
LoadEnvironment(env_.get());
152152
LWNODE_DEV_LOG("[LWNodeMainRunner::Run] load environment");
153+
LoadEnvironment(env_.get());
154+
LWNODE_DEV_LOG("[LWNodeMainRunner::Run] /load environment");
153155

154156
env_->set_trace_sync_io(env_->options()->trace_sync_io);
155157

156158
try {
157159
LWNODE_PERF_LOG("[LWNodeMainRunner::Run] loaded script");
160+
LWNODE_DEV_LOG("[LWNodeMainRunner::Run] set runtime ready");
158161
promise_.set_value();
159162
} catch (const std::exception& e) {
160-
LWNODE_DEV_LOG("[LWNodeMainRunner::Run] promise error:", e.what());
163+
LWNODE_DEV_LOG("[LWNodeMainRunner::Run] promise error: %s", e.what());
164+
v8::V8::ShutdownPlatform();
165+
return 1;
161166
}
162167

163168
{

deps/node/src/node_process_methods.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,12 @@ void RawDebug(const FunctionCallbackInfo<Value>& args) {
221221
CHECK(args.Length() == 1 && args[0]->IsString() &&
222222
"must be called with a single string");
223223
Utf8Value message(args.GetIsolate(), args[0]);
224-
FPrintF(stderr, "%s\n", message);
225-
fflush(stderr);
224+
#if defined(HOST_TIZEN) || defined(DEV)
225+
LWNode::rawDebug(message.ToString());
226+
#else
227+
// FPrintF(stderr, "%s\n", message);
228+
// fflush(stderr);
229+
#endif
226230
}
227231

228232
static void Umask(const FunctionCallbackInfo<Value>& args) {

deps/node/test/skip_tests.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ test/parallel/test-process-env-allowed-flags-are-documented.js
6464
test/parallel/test-process-env-symbols.js
6565
test/parallel/test-process-env-tz.js
6666
test/parallel/test-process-env.js
67+
test/parallel/test-process-raw-debug.js # rawDebug 는 js 로그로 사용
6768
test/parallel/test-process-versions.js
6869
test/parallel/test-promise-reject-callback-exception.js
6970
test/parallel/test-promise-swallowed-event.js

include/lwnode/lwnode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ void SetCanCallIntoJS(bool can_call_into_js);
5858
void IdleGC(v8::Isolate* isolate = nullptr);
5959
void initDebugger();
6060
bool dumpSelfMemorySnapshot();
61+
void rawDebug(std::string message);
6162

6263
class MessageLoop {
6364
using WakeupMainloopHandler = std::function<void()>;

src/api/utils/logger/logger.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,21 @@
2020
#include "logger-impl.h"
2121
#include "logger-util.h"
2222

23+
#if defined(HOST_TIZEN)
24+
#include <dlog.h>
25+
#endif
26+
2327
// loggers using LWNodeLogger which supports dlog
2428
#define LWNODE_USER_LOG(...) LWNodeLogger(LogKind::user()).log(__VA_ARGS__)
29+
2530
#if defined(HOST_TIZEN)
26-
#define LWNODE_DEV_LOG(...) LWNodeLogger(LogKind::lwnode()).log(__VA_ARGS__)
31+
#define LWNODE_DEV_LOG(...) dlog_print(DLOG_INFO, "LWNODE", __VA_ARGS__);
32+
#elif defined(DEV)
33+
#define LWNODE_DEV_LOG(fmt, ...) printf(fmt "\n", ##__VA_ARGS__);
2734
#else
28-
#define LWNODE_DEV_LOG(...)
35+
#define LWNODE_DEV_LOG(fmt, ...)
2936
#endif
37+
3038
#define LWNODE_DEV_LOGF(fmt, ...) \
3139
LWNodeLogger(LogKind::lwnode()).print(fmt, ##__VA_ARGS__)
3240

@@ -36,7 +44,7 @@
3644
#define LWNODE_PERF_LOG(...) \
3745
dlog_print(DLOG_INFO, \
3846
"LWNODE", \
39-
"[%.0lfms] %s\n", \
47+
"[%.0lfms] %s", \
4048
measurePerformance(), \
4149
##__VA_ARGS__);
4250
#elif !defined(NDEBUG)

src/lwnode/lwnode.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ bool dumpSelfMemorySnapshot() {
103103
return dumpMemorySnapshot(createDumpFilePath(), smaps);
104104
}
105105

106+
void rawDebug(std::string message) {
107+
LWNODE_DEV_LOG("%s", message.c_str());
108+
}
109+
106110
static ValueRef* PssUsage(ExecutionStateRef* state,
107111
ValueRef* thisValue,
108112
size_t argc,
@@ -332,6 +336,7 @@ void IdleGC(v8::Isolate* isolate) {
332336
}
333337
Escargot::Memory::gc();
334338
malloc_trim(0);
339+
LWNODE_DEV_LOG("[GC] heap %zu", Escargot::Memory::heapSize());
335340
}
336341

337342
void initDebugger() {

src/lwnode/nd-vm-main-message-port.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void MainMessagePort::Init(ContextRef* context, uv_loop_t* loop) {
5757
try {
5858
internal_->uv_promise_.set_value(uv_loop_);
5959
} catch (const std::exception& e) {
60-
LWNODE_DEV_LOG("[MainMessagePort::Init] promise error:", e.what());
60+
LWNODE_DEV_LOG("[MainMessagePort::Init] promise error: %s", e.what());
6161
}
6262

6363
Channel::DrainPendingMessages(uv_loop_);

0 commit comments

Comments
 (0)