Skip to content

Implemented Snapshot.export - #58

Closed
3y3 wants to merge 1 commit into
node-inspector:masterfrom
3y3:export
Closed

3y3 wants to merge 1 commit into
node-inspector:masterfrom
3y3:export

Conversation

@3y3

@3y3 3y3 commented May 1, 2015

Copy link
Copy Markdown
Member

For @thlorenz review.

@thlorenz

thlorenz commented May 1, 2015

Copy link
Copy Markdown
Contributor

Looks nice after quick review and should solve the problem I was trying to tackle in #55.
I'll review this in more detail and give you better feedback by Monday.

@3y3

3y3 commented May 5, 2015

Copy link
Copy Markdown
Member Author

@thlorenz , Ok, thanks.
@bajtos , any thoughts?

@bajtos

bajtos commented May 5, 2015

Copy link
Copy Markdown
Member

I'd say the solution is overcomplicated, it should be enough to support the flavour export().pipe(). Everything else can be achieved by stream composition, there is no need to repeat it in v8-profiler.

@3y3

3y3 commented May 5, 2015

Copy link
Copy Markdown
Member Author

@bajtos , are you propose to return Writable stream if there are no arguments passed to function, or you also propose to completely remove callback strategy for this method?

@bajtos

bajtos commented May 5, 2015

Copy link
Copy Markdown
Member

are you propose to return Writable stream if there are no arguments passed to function, or you also propose to completely remove callback strategy for this method?

Yes and yes.

See concat-stream for an example of converting a stream-based interface to a callback-based one.

@bajtos

bajtos commented May 5, 2015

Copy link
Copy Markdown
Member

Code sample:

var callback = function(err, data) { /*...*/ };
var concatStream = require('concat-stream')(function(data) { callback(null, data); });
profiler.takeSnapshot().export()
  .on('error', callback)
  .pipe(concatStream)
  .on('error', callback);

@bajtos

bajtos commented May 5, 2015

Copy link
Copy Markdown
Member

Also toStream() may be a better method name than export.

@3y3

3y3 commented May 5, 2015

Copy link
Copy Markdown
Member Author

Also toStream() may be a better method name than export.

I take export name, because I want to implement also import.snapshot method.
Completed API will look like:

var fs = require('fs') ;

profiler.gc().takeSnapshot().export() // We don't need to keep snapshot in memory
  .pipe(fs.createWriteStream('snapshot1'))
  .on('finish', profiler.gc)
  .on('finish', function test() {
    // Do something here.
    //...
    compareHeapState();
  });

function compareHeapState() {
  var currentHeap = profiler.takeSnapshot(),
    startHeap = profiler.import.snapshot('snapshot1');

  return currentHeap.compare(startHeap);
}

Of course we don't have gc method now =)

@3y3
3y3 force-pushed the master branch 3 times, most recently from d8da5e6 to 1a24629 Compare May 12, 2015 21:07
@eljefedelrodeodeljefe

Copy link
Copy Markdown

@3y3 are you moving forwards with this?

@3y3

3y3 commented Aug 31, 2015

Copy link
Copy Markdown
Member Author

Landed.
I prefer to keep callback api, because not a good idea to install external dependencie only to have ability to save snapshot.

@3y3 3y3 closed this Aug 31, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants