No reason for that callgrind stuff to be a big macro

This commit is contained in:
K. Lange 2022-07-05 17:43:44 +09:00
parent ee1420cd35
commit 92378917b0

View File

@ -89,27 +89,38 @@ void krk_forceThreadData(void) {
#endif #endif
#if !defined(KRK_NO_TRACING) && !defined(__EMSCRIPTEN__) #if !defined(KRK_NO_TRACING) && !defined(__EMSCRIPTEN__)
# define FRAME_IN(frame) if (vm.globalFlags & KRK_GLOBAL_CALLGRIND) { clock_gettime(CLOCK_MONOTONIC, &frame->in_time); } static void _frame_in(KrkCallFrame * frame) {
# define FRAME_OUT(frame) \ clock_gettime(CLOCK_MONOTONIC, &frame->in_time);
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; \ static void _frame_out(KrkCallFrame * frame) {
struct timespec outTime; \ if (frame->closure->function->obj.flags & KRK_OBJ_FLAGS_CODEOBJECT_IS_GENERATOR) return;
clock_gettime(CLOCK_MONOTONIC, &outTime); \
struct timespec diff; \ KrkCallFrame * caller = krk_currentThread.frameCount > 1 ? &krk_currentThread.frames[krk_currentThread.frameCount-2] : NULL;
diff.tv_sec = outTime.tv_sec - frame->in_time.tv_sec; \
diff.tv_nsec = outTime.tv_nsec - frame->in_time.tv_nsec; \ struct timespec outTime, diff;
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", \ clock_gettime(CLOCK_MONOTONIC, &outTime);
caller ? (caller->closure->function->chunk.filename->chars) : "stdin", \ diff.tv_sec = outTime.tv_sec - frame->in_time.tv_sec;
caller ? (caller->closure->function->qualname ? caller->closure->function->qualname->chars : caller->closure->function->name->chars) : "(root)", \ diff.tv_nsec = outTime.tv_nsec - frame->in_time.tv_nsec;
caller ? ((void*)caller->closure->function) : NULL, \
caller ? ((int)krk_lineNumber(&caller->closure->function->chunk, caller->ip - caller->closure->function->chunk.code)) : 1, \ if (diff.tv_nsec < 0) {
frame->closure->function->chunk.filename->chars, \ diff.tv_sec--;
frame->closure->function->qualname ? frame->closure->function->qualname->chars : frame->closure->function->name->chars, \ diff.tv_nsec += 1000000000L;
(void*)frame->closure->function, \
(int)krk_lineNumber(&frame->closure->function->chunk, 0), \
(long long)diff.tv_sec, diff.tv_nsec); \
} }
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 #else
# define FRAME_IN(frame) # define FRAME_IN(frame)
# define FRAME_OUT(frame) # define FRAME_OUT(frame)