Commit 3bacc2ae authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

Migrate InspectorMemoryAgent to AgentStateFields.

This one is real simple.

I've also tweaked the constant for the native default to
be of the same type as the fromNative that uses it, so
it's slightly easier to read.

Change-Id: Iaaa24d4ee9dbf195ec520a568006812d4549f72e
Reviewed-on: https://chromium-review.googlesource.com/1158997Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579984}
parent 3a71aae9
......@@ -41,17 +41,13 @@
namespace blink {
const unsigned kDefaultNativeMemorySamplingInterval = 128 * 1024;
namespace MemoryAgentState {
static const char samplingProfileInterval[] =
"memoryAgentSamplingProfileInterval";
} // namespace MemoryAgentState
constexpr int kDefaultNativeMemorySamplingInterval = 128 * 1024;
using protocol::Response;
InspectorMemoryAgent::InspectorMemoryAgent(InspectedFrames* inspected_frames)
: frames_(inspected_frames) {}
: frames_(inspected_frames),
sampling_profile_interval_(&agent_state_, /*default_value=*/0) {}
InspectorMemoryAgent::~InspectorMemoryAgent() = default;
......@@ -72,11 +68,8 @@ void InspectorMemoryAgent::Trace(blink::Visitor* visitor) {
}
void InspectorMemoryAgent::Restore() {
int sampling_interval = 0;
state_->getInteger(MemoryAgentState::samplingProfileInterval,
&sampling_interval);
// The action below won't start sampling if the sampling_interval is zero.
startSampling(protocol::Maybe<int>(sampling_interval),
startSampling(protocol::Maybe<int>(sampling_profile_interval_.Get()),
protocol::Maybe<bool>());
}
......@@ -88,7 +81,7 @@ Response InspectorMemoryAgent::startSampling(
if (interval <= 0)
return Response::Error("Invalid sampling rate.");
base::SamplingHeapProfiler::GetInstance()->SetSamplingInterval(interval);
state_->setInteger(MemoryAgentState::samplingProfileInterval, interval);
sampling_profile_interval_.Set(interval);
if (in_suppressRandomness.fromMaybe(false))
base::SamplingHeapProfiler::GetInstance()->SuppressRandomnessForTest(true);
profile_id_ = base::SamplingHeapProfiler::GetInstance()->Start();
......@@ -96,13 +89,10 @@ Response InspectorMemoryAgent::startSampling(
}
Response InspectorMemoryAgent::stopSampling() {
int sampling_interval = 0;
state_->getInteger(MemoryAgentState::samplingProfileInterval,
&sampling_interval);
if (!sampling_interval)
if (sampling_profile_interval_.Get() == 0)
return Response::Error("Sampling profiler is not started.");
base::SamplingHeapProfiler::GetInstance()->Stop();
state_->setInteger(MemoryAgentState::samplingProfileInterval, 0);
sampling_profile_interval_.Clear();
return Response::OK();
}
......
......@@ -76,6 +76,7 @@ class CORE_EXPORT InspectorMemoryAgent final
uint32_t profile_id_ = 0;
HashMap<void*, std::string> symbols_cache_;
InspectorAgentState::Integer sampling_profile_interval_;
DISALLOW_COPY_AND_ASSIGN(InspectorMemoryAgent);
};
......
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