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

Instrument basic metrics within the compositor

上级 d9cde931
......@@ -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",
......
// 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() {
}
void PaintContext::beginFrame() {
frame_count_.increment();
frame_time_.start();
}
void PaintContext::endFrame() {
rasterizer_.PurgeCache();
frame_time_.stop();
}
PaintContext::ScopedFrame PaintContext::AcquireFrame(SkCanvas& canvas,
......
......@@ -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();
......
......@@ -38,10 +38,10 @@ PictureRasterzier::Value::Value()
PictureRasterzier::Value::~Value() {
}
static RefPtr<SkImage> ImageFromPicture(PaintContext& context,
GrContext* gr_context,
SkPicture* picture,
const SkISize& size) {
RefPtr<SkImage> 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<SkImage> ImageFromPicture(PaintContext& context,
RefPtr<SkImage> image = adoptRef(
SkImage::NewFromTexture(gr_context, backendDesc, kPremul_SkAlphaType,
&ImageReleaseProc, texture));
if (image) {
cache_fills_.increment();
}
return image;
}
......@@ -123,6 +128,10 @@ RefPtr<SkImage> 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);
}
......
......@@ -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<Key, Value, KeyHash, KeyEqual>;
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);
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册