Skip to content

Commit

Permalink
Record stacks with suspended markers
Browse files Browse the repository at this point in the history
  • Loading branch information
jhawthorn committed Aug 29, 2023
1 parent edc05b1 commit fe8e509
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
22 changes: 12 additions & 10 deletions ext/vernier/vernier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,10 @@ class Marker {
TimeStamp timestamp;
TimeStamp finish;
native_thread_id_t thread_id;
int stack_index = -1;

VALUE to_array() {
VALUE record[5] = {0};
VALUE record[6] = {0};
record[0] = ULL2NUM(thread_id);
record[1] = INT2NUM(type);
record[2] = INT2NUM(phase);
Expand All @@ -613,8 +614,9 @@ class Marker {
else {
record[4] = Qnil;
}
record[5] = stack_index == -1 ? Qnil : INT2NUM(stack_index);

return rb_ary_new_from_values(5, record);
return rb_ary_new_from_values(6, record);
}
};

Expand All @@ -630,19 +632,19 @@ class MarkerTable {
}

void record_gc_leave() {
list.push_back({ Marker::MARKER_GC_PAUSE, Marker::INTERVAL, last_gc_entry, TimeStamp::Now(), get_native_thread_id() });
list.push_back({ Marker::MARKER_GC_PAUSE, Marker::INTERVAL, last_gc_entry, TimeStamp::Now(), get_native_thread_id(), -1 });
}

void record_interval(Marker::Type type, TimeStamp from, TimeStamp to) {
void record_interval(Marker::Type type, TimeStamp from, TimeStamp to, int stack_index = -1) {
const std::lock_guard<std::mutex> lock(mutex);

list.push_back({ type, Marker::INTERVAL, from, to, get_native_thread_id() });
list.push_back({ type, Marker::INTERVAL, from, to, get_native_thread_id(), stack_index });
}

void record(Marker::Type type) {
void record(Marker::Type type, int stack_index = -1) {
const std::lock_guard<std::mutex> lock(mutex);

list.push_back({ type, Marker::INSTANT, TimeStamp::Now(), TimeStamp(), get_native_thread_id() });
list.push_back({ type, Marker::INSTANT, TimeStamp::Now(), TimeStamp(), get_native_thread_id(), stack_index });
}
};

Expand Down Expand Up @@ -766,8 +768,8 @@ class Thread {
// If the GVL is immediately ready, and we measure no times
// stalled, skip emitting the interval.
if (from != now) {
markers->record_interval(Marker::Type::MARKER_THREAD_STALLED, from, now);
}
markers->record_interval(Marker::Type::MARKER_THREAD_STALLED, from, now);
}
break;
case State::READY:
// The ready state means "I would like to do some work, but I can't
Expand All @@ -779,7 +781,7 @@ class Thread {
// so I'll put you in the 'ready' (or stalled) state"
assert(state == State::SUSPENDED || state == State::RUNNING);
if (state == State::SUSPENDED) {
markers->record_interval(Marker::Type::MARKER_THREAD_SUSPENDED, from, now);
markers->record_interval(Marker::Type::MARKER_THREAD_SUSPENDED, from, now, stack_on_suspend_idx);
}
else {
markers->record_interval(Marker::Type::MARKER_THREAD_RUNNING, from, now);
Expand Down
6 changes: 4 additions & 2 deletions lib/vernier/collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ def stop

marker_strings = Marker.name_table

markers = self.markers.map do |(tid, type, phase, ts, te)|
markers = self.markers.map do |(tid, type, phase, ts, te, stack)|
name = marker_strings[type]
sym = Marker::MARKER_SYMBOLS[type]
[tid, name, ts, te, phase, { type: sym }]
data = { type: sym }
data[:cause] = { stack: stack } if stack
[tid, name, ts, te, phase, data]
end

markers.concat @markers
Expand Down

0 comments on commit fe8e509

Please sign in to comment.