No reason for that callgrind stuff to be a big macro
This commit is contained in:
parent
ee1420cd35
commit
92378917b0
51
src/vm.c
51
src/vm.c
@ -89,27 +89,38 @@ void krk_forceThreadData(void) {
|
||||
#endif
|
||||
|
||||
#if !defined(KRK_NO_TRACING) && !defined(__EMSCRIPTEN__)
|
||||
# define FRAME_IN(frame) if (vm.globalFlags & KRK_GLOBAL_CALLGRIND) { clock_gettime(CLOCK_MONOTONIC, &frame->in_time); }
|
||||
# define FRAME_OUT(frame) \
|
||||
if (vm.globalFlags & KRK_GLOBAL_CALLGRIND && !(frame->closure->function->obj.flags & KRK_OBJ_FLAGS_CODEOBJECT_IS_GENERATOR)) { \
|
||||
KrkCallFrame * caller = krk_currentThread.frameCount > 1 ? &krk_currentThread.frames[krk_currentThread.frameCount-2] : NULL; \
|
||||
struct timespec outTime; \
|
||||
clock_gettime(CLOCK_MONOTONIC, &outTime); \
|
||||
struct timespec diff; \
|
||||
diff.tv_sec = outTime.tv_sec - frame->in_time.tv_sec; \
|
||||
diff.tv_nsec = outTime.tv_nsec - frame->in_time.tv_nsec; \
|
||||
if (diff.tv_nsec < 0) { diff.tv_sec--; diff.tv_nsec += 1000000000L; } \
|
||||
fprintf(vm.callgrindFile, "%s %s@%p %d %s %s@%p %d %lld.%.9ld\n", \
|
||||
caller ? (caller->closure->function->chunk.filename->chars) : "stdin", \
|
||||
caller ? (caller->closure->function->qualname ? caller->closure->function->qualname->chars : caller->closure->function->name->chars) : "(root)", \
|
||||
caller ? ((void*)caller->closure->function) : NULL, \
|
||||
caller ? ((int)krk_lineNumber(&caller->closure->function->chunk, caller->ip - caller->closure->function->chunk.code)) : 1, \
|
||||
frame->closure->function->chunk.filename->chars, \
|
||||
frame->closure->function->qualname ? frame->closure->function->qualname->chars : frame->closure->function->name->chars, \
|
||||
(void*)frame->closure->function, \
|
||||
(int)krk_lineNumber(&frame->closure->function->chunk, 0), \
|
||||
(long long)diff.tv_sec, diff.tv_nsec); \
|
||||
static void _frame_in(KrkCallFrame * frame) {
|
||||
clock_gettime(CLOCK_MONOTONIC, &frame->in_time);
|
||||
}
|
||||
static void _frame_out(KrkCallFrame * frame) {
|
||||
if (frame->closure->function->obj.flags & KRK_OBJ_FLAGS_CODEOBJECT_IS_GENERATOR) return;
|
||||
|
||||
KrkCallFrame * caller = krk_currentThread.frameCount > 1 ? &krk_currentThread.frames[krk_currentThread.frameCount-2] : NULL;
|
||||
|
||||
struct timespec outTime, diff;
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &outTime);
|
||||
diff.tv_sec = outTime.tv_sec - frame->in_time.tv_sec;
|
||||
diff.tv_nsec = outTime.tv_nsec - frame->in_time.tv_nsec;
|
||||
|
||||
if (diff.tv_nsec < 0) {
|
||||
diff.tv_sec--;
|
||||
diff.tv_nsec += 1000000000L;
|
||||
}
|
||||
|
||||
fprintf(vm.callgrindFile, "%s %s@%p %d %s %s@%p %d %lld.%.9ld\n",
|
||||
caller ? (caller->closure->function->chunk.filename->chars) : "stdin",
|
||||
caller ? (caller->closure->function->qualname ? caller->closure->function->qualname->chars : caller->closure->function->name->chars) : "(root)",
|
||||
caller ? ((void*)caller->closure->function) : NULL,
|
||||
caller ? ((int)krk_lineNumber(&caller->closure->function->chunk, caller->ip - caller->closure->function->chunk.code)) : 1,
|
||||
frame->closure->function->chunk.filename->chars,
|
||||
frame->closure->function->qualname ? frame->closure->function->qualname->chars : frame->closure->function->name->chars,
|
||||
(void*)frame->closure->function,
|
||||
(int)krk_lineNumber(&frame->closure->function->chunk, 0),
|
||||
(long long)diff.tv_sec, diff.tv_nsec);
|
||||
}
|
||||
# define FRAME_IN(frame) if (unlikely(vm.globalFlags & KRK_GLOBAL_CALLGRIND)) { _frame_in(frame); }
|
||||
# define FRAME_OUT(frame) if (unlikely(vm.globalFlags & KRK_GLOBAL_CALLGRIND)) { _frame_out(frame); }
|
||||
#else
|
||||
# define FRAME_IN(frame)
|
||||
# define FRAME_OUT(frame)
|
||||
|
Loading…
Reference in New Issue
Block a user