From d677d9e5e2da76fc06d628d80bce9cfa1a579c48 Mon Sep 17 00:00:00 2001 From: pajama-coder Date: Tue, 14 May 2024 17:32:37 +0800 Subject: [PATCH] [core] Added log topic 'thread' --- src/log.hpp | 31 ++++++++++++++++--------------- src/main-options.cpp | 1 + src/worker-thread.cpp | 8 ++++---- test/benchmark/run.js | 2 +- test/curl/run.js | 2 +- test/mux/run.js | 2 +- test/stress/run.js | 2 +- 7 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/log.hpp b/src/log.hpp index 4446d75e..ddfe889e 100644 --- a/src/log.hpp +++ b/src/log.hpp @@ -54,21 +54,22 @@ class Log { enum Topic { NO_TOPIC = 0, ALLOC = 1<<0, - PIPELINE = 1<<1, - DUMP = 1<<2, - LISTENER = 1<<3, - INBOUND = 1<<4, - OUTBOUND = 1<<5, - SOCKET = 1<<6, - FILES = 1<<7, - SUBPROC = 1<<8, - NETLINK = 1<<9, - TCP = 1<<10, - UDP = 1<<11, - HTTP2 = 1<<12, - ELF = 1<<13, - BPF = 1<<14, - USER = 1<<15, + THREAD = 1<<1, + PIPELINE = 1<<2, + DUMP = 1<<3, + LISTENER = 1<<4, + INBOUND = 1<<5, + OUTBOUND = 1<<6, + SOCKET = 1<<7, + FILES = 1<<8, + SUBPROC = 1<<9, + NETLINK = 1<<10, + TCP = 1<<11, + UDP = 1<<12, + HTTP2 = 1<<13, + ELF = 1<<14, + BPF = 1<<15, + USER = 1<<16, }; static void init(); diff --git a/src/main-options.cpp b/src/main-options.cpp index 1378c0f8..d8f65a1c 100644 --- a/src/main-options.cpp +++ b/src/main-options.cpp @@ -92,6 +92,7 @@ static const struct { const char *name; } s_topic_names[] = { { Log::ALLOC , "alloc" }, + { Log::THREAD , "thread" }, { Log::PIPELINE , "pipeline" }, { Log::DUMP , "dump" }, { Log::LISTENER , "listener" }, diff --git a/src/worker-thread.cpp b/src/worker-thread.cpp index 9e49e939..8a529714 100644 --- a/src/worker-thread.cpp +++ b/src/worker-thread.cpp @@ -484,7 +484,7 @@ void WorkerThread::main() { } if (started && !failed) { - Log::info("[worker] Thread %d started", m_index); + Log::debug(Log::THREAD, "[thread] Thread %d started", m_index); init_metrics(); @@ -495,7 +495,7 @@ void WorkerThread::main() { m_done = true; m_manager->on_thread_done(m_index); - Log::info("[worker] Thread %d done", m_index); + Log::debug(Log::THREAD, "[thread] Thread %d done", m_index); if (m_shutdown) break; @@ -511,11 +511,11 @@ void WorkerThread::main() { if (m_working) { m_done = false; Net::current().restart(); - Log::info("[worker] Thread %d restarted", m_index); + Log::debug(Log::THREAD, "[thread] Thread %d restarted", m_index); } } - Log::info("[worker] Thread %d ended", m_index); + Log::debug(Log::THREAD, "[thread] Thread %d ended", m_index); } else { m_new_worker->stop(true); diff --git a/test/benchmark/run.js b/test/benchmark/run.js index da70ac22..9423988b 100755 --- a/test/benchmark/run.js +++ b/test/benchmark/run.js @@ -276,7 +276,7 @@ function startBaseline() { function startPipy(args, env) { return startProcess( - join(binPath, pipyExe), args, env, + join(binPath, pipyExe), ['--log-level=debug:thread', ...args], env, 'pipy', 'Thread 0 started', ); } diff --git a/test/curl/run.js b/test/curl/run.js index bd67e2a8..f6d306e8 100755 --- a/test/curl/run.js +++ b/test/curl/run.js @@ -118,7 +118,7 @@ async function test(name) { async function startPipy(filename) { log('Starting Pipy...'); log(pipyBinPath, filename); - const proc = spawn(pipyBinPath, [filename]); + const proc = spawn(pipyBinPath, [filename, '--log-level=debug:thread']); const lineBuffer = []; let started = false; return await Promise.race([ diff --git a/test/mux/run.js b/test/mux/run.js index 2978fccd..af9ccfea 100755 --- a/test/mux/run.js +++ b/test/mux/run.js @@ -155,7 +155,7 @@ async function startCodebase(url, opt) { new Promise( resolve => { const proc = startProcess( - pipyBinPath, ['--no-graph', url, ...(opt?.options || [])], + pipyBinPath, ['--no-graph', '--log-level=debug:thread', url, ...(opt?.options || [])], line => { if (!opt?.silent || !started) { log(chalk.bgGreen('worker >>>'), line); diff --git a/test/stress/run.js b/test/stress/run.js index 63bb3471..d2080530 100755 --- a/test/stress/run.js +++ b/test/stress/run.js @@ -153,7 +153,7 @@ function startCodebase(url, opt) { resolve => { let started = false; const proc = startProcess( - pipyBinPath, ['--no-graph', url, ...(opt?.options || [])], + pipyBinPath, ['--no-graph', '--log-level=debug:thread', url, ...(opt?.options || [])], line => { if (!opt?.silent || !started) { log(chalk.bgGreen('worker >>>'), line);