aboutsummaryrefslogtreecommitdiffstats
path: root/debug.c
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2023-04-26 16:54:34 +0900
committerKoichi Sasada <ko1@atdot.net>2023-04-26 17:57:32 +0900
commit457824e2d3ddebef6435d43e0a4b22f738f9fae4 (patch)
tree87f12bee0a320946fa0b31f763b204d8d1b1129d /debug.c
parentb90d87bf255c746cd103becd525e8550253602a4 (diff)
downloadruby-457824e2d3ddebef6435d43e0a4b22f738f9fae4.tar.gz
`RUBY_DEBUG_LOG_PID` for `RUBY_DEBUG_LOG()`
`RUBY_DEBUG_LOG=stderr RUBY_DEBUG_LOG_PID=1 ruby ...` will prints debug logs with PID.
Diffstat (limited to 'debug.c')
-rw-r--r--debug.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/debug.c b/debug.c
index 054e715d3b..ed670a86b8 100644
--- a/debug.c
+++ b/debug.c
@@ -290,6 +290,7 @@ static struct {
unsigned int cnt;
struct debug_log_filter filters[MAX_DEBUG_LOG_FILTER_NUM];
unsigned int filters_num;
+ bool show_pid;
rb_nativethread_lock_t lock;
FILE *output;
} debug_log;
@@ -406,6 +407,10 @@ setup_debug_log(void)
rb_nativethread_lock_initialize(&debug_log.lock);
setup_debug_log_filter();
+
+ if (getenv("RUBY_DEBUG_LOG_PID")) {
+ debug_log.show_pid = true;
+ }
}
}
@@ -501,6 +506,12 @@ ruby_debug_log(const char *file, int line, const char *func_name, const char *fm
int len = 0;
int r = 0;
+ if (debug_log.show_pid) {
+ r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN, "pid:%d\t", getpid());
+ if (r < 0) rb_bug("ruby_debug_log returns %d\n", r);
+ len += r;
+ }
+
// message title
if (func_name && len < MAX_DEBUG_LOG_MESSAGE_LEN) {
r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN, "%s\t", func_name);