radare2/libr/util/prof.c
pancake 3da650d4b1 * Write and install manpages
* Merge r_trace into r_debug (RDebugTrace)
  - Implement 'dt' command to manage debugging traces
  - TODO: Track register values and memory changes
  - Added dbg.trace and dbg.trace.tag
* Added r_sys_now() to retrieve ut64 value of current time
  - Must check endianness issues
* Initial work trying to implement RPATH support to ELF
* Less flat command tree
  - 'dt' is now 'dbt'
  - 'dk' is now 'dpk'
* Some more random syntax cleanup fixes
* Say 'yes/no' instead of 'ok/fail' in check-langs script
2010-03-12 18:46:11 +01:00

44 lines
1.3 KiB
C

/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
#include "r_util.h"
typedef struct timeval tv;
// Subtract the 'tv' values begin from end, storing result in RESULT
// Return 1 if the difference is negative, otherwise 0.
static int timeval_subtract(tv *result, tv *end, tv *begin) {
// Perform the carry for the later subtraction by updating Y
if (end->tv_usec < begin->tv_usec) {
int nsec = (begin->tv_usec - end->tv_usec) / 1000000 + 1;
begin->tv_usec -= 1000000 * nsec;
begin->tv_sec += nsec;
}
if (end->tv_usec - begin->tv_usec > 1000000) {
int nsec = (end->tv_usec - begin->tv_usec) / 1000000;
begin->tv_usec += 1000000 * nsec;
begin->tv_sec -= nsec;
}
// Compute the time remaining to wait. 'tv_usec' is certainly positive.
result->tv_sec = end->tv_sec - begin->tv_sec;
result->tv_usec = end->tv_usec - begin->tv_usec;
// Return 1 if result is negative
return end->tv_sec < begin->tv_sec;
}
R_API void r_prof_start(struct r_prof_t *p) {
tv *begin = &p->begin;
p->result = 0.0;
gettimeofday(begin, NULL);
}
R_API double r_prof_end(struct r_prof_t *p) {
tv end, diff, *begin = &p->begin;
int sign;
gettimeofday (&end, NULL);
sign = timeval_subtract (&diff, begin, &end);
p->result = R_ABS (((double)(diff.tv_sec) + ((double)diff.tv_usec / 1000000.)));
return R_ABS(sign);
}