Skip to content

Commit 77875a2

Browse files
committed
feat: implement web-tracing-framework support
This includes implementation and minimal instrumentation Closes angular#2610
1 parent 6d272cc commit 77875a2

File tree

17 files changed

+357
-19
lines changed

17 files changed

+357
-19
lines changed

modules/angular2/angular2.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ export * from './directives';
1515
export * from './http';
1616
export * from './forms';
1717
export * from './render';
18+
export * from './profile';

modules/angular2/angular2_exports.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export * from './directives';
66
export * from './http';
77
export * from './forms';
88
export * from './render';
9+
export * from './profile';

modules/angular2/profile.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export {
2+
wtfCreateScope,
3+
wtfLeave,
4+
wtfStartTimeRange,
5+
wtfEndTimeRange,
6+
WtfScopeFn
7+
} from './src/profile/profile';

modules/angular2/src/change_detection/abstract_change_detector.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import {BindingRecord} from './binding_record';
1414
import {Locals} from './parser/locals';
1515
import {Pipes} from './pipes/pipes';
1616
import {CHECK_ALWAYS, CHECK_ONCE, CHECKED, DETACHED, ON_PUSH} from './constants';
17+
import {wtfCreateScope, wtfLeave, WtfScopeFn} from '../profile/profile';
18+
19+
var _scope_check: WtfScopeFn = wtfCreateScope(`ChangeDetector#check(ascii id, bool throwOnChange)`);
1720

