From: jean.boussier@... Date: 2021-08-09T14:58:34+00:00 Subject: [ruby-core:104846] [Ruby master Feature#10917] Add GC.stat[:total_time] when GC profiling enabled Issue #10917 has been updated by byroot (Jean Boussier). > That patch contains too many unrelated changes. You mean mine? Or the original one? If mine, most of the diff is because I renamed a bunch of `gc_prof_*` in just `gc_*` as they are no longer `GC::Profiler` specific. Also the link I posted was just a rough first try, I improved it in https://github.com/ruby/ruby/pull/4724/files?w=1 > And my concern is if :time is clear enough. Can you tell its unit by that name? That's unfortunately the case with most time metrics. Some people tend to append `_ms` to the name to make it clearer, not sure if it's worth not being compatible with JRuby/TruffleRuby over this. ---------------------------------------- Feature #10917: Add GC.stat[:total_time] when GC profiling enabled https://bugs.ruby-lang.org/issues/10917#change-93185 * Author: jasonrclark (Jason Clark) * Status: Open * Priority: Normal ---------------------------------------- This patch includes a `:total_time` value in `GC.stat` as a `Fixnum` of microseconds equivalent to `GC::Profiler.total_time`. A non-zero value is only provided if GC profiling is enabled. This avoids problems with `GC::Profiler`'s API in the presence of multiple callers. Well-behaved clients of `GC::Profiler` are expected to call `clear` periodically to constrain memory usage of the profiling structures. However, this causes problems when multiple callers--unaware of each other--rely on the value of `GC::Profiler.total_time` being unaltered since their last `clear`. Using a single value in `GC.stat` avoids this by providing a monotonically increasing count with every GC, not influenced by `clear`. **Considerations and Questions** * Because the individual GC times are potentially small, I tracked the total as a double and only convert to `Fixnum` when constructing `GC.stat`'s return. Is there something better I should be doing there, in light of `GC.stat`'s insistence that the stats returned be if type `size_t`? * What should I do (if anything) to cope with potential overflows? If Ruby is on a platform where `size_t` is 32 bits, we'd hit an overflow after 1.2 hours worth of cumulative GC time. **Future Directions** Is there any possibility of moving the GC timing (not the deeper profiling data) outside `GC::Profiler.enable`'s gating? I would love avoid clients needing to make code changes to track their GC time with my gem (newrelic_rpm). As it stands invocation start times are held on the GC profiling structures, so it felt like a much bigger change to alter that, and I thought I'd pitch this simpler change first. Any advice on whether that would be possible? Is timing too slow to do by default, or is the gating just an artifact of how it was implemented with `GC::Profiler`? ---Files-------------------------------- gc-total-time.patch (3.43 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: