Skip to content

Commit 725a609

Browse files
committed
Add time to GC.stat
1 parent b808dd1 commit 725a609

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Diff for: gc/mmtk.c

+14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
struct objspace {
1515
size_t gc_count;
16+
size_t total_gc_time;
1617
size_t total_allocated_objects;
1718

1819
st_table *id_to_obj_tbl;
@@ -134,6 +135,9 @@ rb_mmtk_block_for_gc(MMTk_VMMutatorThread mutator)
134135
else {
135136
objspace->gc_count++;
136137

138+
struct timespec gc_start_time;
139+
clock_gettime(CLOCK_MONOTONIC, &gc_start_time);
140+
137141
int lock_lev = rb_gc_vm_lock();
138142
rb_gc_vm_barrier();
139143

@@ -151,6 +155,13 @@ rb_mmtk_block_for_gc(MMTk_VMMutatorThread mutator)
151155
mutator->execution_context = NULL;
152156

153157
rb_gc_vm_unlock(lock_lev);
158+
159+
struct timespec gc_end_time;
160+
clock_gettime(CLOCK_MONOTONIC, &gc_end_time);
161+
162+
objspace->total_gc_time +=
163+
(gc_end_time.tv_sec - gc_start_time.tv_sec) * (1000 * 1000 * 1000) +
164+
(gc_end_time.tv_nsec - gc_start_time.tv_nsec);
154165
}
155166

156167
if ((err = pthread_mutex_unlock(&objspace->mutex)) != 0) {
@@ -1076,6 +1087,7 @@ VALUE rb_gc_impl_latest_gc_info(void *objspace_ptr, VALUE key) { }
10761087

10771088
enum gc_stat_sym {
10781089
gc_stat_sym_count,
1090+
gc_stat_sym_time,
10791091
gc_stat_sym_total_allocated_objects,
10801092
gc_stat_sym_total_bytes,
10811093
gc_stat_sym_used_bytes,
@@ -1093,6 +1105,7 @@ setup_gc_stat_symbols(void)
10931105
if (gc_stat_symbols[0] == 0) {
10941106
#define S(s) gc_stat_symbols[gc_stat_sym_##s] = ID2SYM(rb_intern_const(#s))
10951107
S(count);
1108+
S(time);
10961109
S(total_allocated_objects);
10971110
S(total_bytes);
10981111
S(used_bytes);
@@ -1127,6 +1140,7 @@ rb_gc_impl_stat(void *objspace_ptr, VALUE hash_or_sym)
11271140
rb_hash_aset(hash, gc_stat_symbols[gc_stat_sym_##name], SIZET2NUM(attr));
11281141

11291142
SET(count, objspace->gc_count);
1143+
SET(time, objspace->total_gc_time / (1000 * 1000));
11301144
SET(total_allocated_objects, objspace->total_allocated_objects);
11311145
SET(total_bytes, mmtk_total_bytes());
11321146
SET(used_bytes, mmtk_used_bytes());

0 commit comments

Comments
 (0)