diff --git a/src/modules/pkpy.c b/src/modules/pkpy.c index 47a97e39..1bc2661d 100644 --- a/src/modules/pkpy.c +++ b/src/modules/pkpy.c @@ -493,7 +493,9 @@ static bool pkpy_profiler_reset(int argc, py_Ref argv) { static bool pkpy_profiler_report(int argc, py_Ref argv) { PY_CHECK_ARGC(0); - c11_string* report = LineProfiler__get_report(&pk_current_vm->line_profiler); + LineProfiler* lp = &pk_current_vm->line_profiler; + if(lp->enabled) LineProfiler__end(lp); + c11_string* report = LineProfiler__get_report(lp); bool ok = py_json_loads(report->data); c11_string__delete(report); return ok; diff --git a/src2/main.c b/src2/main.c index e3fa2545..9cebc1f9 100644 --- a/src2/main.c +++ b/src2/main.c @@ -51,9 +51,8 @@ int main(int argc, char** argv) { py_initialize(); py_sys_setargv(argc, argv); - if(profile) py_sys_settrace(py_LineProfiler_tracefunc, true); - if(filename == NULL) { + if(profile) printf("Warning: --profile is ignored in REPL mode.\n"); printf("pocketpy " PK_VERSION " (" __DATE__ ", " __TIME__ ") "); printf("[%d bit] on %s", (int)(sizeof(void*) * 8), PY_SYS_PLATFORM_STRING); #ifndef NDEBUG @@ -79,6 +78,7 @@ int main(int argc, char** argv) { } } } else { + if(profile) py_sys_settrace(py_LineProfiler_tracefunc, true); char* source = read_file(filename); if(source) { if(!py_exec(source, filename, EXEC_MODE, NULL)) py_printexc();