Skip to content

Commit fb013d2

Browse files
committed
Update to 3.1.0
1 parent 42249ee commit fb013d2

File tree

6 files changed

+108
-8
lines changed

6 files changed

+108
-8
lines changed

dist/ProtoSSChe.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ class ProtoSSChe {
368368
};
369369
o.updateCookies(request, response, headers);
370370
response.writeHead(200, headers);
371+
response.__timestamp = new Date().getTime();
371372
response.end(input);
372373
return o;
373374
}
@@ -421,6 +422,7 @@ function getModuleInstance(xmodule) {
421422
serverche.env = env;
422423
function requestListener(req, res) {
423424
try {
425+
req.__timestamp = new Date().getTime();
424426
if (serverche.acceptAppRequests) req = serverche.getAppRequest(req);
425427
serverche.onRequest(req, res);
426428
} catch (e) {}

dist/modules/XProtoSSChe.js

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
33
var http = require("http"),
4-
http2 = require("http2");
4+
http2 = require("http2"),
5+
os = require("os");
56
var ExtendProtoSSChe;
67
const EVENTS = {
78
INIT_REQUEST: "initRequest",
@@ -42,6 +43,9 @@ function getExtendedServerProtoSS(ProtoSSChe) {
4243
asyncBuffer;
4344
asyncInterval;
4445
asyncId;
46+
collectionRR;
47+
collectionStats;
48+
collectionMax;
4549
constructor(routeCallback, routeScope, routeData) {
4650
super();
4751
var o = this;
@@ -58,6 +62,9 @@ function getExtendedServerProtoSS(ProtoSSChe) {
5862
o.asyncBuffer = [];
5963
o.asyncInterval = 1000;
6064
o.asyncId = null;
65+
o.collectionRR = [];
66+
o.collectionStats = [];
67+
o.collectionMax = 300;
6168
o.initRoute();
6269
o.initAsyncGrid();
6370
}
@@ -72,7 +79,7 @@ function getExtendedServerProtoSS(ProtoSSChe) {
7279
clearInterval(o.asyncId);
7380
o.asyncId = null;
7481
}
75-
flushAsyncBuffer() {
82+
exeAsyncBuffer() {
7683
var o = this;
7784
if (o.asyncBuffer.length > 0) {
7885
o.asyncBuffer.forEach((e) => o.routeCallback.call(o.routeScope, o.routeData, e[1].__body, e[0], e[1]));
@@ -82,6 +89,47 @@ function getExtendedServerProtoSS(ProtoSSChe) {
8289
o.asyncBuffer = [];
8390
}
8491
}
92+
exeCollection() {
93+
var o = this;
94+
if (o.collectionRR.length > 0) {
95+
let count = o.collectionRR.length;
96+
let stats = {
97+
requests: count,
98+
time: 0,
99+
avrgTime: 0,
100+
average: 0,
101+
units: 0,
102+
cpus: 0,
103+
cpuTypes: [],
104+
memory: os.totalmem(),
105+
};
106+
let firstin = o.collectionRR[0][0];
107+
let lastout = o.collectionRR[count - 1][1];
108+
stats.time = lastout.__timestamp - firstin.__timestamp;
109+
o.collectionRR.forEach((e) => {
110+
stats.avrgTime += e[1].__timestamp - e[0].__timestamp;
111+
stats.units += e[0].__units || 0;
112+
stats.units += e[1].__units || 0;
113+
});
114+
stats.average = stats.avrgTime / count;
115+
o.collectionRR = [];
116+
o.collectionStats.push(stats);
117+
if (o.collectionStats.length > o.collectionMax) o.collectionStats.shift();
118+
var cpus = os.cpus();
119+
var i, type, cpu, total;
120+
stats.cpus = cpus.length;
121+
for (i = 0; i < stats.cpus; i++) {
122+
(cpu = cpus[i]), (total = 0);
123+
for (type in cpu.times) total += cpu.times[type];
124+
for (type in cpu.times) stats.cpuTypes.push([type, Math.round((100 * cpu.times[type]) / total)]);
125+
}
126+
}
127+
}
128+
flushAsyncBuffer() {
129+
var o = this;
130+
o.exeAsyncBuffer();
131+
o.exeCollection();
132+
}
85133
async onReadRequestBody(request, body, response) {
86134
var o = this;
87135
if (o.emitRR) request.emit(EVENTS.INIT_REQUEST, o, request, response);
@@ -184,6 +232,8 @@ function getExtendedServerProtoSS(ProtoSSChe) {
184232
}
185233
if (!response.headersSent) response.writeHead(response.__rcode || 200, headers);
186234
response.end(input, response.__encoding);
235+
response.__timestamp = new Date().getTime();
236+
o.collectionRR.push([request, response]);
187237
return o;
188238
}
189239
};

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "protoss-nodejs-basic",
3-
"version": "3.0.6",
3+
"version": "3.1.0",
44
"author": "Zeta Ret",
55
"license": "MIT",
66
"type": "commonjs",
@@ -21,6 +21,6 @@
2121
"start-ts": "node dist/indexTS.js"
2222
},
2323
"dependencies": {
24-
"@types/protoss-nodejs-basic": "git+https://github.com/ZetaRet/protoss-nodejs-basic-types.git#v3.0.6"
24+
"@types/protoss-nodejs-basic": "git+https://github.com/ZetaRet/protoss-nodejs-basic-types.git#v3.1.0"
2525
}
2626
}

protossdox.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
"relative": true,
1010
"markdown": true,
1111
"ext": ["js", "ts"],
12-
"version": "3.0.6",
12+
"version": "3.1.0",
1313
"license": "MIT"
1414
}

src/ProtoSSChe.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ class ProtoSSChe implements zetaret.node.ProtoSSChe {
413413
};
414414
o.updateCookies(request, response, headers);
415415
(response as any).writeHead(200, headers);
416+
(response as zetaret.node.AugmentResponse).__timestamp = new Date().getTime();
416417
response.end(input);
417418
return o;
418419
}
@@ -471,6 +472,7 @@ function getModuleInstance(xmodule: string): zetaret.node.ModuleInstance {
471472

472473
function requestListener(req: any, res: any) {
473474
try {
475+
(req as zetaret.node.AugmentRequest).__timestamp = new Date().getTime();
474476
if (serverche.acceptAppRequests) req = serverche.getAppRequest(req);
475477
serverche.onRequest(req, res);
476478
} catch (e) { }

src/modules/XProtoSSChe.ts

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ declare module "protoss-nodejs-basic/dist/modules/XProtoSSChe.js";
99
export { }
1010

1111
var http = require("http"),
12-
http2 = require("http2");
12+
http2 = require("http2"),
13+
os = require("os");
1314

1415
var ExtendProtoSSChe: zetaret.node.ProtoSSCheCTOR;
1516

@@ -54,6 +55,9 @@ function getExtendedServerProtoSS(ProtoSSChe: zetaret.node.ProtoSSCheCTOR): zeta
5455
asyncBuffer: Array<object>;
5556
asyncInterval: number;
5657
asyncId: number | object | any;
58+
collectionRR: any[];
59+
collectionStats: any[];
60+
collectionMax: number;
5761

5862
constructor(routeCallback?: Function, routeScope?: object, routeData?: object) {
5963
super();
@@ -71,11 +75,14 @@ function getExtendedServerProtoSS(ProtoSSChe: zetaret.node.ProtoSSCheCTOR): zeta
7175
o.asyncBuffer = [];
7276
o.asyncInterval = 1000;
7377
o.asyncId = null;
78+
o.collectionRR = [];
79+
o.collectionStats = [];
80+
o.collectionMax = 300;
7481
o.initRoute();
7582
o.initAsyncGrid();
7683
}
7784

78-
routeCallback(routeData: object, body: string, request: zetaret.node.Input, response: zetaret.node.Output): void {}
85+
routeCallback(routeData: object, body: string, request: zetaret.node.Input, response: zetaret.node.Output): void { }
7986

8087
initRoute(): void { }
8188

@@ -90,7 +97,7 @@ function getExtendedServerProtoSS(ProtoSSChe: zetaret.node.ProtoSSCheCTOR): zeta
9097
o.asyncId = null;
9198
}
9299

93-
flushAsyncBuffer(): void {
100+
exeAsyncBuffer(): void {
94101
var o = this;
95102
if (o.asyncBuffer.length > 0) {
96103
o.asyncBuffer.forEach((e: any) => o.routeCallback.call(o.routeScope, o.routeData, e[1].__body, e[0], e[1]));
@@ -101,6 +108,43 @@ function getExtendedServerProtoSS(ProtoSSChe: zetaret.node.ProtoSSCheCTOR): zeta
101108
}
102109
}
103110

111+
exeCollection(): void {
112+
var o = this;
113+
if (o.collectionRR.length > 0) {
114+
let count = o.collectionRR.length;
115+
let stats: any = {
116+
requests: count, time: 0, avrgTime: 0, average: 0, units: 0,
117+
cpus: 0, cpuTypes: [], memory: os.totalmem()
118+
};
119+
let firstin = o.collectionRR[0][0];
120+
let lastout = o.collectionRR[count - 1][1];
121+
stats.time = lastout.__timestamp - firstin.__timestamp;
122+
o.collectionRR.forEach((e: any) => {
123+
stats.avrgTime += e[1].__timestamp - e[0].__timestamp;
124+
stats.units += e[0].__units || 0;
125+
stats.units += e[1].__units || 0;
126+
});
127+
stats.average = stats.avrgTime / count;
128+
o.collectionRR = [];
129+
o.collectionStats.push(stats);
130+
if (o.collectionStats.length > o.collectionMax) o.collectionStats.shift();
131+
var cpus = os.cpus();
132+
var i, type, cpu, total;
133+
stats.cpus = cpus.length;
134+
for (i = 0; i < stats.cpus; i++) {
135+
cpu = cpus[i], total = 0;
136+
for (type in cpu.times) total += cpu.times[type];
137+
for (type in cpu.times) stats.cpuTypes.push([type, Math.round(100 * cpu.times[type] / total)]);
138+
}
139+
}
140+
}
141+
142+
flushAsyncBuffer(): void {
143+
var o = this;
144+
o.exeAsyncBuffer();
145+
o.exeCollection();
146+
}
147+
104148
async onReadRequestBody(request: zetaret.node.Input, body: string, response: zetaret.node.Output): Promise<zetaret.node.modules.XProtoSSChe> {
105149
var o = this;
106150

@@ -217,6 +261,8 @@ function getExtendedServerProtoSS(ProtoSSChe: zetaret.node.ProtoSSCheCTOR): zeta
217261

218262
if (!response.headersSent) (response as Http2Response).writeHead((response as zetaret.node.AugmentResponse).__rcode || 200, headers);
219263
response.end(input, (response as zetaret.node.AugmentResponse).__encoding as any);
264+
(response as zetaret.node.AugmentResponse).__timestamp = new Date().getTime();
265+
o.collectionRR.push([request, response]);
220266
return o;
221267
}
222268
};

0 commit comments

Comments
 (0)