1821
class _Context {
1922
constructor(public element: any, public componentElement: any, public instance: any,
@@ -69,16 +72,13 @@ export class AbstractChangeDetector<T> implements ChangeDetector {
6972

7073
runDetectChanges(throwOnChange: boolean): void {
7174
if (this.mode === DETACHED || this.mode === CHECKED) return;
72-
75+
var s = _scope_check(this.id, throwOnChange);
7376
this.detectChangesInRecords(throwOnChange);
74-
7577
this._detectChangesInLightDomChildren(throwOnChange);
76-
7778
if (throwOnChange === false) this.callOnAllChangesDone();
78-
7979
this._detectChangesInShadowDomChildren(throwOnChange);
80-
8180
if (this.mode === CHECK_ONCE) this.mode = CHECKED;
81+
wtfLeave(s);
8282
}
8383

8484
// This method is not intended to be overridden. Subclasses should instead provide an

modules/angular2/src/core/application_common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import {
7171
} from 'angular2/src/render/dom/view/shared_styles_host';
7272
import {internalView} from 'angular2/src/core/compiler/view_ref';
7373
import {appComponentRefPromiseToken, appComponentTypeToken} from './application_tokens';
74+
import {wtfInit} from '../profile/wtf_init';
7475

7576
var _rootInjector: Injector;
7677

@@ -290,6 +291,7 @@ export function commonBootstrap(
290291
appComponentType: /*Type*/ any,
291292
componentInjectableBindings: List<Type | Binding | List<any>> = null): Promise<ApplicationRef> {
292293
BrowserDomAdapter.makeCurrent();
294+
wtfInit();
293295
var bootstrapProcess = PromiseWrapper.completer();
294296
var zone = createNgZone(new ExceptionHandler(DOM, isDart ? false : true));
295297
zone.run(() => {

modules/angular2/src/core/compiler/compiler.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {ProtoViewFactory} from './proto_view_factory';
2525
import {UrlResolver} from 'angular2/src/services/url_resolver';
2626
import {AppRootUrl} from 'angular2/src/services/app_root_url';
2727
import {ElementBinder} from './element_binder';
28+
import {wtfStartTimeRange, wtfEndTimeRange} from '../../profile/profile';
2829

2930
import * as renderApi from 'angular2/src/render/api';
3031

@@ -127,6 +128,7 @@ export class Compiler {
127128
compileInHost(componentTypeOrBinding: Type | Binding): Promise<ProtoViewRef> {
128129
var componentType = isType(componentTypeOrBinding) ? componentTypeOrBinding :
129130
(<Binding>componentTypeOrBinding).token;
131+
var r = wtfStartTimeRange('Compiler#compile()', stringify(componentType));
130132

131133
var hostAppProtoView = this._compilerCache.getHost(componentType);
132134
var hostPvPromise;
@@ -149,7 +151,10 @@ export class Compiler {
149151
return appProtoView;
150152
});
151153
}
152-
return hostPvPromise.then(hostAppProtoView => hostAppProtoView.ref);
154+
return hostPvPromise.then((hostAppProtoView) => {
155+
wtfEndTimeRange(r);
156+
return hostAppProtoView.ref;
157+
});
153158
}
154159

155160
private _compile(componentBinding: DirectiveBinding,

modules/angular2/src/core/compiler/view_manager.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
import {AppViewManagerUtils} from './view_manager_utils';
1616
import {AppViewPool} from './view_pool';
1717
import {AppViewListener} from './view_listener';
18+
import {wtfCreateScope, wtfLeave, WtfScopeFn} from '../../profile/profile';
1819

1920
/**
2021
* Entry point for creating, moving views in the view hierarchy and destroying views.
@@ -83,6 +84,7 @@ export class AppViewManager {
8384
return this._utils.getComponentInstance(hostView, boundElementIndex);
8485
}
8586

87+
_scope_createRootHostView: WtfScopeFn = wtfCreateScope('AppViewManager#createRootHostView()');
8688
/**
8789
* Load component view into existing element.
8890
*
@@ -139,6 +141,7 @@ export class AppViewManager {
139141
*/
140142
createRootHostView(hostProtoViewRef: ProtoViewRef, overrideSelector: string,
141143
injector: Injector): HostViewRef {
144+
var s = this._scope_createRootHostView();
142145
var hostProtoView: viewModule.AppProtoView = internalProtoView(hostProtoViewRef);
143146
var hostElementSelector = overrideSelector;
144147
if (isBlank(hostElementSelector)) {
@@ -151,51 +154,60 @@ export class AppViewManager {
151154

152155
this._renderer.hydrateView(hostView.render);
153156
this._utils.hydrateRootHostView(hostView, injector);
154-
155-
return hostView.ref;
157+
return wtfLeave(s, hostView.ref);
156158
}
157159

160+
_scope_destroyRootHostView: WtfScopeFn = wtfCreateScope('AppViewManager#destroyRootHostView()');
158161
/**
159162
* Remove the View created with {@link AppViewManager#createRootHostView}.
160163
*/
161164
destroyRootHostView(hostViewRef: HostViewRef) {
162165
// Note: Don't put the hostView into the view pool
163166
// as it is depending on the element for which it was created.
167+
var s = this._scope_destroyRootHostView();
164168
var hostView = internalView(<ViewRef>hostViewRef);
165169
this._renderer.detachFragment(hostView.renderFragment);
166170
this._renderer.dehydrateView(hostView.render);
167171
this._viewDehydrateRecurse(hostView);
168172
this._viewListener.viewDestroyed(hostView);
169173
this._renderer.destroyView(hostView.render);
174+
wtfLeave(s);
170175
}
171176

177+
_scope_createEmbeddedViewInContainer: WtfScopeFn =
178+
wtfCreateScope('AppViewManager#createEmbeddedViewInContainer()');
172179
/**
173180
*
174181
* See {@link AppViewManager#destroyViewInContainer}.
175182
*/
176183
createEmbeddedViewInContainer(viewContainerLocation: ElementRef, atIndex: number,
177184
templateRef: TemplateRef): ViewRef {
185+
var s = this._scope_createEmbeddedViewInContainer();
178186
var protoView = internalProtoView(templateRef.protoViewRef);
179187
if (protoView.type !== ViewType.EMBEDDED) {
180188
throw new BaseException('This method can only be called with embedded ProtoViews!');
181189
}
182-
return this._createViewInContainer(viewContainerLocation, atIndex, protoView,
183-
templateRef.elementRef, null);
190+
return wtfLeave(s, this._createViewInContainer(viewContainerLocation, atIndex, protoView,
191+
templateRef.elementRef, null));
184192
}
185193

194+
_scope_createHostViewInContainer: WtfScopeFn =
195+
wtfCreateScope('AppViewManager#createHostViewInContainer()');
186196
/**
187197
*
188198
* See {@link AppViewManager#destroyViewInContainer}.
189199
*/
190200
createHostViewInContainer(viewContainerLocation: ElementRef, atIndex: number,
191201
protoViewRef: ProtoViewRef,
192202
imperativelyCreatedInjector: ResolvedBinding[]): HostViewRef {
203+
var s = this._scope_createHostViewInContainer();
193204
var protoView = internalProtoView(protoViewRef);
194205
if (protoView.type !== ViewType.HOST) {
195206
throw new BaseException('This method can only be called with host ProtoViews!');
196207
}
197-
return this._createViewInContainer(viewContainerLocation, atIndex, protoView,
198-
viewContainerLocation, imperativelyCreatedInjector);
208+
return wtfLeave(
209+
s, this._createViewInContainer(viewContainerLocation, atIndex, protoView,
210+
viewContainerLocation, imperativelyCreatedInjector));
199211
}
200212

201213
/**
@@ -243,22 +255,27 @@ export class AppViewManager {
243255
}
244256
}
245257

258+
_scope_destroyViewInContainer = wtfCreateScope('AppViewMananger#destroyViewInContainer()');
246259
/**
247260
*
248261
* See {@link AppViewManager#createViewInContainer}.
249262
*/
250263
destroyViewInContainer(viewContainerLocation: ElementRef, atIndex: number) {
264+
var s = this._scope_destroyViewInContainer();
251265
var parentView = internalView(viewContainerLocation.parentView);
252266
var boundElementIndex = viewContainerLocation.boundElementIndex;
253267
this._destroyViewInContainer(parentView, boundElementIndex, atIndex);
268+
wtfLeave(s);
254269
}
255270

271+
_scope_attachViewInContainer = wtfCreateScope('AppViewMananger#attachViewInContainer()');
256272
/**
257273
*
258274
* See {@link AppViewManager#detachViewInContainer}.
259275
*/
260276
attachViewInContainer(viewContainerLocation: ElementRef, atIndex: number,
261277
viewRef: ViewRef): ViewRef {
278+
var s = this._scope_attachViewInContainer();
262279
var view = internalView(viewRef);
263280
var parentView = internalView(viewContainerLocation.parentView);
264281
var boundElementIndex = viewContainerLocation.boundElementIndex;
@@ -270,21 +287,23 @@ export class AppViewManager {
270287
// context view that might have been used.
271288
this._utils.attachViewInContainer(parentView, boundElementIndex, null, null, atIndex, view);
272289
this._attachRenderView(parentView, boundElementIndex, atIndex, view);
273-
return viewRef;
290+
return wtfLeave(s, viewRef);
274291
}
275292

293+
_scope_detachViewInContainer = wtfCreateScope('AppViewMananger#detachViewInContainer()');
276294
/**
277295
*
278296
* See {@link AppViewManager#attachViewInContainer}.
279297
*/
280298
detachViewInContainer(viewContainerLocation: ElementRef, atIndex: number): ViewRef {
299+
var s = this._scope_detachViewInContainer();
281300
var parentView = internalView(viewContainerLocation.parentView);
282301
var boundElementIndex = viewContainerLocation.boundElementIndex;
283302
var viewContainer = parentView.viewContainers[boundElementIndex];
284303
var view = viewContainer.views[atIndex];
285304
this._utils.detachViewInContainer(parentView, boundElementIndex, atIndex);
286305
this._renderer.detachFragment(view.renderFragment);
287-
return view.ref;
306+
return wtfLeave(s, view.ref);
288307
}
289308

290309
_createMainView(protoView: viewModule.AppProtoView,

modules/angular2/src/core/life_cycle/life_cycle.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {Injectable} from 'angular2/di';
22
import {ChangeDetector} from 'angular2/src/change_detection/change_detection';
33
import {NgZone} from 'angular2/src/core/zone/ng_zone';
44
import {isPresent, BaseException} from 'angular2/src/facade/lang';
5+
import {wtfLeave, wtfCreateScope, WtfScopeFn} from '../../profile/profile';
56

67
/**
78
* Provides access to explicitly trigger change detection in an application.
@@ -31,6 +32,8 @@ import {isPresent, BaseException} from 'angular2/src/facade/lang';
3132
*/
3233
@Injectable()
3334
export class LifeCycle {
35+
static _scope_tick: WtfScopeFn = wtfCreateScope('LifeCycle#tick()');
36+
3437
_changeDetector: ChangeDetector;
3538
_enforceNoNewChanges: boolean;
3639
_runningTick: boolean = false;
@@ -71,6 +74,7 @@ export class LifeCycle {
7174
throw new BaseException("LifeCycle.tick is called recursively");
7275
}
7376

77+
var s = LifeCycle._scope_tick();
7478
try {
7579
this._runningTick = true;
7680
this._changeDetector.detectChanges();
@@ -79,6 +83,7 @@ export class LifeCycle {
7983
}
8084
} finally {
8185
this._runningTick = false;
86+
wtfLeave(s);
8287
}
8388
}
8489
}

modules/angular2/src/core/zone/ng_zone.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {List, ListWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
22
import {normalizeBlank, isPresent, global} from 'angular2/src/facade/lang';
3+
import {wtfLeave, wtfCreateScope, WtfScopeFn} from '../../profile/profile';
4+
35

46
export interface NgZoneZone extends Zone { _innerZone: boolean; }
57

@@ -13,6 +15,9 @@ export interface NgZoneZone extends Zone { _innerZone: boolean; }
1315
* `Zone`. The default `onTurnDone` runs the Angular change detection.
1416
*/
1517
export class NgZone {
18+
_zone_run_scope: WtfScopeFn = wtfCreateScope(`NgZone#run()`);
19+
_zone_microtask: WtfScopeFn = wtfCreateScope(`NgZone#microtask()`);
20+
1621
// Code executed in _mountZone does not trigger the onTurnDone.
1722
_mountZone;
1823
// _innerZone is the child of _mountZone. Any code executed in this zone will trigger the
@@ -134,7 +139,12 @@ export class NgZone {
134139
*/
135140
run(fn: () => any): any {
136141
if (this._disabled) {
137-
return fn();
142+
var s = this._zone_run_scope();
143+
try {
144+
return fn();
145+
} finally {
146+
wtfLeave(s);
147+
}
138148
} else {
139149
return this._innerZone.run(fn);
140150
}
@@ -165,6 +175,7 @@ export class NgZone {
165175
}
166176

167177
_createInnerZone(zone, enableLongStackTrace) {
178+
var _zone_microtask = this._zone_microtask;
168179
var ngZone = this;
169180
var errorHandling;
170181

@@ -217,10 +228,12 @@ export class NgZone {
217228
return function(fn) {
218229
ngZone._pendingMicrotasks++;
219230
var microtask = function() {
231+
var s = _zone_microtask();
220232
try {
221233
fn();
222234
} finally {
223235
ngZone._pendingMicrotasks--;
236+
wtfLeave(s);
224237
}
225238
};
226239
parentScheduleMicrotask.call(this, microtask);

0 commit comments

Comments
 (0)