Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions apps/perf-tests/ComplexObjectGraphMemoryTest/mainPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import fps = require("fps-meter");

export function createPage() {
fps.addCallback(function (fps, minFps) {
trace.write("fps=" + fps + " minFps=" + minFps, trace.categories.Test, trace.messageType.info);
if (trace.enabled) {
trace.write("fps=" + fps + " minFps=" + minFps, trace.categories.Test, trace.messageType.info);
}
});
fps.start();

Expand All @@ -27,7 +29,9 @@ export function createPage() {
var button;
var childStackLayout;
var childStackLayoutCount = count / buttonsPerRow;
trace.write("Creating " + count + " buttons.", trace.categories.Test, trace.messageType.info);
if (trace.enabled) {
trace.write("Creating " + count + " buttons.", trace.categories.Test, trace.messageType.info);
}
console.time("creatingButtons");
for (var i = 0; i < childStackLayoutCount; i++) {
childStackLayout = new stackLayoutModule.StackLayout();
Expand All @@ -36,15 +40,19 @@ export function createPage() {
for (var j = 0; j < buttonsPerRow; j++) {
button = new buttonModule.Button();
button.on(buttonModule.Button.tapEvent, function (data) {
trace.write("eventName=" + data.eventName + " object=" + data.object, trace.categories.Test, trace.messageType.info);
if (trace.enabled) {
trace.write("eventName=" + data.eventName + " object=" + data.object, trace.categories.Test, trace.messageType.info);
}
});
button.text = "" + i + j;
childStackLayout.addChild(button);
}
}
console.timeEnd("creatingButtons");
var message = "Created " + count + " buttons";
trace.write(message, trace.categories.Test, trace.messageType.info);
if (trace.enabled) {
trace.write(message, trace.categories.Test, trace.messageType.info);
}
label.text = message;

var page = new pagesModule.Page();
Expand Down
11 changes: 9 additions & 2 deletions apps/perf-tests/LargeObjectArrayMemoryTest/mainPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@ export function createPage() {
var label = new labelModule.Label();
page.content = label;

trace.write("Creating " + count + " objects.", trace.categories.Test, trace.messageType.info);
if (trace.enabled) {
trace.write("Creating " + count + " objects.", trace.categories.Test, trace.messageType.info);
}

console.time("creatingObjects");
for (var i = 0; i < count; i++) {
people[i] = new common.Person("John Doe", 33, 1234.56);
}
console.timeEnd("creatingObjects");
var message = "Created " + people.length + " objects";
trace.write(message, trace.categories.Test, trace.messageType.info);

if (trace.enabled) {
trace.write(message, trace.categories.Test, trace.messageType.info);
}

label.text = message;
return page;
}
13 changes: 10 additions & 3 deletions apps/perf-tests/SpeedTests/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export function compareNativeDates(count: number): string {
var elapsedTime = Math.round(new Date().getMilliseconds() - startTime);
var averageTime = (elapsedTime / count);
var message = "Total: " + elapsedTime + " ms. Avg: " + averageTime + " ms.";
trace.write(message, trace.categories.Test, trace.messageType.info);

if (trace.enabled) {
trace.write(message, trace.categories.Test, trace.messageType.info);
}
return message;
}

Expand All @@ -25,7 +28,9 @@ export function compareJavaScriptDates(count: number): string {
var elapsedTime = Math.round(new Date().getMilliseconds() - startTime);
var averageTime = (elapsedTime / count);
var message = "Total: " + elapsedTime + " ms. Avg: " + averageTime + " ms.";
trace.write(message, trace.categories.Test, trace.messageType.info);
if (trace.enabled) {
trace.write(message, trace.categories.Test, trace.messageType.info);
}
return message;
}

Expand All @@ -46,7 +51,9 @@ export function decodeAndEncodeBitmap(count: number, finishedCallback: (message)
var elapsedTime = Math.round(new Date().getMilliseconds() - startTime);
var averageTime = (elapsedTime / count);
var message = "Total: " + elapsedTime + " ms. Avg: " + averageTime + " ms.";
trace.write(message, trace.categories.Test, trace.messageType.info);
if (trace.enabled) {
trace.write(message, trace.categories.Test, trace.messageType.info);
}
return finishedCallback(message);
}, function (error) {
console.log(error.message);
Expand Down
8 changes: 6 additions & 2 deletions apps/perf-tests/controls-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export class ControlsPage extends pagesModule.Page implements definition.Control
}

public onNavigatedTo() {
trace.write("Creating " + this._count + " controls...", trace.categories.Test, trace.messageType.info);
if (trace.enabled) {
trace.write("Creating " + this._count + " controls...", trace.categories.Test, trace.messageType.info);
}
this._infoLabel.text = "Creating " + this._count + " controls...";
var startTime = new Date().getMilliseconds();
for (var i = 0; i < this._childStackLayoutCount; i++) {
Expand All @@ -55,7 +57,9 @@ export class ControlsPage extends pagesModule.Page implements definition.Control
}
var elapsedTime = Math.round(new Date().getMilliseconds() - startTime);
var message = "Created " + this._count + " controls in " + elapsedTime + " ms.";
trace.write(message, trace.categories.Test, trace.messageType.info);
if (trace.enabled) {
trace.write(message, trace.categories.Test, trace.messageType.info);
}
this._infoLabel.text = message;
}
}
4 changes: 3 additions & 1 deletion apps/tests/TKUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export function time(): number {

export var write = function write(message: string, type?: number) {
//console.log(message);
trace.write(message, trace.categories.Test, type);
if (trace.enabled) {
trace.write(message, trace.categories.Test, type);
}
}

var runTest = function (testInfo: TestInfoEntry) {
Expand Down
4 changes: 3 additions & 1 deletion apps/tests/navigation/transition-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {AnimationCurve} from "ui/enums"

function _testTransition(navigationTransition: NavigationTransition) {
var testId = `Transition[${JSON.stringify(navigationTransition)}]`;
trace.write(`Testing ${testId}`, trace.categories.Test);
if (trace.enabled) {
trace.write(`Testing ${testId}`, trace.categories.Test);
}
var navigationEntry: NavigationEntry = {
create: function (): Page {
let page = new Page();
Expand Down
4 changes: 3 additions & 1 deletion apps/tests/trace-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export var test_DummyTestForSnippetOnly2 = function () {
// >> trace-message
trace.setCategories(trace.categories.Debug);
trace.enable();
trace.write("My Debug Message", trace.categories.Debug);
if (trace.enabled) {
trace.write("My Debug Message", trace.categories.Debug);
}
// << trace-message
}
12 changes: 9 additions & 3 deletions file-system/file-name-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ export class FileNameResolver implements definition.FileNameResolver {
var candidates = this.getFileCandidatesFromFolder(path, ext);
result = findFileMatch(path, ext, candidates, this._context);

trace.write("Resolved file name for \"" + path + ext + "\" result: " + (result ? result : "no match found"), trace.categories.Navigation);
if (trace.enabled) {
trace.write("Resolved file name for \"" + path + ext + "\" result: " + (result ? result : "no match found"), trace.categories.Navigation);
}
return result;
}

Expand All @@ -160,7 +162,9 @@ export class FileNameResolver implements definition.FileNameResolver {
});
}
else {
trace.write("Could not find folder " + folderPath + " when loading " + path + ext, trace.categories.Navigation);
if (trace.enabled) {
trace.write("Could not find folder " + folderPath + " when loading " + path + ext, trace.categories.Navigation);
}
}

return candidates;
Expand All @@ -171,7 +175,9 @@ export function findFileMatch(path: string, ext: string, candidates: Array<strin
var bestValue = -1
var result: string = null;

trace.write("Candidates for " + path + ext + ": " + candidates.join(", "), trace.categories.Navigation);
if (trace.enabled) {
trace.write("Candidates for " + path + ext + ": " + candidates.join(", "), trace.categories.Navigation);
}
for (var i = 0; i < candidates.length; i++) {
var filePath = candidates[i];
var qualifiersStr: string = filePath.substr(path.length, filePath.length - path.length - ext.length);
Expand Down
7 changes: 7 additions & 0 deletions trace/trace.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ declare module "trace" {
* Disables the trace module.
*/
export function disable(): void;

/**
* A field that indicates if the tracer is enabled and there is a point in writing messages.
* Check this to avoid writing complex string templates.
* Send error messages should even if tracing is disabled.
*/
export var enabled: boolean;

/**
* Adds a TraceWriter instance to the trace module.
Expand Down
10 changes: 5 additions & 5 deletions trace/trace.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import definition = require("trace");
import * as types from "utils/types";

var _enabled = false;
export var enabled = false;
var _categories = {};
var _writers: Array<definition.TraceWriter> = [];
var _eventListeners: Array<definition.EventListener> = [];

export function enable() {
_enabled = true;
enabled = true;
}

export function disable() {
_enabled = false;
enabled = false;
}

export function isCategorySet(category: string): boolean {
Expand Down Expand Up @@ -56,7 +56,7 @@ export function write(message: any, category: string, type?: number) {
}
}

if (!_enabled) {
if (!enabled) {
return;
}

Expand All @@ -71,7 +71,7 @@ export function write(message: any, category: string, type?: number) {
}

export function notifyEvent(object: Object, name: string, data?: any) {
if (!_enabled) {
if (!enabled) {
return;
}

Expand Down
8 changes: 6 additions & 2 deletions ui/animation/animation-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ export class Animation implements definition.Animation {

ensureTrace();

trace.write("Analyzing " + animationDefinitions.length + " animation definitions...", trace.categories.Animation);
if (trace.enabled) {
trace.write("Analyzing " + animationDefinitions.length + " animation definitions...", trace.categories.Animation);
}
this._propertyAnimations = new Array<PropertyAnimation>();
var i = 0;
var length = animationDefinitions.length;
Expand All @@ -126,7 +128,9 @@ export class Animation implements definition.Animation {
if (this._propertyAnimations.length === 0) {
throw new Error("Nothing to animate.");
}
trace.write("Created " + this._propertyAnimations.length + " individual property animations.", trace.categories.Animation);
if (trace.enabled) {
trace.write("Created " + this._propertyAnimations.length + " individual property animations.", trace.categories.Animation);
}

this._playSequentially = playSequentially;
}
Expand Down
57 changes: 43 additions & 14 deletions ui/animation/animation.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,19 @@ export class Animation extends common.Animation implements definition.Animation
}
}

trace.write("Starting " + this._nativeAnimatorsArray.length + " animations " + (this._playSequentially ? "sequentially." : "together."), trace.categories.Animation);
if (trace.enabled) {
trace.write("Starting " + this._nativeAnimatorsArray.length + " animations " + (this._playSequentially ? "sequentially." : "together."), trace.categories.Animation);
}
this._animatorSet.setupStartValues();
this._animatorSet.start();
return animationFinishedPromise;
}

public cancel(): void {
super.cancel();
trace.write("Cancelling AnimatorSet.", trace.categories.Animation);
if (trace.enabled) {
trace.write("Cancelling AnimatorSet.", trace.categories.Animation);
}
this._animatorSet.cancel();
}

Expand All @@ -94,17 +98,25 @@ export class Animation extends common.Animation implements definition.Animation
let that = this;
this._animatorListener = new android.animation.Animator.AnimatorListener({
onAnimationStart: function (animator: android.animation.Animator): void {
trace.write("MainAnimatorListener.onAndroidAnimationStart(" + animator +")", trace.categories.Animation);
if (trace.enabled) {
trace.write("MainAnimatorListener.onAndroidAnimationStart(" + animator +")", trace.categories.Animation);
}
},
onAnimationRepeat: function (animator: android.animation.Animator): void {
trace.write("MainAnimatorListener.onAnimationRepeat(" + animator + ")", trace.categories.Animation);
if (trace.enabled) {
trace.write("MainAnimatorListener.onAnimationRepeat(" + animator + ")", trace.categories.Animation);
}
},
onAnimationEnd: function (animator: android.animation.Animator): void {
trace.write("MainAnimatorListener.onAnimationEnd(" + animator + ")", trace.categories.Animation);
if (trace.enabled) {
trace.write("MainAnimatorListener.onAnimationEnd(" + animator + ")", trace.categories.Animation);
}
that._onAndroidAnimationEnd();
},
onAnimationCancel: function (animator: android.animation.Animator): void {
trace.write("MainAnimatorListener.onAnimationCancel(" + animator + ")", trace.categories.Animation);
if (trace.enabled) {
trace.write("MainAnimatorListener.onAnimationCancel(" + animator + ")", trace.categories.Animation);
}
that._onAndroidAnimationCancel();
}
});
Expand Down Expand Up @@ -139,7 +151,9 @@ export class Animation extends common.Animation implements definition.Animation
return;
}

trace.write("Creating ObjectAnimator(s) for animation: " + common.Animation._getAnimationInfo(propertyAnimation) + "...", trace.categories.Animation);
if (trace.enabled) {
trace.write("Creating ObjectAnimator(s) for animation: " + common.Animation._getAnimationInfo(propertyAnimation) + "...", trace.categories.Animation);
}

if (types.isNullOrUndefined(propertyAnimation.target)) {
throw new Error("Animation target cannot be null or undefined!");
Expand Down Expand Up @@ -347,7 +361,10 @@ export class Animation extends common.Animation implements definition.Animation
if (propertyAnimation.curve !== undefined) {
animators[i].setInterpolator(propertyAnimation.curve);
}
trace.write("Animator created: " + animators[i], trace.categories.Animation);

if (trace.enabled) {
trace.write("Animator created: " + animators[i], trace.categories.Animation);
}
}

this._animators = this._animators.concat(animators);
Expand All @@ -368,24 +385,36 @@ let bounce = lazy(() => new android.view.animation.BounceInterpolator());
export function _resolveAnimationCurve(curve: any): any {
switch (curve) {
case enums.AnimationCurve.easeIn:
trace.write("Animation curve resolved to android.view.animation.AccelerateInterpolator(1).", trace.categories.Animation);
if (trace.enabled) {
trace.write("Animation curve resolved to android.view.animation.AccelerateInterpolator(1).", trace.categories.Animation);
}
return easeIn();
case enums.AnimationCurve.easeOut:
trace.write("Animation curve resolved to android.view.animation.DecelerateInterpolator(1).", trace.categories.Animation);
if (trace.enabled) {
trace.write("Animation curve resolved to android.view.animation.DecelerateInterpolator(1).", trace.categories.Animation);
}
return easeOut();
case enums.AnimationCurve.easeInOut:
trace.write("Animation curve resolved to android.view.animation.AccelerateDecelerateInterpolator().", trace.categories.Animation);
if (trace.enabled) {
trace.write("Animation curve resolved to android.view.animation.AccelerateDecelerateInterpolator().", trace.categories.Animation);
}
return easeInOut();
case enums.AnimationCurve.linear:
trace.write("Animation curve resolved to android.view.animation.LinearInterpolator().", trace.categories.Animation);
if (trace.enabled) {
trace.write("Animation curve resolved to android.view.animation.LinearInterpolator().", trace.categories.Animation);
}
return linear();
case enums.AnimationCurve.spring:
trace.write("Animation curve resolved to android.view.animation.BounceInterpolator().", trace.categories.Animation);
if (trace.enabled) {
trace.write("Animation curve resolved to android.view.animation.BounceInterpolator().", trace.categories.Animation);
}
return bounce();
case enums.AnimationCurve.ease:
return (<any>android).support.v4.view.animation.PathInterpolatorCompat.create(0.25, 0.1, 0.25, 1.0);
default:
trace.write("Animation curve resolved to original: " + curve, trace.categories.Animation);
if (trace.enabled) {
trace.write("Animation curve resolved to original: " + curve, trace.categories.Animation);
}
if (curve instanceof common.CubicBezierAnimationCurve) {
let animationCurve = <common.CubicBezierAnimationCurve>curve;
let interpolator = (<any>android).support.v4.view.animation.PathInterpolatorCompat.create(animationCurve.x1, animationCurve.y1, animationCurve.x2, animationCurve.y2);
Expand Down
Loading