提交 8633293b 编写于 作者: C Chinmay Garde

Instrument basic metrics within the compositor

上级 d9cde931
...@@ -18,6 +18,8 @@ source_set("compositor") { ...@@ -18,6 +18,8 @@ source_set("compositor") {
"compositor_options.h", "compositor_options.h",
"container_layer.cc", "container_layer.cc",
"container_layer.h", "container_layer.h",
"instrumentation.cc",
"instrumentation.h",
"layer.cc", "layer.cc",
"layer.h", "layer.h",
"layer_tree.cc", "layer_tree.cc",
......
// 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
// 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_
...@@ -12,10 +12,13 @@ PaintContext::PaintContext() { ...@@ -12,10 +12,13 @@ PaintContext::PaintContext() {
} }
void PaintContext::beginFrame() { void PaintContext::beginFrame() {
frame_count_.increment();
frame_time_.start();
} }
void PaintContext::endFrame() { void PaintContext::endFrame() {
rasterizer_.PurgeCache(); rasterizer_.PurgeCache();
frame_time_.stop();
} }
PaintContext::ScopedFrame PaintContext::AcquireFrame(SkCanvas& canvas, PaintContext::ScopedFrame PaintContext::AcquireFrame(SkCanvas& canvas,
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/logging.h" #include "base/logging.h"
#include "sky/compositor/compositor_options.h" #include "sky/compositor/compositor_options.h"
#include "sky/compositor/instrumentation.h"
#include "sky/compositor/picture_rasterizer.h" #include "sky/compositor/picture_rasterizer.h"
namespace sky { namespace sky {
...@@ -58,6 +59,9 @@ class PaintContext { ...@@ -58,6 +59,9 @@ class PaintContext {
PictureRasterzier rasterizer_; PictureRasterzier rasterizer_;
CompositorOptions options_; CompositorOptions options_;
instrumentation::Counter frame_count_;
instrumentation::Stopwatch frame_time_;
void beginFrame(); void beginFrame();
void endFrame(); void endFrame();
......
...@@ -38,10 +38,10 @@ PictureRasterzier::Value::Value() ...@@ -38,10 +38,10 @@ PictureRasterzier::Value::Value()
PictureRasterzier::Value::~Value() { PictureRasterzier::Value::~Value() {
} }
static RefPtr<SkImage> ImageFromPicture(PaintContext& context, RefPtr<SkImage> PictureRasterzier::ImageFromPicture(PaintContext& context,
GrContext* gr_context, GrContext* gr_context,
SkPicture* picture, SkPicture* picture,
const SkISize& size) { const SkISize& size) {
// Step 1: Create a texture from the context's texture provider // Step 1: Create a texture from the context's texture provider
GrSurfaceDesc desc; GrSurfaceDesc desc;
...@@ -94,6 +94,11 @@ static RefPtr<SkImage> ImageFromPicture(PaintContext& context, ...@@ -94,6 +94,11 @@ static RefPtr<SkImage> ImageFromPicture(PaintContext& context,
RefPtr<SkImage> image = adoptRef( RefPtr<SkImage> image = adoptRef(
SkImage::NewFromTexture(gr_context, backendDesc, kPremul_SkAlphaType, SkImage::NewFromTexture(gr_context, backendDesc, kPremul_SkAlphaType,
&ImageReleaseProc, texture)); &ImageReleaseProc, texture));
if (image) {
cache_fills_.increment();
}
return image; return image;
} }
...@@ -123,6 +128,10 @@ RefPtr<SkImage> PictureRasterzier::GetCachedImageIfPresent( ...@@ -123,6 +128,10 @@ RefPtr<SkImage> PictureRasterzier::GetCachedImageIfPresent(
value.image = ImageFromPicture(context, gr_context, picture, size); value.image = ImageFromPicture(context, gr_context, picture, size);
} }
if (value.image) {
cache_hits_.increment();
}
return value.image; return value.image;
} }
...@@ -136,6 +145,8 @@ void PictureRasterzier::PurgeCache() { ...@@ -136,6 +145,8 @@ void PictureRasterzier::PurgeCache() {
} }
} }
cache_evictions_.increment(keys_to_purge.size());
for (const auto& key : keys_to_purge) { for (const auto& key : keys_to_purge) {
cache_.erase(key); cache_.erase(key);
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "third_party/skia/include/core/SkSize.h" #include "third_party/skia/include/core/SkSize.h"
#include "third_party/skia/include/core/SkImage.h" #include "third_party/skia/include/core/SkImage.h"
#include "sky/compositor/instrumentation.h"
#include "sky/engine/wtf/PassRefPtr.h" #include "sky/engine/wtf/PassRefPtr.h"
#include "sky/engine/wtf/RefPtr.h" #include "sky/engine/wtf/RefPtr.h"
...@@ -66,6 +67,14 @@ class PictureRasterzier { ...@@ -66,6 +67,14 @@ class PictureRasterzier {
using Cache = std::unordered_map<Key, Value, KeyHash, KeyEqual>; using Cache = std::unordered_map<Key, Value, KeyHash, KeyEqual>;
Cache cache_; Cache cache_;
instrumentation::Counter cache_fills_;
instrumentation::Counter cache_hits_;
instrumentation::Counter cache_evictions_;
RefPtr<SkImage> ImageFromPicture(PaintContext& context,
GrContext* gr_context,
SkPicture* picture,
const SkISize& size);
DISALLOW_COPY_AND_ASSIGN(PictureRasterzier); DISALLOW_COPY_AND_ASSIGN(PictureRasterzier);
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册