mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
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:
parent
e42426a37c
commit
f3df64fa3d
@ -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",
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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;
|
||||
|
||||
33
engine/core/frame/Tracing.cpp
Normal file
33
engine/core/frame/Tracing.cpp
Normal 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
|
||||
30
engine/core/frame/Tracing.h
Normal file
30
engine/core/frame/Tracing.h
Normal 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_
|
||||
8
engine/core/frame/Tracing.idl
Normal file
8
engine/core/frame/Tracing.idl
Normal 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);
|
||||
};
|
||||
@ -72,6 +72,8 @@
|
||||
long requestAnimationFrame(RequestAnimationFrameCallback callback);
|
||||
void cancelAnimationFrame(long id);
|
||||
|
||||
readonly attribute Tracing tracing;
|
||||
|
||||
// [Replaceable] readonly attribute CSS CSS;
|
||||
};
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
@ -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;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
12
framework/debug/tracing.dart
Normal file
12
framework/debug/tracing.dart
Normal 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;
|
||||
}
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user