77#include < absl/container/flat_hash_map.h>
88#include < absl/container/flat_hash_set.h>
99#include < absl/flags/flag.h>
10+ #include < absl/flags/internal/flag.h>
1011#include < absl/hash/hash.h>
1112#include < absl/strings/match.h>
1213#include < absl/strings/str_cat.h>
117118
118119using orbit_base::CanceledOr;
119120using orbit_base::Future;
121+ using orbit_base::kAllProcessThreadsTid ;
120122using orbit_base::NotFoundOr;
121123
122124using orbit_capture_client::CaptureClient;
@@ -183,6 +185,8 @@ namespace {
183185constexpr const char * kNtdllSoFileName = " ntdll.so" ;
184186constexpr const char * kWineSyscallDispatcherFunctionName = " __wine_syscall_dispatcher" ;
185187constexpr std::string_view kGgpVlkModulePathSubstring = " ggpvlk.so" ;
188+ const TimeRange kDefaultTimeRange =
189+ TimeRange (std::numeric_limits<uint64_t >::min(), std::numeric_limits<uint64_t >::max());
186190
187191orbit_data_views::PresetLoadState GetPresetLoadStateForProcess (const PresetFile& preset,
188192 const ProcessData* process) {
@@ -2156,9 +2160,15 @@ void OrbitApp::SetVisibleScopeIds(absl::flat_hash_set<ScopeId> visible_scope_ids
21562160}
21572161
21582162bool OrbitApp::IsTimerActive (const TimerInfo& timer) const {
2159- const std::optional<TimeRange>& time_range = data_manager_->GetSelectionTimeRange ();
2160- if (time_range.has_value () && !time_range.value ().IsTimerInRange (timer)) {
2161- return false ;
2163+ if (absl::GetFlag (FLAGS_time_range_selection)) {
2164+ const std::optional<TimeRange>& time_range = data_manager_->GetSelectionTimeRange ();
2165+ if (time_range.has_value () && !time_range.value ().IsTimerInRange (timer)) {
2166+ return false ;
2167+ }
2168+ const uint32_t thread_id = data_manager_->selected_thread_id ();
2169+ if (thread_id != kAllProcessThreadsTid && thread_id != timer.thread_id ()) {
2170+ return false ;
2171+ }
21622172 }
21632173 const std::optional<ScopeId> scope_id = GetCaptureData ().ProvideScopeId (timer);
21642174 if (!scope_id.has_value ()) {
@@ -2180,7 +2190,8 @@ ThreadID OrbitApp::selected_thread_id() const { return data_manager_->selected_t
21802190
21812191void OrbitApp::set_selected_thread_id (ThreadID thread_id) {
21822192 RequestUpdatePrimitives ();
2183- return data_manager_->set_selected_thread_id (thread_id);
2193+ data_manager_->set_selected_thread_id (thread_id);
2194+ OnThreadOrTimeRangeSelectionChange ();
21842195}
21852196
21862197std::optional<ThreadStateSliceInfo> OrbitApp::selected_thread_state_slice () const {
@@ -2290,8 +2301,7 @@ void OrbitApp::InspectCallstackEvents(absl::Span<const CallstackEvent> selected_
22902301 FireRefreshCallbacks ();
22912302}
22922303
2293- void OrbitApp::ClearAllSelections () {
2294- ClearInspection ();
2304+ void OrbitApp::ClearSelectionTabs () {
22952305 ClearSelectionReport ();
22962306 ClearSelectionTopDownView ();
22972307 ClearSelectionBottomUpView ();
@@ -2806,33 +2816,57 @@ const ProcessData& OrbitApp::GetConnectedOrLoadedProcess() const {
28062816}
28072817
28082818void OrbitApp::OnTimeRangeSelection (TimeRange time_range) {
2809- ClearAllSelections ();
2810-
2811- auto selected_callstack_events =
2812- GetCaptureData ().GetCallstackData ().GetCallstackEventsInTimeRange (time_range.start ,
2813- time_range.end );
2814- SetCaptureDataSelectionFields (selected_callstack_events, /* origin_is_multiple_threads=*/ true );
2815-
2816- main_window_->SetLiveTabScopeStatsCollection (
2817- GetCaptureData ().CreateScopeStatsCollection (time_range.start , time_range.end ));
2818- SetTopDownView (GetCaptureData ().selection_post_processed_sampling_data ());
2819- SetBottomUpView (GetCaptureData ().selection_post_processed_sampling_data ());
2820- SetSamplingReport (&GetCaptureData ().selection_callstack_data (),
2821- &GetCaptureData ().selection_post_processed_sampling_data ());
28222819 data_manager_->SetSelectionTimeRange (time_range);
2823-
2824- FireRefreshCallbacks ();
2820+ OnThreadOrTimeRangeSelectionChange ();
28252821}
28262822
28272823void OrbitApp::ClearTimeRangeSelection () {
2828- ClearAllSelections ();
2824+ data_manager_->ClearSelectionTimeRange ();
2825+ OnThreadOrTimeRangeSelectionChange ();
2826+ }
28292827
2828+ void OrbitApp::ClearThreadAndTimeRangeSelection () {
28302829 main_window_->SetLiveTabScopeStatsCollection (GetCaptureData ().GetAllScopeStatsCollection ());
28312830 SetTopDownView (GetCaptureData ().post_processed_sampling_data ());
28322831 SetBottomUpView (GetCaptureData ().post_processed_sampling_data ());
28332832 SetSamplingReport (&GetCaptureData ().GetCallstackData (),
28342833 &GetCaptureData ().post_processed_sampling_data ());
2835- data_manager_->ClearSelectionTimeRange ();
2834+
2835+ FireRefreshCallbacks ();
2836+ }
2837+
2838+ void OrbitApp::OnThreadOrTimeRangeSelectionChange () {
2839+ if (!HasCaptureData () || !absl::GetFlag (FLAGS_time_range_selection)) return ;
2840+
2841+ ClearSelectionTabs ();
2842+ ClearInspection ();
2843+
2844+ uint32_t thread_id = data_manager_->selected_thread_id ();
2845+ bool has_time_range = data_manager_->GetSelectionTimeRange ().has_value ();
2846+ if (thread_id == kAllProcessThreadsTid && !has_time_range) {
2847+ ClearThreadAndTimeRangeSelection ();
2848+ return ;
2849+ }
2850+
2851+ TimeRange time_range =
2852+ has_time_range ? data_manager_->GetSelectionTimeRange ().value () : kDefaultTimeRange ;
2853+ if (thread_id == kAllProcessThreadsTid ) {
2854+ SetCaptureDataSelectionFields (GetCaptureData ().GetCallstackData ().GetCallstackEventsInTimeRange (
2855+ time_range.start , time_range.end ),
2856+ /* origin_is_multiple_threads=*/ true );
2857+ } else {
2858+ SetCaptureDataSelectionFields (
2859+ GetCaptureData ().GetCallstackData ().GetCallstackEventsOfTidInTimeRange (
2860+ thread_id, time_range.start , time_range.end ),
2861+ /* origin_is_multiple_threads=*/ false );
2862+ }
2863+
2864+ main_window_->SetLiveTabScopeStatsCollection (
2865+ GetCaptureData ().CreateScopeStatsCollection (thread_id, time_range.start , time_range.end ));
2866+ SetTopDownView (GetCaptureData ().selection_post_processed_sampling_data ());
2867+ SetBottomUpView (GetCaptureData ().selection_post_processed_sampling_data ());
2868+ SetSamplingReport (&GetCaptureData ().selection_callstack_data (),
2869+ &GetCaptureData ().selection_post_processed_sampling_data ());
28362870
28372871 FireRefreshCallbacks ();
28382872}
0 commit comments