Skip to content

Commit

Permalink
add prof_time_t
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed Jan 15, 2013
1 parent 0610a78 commit dba1c34
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions ext/rblineprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
#include <st.h>
#include <re.h>

typedef uint64_t prof_time_t;

static VALUE gc_hook;

typedef struct {
char *filename;
uint64_t *lines;
prof_time_t *lines;
long nlines;

uint64_t last_time;
prof_time_t last_time;
long last_line;
} sourcefile_t;

Expand Down Expand Up @@ -44,33 +46,33 @@ rblineprof = {
.last_sourcefile = NULL
};

static uint64_t
static prof_time_t
timeofday_usec()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return (uint64_t)tv.tv_sec*1e6 +
(uint64_t)tv.tv_usec;
return (prof_time_t)tv.tv_sec*1e6 +
(prof_time_t)tv.tv_usec;
}

static inline void
sourcefile_record(sourcefile_t *sourcefile, uint64_t now)
sourcefile_record(sourcefile_t *sourcefile, prof_time_t now)
{
if (sourcefile->last_time && sourcefile->last_line) {
/* allocate space for per-line data the first time */
if (sourcefile->lines == NULL) {
sourcefile->nlines = sourcefile->last_line + 100;
sourcefile->lines = ALLOC_N(uint64_t, sourcefile->nlines);
MEMZERO(sourcefile->lines, uint64_t, sourcefile->nlines);
sourcefile->lines = ALLOC_N(prof_time_t, sourcefile->nlines);
MEMZERO(sourcefile->lines, prof_time_t, sourcefile->nlines);
}

/* grow the per-line array if necessary */
if (sourcefile->last_line >= sourcefile->nlines) {
long prev_nlines = sourcefile->nlines;
sourcefile->nlines = sourcefile->last_line + 100;

REALLOC_N(sourcefile->lines, uint64_t, sourcefile->nlines);
MEMZERO(sourcefile->lines + prev_nlines, uint64_t, sourcefile->nlines - prev_nlines);
REALLOC_N(sourcefile->lines, prof_time_t, sourcefile->nlines);
MEMZERO(sourcefile->lines + prev_nlines, prof_time_t, sourcefile->nlines - prev_nlines);
}

/* record the sample */
Expand Down Expand Up @@ -126,7 +128,7 @@ profiler_hook(rb_event_t event, NODE *node, VALUE self, ID mid, VALUE klass)
}

if (sourcefile) {
uint64_t now = timeofday_usec();
prof_time_t now = timeofday_usec();

/* increment if the line in the current file changed */
if (sourcefile->last_line != line) {
Expand Down

0 comments on commit dba1c34

Please sign in to comment.