@@ -27,6 +27,7 @@ var popupRenderPosition = 'left';
2727
2828// EXPORTS
2929exports . configure = configure ;
30+ configure ( ) ;
3031
3132for ( let framework of [ 'koa' , 'express' , 'hapi' ] ) {
3233 let func = require ( `./middlewares/${ framework } .js` ) ;
@@ -174,8 +175,6 @@ function results(req, res, lastPathSegment, done) {
174175 var body = '' ;
175176 req . on ( 'data' , function ( data ) {
176177 body += data ;
177- if ( body . length > 1e6 )
178- req . connection . destroy ( ) ;
179178 } ) ;
180179
181180 req . on ( 'end' , function ( ) {
@@ -222,13 +221,12 @@ function include(id) {
222221 */
223222function configure ( options ) {
224223 options = options || { } ;
225- if ( options ) {
226- storage = options . storage || storage ;
227- ignoredPaths = options . ignoredPaths || ignoredPaths ;
228- trivialDurationThresholdMilliseconds = options . trivialDurationThresholdMilliseconds || trivialDurationThresholdMilliseconds ;
229- popupShowTimeWithChildren = options . popupShowTimeWithChildren || popupShowTimeWithChildren ;
230- popupRenderPosition = options . popupRenderPosition || popupRenderPosition ;
231- }
224+
225+ storage = options . storage || storage ;
226+ ignoredPaths = options . ignoredPaths || ignoredPaths ;
227+ trivialDurationThresholdMilliseconds = options . trivialDurationThresholdMilliseconds || trivialDurationThresholdMilliseconds ;
228+ popupShowTimeWithChildren = options . popupShowTimeWithChildren || popupShowTimeWithChildren ;
229+ popupRenderPosition = options . popupRenderPosition || popupRenderPosition ;
232230}
233231
234232/*
@@ -249,6 +247,7 @@ function startProfiling(request, enabled) {
249247 currentRequestExtension . customTimings = { } ;
250248 debug ( `Profiling started for ${ path } with id ${ currentRequestExtension . id } ` ) ;
251249 }
250+
252251 currentRequestExtension . timeQuery = function ( ) {
253252 var args = Array . prototype . slice . call ( arguments , enabled ? 0 : 3 ) ;
254253 if ( enabled ) {
@@ -258,6 +257,15 @@ function startProfiling(request, enabled) {
258257 arguments [ 2 ] . apply ( this , args ) ;
259258 }
260259 } ;
260+
261+ currentRequestExtension . startTimeQuery = function ( type , query ) {
262+ return startTimeQuery . call ( this , currentRequestExtension , type , query ) ;
263+ } ;
264+
265+ currentRequestExtension . stopTimeQuery = function ( timing ) {
266+ return stopTimeQuery . call ( this , timing ) ;
267+ } ;
268+
261269 currentRequestExtension . step = function ( name , call ) {
262270 //var args = Array.prototype.slice.call(arguments, enabled ? 0 : 2);
263271 if ( enabled ) {
@@ -266,6 +274,7 @@ function startProfiling(request, enabled) {
266274 call ( ) ;
267275 }
268276 } ;
277+
269278 currentRequestExtension . include = function ( ) {
270279 return enabled ? include ( currentRequestExtension . id ) : '' ;
271280 } ;
@@ -283,9 +292,14 @@ function stopProfiling(request){
283292 var extension = request . miniprofiler ;
284293 var time = process . hrtime ( ) ;
285294 debug ( `Profiling stopped for ${ path } with id ${ extension . id } ` ) ;
286- if ( extension . stepGraph . parent != null ) {
287- throw new Error ( 'profiling ended while still in a function, was left in [' + extension . stepGraph . name + ']' ) ;
288- }
295+
296+ /*
297+ * Do we still need this?
298+ *
299+ if(extension.stepGraph.parent != null){
300+ throw new Error('profiling ended while still in a function, was left in ['+extension.stepGraph.name+']');
301+ }
302+ */
289303
290304 extension . stopTime = time ;
291305 extension . stepGraph . stopTime = time ;
@@ -340,13 +354,35 @@ function step(name, request, call) {
340354 * to have ended the query.
341355 */
342356function timeQuery ( extension , type , query , executeFunction ) {
343- debug ( `Started timed query "${ type } " with command "${ query } "` ) ;
357+ var timing = startTimeQuery ( extension , type , query ) ;
358+ var params = Array . prototype . slice . call ( arguments , 4 ) ;
359+
360+ for ( var i = 0 ; i < params . length ; i ++ ) {
361+ if ( _ . isFunction ( params [ i ] ) ) {
362+ var param = params [ i ] ;
363+ params [ i ] = function ( ) {
364+ debug ( `Stopped timed query "${ type } " with command "${ query } "` ) ;
365+ extension . stopTimeQuery ( timing ) ;
366+ var ret = param . apply ( this , arguments ) ;
367+ return ret ;
368+ } ;
369+ }
370+ }
371+
372+ var ret = executeFunction . apply ( this , params ) ;
373+ return ret ;
374+ }
375+
376+ function stopTimeQuery ( timing ) {
377+ timing . stopTime = process . hrtime ( ) ;
378+ }
379+
380+ function startTimeQuery ( extension , type , query ) {
381+ debug ( `Started timed query "${ type } " with command "${ query } "` ) ;
344382
345383 var time = process . hrtime ( ) ;
346384 var startDate = Date . now ( ) ;
347385
348- var params = Array . prototype . slice . call ( arguments , 4 ) ;
349-
350386 extension . stepGraph . customTimings [ type ] = extension . stepGraph . customTimings [ type ] || [ ] ;
351387
352388 var customTiming = {
@@ -360,31 +396,21 @@ function timeQuery(extension, type, query, executeFunction) {
360396
361397 extension . stepGraph . customTimings [ type ] . push ( customTiming ) ;
362398
363- for ( var i = 0 ; i < params . length ; i ++ ) {
364- if ( _ . isFunction ( params [ i ] ) ) {
365- var param = params [ i ] ;
366- params [ i ] = function ( ) {
367- debug ( `Stopped timed query "${ type } " with command "${ query } "` ) ;
368- customTiming . stopTime = process . hrtime ( ) ;
369- var ret = param . apply ( this , arguments ) ;
370- return ret ;
371- } ;
372- }
373- }
374-
375- var ret = executeFunction . apply ( this , params ) ;
376-
377- return ret ;
399+ return customTiming ;
378400}
379401
380402function unstep ( name , request ) {
381403 var time = process . hrtime ( ) ;
382404
383405 var extension = request . miniprofiler ;
384406
385- if ( extension . stepGraph . name != name ) {
386- throw new Error ( 'profiling stepped out of the wrong function, found [' + name + '] expected [' + extension . stepGraph . name + ']' ) ;
387- }
407+ /*
408+ * Do we still need this?
409+ *
410+ if(extension.stepGraph.name != name){
411+ throw new Error('profiling stepped out of the wrong function, found ['+name+'] expected ['+extension.stepGraph.name+']');
412+ }
413+ */
388414
389415 extension . stepGraph . stopTime = time ;
390416
@@ -407,10 +433,14 @@ function describePerformance(root, request) {
407433}
408434
409435function diff ( start , stop ) {
436+ /*
437+ * Do we still need this?
438+ *
410439 if (!stop) {
411440 stop = process.hrtime();
412441 debug('missing stop, using', stop);
413442 }
443+ */
414444 var deltaSecs = stop [ 0 ] - start [ 0 ] ;
415445 var deltaNanoSecs = stop [ 1 ] - start [ 1 ] ;
416446
0 commit comments