Commit ed230ab9 authored by Benoît Lizé's avatar Benoît Lizé Committed by Commit Bot

blink/bindings: Add (de)compression histograms for ParkableString.

Records the size, latency and throughput of parkable strings at compression and
decompression time. As these values are correlated, recording separate
histograms is necessary, and as not all compressed strings are decompressed,
separate histograms for compression and decompression are required.

Bug: 877044
Change-Id: Iec53e6d4f249e109165b0b3be6e2e245fc2bfd40
Reviewed-on: https://chromium-review.googlesource.com/c/1307440Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Benoit L <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605296}
parent 5528336d
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/timer/elapsed_timer.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/platform/bindings/parkable_string_manager.h" #include "third_party/blink/renderer/platform/bindings/parkable_string_manager.h"
...@@ -30,6 +31,37 @@ void RecordParkingAction(ParkableStringImpl::ParkingAction action) { ...@@ -30,6 +31,37 @@ void RecordParkingAction(ParkableStringImpl::ParkingAction action) {
UMA_HISTOGRAM_ENUMERATION("Memory.MovableStringParkingAction", action); UMA_HISTOGRAM_ENUMERATION("Memory.MovableStringParkingAction", action);
} }
void RecordStatistics(size_t size,
base::TimeDelta duration,
ParkableStringImpl::ParkingAction action) {
size_t throughput_mb_s =
static_cast<size_t>(size / duration.InSecondsF()) / 1000000;
size_t size_kb = size / 1000;
if (action == ParkableStringImpl::ParkingAction::kParkedInBackground) {
UMA_HISTOGRAM_COUNTS_10000("Memory.ParkableString.Compression.SizeKb",
size_kb);
// Size is at least 10kB, and at most ~1MB, and compression throughput
// ranges from single-digit MB/s to ~40MB/s depending on the CPU, hence
// the range.
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Memory.ParkableString.Compression.Latency", duration,
base::TimeDelta::FromMicroseconds(500), base::TimeDelta::FromSeconds(1),
100);
UMA_HISTOGRAM_COUNTS_1000(
"Memory.ParkableString.Compression.ThroughputMBps", throughput_mb_s);
} else {
UMA_HISTOGRAM_COUNTS_10000("Memory.ParkableString.Decompression.SizeKb",
size_kb);
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Memory.ParkableString.Decompression.Latency", duration,
base::TimeDelta::FromMicroseconds(500), base::TimeDelta::FromSeconds(1),
100);
// Decompression speed can go up to >500MB/s.
UMA_HISTOGRAM_COUNTS_1000(
"Memory.ParkableString.Decompression.ThroughputMBps", throughput_mb_s);
}
}
void AsanPoisonString(const String& string) { void AsanPoisonString(const String& string) {
#if defined(ADDRESS_SANITIZER) #if defined(ADDRESS_SANITIZER)
if (string.IsNull()) if (string.IsNull())
...@@ -207,6 +239,7 @@ void ParkableStringImpl::Unpark() { ...@@ -207,6 +239,7 @@ void ParkableStringImpl::Unpark() {
TRACE_EVENT1("blink", "ParkableStringImpl::Unpark", "size", TRACE_EVENT1("blink", "ParkableStringImpl::Unpark", "size",
CharactersSizeInBytes()); CharactersSizeInBytes());
DCHECK(compressed_); DCHECK(compressed_);
base::ElapsedTimer timer;
base::StringPiece compressed_string_piece( base::StringPiece compressed_string_piece(
reinterpret_cast<const char*>(compressed_->data()), reinterpret_cast<const char*>(compressed_->data()),
...@@ -238,12 +271,14 @@ void ParkableStringImpl::Unpark() { ...@@ -238,12 +271,14 @@ void ParkableStringImpl::Unpark() {
compressed_ = nullptr; compressed_ = nullptr;
string_ = uncompressed; string_ = uncompressed;
state_ = State::kUnparked; state_ = State::kUnparked;
ParkableStringManager::Instance().OnUnparked(this, string_.Impl());
bool backgrounded = bool backgrounded =
ParkableStringManager::Instance().IsRendererBackgrounded(); ParkableStringManager::Instance().IsRendererBackgrounded();
RecordParkingAction(backgrounded ? ParkingAction::kUnparkedInBackground auto action = backgrounded ? ParkingAction::kUnparkedInBackground
: ParkingAction::kUnparkedInForeground); : ParkingAction::kUnparkedInForeground;
ParkableStringManager::Instance().OnUnparked(this, string_.Impl()); RecordParkingAction(action);
RecordStatistics(CharactersSizeInBytes(), timer.Elapsed(), action);
} }
void ParkableStringImpl::OnParkingCompleteOnMainThread( void ParkableStringImpl::OnParkingCompleteOnMainThread(
...@@ -282,6 +317,7 @@ void ParkableStringImpl::CompressInBackground( ...@@ -282,6 +317,7 @@ void ParkableStringImpl::CompressInBackground(
TRACE_EVENT1("blink", "ParkableStringImpl::CompressInBackground", "size", TRACE_EVENT1("blink", "ParkableStringImpl::CompressInBackground", "size",
params->size); params->size);
base::ElapsedTimer timer;
// Compression touches the string. // Compression touches the string.
AsanUnpoisonString(params->string->string_); AsanUnpoisonString(params->string->string_);
base::StringPiece data(reinterpret_cast<const char*>(params->data), base::StringPiece data(reinterpret_cast<const char*>(params->data),
...@@ -299,6 +335,7 @@ void ParkableStringImpl::CompressInBackground( ...@@ -299,6 +335,7 @@ void ParkableStringImpl::CompressInBackground(
AsanPoisonString(params->string->string_); AsanPoisonString(params->string->string_);
auto* task_runner = params->callback_task_runner.get(); auto* task_runner = params->callback_task_runner.get();
size_t size = params->size;
PostCrossThreadTask( PostCrossThreadTask(
*task_runner, FROM_HERE, *task_runner, FROM_HERE,
CrossThreadBind( CrossThreadBind(
...@@ -309,6 +346,7 @@ void ParkableStringImpl::CompressInBackground( ...@@ -309,6 +346,7 @@ void ParkableStringImpl::CompressInBackground(
std::move(compressed)); std::move(compressed));
}, },
WTF::Passed(std::move(params)), WTF::Passed(std::move(compressed)))); WTF::Passed(std::move(params)), WTF::Passed(std::move(compressed))));
RecordStatistics(size, timer.Elapsed(), ParkingAction::kParkedInBackground);
} }
ParkableString::ParkableString(scoped_refptr<StringImpl>&& impl) { ParkableString::ParkableString(scoped_refptr<StringImpl>&& impl) {
......
...@@ -350,6 +350,8 @@ TEST_F(ParkableStringTest, AsanPoisoningTest) { ...@@ -350,6 +350,8 @@ TEST_F(ParkableStringTest, AsanPoisoningTest) {
#endif // defined(ADDRESS_SANITIZER) #endif // defined(ADDRESS_SANITIZER)
TEST_F(ParkableStringTest, Compression) { TEST_F(ParkableStringTest, Compression) {
base::HistogramTester histogram_tester;
ParkableString parkable(MakeLargeString().Impl()); ParkableString parkable(MakeLargeString().Impl());
ParkableStringImpl* impl = parkable.Impl(); ParkableStringImpl* impl = parkable.Impl();
EXPECT_TRUE(impl->Park()); EXPECT_TRUE(impl->Park());
...@@ -362,6 +364,19 @@ TEST_F(ParkableStringTest, Compression) { ...@@ -362,6 +364,19 @@ TEST_F(ParkableStringTest, Compression) {
parkable.ToString(); parkable.ToString();
EXPECT_FALSE(impl->is_parked()); EXPECT_FALSE(impl->is_parked());
EXPECT_EQ(nullptr, impl->compressed_); EXPECT_EQ(nullptr, impl->compressed_);
histogram_tester.ExpectUniqueSample(
"Memory.ParkableString.Compression.SizeKb", kSizeKb, 1);
histogram_tester.ExpectTotalCount("Memory.ParkableString.Compression.Latency",
1);
histogram_tester.ExpectTotalCount(
"Memory.ParkableString.Compression.ThroughputMBps", 1);
histogram_tester.ExpectUniqueSample(
"Memory.ParkableString.Decompression.SizeKb", kSizeKb, 1);
histogram_tester.ExpectTotalCount(
"Memory.ParkableString.Decompression.Latency", 1);
histogram_tester.ExpectTotalCount(
"Memory.ParkableString.Decompression.ThroughputMBps", 1);
} }
} // namespace blink } // namespace blink
...@@ -48798,6 +48798,49 @@ uploading your change for review. ...@@ -48798,6 +48798,49 @@ uploading your change for review.
</summary> </summary>
</histogram> </histogram>
<histogram name="Memory.ParkableString.Compression.Latency"
units="microseconds">
<owner>lizeb@chromium.org</owner>
<summary>Time to compress a parkable string, in ms.</summary>
</histogram>
<histogram name="Memory.ParkableString.Compression.SizeKb" units="KB">
<owner>lizeb@chromium.org</owner>
<summary>
Size of a compressed parkable string, recorded at compression time.
</summary>
</histogram>
<histogram name="Memory.ParkableString.Compression.ThroughputMBps" units="MBps">
<owner>lizeb@chromium.org</owner>
<summary>
Size of a compressed parkable string, recorded at compression time.
</summary>
</histogram>
<histogram name="Memory.ParkableString.Decompression.Latency"
units="microseconds">
<owner>lizeb@chromium.org</owner>
<summary>Time to decompress a parkable string, in ms.</summary>
</histogram>
<histogram name="Memory.ParkableString.Decompression.SizeKb" units="KB">
<owner>lizeb@chromium.org</owner>
<summary>
Original size of a compressed parkable string, recorded at decompression
time.
</summary>
</histogram>
<histogram name="Memory.ParkableString.Decompression.ThroughputMBps"
units="MBps">
<owner>lizeb@chromium.org</owner>
<summary>
Original size of a compressed parkable string, recorded at decompression
time.
</summary>
</histogram>
<histogram name="Memory.PepperFlashPlugin" units="KB"> <histogram name="Memory.PepperFlashPlugin" units="KB">
<obsolete> <obsolete>
Deprecated 11/2017. No direct replacement. Deprecated 11/2017. No direct replacement.
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