Skip to content

Commit

Permalink
Categorize as GC
Browse files Browse the repository at this point in the history
  • Loading branch information
jhawthorn committed Nov 27, 2024
1 parent a96dd80 commit c67a130
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions ext/vernier/vernier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,8 @@ class RawSample {
return;
}

if (rb_during_gc()) {
gc = true;
} else {
len = rb_profile_frames(0, MAX_LEN, frames, lines);
this->offset = std::min(offset, len);
}
len = rb_profile_frames(0, MAX_LEN, frames, lines);
this->offset = std::min(offset, len);
}

void clear() {
Expand Down Expand Up @@ -858,7 +854,8 @@ class GCMarkerTable: public MarkerTable {
enum Category{
CATEGORY_NORMAL,
CATEGORY_IDLE,
CATEGORY_STALLED
CATEGORY_STALLED,
CATEGORY_GC
};

class ObjectSampleList {
Expand Down Expand Up @@ -1552,6 +1549,8 @@ class TimeCollector : public BaseCollector {
unsigned int allocation_interval;
unsigned int allocation_tick = 0;

atomic_bool gc_running;

VALUE tp_newobj = Qnil;

static void newobj_i(VALUE tpval, void *data) {
Expand Down Expand Up @@ -1589,7 +1588,10 @@ class TimeCollector : public BaseCollector {
BaseCollector::write_meta(meta, result);
rb_hash_aset(meta, sym("interval"), ULL2NUM(interval.microseconds()));
rb_hash_aset(meta, sym("allocation_interval"), ULL2NUM(allocation_interval));
}

void set_gc_running(bool value) {
gc_running = value;
}

private:
Expand Down Expand Up @@ -1652,7 +1654,7 @@ class TimeCollector : public BaseCollector {
} else if (sample.sample.empty()) {
// fprintf(stderr, "skipping GC sample\n");
} else {
record_sample(sample.sample, sample_start, thread, CATEGORY_NORMAL);
record_sample(sample.sample, sample_start, thread, gc_running ? CATEGORY_GC : CATEGORY_NORMAL);
}
} else if (thread.state == Thread::State::SUSPENDED) {
thread.samples.record_sample(
Expand Down Expand Up @@ -1725,9 +1727,11 @@ class TimeCollector : public BaseCollector {
collector->gc_markers.record_gc_end_sweep();
break;
case RUBY_INTERNAL_EVENT_GC_ENTER:
collector->set_gc_running(true);
collector->gc_markers.record_gc_entered();
break;
case RUBY_INTERNAL_EVENT_GC_EXIT:
collector->set_gc_running(false);
collector->gc_markers.record_gc_leave();
break;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/vernier/output/firefox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def initialize
add_category(name: "Idle", color: "transparent")
add_category(name: "Stalled", color: "transparent")

add_category(name: "GC", color: "red")
add_category(name: "GC", color: "orange")
add_category(name: "cfunc", color: "yellow", matcher: "<cfunc>")

add_category(name: "Thread", color: "grey")
Expand Down

0 comments on commit c67a130

Please sign in to comment.