blueloveTH 6 달 전
부모
커밋
4633ca7242
2개의 변경된 파일5개의 추가작업 그리고 3개의 파일을 삭제
  1. 3 1
      src/modules/pkpy.c
  2. 2 2
      src2/main.c

+ 3 - 1
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;

+ 2 - 2
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();