Skip to content

Commit

Permalink
Update to Mojo 4e4d51ce28a8edcb32b9c7f555e38e2ae84a825e, update deps
Browse files Browse the repository at this point in the history
This updates to mojo 4e4d51ce28a and mojo sdk 711a0bcfb141b4 and updates the sky
package's pubspec.yaml dependency to '>=0.1.0 <0.2.0' to be compatible with
the current mojo package. This includes an update to the Mojo Dart generator to
produce real classes for enums and the corresponding updates for users of the
KeyboardType enum in Sky as well as one scoped_ptr->std::unique_ptr in shell
corresponding to a change in the Mojo EDK.

When a new version of the sky and sky_services package are pushed this will fix
domokit/mojo#440.
  • Loading branch information
jamesr committed Sep 24, 2015
1 parent 3cb73a0 commit 5bb2480
Show file tree
Hide file tree
Showing 208 changed files with 2,614 additions and 3,745 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

vars = {
'chromium_git': 'https://chromium.googlesource.com',
'mojo_sdk_revision': '3ec8c53e9c9e5a8cd3cf251c4ae4754b75172225',
'mojo_sdk_revision': '711a0bcfb141b481f51ac1c9c62ec73e9b988615',
'mojo_devtools_revision': '49879d78ce4486e10c2214a101d9b2e82794b2f4',
'skia_revision': '0d39d37ddcfb3847795639eaef513f1112eba627',
'dart_revision': 'cab003366785773ace16b5305ac1f33c228cac54',
Expand Down
2 changes: 1 addition & 1 deletion examples/fitness/lib/measurement.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class MeasurementFragment extends StatefulComponent {
new Input(
key: weightKey,
placeholder: 'Enter weight',
keyboardType: KeyboardType_NUMBER,
keyboardType: KeyboardType.NUMBER,
onChanged: _handleWeightChanged
),
], alignItems: FlexAlignItems.stretch)
Expand Down
2 changes: 1 addition & 1 deletion examples/fitness/lib/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class SettingsFragment extends StatefulComponent {
content: new Input(
key: weightGoalKey,
placeholder: 'Goal weight in lbs',
keyboardType: KeyboardType_NUMBER,
keyboardType: KeyboardType.NUMBER,
onChanged: _handleGoalWeightChanged
),
onDismiss: () {
Expand Down
3 changes: 2 additions & 1 deletion mojo/android/javatests/init_library.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ bool RegisterJNI(JNIEnv* env) {
}

bool Init() {
mojo::embedder::Init(scoped_ptr<mojo::embedder::PlatformSupport>(
// TODO(vtl): Use make_unique when C++14 is available.
mojo::embedder::Init(std::unique_ptr<mojo::embedder::PlatformSupport>(
new mojo::embedder::SimplePlatformSupport()));
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,20 @@ private static void runTest(String prefix, MessageReceiver messageReceiver)
handles.add(new HandleMock());
}
Message message = new Message(test.inputData.getData(), handles);
boolean passed = messageReceiver.accept(message);
if (passed && !test.expectedResult.equals("PASS")) {
fail("Input: " + test.dataFile.getName()
+ ": The message should have been refused. Expected error: "
+ test.expectedResult);
}
if (!passed && test.expectedResult.equals("PASS")) {
fail("Input: " + test.dataFile.getName()
+ ": The message should have been accepted.");
try {
boolean passed = messageReceiver.accept(message);
if (passed && !test.expectedResult.equals("PASS")) {
fail("Input: " + test.dataFile.getName()
+ ": The message should have been refused. Expected error: "
+ test.expectedResult);
}
if (!passed && test.expectedResult.equals("PASS")) {
fail("Input: " + test.dataFile.getName()
+ ": The message should have been accepted.");
}
} catch (SerializationException e) {
e.printStackTrace();
fail("Input: " + test.dataFile.getName() + ": Serialization error.");
}
}
}
Expand Down
35 changes: 31 additions & 4 deletions mojo/common/dart/lib/trace_provider_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,37 @@

import 'dart:async';

import 'package:mojo/application.dart';
import 'package:mojo/bindings.dart';
import 'package:mojo/core.dart';
import 'package:mojo_services/tracing/tracing.mojom.dart';

class TraceProviderImpl implements TraceProvider {
// Any messages sent before the tracing service connects to us will be
// recorded and kept until one second after construction of the trace
// provider. If the tracing service connects before that time, we will replay
// the recorded trace events.
//
// This allows the client to record trace events early during initialization
// of the app.
List<String> _message_queue;
bool _enqueuing;

TraceProviderStub _stub;
TraceRecorderProxy _recorder;
// TODO(rudominer) We currently ignore _categories.
String _categories;

TraceProviderImpl.fromEndpoint(MojoMessagePipeEndpoint e) {
TraceProviderImpl() {
_message_queue = [];
_enqueuing = true;
new Future(() {
new Future.delayed(const Duration(seconds: 1), () {
_enqueuing = false;
_message_queue.clear();
});
});
}

void connect(MojoMessagePipeEndpoint e) {
_stub = TraceProviderStub.newFromEndpoint(e);
_stub.impl = this;
}
Expand All @@ -25,6 +44,12 @@ class TraceProviderImpl implements TraceProvider {
assert(_recorder == null);
_recorder = recorder;
_categories = categories;

for (String message in _message_queue) {
_recorder.ptr.record(message);
}
_enqueuing = false;
_message_queue.clear();
}

@override
Expand All @@ -35,12 +60,14 @@ class TraceProviderImpl implements TraceProvider {
}

bool isActive() {
return _recorder != null;
return _enqueuing || _recorder != null;
}

void sendTraceMessage(String message) {
if (_recorder != null) {
_recorder.ptr.record(message);
} else if (_enqueuing) {
_message_queue.add(message);
}
}
}
124 changes: 92 additions & 32 deletions mojo/common/dart/lib/tracing_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,64 +13,100 @@ import 'dart:io';
import 'dart:isolate';

import 'package:mojo/application.dart';
import 'package:mojo/bindings.dart';
import 'package:mojo/core.dart';
import 'package:mojo_services/tracing/tracing.mojom.dart';

// Phases indicating the nature of the event in the trace log.
// These should be in sync with definitions in
// //base/trace_event/trace_event.h
const traceEventInstant = "I";
const traceEventPhaseBegin = "B";
const traceEventPhaseEnd = "E";
const traceEventPhaseAsyncBegin = "S";
const traceEventPhaseAsyncEnd = "F";

// TracingHelper is used by Dart code running in the Mojo shell in order
// to perform tracing.
class TracingHelper {
TraceProviderImpl _impl;
String _tid;

int _tid;
static TracingHelper _tracing;
// Construct an instance of TracingHelper from within your application's
// |initialize()| method. |appName| will be used to form a thread identifier
// for use in trace messages. If |appName| is longer than 20 characters then
// only the last 20 characters of |appName| will be used.
TracingHelper(Application app, String appName) {
// We use only the last 20 characters of appName to form the tid so that
// the 9-digit Isolate hash code we are appending won't get truncated by the
// tracing UI.
if (appName.length > 20) {
appName = appName.substring(appName.length - 20);
}
_tid = "${appName}/${Isolate.current.hashCode.toString()}";
TracingHelper.fromApplication(Application app, String appName) {
_tid = [appName, Isolate.current].fold(7,
(hash, element) => 31 * hash + element.hashCode);
_impl = new TraceProviderImpl();
ApplicationConnection connection = app.connectToApplication("mojo:tracing");
connection.provideService(TraceProviderName, (e) {
assert(_impl == null);
_impl = new TraceProviderImpl.fromEndpoint(e);
_impl.connect(e);
});
assert(_tracing == null);
_tracing = this;
}

// Factory to return the singleton instance of the TracingHelper. The isolate
// must have constructed the object using TracingHelper.fromApplication
// atleast once before using this factory.
factory TracingHelper() {
assert(_tracing != null);
return _tracing;
}

bool isActive() {
return (_impl != null) && _impl.isActive();
}

// Invoke this at the beginning of a function whose duration you wish to
// trace. Invoke |end()| on the returned object.
FunctionTrace beginFunction(String functionName, {Map<String, String> args}) {
assert(functionName != null);
if (isActive()) {
_sendTraceMessage(functionName, "B", args: args);
} else {
functionName = null;
}
return new _FunctionTraceImpl(this, functionName);
// Invoke this at the beginning of a synchronous function whose
// duration you wish to trace. Invoke |end()| on the returned object.
FunctionTrace begin(String functionName, String categories,
{Map<String, String> args}) {
return _beginFunction(functionName, categories, traceEventPhaseBegin,
args: args);
}

void _endFunction(String functionName) {
_sendTraceMessage(functionName, "E");
// Invoke this right before an asynchronous function whose duration
// you wish to trace. Invoke |end()| on the returned object.
FunctionTrace beginAsync(String functionName, String categories,
{Map<String, String> args}) {
return _beginFunction(functionName, categories, traceEventPhaseAsyncBegin,
args: args);
}

void _sendTraceMessage(String name, String phase,
void traceInstant(String name, String categories,
{Map<String, String> args}) {
_sendTraceMessage(name, categories, traceEventInstant, 0, args: args);
}

FunctionTrace _beginFunction(String functionName, String categories,
String phase, {Map<String, String> args}) {
assert(functionName != null);
final trace =
new _FunctionTraceImpl(this, isActive() ? functionName : null,
categories, phase);
_sendTraceMessage(functionName, categories, phase, trace.hashCode,
args: args);
return trace;
}

void _endFunction(String functionName, String categories, String phase,
int traceId) {
_sendTraceMessage(functionName, categories, phase, traceId);
}

void _sendTraceMessage(String name, String categories, String phase,
int traceId, {Map<String, String> args}) {
if (isActive()) {
var map = {};
map["name"] = name;
map["cat"] = categories;
map["ph"] = phase;
map["ts"] = getTimeTicksNow();
map["pid"] = pid;
map["tid"] = _tid;
map["id"] = traceId;
if (args != null) {
map["args"] = args;
}
Expand All @@ -80,30 +116,54 @@ class TracingHelper {

// A convenience method that wraps a closure in a begin-end pair of
// tracing calls.
dynamic trace(String functionName, closure(), {Map<String, String> args}) {
FunctionTrace ft = beginFunction(functionName, args: args);
dynamic trace(String functionName, String categories, closure(),
{Map<String, String> args}) {
FunctionTrace ft = begin(functionName, categories, args: args);
final returnValue = closure();
ft.end();
return returnValue;
}

// A convenience method that wraps a closure in a begin-end pair of
// async tracing calls. The return value should either be returned or awaited.
Future traceAsync(String functionName, String categories, Future closure(),
{Map<String, String> args}) {
FunctionTrace ft = beginAsync(functionName, categories, args: args);
final Future returnValue = closure();
returnValue.whenComplete(ft.end);
return returnValue;
}
}

// A an instance of FunctionTrace is returned from |beginFunction()|.
// Invoke |end()| from every exit point in the function you are tracing.
// An instance of FunctionTrace is returned from |begin()|, |beginAsync()|.
// Invoke |end()| to end the trace from every exit point in the function you are
// tracing.
abstract class FunctionTrace {
void end();
}

class _FunctionTraceImpl implements FunctionTrace {
TracingHelper _tracing;
String _functionName;
String _categories;
String _beginPhase;

_FunctionTraceImpl(this._tracing, this._functionName);
_FunctionTraceImpl(this._tracing, this._functionName, this._categories,
this._beginPhase) {
assert(_beginPhase == traceEventPhaseBegin ||
_beginPhase == traceEventPhaseAsyncBegin);
}

@override
void end() {
if (_functionName != null) {
_tracing._endFunction(_functionName);
if (_beginPhase == traceEventPhaseBegin) {
_tracing._endFunction(_functionName, _categories, traceEventPhaseEnd,
hashCode);
} else if (_beginPhase == traceEventPhaseAsyncBegin) {
_tracing._endFunction(_functionName, _categories,
traceEventPhaseAsyncEnd, hashCode);
}
}
}
}
Loading

0 comments on commit 5bb2480

Please sign in to comment.