@@ -584,7 +584,7 @@ ThreadInfo::sample(EchionSampler& echion, int64_t iid, PyThreadState* tstate, mi
584584 return ErrorKind::CpuTimeError;
585585 }
586586
587- Renderer::get ().render_cpu_time (is_running () ? cpu_time - previous_cpu_time : 0 );
587+ Renderer::get ().render_cpu_time (cpu_time - previous_cpu_time);
588588
589589 this ->unwind (echion, tstate);
590590
@@ -640,29 +640,18 @@ Result<void>
640640ThreadInfo::update_cpu_time ()
641641{
642642#if defined PL_LINUX
643- struct timespec ts1 ;
644- if (clock_gettime (cpu_clock_id, &ts1 )) {
643+ struct timespec ts ;
644+ if (clock_gettime (cpu_clock_id, &ts )) {
645645 // If the clock is invalid, we skip updating the CPU time.
646646 // This can happen if we try to compute CPU time for a thread that has exited.
647647 if (errno == EINVAL) {
648- this ->running_ = false ;
649648 return Result<void >::ok ();
650649 }
651650
652651 return ErrorKind::CpuTimeError;
653652 }
654653
655- this ->cpu_time = TS_TO_MICROSECOND (ts1);
656-
657- // Determine if running by checking if CPU time advances between two back-to-back
658- // measurements. This is done here to avoid a separate is_running() call with
659- // its own syscalls (reduces 3 syscalls per thread to 2).
660- struct timespec ts2;
661- if (clock_gettime (cpu_clock_id, &ts2) != 0 ) {
662- this ->running_ = false ;
663- } else {
664- this ->running_ = (ts1.tv_sec != ts2.tv_sec || ts1.tv_nsec != ts2.tv_nsec );
665- }
654+ this ->cpu_time = TS_TO_MICROSECOND (ts);
666655#elif defined PL_DARWIN
667656 thread_basic_info_data_t info;
668657 mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT;
@@ -673,33 +662,22 @@ ThreadInfo::update_cpu_time()
673662 // If the thread is invalid, we skip updating the CPU time.
674663 // This can happen if we try to compute CPU time for a thread that has exited.
675664 if (kr == KERN_INVALID_ARGUMENT) {
676- this ->running_ = false ;
677665 return Result<void >::ok ();
678666 }
679667
680668 return ErrorKind::CpuTimeError;
681669 }
682670
683671 if (info.flags & TH_FLAGS_IDLE) {
684- this ->running_ = false ;
685672 return Result<void >::ok ();
686673 }
687674
688675 this ->cpu_time = TV_TO_MICROSECOND (info.user_time ) + TV_TO_MICROSECOND (info.system_time );
689- // On macOS, thread_info already gives us run_state, so no need to check if the clock is advancing
690- this ->running_ = (info.run_state == TH_STATE_RUNNING);
691676#endif
692677
693678 return Result<void >::ok ();
694679}
695680
696- bool
697- ThreadInfo::is_running ()
698- {
699- // Running state is computed in update_cpu_time by taking two back-to-back measurements of the CPU time.
700- return this ->running_ ;
701- }
702-
703681void
704682for_each_thread (EchionSampler& echion, InterpreterInfo& interp, PyThreadStateCallback callback)
705683{
0 commit comments