Skip to content

Commit 594c218

Browse files
committed
Add marking and sweeping time as Process stat
Introduced in https://bugs.ruby-lang.org/issues/19437
1 parent 83a8979 commit 594c218

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ end
371371
| Counter | `major_gc_ops_total` | Major GC operations by process |
372372
| Counter | `minor_gc_ops_total` | Minor GC operations by process |
373373
| Counter | `allocated_objects_total` | Total number of allocated objects by process |
374+
| Gauge | `marking_time` | Marking time spent |
375+
| Gauge | `sweeping_time` | Sweeping time spent |
374376

375377
_Metrics marked with * are only collected when `MiniRacer` is defined._
376378

lib/prometheus_exporter/instrumentation/process.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ def collect_gc_stats(metric)
6363
metric[:major_gc_ops_total] = stat[:major_gc_count]
6464
metric[:minor_gc_ops_total] = stat[:minor_gc_count]
6565
metric[:allocated_objects_total] = stat[:total_allocated_objects]
66+
metric[:marking_time] = stat[:marking_time]
67+
metric[:sweeping_time] = stat[:sweeping_time]
6668
end
6769

6870
def collect_v8_stats(metric)

lib/prometheus_exporter/server/process_collector.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class ProcessCollector < TypeCollector
1313
v8_physical_size: "Physical size consumed by V8 heaps.",
1414
v8_heap_count: "Number of V8 contexts running.",
1515
rss: "Total RSS used by process.",
16+
marking_time: "Time spent in GC marking.",
17+
sweeping_time: "Time spent in GC sweeping.",
1618
}
1719

1820
PROCESS_COUNTERS = {

test/server/process_collector_test.rb

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@ def base_data
2626
"rss" => 3000,
2727
"major_gc_ops_total" => 4000,
2828
"minor_gc_ops_total" => 4001,
29-
"allocated_objects_total" => 4002
29+
"allocated_objects_total" => 4002,
30+
"marking_time" => 4003,
31+
"sweeping_time" => 4004,
3032
}
3133
end
3234

3335
def test_metrics_collection
3436
collector.collect(base_data)
3537

36-
assert_equal 10, collector.metrics.size
38+
assert_equal 12, collector.metrics.size
3739
assert_equal [
3840
'heap_free_slots{pid="1000",hostname="localhost"} 1000',
3941
'heap_live_slots{pid="1000",hostname="localhost"} 1001',
@@ -42,30 +44,32 @@ def test_metrics_collection
4244
'v8_physical_size{pid="1000",hostname="localhost"} 2003',
4345
'v8_heap_count{pid="1000",hostname="localhost"} 2004',
4446
'rss{pid="1000",hostname="localhost"} 3000',
47+
'marking_time{pid="1000",hostname="localhost"} 4003',
48+
'sweeping_time{pid="1000",hostname="localhost"} 4004',
4549
'major_gc_ops_total{pid="1000",hostname="localhost"} 4000',
4650
'minor_gc_ops_total{pid="1000",hostname="localhost"} 4001',
47-
'allocated_objects_total{pid="1000",hostname="localhost"} 4002'
51+
'allocated_objects_total{pid="1000",hostname="localhost"} 4002',
4852
], collector_metric_lines
4953
end
5054

5155
def test_metrics_deduplication
5256
collector.collect(base_data)
53-
assert_equal 10, collector.metrics.size
54-
assert_equal 10, collector_metric_lines.size
57+
assert_equal 12, collector.metrics.size
58+
assert_equal 12, collector_metric_lines.size
5559

5660
collector.collect(base_data)
57-
assert_equal 10, collector.metrics.size
58-
assert_equal 10, collector_metric_lines.size
61+
assert_equal 12, collector.metrics.size
62+
assert_equal 12, collector_metric_lines.size
5963

6064
collector.collect(base_data.merge({ "hostname" => "localhost2" }))
61-
assert_equal 10, collector.metrics.size
62-
assert_equal 20, collector_metric_lines.size
65+
assert_equal 12, collector.metrics.size
66+
assert_equal 24, collector_metric_lines.size
6367
end
6468

6569
def test_metrics_expiration
6670
stub_monotonic_clock(0) do
6771
collector.collect(base_data)
68-
assert_equal 10, collector.metrics.size
72+
assert_equal 12, collector.metrics.size
6973
end
7074

7175
stub_monotonic_clock(max_metric_age + 1) do

0 commit comments

Comments
 (0)