Skip to content

Commit

Permalink
reset previous file to 0 when switching to a new file
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed Sep 18, 2012
1 parent f8b4834 commit 3b4c60f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ext/rblineprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ static struct {
// regex mode, store file data in hash table
VALUE source_regex;
st_table *files;
sourcefile_t *last_file;
}
rblineprof = {
.enabled = false,
.source_filename = NULL,
.source_regex = Qfalse,
.files = NULL
.files = NULL,
.last_file = NULL
};

static uint64_t
Expand Down Expand Up @@ -108,6 +110,11 @@ profiler_hook(rb_event_t event, NODE *node, VALUE self, ID mid, VALUE klass)

sourcefile->last_time = now;
sourcefile->last_line = line;

if (rblineprof.last_file && rblineprof.last_file != sourcefile)
rblineprof.last_file->last_time = 0;

rblineprof.last_file = sourcefile;
}
}

Expand Down Expand Up @@ -165,6 +172,7 @@ lineprof(VALUE self, VALUE filename)
}

// cleanup
rblineprof.last_file = NULL;
st_foreach(rblineprof.files, cleanup_files, 0);
if (rblineprof.file.lines) {
free(rblineprof.file.lines);
Expand Down

0 comments on commit 3b4c60f

Please sign in to comment.