This commit is contained in:
blueloveTH 2025-08-08 12:02:31 +08:00
parent bc51c5e19d
commit 4633ca7242
2 changed files with 5 additions and 3 deletions

View File

@ -493,7 +493,9 @@ static bool pkpy_profiler_reset(int argc, py_Ref argv) {
static bool pkpy_profiler_report(int argc, py_Ref argv) { static bool pkpy_profiler_report(int argc, py_Ref argv) {
PY_CHECK_ARGC(0); 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); bool ok = py_json_loads(report->data);
c11_string__delete(report); c11_string__delete(report);
return ok; return ok;

View File

@ -51,9 +51,8 @@ int main(int argc, char** argv) {
py_initialize(); py_initialize();
py_sys_setargv(argc, argv); py_sys_setargv(argc, argv);
if(profile) py_sys_settrace(py_LineProfiler_tracefunc, true);
if(filename == NULL) { if(filename == NULL) {
if(profile) printf("Warning: --profile is ignored in REPL mode.\n");
printf("pocketpy " PK_VERSION " (" __DATE__ ", " __TIME__ ") "); printf("pocketpy " PK_VERSION " (" __DATE__ ", " __TIME__ ") ");
printf("[%d bit] on %s", (int)(sizeof(void*) * 8), PY_SYS_PLATFORM_STRING); printf("[%d bit] on %s", (int)(sizeof(void*) * 8), PY_SYS_PLATFORM_STRING);
#ifndef NDEBUG #ifndef NDEBUG
@ -79,6 +78,7 @@ int main(int argc, char** argv) {
} }
} }
} else { } else {
if(profile) py_sys_settrace(py_LineProfiler_tracefunc, true);
char* source = read_file(filename); char* source = read_file(filename);
if(source) { if(source) {
if(!py_exec(source, filename, EXEC_MODE, NULL)) py_printexc(); if(!py_exec(source, filename, EXEC_MODE, NULL)) py_printexc();