repackaging: all the file moves
This commit is contained in:
80
modules/@angular/core/src/profile/profile.ts
Normal file
80
modules/@angular/core/src/profile/profile.ts
Normal file
@ -0,0 +1,80 @@
|
||||
export {WtfScopeFn} from './wtf_impl';
|
||||
|
||||
import * as impl from "./wtf_impl";
|
||||
|
||||
// Change exports to const once https://github.com/angular/ts2dart/issues/150
|
||||
|
||||
/**
|
||||
* True if WTF is enabled.
|
||||
*/
|
||||
export var wtfEnabled = impl.detectWTF();
|
||||
|
||||
function noopScope(arg0?: any, arg1?: any): any {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create trace scope.
|
||||
*
|
||||
* Scopes must be strictly nested and are analogous to stack frames, but
|
||||
* do not have to follow the stack frames. Instead it is recommended that they follow logical
|
||||
* nesting. You may want to use
|
||||
* [Event
|
||||
* Signatures](http://google.github.io/tracing-framework/instrumenting-code.html#custom-events)
|
||||
* as they are defined in WTF.
|
||||
*
|
||||
* Used to mark scope entry. The return value is used to leave the scope.
|
||||
*
|
||||
* var myScope = wtfCreateScope('MyClass#myMethod(ascii someVal)');
|
||||
*
|
||||
* someMethod() {
|
||||
* var s = myScope('Foo'); // 'Foo' gets stored in tracing UI
|
||||
* // DO SOME WORK HERE
|
||||
* return wtfLeave(s, 123); // Return value 123
|
||||
* }
|
||||
*
|
||||
* Note, adding try-finally block around the work to ensure that `wtfLeave` gets called can
|
||||
* negatively impact the performance of your application. For this reason we recommend that
|
||||
* you don't add them to ensure that `wtfLeave` gets called. In production `wtfLeave` is a noop and
|
||||
* so try-finally block has no value. When debugging perf issues, skipping `wtfLeave`, do to
|
||||
* exception, will produce incorrect trace, but presence of exception signifies logic error which
|
||||
* needs to be fixed before the app should be profiled. Add try-finally only when you expect that
|
||||
* an exception is expected during normal execution while profiling.
|
||||
*
|
||||
*/
|
||||
export var wtfCreateScope: (signature: string, flags?: any) => impl.WtfScopeFn =
|
||||
wtfEnabled ? impl.createScope : (signature: string, flags?: any) => noopScope;
|
||||
|
||||
/**
|
||||
* Used to mark end of Scope.
|
||||
*
|
||||
* - `scope` to end.
|
||||
* - `returnValue` (optional) to be passed to the WTF.
|
||||
*
|
||||
* Returns the `returnValue for easy chaining.
|
||||
*/
|
||||
export var wtfLeave:<T>(scope: any, returnValue?: T) => T =
|
||||
wtfEnabled ? impl.leave : (s: any, r?: any) => r;
|
||||
|
||||
/**
|
||||
* Used to mark Async start. Async are similar to scope but they don't have to be strictly nested.
|
||||
* The return value is used in the call to [endAsync]. Async ranges only work if WTF has been
|
||||
* enabled.
|
||||
*
|
||||
* someMethod() {
|
||||
* var s = wtfStartTimeRange('HTTP:GET', 'some.url');
|
||||
* var future = new Future.delay(5).then((_) {
|
||||
* wtfEndTimeRange(s);
|
||||
* });
|
||||
* }
|
||||
*/
|
||||
export var wtfStartTimeRange: (rangeType: string, action: string) => any =
|
||||
wtfEnabled ? impl.startTimeRange : (rangeType: string, action: string) => null;
|
||||
|
||||
/**
|
||||
* Ends a async time range operation.
|
||||
* [range] is the return value from [wtfStartTimeRange] Async ranges only work if WTF has been
|
||||
* enabled.
|
||||
*/
|
||||
export var wtfEndTimeRange: (range: any) => void = wtfEnabled ? impl.endTimeRange : (r: any) =>
|
||||
null;
|
96
modules/@angular/core/src/profile/wtf_impl.dart
Normal file
96
modules/@angular/core/src/profile/wtf_impl.dart
Normal file
@ -0,0 +1,96 @@
|
||||
/**
|
||||
* Tracing for Dart applications.
|
||||
*
|
||||
* The tracing API hooks up to either [WTF](http://google.github.io/tracing-framework/) or
|
||||
* [Dart Observatory](https://www.dartlang.org/tools/observatory/).
|
||||
*/
|
||||
library angular2.src.core.wtf_impl;
|
||||
|
||||
typedef dynamic WtfScopeFn([arg0, arg1]);
|
||||
|
||||
var context = null;
|
||||
var _trace;
|
||||
var _events;
|
||||
var _createScope;
|
||||
var _leaveScope;
|
||||
var _beginTimeRange;
|
||||
var _endTimeRange;
|
||||
final List _arg1 = [null];
|
||||
final List _arg2 = [null, null];
|
||||
|
||||
bool detectWTF() {
|
||||
if (context != null && context.hasProperty('wtf')) {
|
||||
var wtf = context['wtf'];
|
||||
if (wtf.hasProperty('trace')) {
|
||||
_trace = wtf['trace'];
|
||||
_events = _trace['events'];
|
||||
_createScope = _events['createScope'];
|
||||
_leaveScope = _trace['leaveScope'];
|
||||
_beginTimeRange = _trace['beginTimeRange'];
|
||||
_endTimeRange = _trace['endTimeRange'];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int getArgSize(String signature) {
|
||||
int start = signature.indexOf('(') + 1;
|
||||
int end = signature.indexOf(')', start);
|
||||
bool found = false;
|
||||
int count = 0;
|
||||
for (var i = start; i < end; i++) {
|
||||
var ch = signature[i];
|
||||
if (identical(ch, ',')) {
|
||||
found = false;
|
||||
}
|
||||
if (!found) {
|
||||
found = true;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
dynamic createScope(String signature, [flags]) {
|
||||
_arg2[0] = signature;
|
||||
_arg2[1] = flags;
|
||||
var jsScope = _createScope.apply(_arg2, thisArg: _events);
|
||||
switch (getArgSize(signature)) {
|
||||
case 0:
|
||||
return ([arg0, arg1]) {
|
||||
return jsScope.apply(const []);
|
||||
};
|
||||
case 1:
|
||||
return ([arg0, arg1]) {
|
||||
_arg1[0] = arg0;
|
||||
return jsScope.apply(_arg1);
|
||||
};
|
||||
case 2:
|
||||
return ([arg0, arg1]) {
|
||||
_arg2[0] = arg0;
|
||||
_arg2[1] = arg1;
|
||||
return jsScope.apply(_arg2);
|
||||
};
|
||||
default:
|
||||
throw "Max 2 arguments are supported.";
|
||||
}
|
||||
}
|
||||
|
||||
void leave(scope, [returnValue]) {
|
||||
_arg2[0] = scope;
|
||||
_arg2[1] = returnValue;
|
||||
_leaveScope.apply(_arg2, thisArg: _trace);
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
dynamic startTimeRange(String rangeType, String action) {
|
||||
_arg2[0] = rangeType;
|
||||
_arg2[1] = action;
|
||||
return _beginTimeRange.apply(_arg2, thisArg: _trace);
|
||||
}
|
||||
|
||||
void endTimeRange(dynamic range) {
|
||||
_arg1[0] = range;
|
||||
_endTimeRange.apply(_arg1, thisArg: _trace);
|
||||
}
|
57
modules/@angular/core/src/profile/wtf_impl.ts
Normal file
57
modules/@angular/core/src/profile/wtf_impl.ts
Normal file
@ -0,0 +1,57 @@
|
||||
import {global} from 'angular2/src/facade/lang';
|
||||
|
||||
/**
|
||||
* A scope function for the Web Tracing Framework (WTF).
|
||||
*/
|
||||
export interface WtfScopeFn { (arg0?: any, arg1?: any): any; }
|
||||
|
||||
interface WTF {
|
||||
trace: Trace;
|
||||
}
|
||||
|
||||
interface Trace {
|
||||
events: Events;
|
||||
leaveScope(scope: Scope, returnValue: any);
|
||||
beginTimeRange(rangeType: string, action: string): Range;
|
||||
endTimeRange(range: Range);
|
||||
}
|
||||
|
||||
export interface Range {}
|
||||
|
||||
interface Events {
|
||||
createScope(signature: string, flags: any): Scope;
|
||||
}
|
||||
|
||||
export interface Scope { (...args): any; }
|
||||
|
||||
var trace: Trace;
|
||||
var events: Events;
|
||||
|
||||
export function detectWTF(): boolean {
|
||||
var wtf: WTF = global['wtf'];
|
||||
if (wtf) {
|
||||
trace = wtf['trace'];
|
||||
if (trace) {
|
||||
events = trace['events'];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function createScope(signature: string, flags: any = null): any {
|
||||
return events.createScope(signature, flags);
|
||||
}
|
||||
|
||||
export function leave<T>(scope: Scope, returnValue?: T): T {
|
||||
trace.leaveScope(scope, returnValue);
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
export function startTimeRange(rangeType: string, action: string): Range {
|
||||
return trace.beginTimeRange(rangeType, action);
|
||||
}
|
||||
|
||||
export function endTimeRange(range: Range): void {
|
||||
trace.endTimeRange(range);
|
||||
}
|
14
modules/@angular/core/src/profile/wtf_init.dart
Normal file
14
modules/@angular/core/src/profile/wtf_init.dart
Normal file
@ -0,0 +1,14 @@
|
||||
library angular2.src.core.wtf_init;
|
||||
|
||||
import 'dart:js' as js;
|
||||
import 'wtf_impl.dart' as impl;
|
||||
|
||||
/**
|
||||
* Must be executed explicitly in Dart to set the JS Context.
|
||||
*
|
||||
* NOTE: this is done explicitly to allow WTF api not to depend on
|
||||
* JS context and possible to run the noop WTF stubs outside the browser.
|
||||
*/
|
||||
wtfInit() {
|
||||
impl.context = js.context;
|
||||
}
|
4
modules/@angular/core/src/profile/wtf_init.ts
Normal file
4
modules/@angular/core/src/profile/wtf_init.ts
Normal file
@ -0,0 +1,4 @@
|
||||
/**
|
||||
* This is here because DART requires it. It is noop in JS.
|
||||
*/
|
||||
export function wtfInit() {}
|
Reference in New Issue
Block a user