From b4301ff54fab5e9884bc3d89cbf791fad8116844 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Sun, 30 Dec 2018 19:41:17 -0600 Subject: [PATCH] Drop initial_pid and optimize `debug_shared()` fast case If we are running on the main thread, don't call `getpid()` unnecessarily from `debug_shared()`. --- src/common.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/common.cpp b/src/common.cpp index 527210a1f..9362c69b2 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -70,8 +70,6 @@ const wchar_t *program_name; int debug_level = 1; // default maximum debug output level (errors and warnings) int debug_stack_frames = 0; // default number of stack frames to show on debug() calls -/// This allows us to notice when we've forked. -static pid_t initial_pid = 0; /// Be able to restore the term's foreground process group. /// This is set during startup and not modified after. @@ -611,11 +609,11 @@ bool should_suppress_stderr_for_tests() { } static void debug_shared(const wchar_t level, const wcstring &msg) { - pid_t current_pid = getpid(); - - if (current_pid == initial_pid) { + pid_t current_pid; + if (!is_forked_child()) { fwprintf(stderr, L"<%lc> %ls: %ls\n", (unsigned long)level, program_name, msg.c_str()); } else { + current_pid = getpid(); fwprintf(stderr, L"<%lc> %ls: %d: %ls\n", (unsigned long)level, program_name, current_pid, msg.c_str()); }