From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 7BC9E1F47D for ; Sun, 8 Jan 2023 23:43:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1673221404; bh=yVVaHb4jRk7bhaJQomatoxbdWaM+vT2fAFcbsUJDoF4=; h=From:To:Subject:Date:From; b=u7yLEHKuhRHki8UgYFdi62Ba88/2xPCZ9oOsC5jZbl0icAYApJ9Tt4TSaR8wuBEDT gBV1e2hsViAUFe+/saEMb46JFJ6pBNdYswtyrOYoeJoyjWmTz1E14mmxt2R3AuEpJE tE1IuauwVDYK4g8kTQOd0/HC6Y+KcQLjLM6ounsg= From: Eric Wong To: Subject: [PATCH] httpd: show GC count Date: Sun, 8 Jan 2023 23:43:24 +0000 Message-Id: <20230108234324.17034-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We can't call rb_gc_count() safely outside of Ruby threads (especially during startup/teardown), but we can share it's last-known value safely. --- ext/mwrap/httpd.h | 3 +++ ext/mwrap/mwrap_core.h | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ext/mwrap/httpd.h b/ext/mwrap/httpd.h index 03aef9f..0ef6cd9 100644 --- a/ext/mwrap/httpd.h +++ b/ext/mwrap/httpd.h @@ -548,6 +548,9 @@ static void show_stats(FILE *fp) "/ files: %zu / locations: %zu", inc , inc - dec, uatomic_read(&nr_file), uatomic_read(&nr_src_loc)); +#if MWRAP_RUBY + fprintf(fp, " / GC: %zu", uatomic_read(&last_gc_count)); +#endif } /* /$PID/at/$LOCATION endpoint */ diff --git a/ext/mwrap/mwrap_core.h b/ext/mwrap/mwrap_core.h index 48669d5..827ee7b 100644 --- a/ext/mwrap/mwrap_core.h +++ b/ext/mwrap/mwrap_core.h @@ -85,6 +85,7 @@ static size_t *root_locating; /* determines if PL_curcop is our thread */ #if MWRAP_RUBY static void mw_ruby_set_generation(size_t *, size_t); # define SET_GENERATION(gen, size) mw_ruby_set_generation(gen, size) +static size_t last_gc_count; /* for httpd which runs in a non-GVL thread */ #endif /* MWRAP_RUBY */ #ifndef SET_GENERATION /* C-only builds w/o Perl|Ruby */ @@ -1074,8 +1075,10 @@ static void mw_ruby_set_generation(size_t *gen, size_t size) { if (rb_gc_count) { uatomic_add_return(&total_bytes_inc, size); - if (has_ec_p()) + if (has_ec_p()) { *gen = rb_gc_count(); + uatomic_set(&last_gc_count, *gen); + } } else { *gen = uatomic_add_return(&total_bytes_inc, size); }