This is an automated email from the ASF dual-hosted git repository.

panxiaolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 986e410fd5b [Bug](profile) fix wrong count of scan wait worker timer 
(#61064)
986e410fd5b is described below

commit 986e410fd5b50877d53e6d943d70eb2b10471887
Author: Pxl <[email protected]>
AuthorDate: Fri Mar 13 11:05:49 2026 +0800

    [Bug](profile) fix wrong count of scan wait worker timer (#61064)
    
    This pull request improves the accuracy and clarity of scanner timing
    and profiling in the `ScannerScheduler` implementation. The main changes
    clarify the order and logic for updating and recording timing counters,
    ensuring that CPU and wait times are measured more precisely during
    scanner execution and cleanup.
    
    **Enhancements to scanner timing and profiling:**
    
    * Added detailed comments explaining the correct order for setting and
    getting timing counters (`update_wait_worker_timer`,
    `start_scan_cpu_timer`, `update_scan_cpu_timer`,
    `start_wait_worker_timer`) to ensure accurate measurement of scanner CPU
    and wait times.
    * Refactored the `Defer` cleanup logic to only start the wait worker
    timer if the scanner has not failed and has not reached the
    end-of-stream, preventing redundant or incorrect counter updates.
---
 be/src/exec/scan/olap_scanner.cpp      |  5 +++++
 be/src/exec/scan/scanner_scheduler.cpp | 24 ++++++++++++++++--------
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/be/src/exec/scan/olap_scanner.cpp 
b/be/src/exec/scan/olap_scanner.cpp
index 460a6daf321..4fb031912cb 100644
--- a/be/src/exec/scan/olap_scanner.cpp
+++ b/be/src/exec/scan/olap_scanner.cpp
@@ -662,6 +662,11 @@ Status OlapScanner::close(RuntimeState* state) {
 }
 
 void OlapScanner::update_realtime_counters() {
+    if (!_has_prepared) {
+        // Counter update need prepare successfully, or it maybe core. For 
example, olap scanner
+        // will open tablet reader during prepare, if not prepare 
successfully, tablet reader == nullptr.
+        return;
+    }
     OlapScanLocalState* local_state = 
static_cast<OlapScanLocalState*>(_local_state);
     const OlapReaderStatistics& stats = _tablet_reader->stats();
     COUNTER_UPDATE(local_state->_read_compressed_counter, 
stats.compressed_bytes_read);
diff --git a/be/src/exec/scan/scanner_scheduler.cpp 
b/be/src/exec/scan/scanner_scheduler.cpp
index bb1574b05ee..3dfa1fdf4cd 100644
--- a/be/src/exec/scan/scanner_scheduler.cpp
+++ b/be/src/exec/scan/scanner_scheduler.cpp
@@ -152,14 +152,19 @@ void 
ScannerScheduler::_scanner_scan(std::shared_ptr<ScannerContext> ctx,
         Thread::set_thread_nice_value();
     }
 #endif
+
+    // we set and get counter according below order, to make sure the counter 
is updated before get_block, and the time of get_block is recorded in the 
counter.
+    // 1. update_wait_worker_timer to make sure the time of waiting for worker 
thread is recorded in the timer
+    // 2. start_scan_cpu_timer to make sure the cpu timer include the time of 
open and get_block, which is the real cpu time of scanner
+    // 3. update_scan_cpu_timer when defer, to make sure the cpu timer include 
the time of open and get_block, which is the real cpu time of scanner
+    // 4. start_wait_worker_timer when defer, to make sure the time of waiting 
for worker thread is recorded in the timer
+
     MonotonicStopWatch max_run_time_watch;
     max_run_time_watch.start();
     scanner->update_wait_worker_timer();
     scanner->start_scan_cpu_timer();
 
-    // Counter update need prepare successfully, or it maybe core. For 
example, olap scanner
-    // will open tablet reader during prepare, if not prepare successfully, 
tablet reader == nullptr.
-    bool need_update_profile = scanner->has_prepared();
+    bool need_update_profile = true;
     auto update_scanner_profile = [&]() {
         if (need_update_profile) {
             scanner->update_scan_cpu_timer();
@@ -167,13 +172,16 @@ void 
ScannerScheduler::_scanner_scan(std::shared_ptr<ScannerContext> ctx,
             need_update_profile = false;
         }
     };
-    Defer defer_scanner([&] {
-        // WorkloadGroup Policy will check cputime realtime, so that should 
update the counter
-        // as soon as possible, could not update it on close.
-        update_scanner_profile();
-    });
+
     Status status = Status::OK();
     bool eos = false;
+    Defer defer_scanner([&] {
+        if (status.ok() && !eos) {
+            // if status is not ok, it means the scanner is failed, and the 
counter may be not updated correctly, so no need to update counter again. if 
eos is true, it means the scanner is finished successfully, and the counter is 
updated correctly, so no need to update counter again.
+            scanner->start_wait_worker_timer();
+        }
+    });
+
     ASSIGN_STATUS_IF_CATCH_EXCEPTION(
             RuntimeState* state = ctx->state(); DCHECK(nullptr != state);
             // scanner->open may alloc plenty amount of memory(read blocks of 
data),


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to