#ifndef devtools_vprof_vprof_h
#define devtools_vprof_vprof_h
#define THREADED 0
#define THREAD_SAFE 0
#include "VMPI.h"
#if defined(_MSC_VER)
# define vprof_align8(t) __declspec(align(8)) t
#elif defined(__GNUC__)
# define vprof_align8(t) t __attribute__((aligned(8)))
#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
# define vprof_align8(t) t __attribute__((aligned(8)))
#elif defined(VMCFG_SYMBIAN)
# define vprof_align8(t) t __attribute__((aligned(8)))
#endif
#ifdef __cplusplus
extern "C" {
#endif
int initValueProfile(void** id, char* file, int line, ...);
int profileValue(void* id, int64_t value);
int initHistProfile(void** id, char* file, int line, int nbins, ...);
int histValue(void* id, int64_t value);
uint64_t readTimestampCounter();
#ifdef __cplusplus
}
#endif
#ifndef DOPROF
# define _nvprof(e, v)
# ifndef VMCFG_SYMBIAN
# define _vprof(v, ...)
# define _hprof(v, n, ...)
# define _nhprof(e, v, n, ...)
# define _ntprof_begin(e)
# define _ntprof_end(e)
# define _jvprof_init(id, ...)
# define _jnvprof_init(id, e, ...)
# define _jhprof_init(id, n, ...)
# define _jnhprof_init(id, e, n, ...)
# define _jvprof(id, v)
# define _jhprof(id, v)
# endif #else
# define _vprof(v, ...) \
do { \
static void* id = 0; \
if (id == 0) \
initValueProfile(&id, __FILE__, __LINE__, ##__VA_ARGS__, NULL); \
profileValue(id, (int64_t)(v)); \
} while (0)
# define _nvprof(e, v) \
do { \
static void* id = 0; \
if (id == 0) initValueProfile(&id, (char*)(e), -1, NULL); \
profileValue(id, (int64_t)(v)); \
} while (0)
# define _hprof(v, n, ...) \
do { \
static void* id = 0; \
if (id == 0) \
initHistProfile(&id, __FILE__, __LINE__, (int)(n), ##__VA_ARGS__); \
histValue(id, (int64_t)(v)); \
} while (0)
# define _nhprof(e, v, n, ...) \
do { \
static void* id = 0; \
if (id == 0) \
initHistProfile(&id, (char*)(e), -1, (int)(n), ##__VA_ARGS__); \
histValue(id, (int64_t)(v)); \
} while (0)
# define _ntprof_begin(e) \
do { \
static void* id = 0; \
if (id == 0) initValueProfile(&id, (char*)(e), -1, NULL); \
((entry_t)id)->i64var[0] = readTimestampCounter(); \
} while (0)
# define TICKS_PER_USEC 2600
# define _ntprof_end(e) \
do { \
static void* id = 0; \
uint64_t stop = readTimestampCounter(); \
if (id == 0) initValueProfile(&id, (char*)(e), -1, NULL); \
uint64_t start = ((entry_t)id)->i64var[0]; \
uint64_t usecs = (stop - start) / TICKS_PER_USEC; \
profileValue(id, usecs); \
} while (0)
# define _jvprof_init(id, ...) \
if (*(id) == 0) \
initValueProfile((id), __FILE__, __LINE__, ##__VA_ARGS__, NULL)
# define _jnvprof_init(id, e, ...) \
if (*(id) == 0) initValueProfile((id), (char*)(e), -1, ##__VA_ARGS__, NULL)
# define _jhprof_init(id, n, ...) \
if (*(id) == 0) \
initHistProfile((id), __FILE__, __LINE__, (int)(n), ##__VA_ARGS__)
# define _jnhprof_init(id, e, n, ...) \
if (*(id) == 0) \
initHistProfile((id), (char*)(e), -1, (int)(n), ##__VA_ARGS__)
# define _jvprof(id, v) profileValue((id), (int64_t)(v))
# define _jhprof(id, v) histValue((id), (int64_t)(v))
#endif
#define NUM_EVARS 4
enum { LOCK_IS_FREE = 0, LOCK_IS_TAKEN = 1 };
extern
#ifdef __cplusplus
"C"
#endif
long
_InterlockedCompareExchange(long volatile* Destination, long Exchange,
long Comperand);
typedef struct hist hist;
typedef struct hist {
int nbins;
int64_t* lb;
int64_t* count;
} * hist_t;
typedef struct entry entry;
typedef struct entry {
long lock;
char* file;
int line;
int64_t value;
int64_t count;
int64_t sum;
int64_t min;
int64_t max;
void (*func)(void*);
hist* h;
entry* next;
void* genptr;
int ivar[NUM_EVARS];
vprof_align8(int64_t) i64var[NUM_EVARS];
vprof_align8(double) dvar[NUM_EVARS];
char pad[128]; } * entry_t;
#define _VAL ((entry_t)vprofID)->value
#define _COUNT ((entry_t)vprofID)->count
#define _SUM ((entry_t)vprofID)->sum
#define _MIN ((entry_t)vprofID)->min
#define _MAX ((entry_t)vprofID)->max
#define _GENPTR ((entry_t)vprofID)->genptr
#define _IVAR0 ((entry_t)vprofID)->ivar[0]
#define _IVAR1 ((entry_t)vprofID)->ivar[1]
#define _IVAR2 ((entry_t)vprofID)->ivar[2]
#define _IVAR3 ((entry_t)vprofID)->ivar[3]
#define _I64VAR0 ((entry_t)vprofID)->i64var[0]
#define _I64VAR1 ((entry_t)vprofID)->i64var[1]
#define _I64VAR2 ((entry_t)vprofID)->i64var[2]
#define _I64VAR3 ((entry_t)vprofID)->i64var[3]
#define _DVAR0 ((entry_t)vprofID)->dvar[0]
#define _DVAR1 ((entry_t)vprofID)->dvar[1]
#define _DVAR2 ((entry_t)vprofID)->dvar[2]
#define _DVAR3 ((entry_t)vprofID)->dvar[3]
#endif