diff --git a/trace/trace_server.js b/trace/trace_server.js index 993f4ce..99c150b 100644 --- a/trace/trace_server.js +++ b/trace/trace_server.js @@ -402,9 +402,11 @@ define(function(require){ var buf = [] var total = 0 - function flush(){ + function flush(end){ if(buf.length){ gz.write(buf.join('')) + gz.flush(); + if (end) gz.end(); buf = [] total = 0 } @@ -427,18 +429,18 @@ define(function(require){ process.on('exit', function(){ console.log('exit!') - //gz.end() }) return function(m){ - if(!terminated){ - // we should buffer atleast a megabyte - var data = '\x1f'+JSON.stringify(m)+'\x17' - buf.push(data) - total += data.length - if(total > 1024*1024) flush() - } + if (!m) flush(true); + else { + // we should buffer atleast a megabyte + var data = '\x1f'+JSON.stringify(m)+'\x17' + buf.push(data) + total += data.length + if(total > 1024*1024) flush() + } } } @@ -526,6 +528,10 @@ define(function(require){ child.on('message', function(m){ sender(m) }) + + child.on('exit', function () { + sender(false); + }) } function proxyMode(filter, port, bind, proxy, sender){ diff --git a/tracegl.js b/tracegl.js index a14e802..17f0259 100644 --- a/tracegl.js +++ b/tracegl.js @@ -403,9 +403,11 @@ define('/trace/trace_server',function(require){ var buf = [] var total = 0 - function flush(){ + function flush(end){ if(buf.length){ gz.write(buf.join('')) + gz.flush(); + if (end) gz.end(); buf = [] total = 0 } @@ -428,18 +430,18 @@ define('/trace/trace_server',function(require){ process.on('exit', function(){ console.log('exit!') - //gz.end() }) return function(m){ - if(!terminated){ - // we should buffer atleast a megabyte - var data = '\x1f'+JSON.stringify(m)+'\x17' - buf.push(data) - total += data.length - if(total > 1024*1024) flush() - } + if (!m) flush(true); + else { + // we should buffer atleast a megabyte + var data = '\x1f'+JSON.stringify(m)+'\x17' + buf.push(data) + total += data.length + if(total > 1024*1024) flush() + } } } @@ -527,6 +529,10 @@ define('/trace/trace_server',function(require){ child.on('message', function(m){ sender(m) }) + + child.on('exit', function () { + sender(false); + }) } function proxyMode(filter, port, bind, proxy, sender){