Skip to content

Commit 6befe17

Browse files
committed
(startup-test) Add a starter shim that records startup time.
1 parent ab2eabf commit 6befe17

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

startup-test/app/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require("globals");
22
var profiling = require('./profiling');
3-
profiling.start('application-start');
3+
//profiling.start('application-start');
44

55
var reflectMetadata = require("reflect-metadata");
66

startup-test/app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "tns-template-hello-world",
3+
"main": "starter.js",
34
"jsoptions": "--expose_gc",
45
"version": "1.4.0",
56
"author": "Telerik <support@telerik.com>",

startup-test/app/profiling.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ function time() {
1111
}
1212
}
1313
exports.time = time;
14-
var timers = new Map();
14+
if (!global.timers) {
15+
global.timers = new Map();
16+
}
1517
function start(name) {
1618
if (!exports.ENABLE_PROFILING) {
1719
return;
1820
}
1921
var info;
20-
if (timers.has(name)) {
21-
info = timers.get(name);
22+
if (global.timers.has(name)) {
23+
info = global.timers.get(name);
2224
if (info.currentStart != 0) {
2325
throw new Error("Timer already started: " + name);
2426
}
@@ -30,7 +32,7 @@ function start(name) {
3032
count: 0,
3133
currentStart: time()
3234
};
33-
timers.set(name, info);
35+
global.timers.set(name, info);
3436
}
3537
}
3638
exports.start = start;
@@ -48,14 +50,15 @@ function stop(name) {
4850
}
4951
var info = pauseInternal(name);
5052
console.log("---- [" + name + "] STOP total: " + info.totalTime + " count:" + info.count);
51-
timers.delete(name);
53+
global.timers.delete(name);
5254
}
5355
exports.stop = stop;
5456
function pauseInternal(name) {
55-
var info = timers.get(name);
57+
var info = global.timers.get(name);
5658
if (!info) {
5759
throw new Error("No timer started: " + name);
5860
}
61+
console.dump(info);
5962
info.lastTime = Math.round(time() - info.currentStart);
6063
info.totalTime += info.lastTime;
6164
info.count++;

startup-test/app/starter.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
if (!global.timers) {
2+
global.timers = new Map();
3+
}
4+
5+
function time() {
6+
if (global.android) {
7+
return java.lang.System.nanoTime() / 1000000; // 1 ms = 1000000 ns
8+
}
9+
else {
10+
return CACurrentMediaTime() * 1000;
11+
}
12+
}
13+
14+
var timerEntry = {
15+
totalTime: 0,
16+
count: 0,
17+
currentStart: time()
18+
};
19+
20+
global.timers.set("application-start", timerEntry);
21+
22+
require("./index.js");

0 commit comments

Comments
 (0)