This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Started shutting down the sampler when it gets deleted #23012
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
621f99c
Started shutting down the sampler when it gets deleted. Previously
gaaclarke fc7f3a7
added test
gaaclarke 8006e06
fixed typo
gaaclarke f317b47
fixed build.gn hopefully
gaaclarke 37470cc
removed usleep to unblock windows
gaaclarke 5466ea1
format
gaaclarke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #include "flutter/shell/profiling/sampling_profiler.h" | ||
| #include "flutter/fml/message_loop_impl.h" | ||
| #include "flutter/fml/thread.h" | ||
| #include "flutter/testing/testing.h" | ||
| #include "gmock/gmock.h" | ||
|
|
||
| using testing::_; | ||
| using testing::Invoke; | ||
|
|
||
| namespace fml { | ||
| namespace { | ||
| class MockTaskRunner : public fml::TaskRunner { | ||
| public: | ||
| inline static RefPtr<MockTaskRunner> Create() { | ||
| return AdoptRef(new MockTaskRunner()); | ||
| } | ||
| MOCK_METHOD1(PostTask, void(const fml::closure& task)); | ||
| MOCK_METHOD2(PostTaskForTime, | ||
| void(const fml::closure& task, fml::TimePoint target_time)); | ||
| MOCK_METHOD2(PostDelayedTask, | ||
| void(const fml::closure& task, fml::TimeDelta delay)); | ||
| MOCK_METHOD0(RunsTasksOnCurrentThread, bool()); | ||
| MOCK_METHOD0(GetTaskQueueId, TaskQueueId()); | ||
|
|
||
| private: | ||
| MockTaskRunner() : TaskRunner(fml::RefPtr<MessageLoopImpl>()) {} | ||
| }; | ||
| } // namespace | ||
| } // namespace fml | ||
|
|
||
| namespace flutter { | ||
|
|
||
| TEST(SamplingProfilerTest, DeleteAfterStart) { | ||
| auto thread = | ||
| std::make_unique<fml::Thread>(flutter::testing::GetCurrentTestName()); | ||
| auto task_runner = fml::MockTaskRunner::Create(); | ||
| std::atomic<int> invoke_count = 0; | ||
|
|
||
| // Ignore calls to PostTask since that would require mocking out calls to | ||
| // Dart. | ||
| EXPECT_CALL(*task_runner, PostDelayedTask(_, _)) | ||
| .WillRepeatedly( | ||
| Invoke([&](const fml::closure& task, fml::TimeDelta delay) { | ||
| invoke_count.fetch_add(1); | ||
| thread->GetTaskRunner()->PostTask(task); | ||
| })); | ||
|
|
||
| { | ||
| auto profiler = SamplingProfiler( | ||
| "profiler", | ||
| /*profiler_task_runner=*/task_runner, [] { return ProfileSample(); }, | ||
| /*num_samples_per_sec=*/1000); | ||
| profiler.Start(); | ||
| } | ||
| int invoke_count_at_delete = invoke_count.load(); | ||
| std::this_thread::sleep_for(std::chrono::milliseconds(2)); // nyquist | ||
| ASSERT_EQ(invoke_count_at_delete, invoke_count.load()); | ||
| } | ||
|
|
||
| } // namespace flutter |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some tests? i.e. you can start and stop and start etc and check the scheduling of samples (even if you mock out the meaty parts). And check that destroying indeed stops.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Man, what a doozy to test, specially since there wasn't any existing tests. Ok, added.