Let Dart code running in Sky add events to the trace timeline

This will let us form a wholistic picture of work done in the framework and in
the engine.

R=ojan@chromium.org, rafaelw@chromium.org

Review URL: https://codereview.chromium.org/1028243003
This commit is contained in:
Adam Barth 2015-03-23 14:48:06 -07:00
parent e42426a37c
commit f3df64fa3d
13 changed files with 140 additions and 29 deletions

View File

@ -703,6 +703,8 @@ sky_core_files = [
"frame/SettingsDelegate.h",
"frame/SuspendableTimer.cpp",
"frame/SuspendableTimer.h",
"frame/Tracing.cpp",
"frame/Tracing.h",
"html/canvas/ANGLEInstancedArrays.cpp",
"html/canvas/ANGLEInstancedArrays.h",
"html/canvas/Canvas2DContextAttributes.cpp",
@ -1186,6 +1188,7 @@ core_idl_files = get_path_info([
"frame/ImageBitmap.idl",
"frame/Location.idl",
"frame/Screen.idl",
"frame/Tracing.idl",
"frame/Window.idl",
"html/canvas/ANGLEInstancedArrays.idl",
"html/canvas/Canvas2DContextAttributes.idl",

View File

@ -57,6 +57,7 @@
#include "sky/engine/core/frame/Location.h"
#include "sky/engine/core/frame/Screen.h"
#include "sky/engine/core/frame/Settings.h"
#include "sky/engine/core/frame/Tracing.h"
#include "sky/engine/core/inspector/ConsoleMessage.h"
#include "sky/engine/core/loader/FrameLoaderClient.h"
#include "sky/engine/core/page/ChromeClient.h"
@ -418,6 +419,13 @@ Location& LocalDOMWindow::location() const
return *m_location;
}
Tracing& LocalDOMWindow::tracing() const
{
if (!m_tracing)
m_tracing = Tracing::create();
return *m_tracing;
}
DOMSelection* LocalDOMWindow::getSelection()
{
return m_frame->document()->getSelection();

View File

@ -67,6 +67,7 @@ class ScheduledAction;
class Screen;
class ScriptCallStack;
class StyleMedia;
class Tracing;
enum PageshowEventPersistence {
PageshowEventNotPersisted = 0,
@ -124,6 +125,8 @@ public:
int screenLeft() const { return screenX(); }
int screenTop() const { return screenY(); }
Tracing& tracing() const;
// FIXME(sky): keeping self for now since js-test.html uses it.
LocalDOMWindow* window() const;
@ -232,7 +235,7 @@ private:
mutable RefPtr<Screen> m_screen;
mutable RefPtr<Location> m_location;
mutable RefPtr<Tracing> m_tracing;
mutable RefPtr<DOMWindowCSS> m_css;
RefPtr<DOMWindowEventQueue> m_eventQueue;

View File

@ -0,0 +1,33 @@
// 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/engine/config.h"
#include "sky/engine/core/frame/Tracing.h"
#include "base/trace_event/trace_event.h"
#include "sky/engine/wtf/text/StringUTF8Adaptor.h"
namespace blink {
Tracing::Tracing()
{
}
Tracing::~Tracing()
{
}
void Tracing::begin(const String& name)
{
StringUTF8Adaptor utf8(name);
TRACE_EVENT_COPY_BEGIN0("script", utf8.data());
}
void Tracing::end(const String& name)
{
StringUTF8Adaptor utf8(name);
TRACE_EVENT_COPY_END0("script", utf8.data());
}
} // namespace blink

View File

@ -0,0 +1,30 @@
// 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_ENGINE_CORE_FRAME_TRACING_H_
#define SKY_ENGINE_CORE_FRAME_TRACING_H_
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/wtf/PassRefPtr.h"
#include "sky/engine/wtf/RefCounted.h"
#include "sky/engine/wtf/text/WTFString.h"
namespace blink {
class Tracing : public RefCounted<Tracing>, public DartWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
~Tracing() override;
static PassRefPtr<Tracing> create() { return adoptRef(new Tracing); }
void begin(const String& name);
void end(const String& name);
private:
Tracing();
};
} // namespace blink
#endif // SKY_ENGINE_CORE_FRAME_TRACING_H_

View File

@ -0,0 +1,8 @@
// 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.
interface Tracing {
void begin(DOMString name);
void end(DOMString name);
};

View File

@ -72,6 +72,8 @@
long requestAnimationFrame(RequestAnimationFrameCallback callback);
void cancelAnimationFrame(long id);
readonly attribute Tracing tracing;
// [Replaceable] readonly attribute CSS CSS;
};

View File

@ -212,6 +212,8 @@ static Dart_Isolate IsolateCreateCallback(const char* script_uri,
}
static void CallHandleMessage(base::WeakPtr<DartState> dart_state) {
TRACE_EVENT0("sky", "CallHandleMessage");
if (!dart_state)
return;

View File

@ -12,6 +12,7 @@ import 'package:sky/framework/components/menu_divider.dart';
import 'package:sky/framework/components/menu_item.dart';
import 'package:sky/framework/components/popup_menu.dart';
import 'package:sky/framework/components/scaffold.dart';
import 'package:sky/framework/debug/tracing.dart';
import 'package:sky/framework/fn.dart';
import 'package:sky/framework/theme/typography.dart' as typography;
import 'stock_data.dart';
@ -42,7 +43,9 @@ class StocksApp extends App {
fetchStockOracle().then((oracle) {
setState(() {
_sortedStocks = oracle.stocks;
_sortedStocks.sort((a, b) => a.symbol.compareTo(b.symbol));
trace('StocksApp::sortStocks', () {
_sortedStocks.sort((a, b) => a.symbol.compareTo(b.symbol));
});
});
});
}

View File

@ -4,17 +4,13 @@
import 'dart:convert';
import 'dart:math';
import 'package:sky/framework/debug/tracing.dart';
import 'package:sky/framework/net/fetch.dart';
// Snapshot from http://www.nasdaq.com/screening/company-list.aspx
// Fetched 2/23/2014.
// "Symbol","Name","LastSale","MarketCap","IPOyear","Sector","industry","Summary Quote",
// final List<List<String>> _kCompanyList = [
// ["TFSC","1347 Capital Corp.","9.43","\$56.09M","2014","Finance","Business Services","http://www.nasdaq.com/symbol/tfsc"],
// ["TFSCR","1347 Capital Corp.","0.37","n/a","2014","Finance","Business Services","http://www.nasdaq.com/symbol/tfscr"],
// ["TFSCU","1347 Capital Corp.","9.97","\$41.67M","2014","n/a","n/a","http://www.nasdaq.com/symbol/tfscu"],
// ["TFSCW","1347 Capital Corp.","0.2","n/a","2014","Finance","Business Services","http://www.nasdaq.com/symbol/tfscw"],
// ];
// Data in stock_data.json
class Stock {
String symbol;
@ -60,8 +56,11 @@ class StockOracle {
Future<StockOracle> fetchStockOracle() async {
Response response = await fetch('lib/stock_data.json');
String json = response.bodyAsString();
JsonDecoder decoder = new JsonDecoder();
var companyList = decoder.convert(json);
return new StockOracle.fromCompanyList(companyList);
return trace('stocks::fetchStockOracle', () {
String json = response.bodyAsString();
JsonDecoder decoder = new JsonDecoder();
var companyList = decoder.convert(json);
return new StockOracle.fromCompanyList(companyList);
});
}

View File

@ -3,6 +3,7 @@
// found in the LICENSE file.
import '../animation/scroll_behavior.dart';
import '../debug/tracing.dart';
import '../fn.dart';
import 'dart:math' as math;
import 'dart:sky' as sky;
@ -30,22 +31,24 @@ abstract class FixedHeightScrollable extends Scrollable {
}) : super(key: key, scrollBehavior: scrollBehavior);
void _measureHeights() {
if (_itemHeight != null)
return;
var root = getRoot();
if (root == null)
return;
var item = root.firstChild.firstChild;
if (item == null)
return;
sky.ClientRect scrollRect = root.getBoundingClientRect();
sky.ClientRect itemRect = item.getBoundingClientRect();
assert(scrollRect.height > 0);
assert(itemRect.height > 0);
trace('FixedHeightScrollable::_measureHeights', () {
if (_itemHeight != null)
return;
var root = getRoot();
if (root == null)
return;
var item = root.firstChild.firstChild;
if (item == null)
return;
sky.ClientRect scrollRect = root.getBoundingClientRect();
sky.ClientRect itemRect = item.getBoundingClientRect();
assert(scrollRect.height > 0);
assert(itemRect.height > 0);
setState(() {
_height = scrollRect.height;
_itemHeight = itemRect.height;
setState(() {
_height = scrollRect.height;
_itemHeight = itemRect.height;
});
});
}

View File

@ -0,0 +1,12 @@
// 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.
import 'dart:sky' as sky;
dynamic trace(String name, Function f) {
sky.window.tracing.begin(name);
var result = f();
sky.window.tracing.end(name);
return result;
}

View File

@ -9,6 +9,8 @@ import 'dart:collection';
import 'dart:sky' as sky;
import 'reflect.dart' as reflect;
final sky.Tracing _tracing = sky.window.tracing;
bool _initIsInCheckedMode() {
String testFn(i) { double d = i; return d.toString(); }
try {
@ -713,8 +715,9 @@ List<Component> _dirtyComponents = new List<Component>();
bool _buildScheduled = false;
bool _inRenderDirtyComponents = false;
void _buildDirtyComponents() {
_tracing.begin('fn::_buildDirtyComponents');
Stopwatch sw;
if (_shouldLogRenderDuration)
sw = new Stopwatch()..start();
@ -737,8 +740,10 @@ void _buildDirtyComponents() {
if (_shouldLogRenderDuration) {
sw.stop();
print("Render took ${sw.elapsedMicroseconds} microseconds");
print('Render took ${sw.elapsedMicroseconds} microseconds');
}
_tracing.end('fn::_buildDirtyComponents');
}
void _scheduleComponentForRender(Component c) {