Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed Sep 10, 2012
1 parent ca630ca commit ccf8b09
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
| end
|
| File.readlines(__FILE__).each_with_index do |line, num|
| sample = per_line[num+1]
| if sample
| printf "% 6d | %s", per_line[num+1], line
| if sample = per_line[num+1]
| printf "% 6d | %s", sample, line
| else
| printf " | %s", line
| end
Expand Down
16 changes: 7 additions & 9 deletions ext/rblineprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,17 @@ profiler_hook(rb_event_t event, NODE *node, VALUE self, ID mid, VALUE klass)
{
char *file = node->nd_file;
long line = nd_line(node);
/* fprintf(stderr, "event: %d, file: %s:%lu\n", event, file, line);*/

if (source_filename == file) {
uint64_t now = timeofday_usec();

if (!start_time) {
start_time = now;
last_line = line;

} else {
per_line[last_line] += now - start_time;
start_time = now;
last_line = line;
if (start_time) {
if (last_line < MAX_LINES)
per_line[last_line] += now - start_time;
}

start_time = now;
last_line = line;
}
}

Expand All @@ -48,6 +45,7 @@ lineprof(VALUE self, VALUE filename)

start_time = 0;
source_filename = rb_source_filename(StringValuePtr(filename));
memset(per_line, 0, sizeof(per_line));

rb_add_event_hook(profiler_hook, RUBY_EVENT_LINE);
rb_yield(Qnil);
Expand Down
5 changes: 2 additions & 3 deletions test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
end

File.readlines(__FILE__).each_with_index do |line, num|
sample = per_line[num+1]
if sample
printf "% 6d | %s", per_line[num+1], line
if sample = per_line[num+1]
printf "% 6d | %s", sample, line
else
printf " | %s", line
end
Expand Down

0 comments on commit ccf8b09

Please sign in to comment.