Commit 20142b79 authored by Xi Cheng's avatar Xi Cheng Committed by Commit Bot

Store serialized profiles in ChildCallStackProfileCollector to save memory

Bug: 888716, 851163
Change-Id: I0fce8657b8ab41c0ac57bff548a029bab302c8b3
Reviewed-on: https://chromium-review.googlesource.com/c/1256106Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Commit-Queue: Xi Cheng <chengx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595901}
parent 481622c5
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "third_party/metrics_proto/sampled_profile.pb.h"
namespace metrics { namespace metrics {
...@@ -20,7 +21,7 @@ ChildCallStackProfileCollector::ProfileState::ProfileState(ProfileState&&) = ...@@ -20,7 +21,7 @@ ChildCallStackProfileCollector::ProfileState::ProfileState(ProfileState&&) =
ChildCallStackProfileCollector::ProfileState::ProfileState( ChildCallStackProfileCollector::ProfileState::ProfileState(
base::TimeTicks start_timestamp, base::TimeTicks start_timestamp,
SampledProfile profile) std::string profile)
: start_timestamp(start_timestamp), profile(std::move(profile)) {} : start_timestamp(start_timestamp), profile(std::move(profile)) {}
ChildCallStackProfileCollector::ProfileState::~ProfileState() = default; ChildCallStackProfileCollector::ProfileState::~ProfileState() = default;
...@@ -48,7 +49,7 @@ void ChildCallStackProfileCollector::SetParentProfileCollector( ...@@ -48,7 +49,7 @@ void ChildCallStackProfileCollector::SetParentProfileCollector(
if (parent_collector_) { if (parent_collector_) {
for (ProfileState& state : profiles_) { for (ProfileState& state : profiles_) {
mojom::SampledProfilePtr mojo_profile = mojom::SampledProfile::New(); mojom::SampledProfilePtr mojo_profile = mojom::SampledProfile::New();
state.profile.SerializeToString(&mojo_profile->contents); mojo_profile->contents = std::move(state.profile);
parent_collector_->Collect(state.start_timestamp, parent_collector_->Collect(state.start_timestamp,
std::move(mojo_profile)); std::move(mojo_profile));
} }
...@@ -77,8 +78,13 @@ void ChildCallStackProfileCollector::Collect(base::TimeTicks start_timestamp, ...@@ -77,8 +78,13 @@ void ChildCallStackProfileCollector::Collect(base::TimeTicks start_timestamp,
mojom::SampledProfilePtr mojo_profile = mojom::SampledProfile::New(); mojom::SampledProfilePtr mojo_profile = mojom::SampledProfile::New();
profile.SerializeToString(&mojo_profile->contents); profile.SerializeToString(&mojo_profile->contents);
parent_collector_->Collect(start_timestamp, std::move(mojo_profile)); parent_collector_->Collect(start_timestamp, std::move(mojo_profile));
} else if (retain_profiles_) { return;
profiles_.push_back(ProfileState(start_timestamp, std::move(profile))); }
if (retain_profiles_) {
std::string serialized_profile;
profile.SerializeToString(&serialized_profile);
profiles_.emplace_back(start_timestamp, std::move(serialized_profile));
} }
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef COMPONENTS_METRICS_CHILD_CALL_STACK_PROFILE_COLLECTOR_H_ #ifndef COMPONENTS_METRICS_CHILD_CALL_STACK_PROFILE_COLLECTOR_H_
#define COMPONENTS_METRICS_CHILD_CALL_STACK_PROFILE_COLLECTOR_H_ #define COMPONENTS_METRICS_CHILD_CALL_STACK_PROFILE_COLLECTOR_H_
#include <string>
#include <vector> #include <vector>
#include "base/macros.h" #include "base/macros.h"
...@@ -12,7 +13,6 @@ ...@@ -12,7 +13,6 @@
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "components/metrics/public/interfaces/call_stack_profile_collector.mojom.h" #include "components/metrics/public/interfaces/call_stack_profile_collector.mojom.h"
#include "third_party/metrics_proto/sampled_profile.pb.h"
namespace service_manager { namespace service_manager {
class InterfaceProvider; class InterfaceProvider;
...@@ -20,6 +20,8 @@ class InterfaceProvider; ...@@ -20,6 +20,8 @@ class InterfaceProvider;
namespace metrics { namespace metrics {
class SampledProfile;
// ChildCallStackProfileCollector collects stacks at startup, caching them // ChildCallStackProfileCollector collects stacks at startup, caching them
// internally until a CallStackProfileCollector interface is available. If a // internally until a CallStackProfileCollector interface is available. If a
// CallStackProfileCollector is provided via the InterfaceProvider supplied to // CallStackProfileCollector is provided via the InterfaceProvider supplied to
...@@ -63,21 +65,21 @@ class ChildCallStackProfileCollector { ...@@ -63,21 +65,21 @@ class ChildCallStackProfileCollector {
private: private:
friend class ChildCallStackProfileCollectorTest; friend class ChildCallStackProfileCollectorTest;
// Bundles together a collected profile and the collection state for // Bundles together a collected serialized profile and the collection state
// storage, pending availability of the parent mojo interface. |profile| // for storage, pending availability of the parent mojo interface. |profile|
// is not const& because it must be passed with std::move. // is not const& because it must be passed with std::move.
struct ProfileState { struct ProfileState {
ProfileState(); ProfileState();
ProfileState(ProfileState&&); ProfileState(ProfileState&&);
ProfileState(base::TimeTicks start_timestamp, SampledProfile profile); ProfileState(base::TimeTicks start_timestamp, std::string profile);
~ProfileState(); ~ProfileState();
ProfileState& operator=(ProfileState&&); ProfileState& operator=(ProfileState&&);
base::TimeTicks start_timestamp; base::TimeTicks start_timestamp;
// The sampled profile. // The serialized sampled profile.
SampledProfile profile; std::string profile;
private: private:
DISALLOW_COPY_AND_ASSIGN(ProfileState); DISALLOW_COPY_AND_ASSIGN(ProfileState);
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/metrics_proto/sampled_profile.pb.h"
namespace metrics { namespace metrics {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment