Commit b919acfe authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

ProfilingCanvas: Measure time in TimeTicks units.

Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I52f3764b856c9b3c6f01f546cd808384bada34c6
Reviewed-on: https://chromium-review.googlesource.com/1105065Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568254}
parent e524381a
......@@ -552,15 +552,15 @@ Response InspectorLayerTreeAgent::profileSnapshot(
FloatRect rect;
if (clip_rect.isJust())
ParseRect(clip_rect.fromJust(), &rect);
std::unique_ptr<PictureSnapshot::Timings> timings = snapshot->Profile(
min_repeat_count.fromMaybe(1), min_duration.fromMaybe(0),
clip_rect.isJust() ? &rect : nullptr);
auto timings =
snapshot->Profile(min_repeat_count.fromMaybe(1),
TimeDelta::FromSecondsD(min_duration.fromMaybe(0)),
clip_rect.isJust() ? &rect : nullptr);
*out_timings = Array<Array<double>>::create();
for (size_t i = 0; i < timings->size(); ++i) {
const Vector<double>& row = (*timings)[i];
for (const auto& row : timings) {
std::unique_ptr<Array<double>> out_row = Array<double>::create();
for (size_t j = 0; j < row.size(); ++j)
out_row->addItem(row[j]);
for (TimeDelta delta : row)
out_row->addItem(delta.InSecondsF());
(*out_timings)->addItem(std::move(out_row));
}
return Response::OK();
......
......@@ -134,26 +134,24 @@ std::unique_ptr<Vector<char>> PictureSnapshot::Replay(unsigned from_step,
return base64_data;
}
std::unique_ptr<PictureSnapshot::Timings> PictureSnapshot::Profile(
Vector<Vector<TimeDelta>> PictureSnapshot::Profile(
unsigned min_repeat_count,
double min_duration,
TimeDelta min_duration,
const FloatRect* clip_rect) const {
std::unique_ptr<PictureSnapshot::Timings> timings =
std::make_unique<PictureSnapshot::Timings>();
timings->ReserveCapacity(min_repeat_count);
Vector<Vector<TimeDelta>> timings;
timings.ReserveInitialCapacity(min_repeat_count);
const SkIRect bounds = picture_->cullRect().roundOut();
SkBitmap bitmap;
bitmap.allocPixels(
SkImageInfo::MakeN32Premul(bounds.width(), bounds.height()));
bitmap.eraseARGB(0, 0, 0, 0);
double now = WTF::CurrentTimeTicksInSeconds();
double stop_time = now + min_duration;
TimeTicks now = WTF::CurrentTimeTicks();
TimeTicks stop_time = now + min_duration;
for (unsigned step = 0; step < min_repeat_count || now < stop_time; ++step) {
timings->push_back(Vector<double>());
Vector<double>* current_timings = &timings->back();
if (timings->size() > 1)
current_timings->ReserveCapacity(timings->begin()->size());
Vector<TimeDelta> current_timings;
if (!timings.IsEmpty())
current_timings.ReserveInitialCapacity(timings.front().size());
ProfilingCanvas canvas(bitmap);
if (clip_rect) {
canvas.clipRect(SkRect::MakeXYWH(clip_rect->X(), clip_rect->Y(),
......@@ -161,9 +159,10 @@ std::unique_ptr<PictureSnapshot::Timings> PictureSnapshot::Profile(
clip_rect->Height()));
canvas.ResetStepCount();
}
canvas.SetTimings(current_timings);
canvas.SetTimings(&current_timings);
picture_->playback(&canvas);
now = WTF::CurrentTimeTicksInSeconds();
timings.push_back(std::move(current_timings));
now = WTF::CurrentTimeTicks();
}
return timings;
}
......
......@@ -38,6 +38,7 @@
#include "third_party/blink/renderer/platform/json/json_values.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/ref_counted.h"
#include "third_party/blink/renderer/platform/wtf/time.h"
#include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
#include "third_party/skia/include/core/SkRefCnt.h"
......@@ -49,8 +50,6 @@ class FloatRect;
class PLATFORM_EXPORT PictureSnapshot : public RefCounted<PictureSnapshot> {
public:
typedef Vector<Vector<double>> Timings;
struct TilePictureStream : RefCounted<TilePictureStream> {
FloatPoint layer_offset;
Vector<char> data;
......@@ -64,9 +63,9 @@ class PLATFORM_EXPORT PictureSnapshot : public RefCounted<PictureSnapshot> {
std::unique_ptr<Vector<char>> Replay(unsigned from_step = 0,
unsigned to_step = 0,
double scale = 1.0) const;
std::unique_ptr<Timings> Profile(unsigned min_iterations,
double min_duration,
const FloatRect* clip_rect) const;
Vector<Vector<TimeDelta>> Profile(unsigned min_iterations,
TimeDelta min_duration,
const FloatRect* clip_rect) const;
std::unique_ptr<JSONArray> SnapshotCommandLog() const;
bool IsEmpty() const;
......
......@@ -36,13 +36,12 @@ namespace blink {
CanvasInterceptor<ProfilingCanvas>::CanvasInterceptor(
InterceptingCanvasBase* canvas)
: CanvasInterceptorBase(canvas),
start_time_(WTF::CurrentTimeTicksInSeconds()) {}
: CanvasInterceptorBase(canvas), start_time_(WTF::CurrentTimeTicks()) {}
CanvasInterceptor<ProfilingCanvas>::~CanvasInterceptor() {
if (!TopLevelCall())
return;
double delta = WTF::CurrentTimeTicksInSeconds() - start_time_;
TimeDelta delta = WTF::CurrentTimeTicks() - start_time_;
if (auto* timings = Canvas()->timings_) {
DCHECK_EQ(timings->size(), Canvas()->CallCount());
timings->push_back(delta);
......@@ -52,7 +51,7 @@ CanvasInterceptor<ProfilingCanvas>::~CanvasInterceptor() {
ProfilingCanvas::ProfilingCanvas(SkBitmap bitmap)
: InterceptingCanvas(bitmap), timings_(nullptr) {}
void ProfilingCanvas::SetTimings(Vector<double>* timings) {
void ProfilingCanvas::SetTimings(Vector<TimeDelta>* timings) {
timings_ = timings;
}
......
......@@ -32,6 +32,7 @@
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_PROFILING_CANVAS_H_
#include "third_party/blink/renderer/platform/graphics/intercepting_canvas.h"
#include "third_party/blink/renderer/platform/wtf/time.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
namespace blink {
......@@ -46,18 +47,18 @@ class CanvasInterceptor<ProfilingCanvas>
~CanvasInterceptor();
private:
double start_time_;
TimeTicks start_time_;
};
class ProfilingCanvas : public InterceptingCanvas<ProfilingCanvas> {
public:
explicit ProfilingCanvas(SkBitmap);
void SetTimings(Vector<double>*);
void SetTimings(Vector<TimeDelta>*);
private:
friend class CanvasInterceptor<ProfilingCanvas>;
Vector<double>* timings_;
Vector<TimeDelta>* timings_;
};
} // namespace blink
......
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