From 7d38f83008da8b3ab93412172cd02568c819df89 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sun, 18 Feb 2024 00:57:56 +0800 Subject: [PATCH] fix a bug --- src/profiler.cpp | 8 ++++---- tests/84_line_profiler.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/profiler.cpp b/src/profiler.cpp index 3aec2201..377a74ed 100644 --- a/src/profiler.cpp +++ b/src/profiler.cpp @@ -49,16 +49,16 @@ void LineProfiler::_step_end(FrameId frame, int line){ FrameRecord& top_frame_record = frames.top(); LineRecord* prev_record = top_frame_record.prev_record; + int id_delta = frame.index - top_frame_record.frame.index; + PK_ASSERT(id_delta >= -1 && id_delta <= 1); + // current line is about to change if(prev_record->line != line){ clock_t delta = now - top_frame_record.prev_time; top_frame_record.prev_time = now; - prev_record->hits++; + if(id_delta != 1) prev_record->hits++; prev_record->time += delta; } - - int id_delta = frame.index - top_frame_record.frame.index; - PK_ASSERT(id_delta >= -1 && id_delta <= 1); if(id_delta == 1){ frames.push({frame, now, nullptr}); diff --git a/tests/84_line_profiler.py b/tests/84_line_profiler.py index b9b7ea00..01401c2a 100644 --- a/tests/84_line_profiler.py +++ b/tests/84_line_profiler.py @@ -15,8 +15,8 @@ lp = LineProfiler() lp.add_function(f2) -lp.runcall(f2, 1000000) -lp.print_stats() +# lp.runcall(f2, 1000000) +# lp.print_stats() ############################### lp.add_function(f1)