ext/stackprof/stackprof.c in stackprof-0.2.11 vs ext/stackprof/stackprof.c in stackprof-0.2.12

- old
+ new

@@ -18,11 +18,11 @@ #define BUF_SIZE 2048 typedef struct { size_t total_samples; size_t caller_samples; - int already_accounted_in_total; + size_t seen_at_sample_number; st_table *edges; st_table *lines; } frame_data_t; static struct { @@ -266,10 +266,11 @@ st_free_table(_stackprof.frames); _stackprof.frames = NULL; if (_stackprof.raw && _stackprof.raw_samples_len) { size_t len, n, o; + VALUE raw_timestamp_deltas; VALUE raw_samples = rb_ary_new_capa(_stackprof.raw_samples_len); for (n = 0; n < _stackprof.raw_samples_len; n++) { len = (size_t)_stackprof.raw_samples[n]; rb_ary_push(raw_samples, SIZET2NUM(len)); @@ -285,11 +286,11 @@ _stackprof.raw_samples_capa = 0; _stackprof.raw_sample_index = 0; rb_hash_aset(results, sym_raw, raw_samples); - VALUE raw_timestamp_deltas = rb_ary_new_capa(_stackprof.raw_timestamp_deltas_len); + raw_timestamp_deltas = rb_ary_new_capa(_stackprof.raw_timestamp_deltas_len); for (n = 0; n < _stackprof.raw_timestamp_deltas_len; n++) { rb_ary_push(raw_timestamp_deltas, INT2FIX(_stackprof.raw_timestamp_deltas[n])); } @@ -431,36 +432,32 @@ _stackprof.raw_timestamp_deltas[_stackprof.raw_timestamp_deltas_len++] = timestamp_delta; } for (i = 0; i < num; i++) { - VALUE frame = _stackprof.frames_buffer[i]; - sample_for(frame)->already_accounted_in_total = 0; - } - - for (i = 0; i < num; i++) { int line = _stackprof.lines_buffer[i]; VALUE frame = _stackprof.frames_buffer[i]; frame_data_t *frame_data = sample_for(frame); - if (!frame_data->already_accounted_in_total) + if (frame_data->seen_at_sample_number != _stackprof.overall_samples) { frame_data->total_samples++; - frame_data->already_accounted_in_total = 1; + } + frame_data->seen_at_sample_number = _stackprof.overall_samples; if (i == 0) { frame_data->caller_samples++; } else if (_stackprof.aggregate) { if (!frame_data->edges) frame_data->edges = st_init_numtable(); st_numtable_increment(frame_data->edges, (st_data_t)prev_frame, 1); } if (_stackprof.aggregate && line > 0) { - if (!frame_data->lines) - frame_data->lines = st_init_numtable(); size_t half = (size_t)1<<(8*SIZEOF_SIZE_T/2); size_t increment = i == 0 ? half + 1 : half; + if (!frame_data->lines) + frame_data->lines = st_init_numtable(); st_numtable_increment(frame_data->lines, (st_data_t)line, increment); } prev_frame = frame; } @@ -472,39 +469,39 @@ void stackprof_record_sample() { int timestamp_delta = 0; + int num; if (_stackprof.raw) { struct timeval t; - gettimeofday(&t, NULL); struct timeval diff; + gettimeofday(&t, NULL); timersub(&t, &_stackprof.last_sample_at, &diff); timestamp_delta = (1000 * diff.tv_sec) + diff.tv_usec; } - int num = rb_profile_frames(0, sizeof(_stackprof.frames_buffer) / sizeof(VALUE), _stackprof.frames_buffer, _stackprof.lines_buffer); + num = rb_profile_frames(0, sizeof(_stackprof.frames_buffer) / sizeof(VALUE), _stackprof.frames_buffer, _stackprof.lines_buffer); stackprof_record_sample_for_stack(num, timestamp_delta); } void stackprof_record_gc_samples() { int delta_to_first_unrecorded_gc_sample = 0; + int i; if (_stackprof.raw) { struct timeval t; - gettimeofday(&t, NULL); struct timeval diff; + gettimeofday(&t, NULL); timersub(&t, &_stackprof.last_sample_at, &diff); // We don't know when the GC samples were actually marked, so let's // assume that they were marked at a perfectly regular interval. delta_to_first_unrecorded_gc_sample = (1000 * diff.tv_sec + diff.tv_usec) - (_stackprof.unrecorded_gc_samples - 1) * _stackprof.interval; if (delta_to_first_unrecorded_gc_sample < 0) { delta_to_first_unrecorded_gc_sample = 0; } } - - int i; _stackprof.frames_buffer[0] = _stackprof.fake_gc_frame; _stackprof.lines_buffer[0] = 0; for (i = 0; i < _stackprof.unrecorded_gc_samples; i++) {