@@ -9,7 +9,8 @@ declare module "protoss-nodejs-basic/dist/modules/XProtoSSChe.js";
99export { }
1010
1111var http = require ( "http" ) ,
12- http2 = require ( "http2" ) ;
12+ http2 = require ( "http2" ) ,
13+ os = require ( "os" ) ;
1314
1415var 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