Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Unified Diff: components/metrics/child_call_stack_profile_collector_unittest.cc

Issue 2438073002: Use movable types for CallStackProfile(s) to remove copying of data. (Closed)
Patch Set: added some comments about std::move Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/metrics/child_call_stack_profile_collector_unittest.cc
diff --git a/components/metrics/child_call_stack_profile_collector_unittest.cc b/components/metrics/child_call_stack_profile_collector_unittest.cc
index 556124feed9b152ddd17f055e4b9e3ede5b82677..c8ef891048247e2efa6a8b5a50215de1694f9f69 100644
--- a/components/metrics/child_call_stack_profile_collector_unittest.cc
+++ b/components/metrics/child_call_stack_profile_collector_unittest.cc
@@ -5,6 +5,7 @@
#include "components/metrics/child_call_stack_profile_collector.h"
#include <memory>
+#include <utility>
#include <vector>
#include "base/bind.h"
@@ -35,11 +36,11 @@ class ChildCallStackProfileCollectorTest : public testing::Test {
void Collect(const CallStackProfileParams& params,
base::TimeTicks start_timestamp,
- const std::vector<CallStackProfile>& profiles) override {
+ std::vector<CallStackProfile> profiles) override {
this->profiles.push_back(ChildCallStackProfileCollector::ProfilesState(
params,
start_timestamp,
- profiles));
+ std::move(profiles)));
}
std::vector<ChildCallStackProfileCollector::ProfilesState> profiles;
@@ -53,10 +54,13 @@ class ChildCallStackProfileCollectorTest : public testing::Test {
ChildCallStackProfileCollectorTest()
: receiver_impl_(new Receiver(GetProxy(&receiver_))) {}
- void CollectProfiles(
+ void CollectEmptyProfiles(
const CallStackProfileParams& params,
- const base::StackSamplingProfiler::CallStackProfiles& profiles) {
- child_collector_.GetProfilerCallback(params).Run(profiles);
+ size_t profile_count) {
+ base::StackSamplingProfiler::CallStackProfiles profiles;
+ for (size_t i = 0; i < profile_count; ++i)
+ profiles.push_back(base::StackSamplingProfiler::CallStackProfile());
+ child_collector_.GetProfilerCallback(params).Run(std::move(profiles));
}
const std::vector<ChildCallStackProfileCollector::ProfilesState>&
@@ -77,13 +81,12 @@ TEST_F(ChildCallStackProfileCollectorTest, InterfaceProvided) {
EXPECT_EQ(0u, profiles().size());
// Add profiles before providing the interface.
- CollectProfiles(
+ CollectEmptyProfiles(
CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS,
CallStackProfileParams::UI_THREAD,
CallStackProfileParams::JANKY_TASK,
CallStackProfileParams::PRESERVE_ORDER),
- { base::StackSamplingProfiler::CallStackProfile(),
- base::StackSamplingProfiler::CallStackProfile() });
+ 2);
ASSERT_EQ(1u, profiles().size());
EXPECT_EQ(CallStackProfileParams::BROWSER_PROCESS,
profiles()[0].params.process);
@@ -111,12 +114,12 @@ TEST_F(ChildCallStackProfileCollectorTest, InterfaceProvided) {
// Add profiles after providing the interface. They should also be passed to
// it.
receiver_impl_->profiles.clear();
- CollectProfiles(
+ CollectEmptyProfiles(
CallStackProfileParams(CallStackProfileParams::GPU_PROCESS,
CallStackProfileParams::GPU_MAIN_THREAD,
CallStackProfileParams::THREAD_HUNG,
CallStackProfileParams::PRESERVE_ORDER),
- { base::StackSamplingProfiler::CallStackProfile() });
+ 1);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(0u, profiles().size());
ASSERT_EQ(1u, receiver_impl_->profiles.size());
@@ -138,13 +141,12 @@ TEST_F(ChildCallStackProfileCollectorTest, InterfaceNotProvided) {
EXPECT_EQ(0u, profiles().size());
// Add profiles before providing a null interface.
- CollectProfiles(
+ CollectEmptyProfiles(
CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS,
CallStackProfileParams::UI_THREAD,
CallStackProfileParams::JANKY_TASK,
CallStackProfileParams::PRESERVE_ORDER),
- { base::StackSamplingProfiler::CallStackProfile(),
- base::StackSamplingProfiler::CallStackProfile() });
+ 2);
ASSERT_EQ(1u, profiles().size());
EXPECT_EQ(CallStackProfileParams::BROWSER_PROCESS,
profiles()[0].params.process);
@@ -163,12 +165,12 @@ TEST_F(ChildCallStackProfileCollectorTest, InterfaceNotProvided) {
EXPECT_EQ(0u, profiles().size());
// Add profiles after providing a null interface. They should also be flushed.
- CollectProfiles(
+ CollectEmptyProfiles(
CallStackProfileParams(CallStackProfileParams::GPU_PROCESS,
CallStackProfileParams::GPU_MAIN_THREAD,
CallStackProfileParams::THREAD_HUNG,
CallStackProfileParams::PRESERVE_ORDER),
- { base::StackSamplingProfiler::CallStackProfile() });
+ 1);
EXPECT_EQ(0u, profiles().size());
}
« no previous file with comments | « components/metrics/child_call_stack_profile_collector.cc ('k') | components/metrics/public/cpp/call_stack_profile.typemap » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698