diff --git a/sky/compositor/BUILD.gn b/sky/compositor/BUILD.gn index 32828d47c9bd8da80660c5b3e731e6ded279f008..78aa86066885e70227cb4afdf57204a8a16199ce 100644 --- a/sky/compositor/BUILD.gn +++ b/sky/compositor/BUILD.gn @@ -18,6 +18,8 @@ source_set("compositor") { "compositor_options.h", "container_layer.cc", "container_layer.h", + "instrumentation.cc", + "instrumentation.h", "layer.cc", "layer.h", "layer_tree.cc", diff --git a/sky/compositor/instrumentation.cc b/sky/compositor/instrumentation.cc new file mode 100644 index 0000000000000000000000000000000000000000..23365f3fa52856c00f8694cd1abb04d7b369d609 --- /dev/null +++ b/sky/compositor/instrumentation.cc @@ -0,0 +1,15 @@ +// Copyright 2015 The Chromium 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 "sky/compositor/instrumentation.h" + +namespace sky { +namespace compositor { +namespace instrumentation { + +// + +} // namespace instrumentation +} // namespace compositor +} // namespace sky diff --git a/sky/compositor/instrumentation.h b/sky/compositor/instrumentation.h new file mode 100644 index 0000000000000000000000000000000000000000..e1b61bcabb23080296a729599c7fed85b70e96af --- /dev/null +++ b/sky/compositor/instrumentation.h @@ -0,0 +1,68 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef SKY_COMPOSITOR_INSTRUMENTATION_H_ +#define SKY_COMPOSITOR_INSTRUMENTATION_H_ + +#include "base/macros.h" +#include "base/time/time.h" + +namespace sky { +namespace compositor { +namespace instrumentation { + +class Stopwatch { + public: + class ScopedLap { + public: + explicit ScopedLap(Stopwatch& stopwatch) : _stopwatch(stopwatch) { + _stopwatch.start(); + } + + ~ScopedLap() { _stopwatch.stop(); } + + private: + Stopwatch& _stopwatch; + + DISALLOW_COPY_AND_ASSIGN(ScopedLap); + }; + + explicit Stopwatch() : _start(base::TimeTicks::Now()), _lastLap() {} + + const base::TimeDelta& lastLap() const { return _lastLap; } + + base::TimeDelta currentLap() const { return base::TimeTicks::Now() - _start; } + + void start() { _start = base::TimeTicks::Now(); } + + void stop() { _lastLap = base::TimeTicks::Now() - _start; } + + private: + base::TimeTicks _start; + base::TimeDelta _lastLap; + + DISALLOW_COPY_AND_ASSIGN(Stopwatch); +}; + +class Counter { + public: + explicit Counter() : _count(0) {} + + size_t count() const { return _count; } + + void reset(size_t count = 0) { _count = count; } + + void increment(size_t count = 1) { _count += count; } + + private: + size_t _count; + + DISALLOW_COPY_AND_ASSIGN(Counter); +}; + +} // namespace instrumentation +} // namespace compositor +} // namespace sky + +#endif // SKY_COMPOSITOR_INSTRUMENTATION_H_ diff --git a/sky/compositor/paint_context.cc b/sky/compositor/paint_context.cc index 36bced89b5f11f947d8093813c175269add2cde0..359f839d42b627b757a5205dffce59199d7eb007 100644 --- a/sky/compositor/paint_context.cc +++ b/sky/compositor/paint_context.cc @@ -12,10 +12,13 @@ PaintContext::PaintContext() { } void PaintContext::beginFrame() { + frame_count_.increment(); + frame_time_.start(); } void PaintContext::endFrame() { rasterizer_.PurgeCache(); + frame_time_.stop(); } PaintContext::ScopedFrame PaintContext::AcquireFrame(SkCanvas& canvas, diff --git a/sky/compositor/paint_context.h b/sky/compositor/paint_context.h index 40d96bc9ac161fe6c4de9be82cd50da1d55d5cb1..37396694d448580f8e2520168a7b98801f462e18 100644 --- a/sky/compositor/paint_context.h +++ b/sky/compositor/paint_context.h @@ -8,6 +8,7 @@ #include "base/macros.h" #include "base/logging.h" #include "sky/compositor/compositor_options.h" +#include "sky/compositor/instrumentation.h" #include "sky/compositor/picture_rasterizer.h" namespace sky { @@ -58,6 +59,9 @@ class PaintContext { PictureRasterzier rasterizer_; CompositorOptions options_; + instrumentation::Counter frame_count_; + instrumentation::Stopwatch frame_time_; + void beginFrame(); void endFrame(); diff --git a/sky/compositor/picture_rasterizer.cc b/sky/compositor/picture_rasterizer.cc index 35af3778ef054e7259d46f657c92959a2491803d..3781018ec0fdc3d02e9b2bf077bdac0bea202f3c 100644 --- a/sky/compositor/picture_rasterizer.cc +++ b/sky/compositor/picture_rasterizer.cc @@ -38,10 +38,10 @@ PictureRasterzier::Value::Value() PictureRasterzier::Value::~Value() { } -static RefPtr ImageFromPicture(PaintContext& context, - GrContext* gr_context, - SkPicture* picture, - const SkISize& size) { +RefPtr PictureRasterzier::ImageFromPicture(PaintContext& context, + GrContext* gr_context, + SkPicture* picture, + const SkISize& size) { // Step 1: Create a texture from the context's texture provider GrSurfaceDesc desc; @@ -94,6 +94,11 @@ static RefPtr ImageFromPicture(PaintContext& context, RefPtr image = adoptRef( SkImage::NewFromTexture(gr_context, backendDesc, kPremul_SkAlphaType, &ImageReleaseProc, texture)); + + if (image) { + cache_fills_.increment(); + } + return image; } @@ -123,6 +128,10 @@ RefPtr PictureRasterzier::GetCachedImageIfPresent( value.image = ImageFromPicture(context, gr_context, picture, size); } + if (value.image) { + cache_hits_.increment(); + } + return value.image; } @@ -136,6 +145,8 @@ void PictureRasterzier::PurgeCache() { } } + cache_evictions_.increment(keys_to_purge.size()); + for (const auto& key : keys_to_purge) { cache_.erase(key); } diff --git a/sky/compositor/picture_rasterizer.h b/sky/compositor/picture_rasterizer.h index 634cb8876767be461c22c052a3cbd29f9b624a5b..fbc072244460677c423f61637248a22af6d577bc 100644 --- a/sky/compositor/picture_rasterizer.h +++ b/sky/compositor/picture_rasterizer.h @@ -8,6 +8,7 @@ #include "base/macros.h" #include "third_party/skia/include/core/SkSize.h" #include "third_party/skia/include/core/SkImage.h" +#include "sky/compositor/instrumentation.h" #include "sky/engine/wtf/PassRefPtr.h" #include "sky/engine/wtf/RefPtr.h" @@ -66,6 +67,14 @@ class PictureRasterzier { using Cache = std::unordered_map; Cache cache_; + instrumentation::Counter cache_fills_; + instrumentation::Counter cache_hits_; + instrumentation::Counter cache_evictions_; + + RefPtr ImageFromPicture(PaintContext& context, + GrContext* gr_context, + SkPicture* picture, + const SkISize& size); DISALLOW_COPY_AND_ASSIGN(PictureRasterzier); };