cleanup(tooling): move tooling to the browser platform and rename profile into instrumentation

BREAKING CHANGE

Before

import * as p from 'angular2/profile';
import * as t from 'angular2/tools';

After

import * as p from 'angular2/instrumentation';
import * as t from 'angular2/platform/browser';
This commit is contained in:
vsavkin
2015-11-23 10:18:04 -08:00
committed by Victor Savkin
parent 9ae171e0c8
commit 89eefcd7b5
54 changed files with 72 additions and 64 deletions

View File

@ -0,0 +1,70 @@
import {ApplicationRef} from 'angular2/src/core/application_ref';
import {ComponentRef, ComponentRef_} from 'angular2/src/core/linker/dynamic_component_loader';
import {isPresent, NumberWrapper} from 'angular2/src/facade/lang';
import {performance, window} from 'angular2/src/facade/browser';
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
/**
* Entry point for all Angular debug tools. This object corresponds to the `ng`
* global variable accessible in the dev console.
*/
export class AngularTools {
profiler: AngularProfiler;
constructor(ref: ComponentRef) { this.profiler = new AngularProfiler(ref); }
}
/**
* Entry point for all Angular profiling-related debug tools. This object
* corresponds to the `ng.profiler` in the dev console.
*/
export class AngularProfiler {
appRef: ApplicationRef;
constructor(ref: ComponentRef) {
this.appRef = (<ComponentRef_>ref).injector.get(ApplicationRef);
}
/**
* Exercises change detection in a loop and then prints the average amount of
* time in milliseconds how long a single round of change detection takes for
* the current state of the UI. It runs a minimum of 5 rounds for a minimum
* of 500 milliseconds.
*
* Optionally, a user may pass a `config` parameter containing a map of
* options. Supported options are:
*
* `record` (boolean) - causes the profiler to record a CPU profile while
* it exercises the change detector. Example:
*
* ```
* ng.profiler.timeChangeDetection({record: true})
* ```
*/
timeChangeDetection(config: any) {
var record = isPresent(config) && config['record'];
var profileName = 'Change Detection';
// Profiler is not available in Android browsers, nor in IE 9 without dev tools opened
var isProfilerAvailable = isPresent(window.console.profile);
if (record && isProfilerAvailable) {
window.console.profile(profileName);
}
var start = DOM.performanceNow();
var numTicks = 0;
while (numTicks < 5 || (DOM.performanceNow() - start) < 500) {
this.appRef.tick();
numTicks++;
}
var end = DOM.performanceNow();
if (record && isProfilerAvailable) {
// need to cast to <any> because type checker thinks there's no argument
// while in fact there is:
//
// https://developer.mozilla.org/en-US/docs/Web/API/Console/profileEnd
(<any>window.console.profileEnd)(profileName);
}
var msPerTick = (end - start) / numTicks;
window.console.log(`ran ${numTicks} change detection cycles`);
window.console.log(`${NumberWrapper.toFixed(msPerTick, 2)} ms per check`);
}
}

View File

@ -0,0 +1,35 @@
library angular2.src.tools.tools;
import 'dart:js';
import 'package:angular2/src/core/linker/dynamic_component_loader.dart'
show ComponentRef;
import 'common_tools.dart' show AngularTools;
/**
* Enabled Angular 2 debug tools that are accessible via your browser's
* developer console.
*
* Usage:
*
* 1. Open developer console (e.g. in Chrome Ctrl + Shift + j)
* 1. Type `ng.` (usually the console will show auto-complete suggestion)
* 1. Try the change detection profiler `ng.profiler.timeChangeDetection()`
* then hit Enter.
*/
void enableDebugTools(ComponentRef ref) {
final tools = new AngularTools(ref);
context['ng'] = new JsObject.jsify({
'profiler': {
'timeChangeDetection': ([config]) {
tools.profiler.timeChangeDetection(config);
}
}
});
}
/**
* Disables Angular 2 tools.
*/
void disableDebugTools() {
context.deleteProperty('ng');
}

View File

@ -0,0 +1,27 @@
import {global} from 'angular2/src/facade/lang';
import {ComponentRef} from 'angular2/src/core/linker/dynamic_component_loader';
import {AngularTools} from './common_tools';
var context = <any>global;
/**
* Enabled Angular 2 debug tools that are accessible via your browser's
* developer console.
*
* Usage:
*
* 1. Open developer console (e.g. in Chrome Ctrl + Shift + j)
* 1. Type `ng.` (usually the console will show auto-complete suggestion)
* 1. Try the change detection profiler `ng.profiler.timeChangeDetection()`
* then hit Enter.
*/
export function enableDebugTools(ref: ComponentRef): void {
context.ng = new AngularTools(ref);
}
/**
* Disables Angular 2 tools.
*/
export function disableDebugTools(): void {
context.ng = undefined;
}

View File

@ -33,13 +33,14 @@ import {wtfInit} from 'angular2/src/core/profile/wtf_init';
export {DOCUMENT} from 'angular2/src/platform/dom/dom_tokens';
export {Title} from 'angular2/src/platform/browser/title';
export {
// DebugElementViewListener,
DebugElementViewListener,
ELEMENT_PROBE_PROVIDERS,
ELEMENT_PROBE_BINDINGS,
inspectNativeElement
} from 'angular2/src/platform/browser/debug/debug_element_view_listener';
export {By} from 'angular2/src/platform/browser/debug/by';
inspectNativeElement,
By
} from 'angular2/platform/common_dom';
export {BrowserDomAdapter} from './browser/browser_adapter';
export {enableDebugTools, disableDebugTools} from 'angular2/src/platform/browser/tools/tools';
export const BROWSER_PROVIDERS: Array<any /*Type | Provider | any[]*/> = CONST_EXPR([
PLATFORM_COMMON_PROVIDERS,