Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to use it in the context of a webserver like Express.js #7

Open
roundrobin opened this issue Oct 24, 2014 · 5 comments
Open

Comments

@roundrobin
Copy link

I tried using async-profile within an endpoint of an express app, but I can't get it to work. Its immediately returning of making a instance an within the endpoint. Here a stripped down demo of my code:

//controller.js

var AsyncProfile = require('async-profile');

function someEndpoint(req, res){

    var profiler = new AsyncProfile({
        callback: function(results){
            console.log("error", "CPU profiling", results);
        }
    });

   //Its return immediately after the instantiation 

   dosomething(function returnCallback(){

    profiler.stop();
    //Expected it to stop here
 });



}
@ConradIrwin
Copy link
Owner

Hey @roundrobin, that should just work :/. Can you link me to the actual code?

@clevertension
Copy link

is it able to print all the stacks of code, for example if i use MVC in express, the stack print should be "Controller","Service","DB" ?

@ConradIrwin
Copy link
Owner

@clevertension In theory, yes. You'd have to modify the code, or use your own output printer though.

@giannif
Copy link

giannif commented Jan 24, 2015

@roundrobin's code works correctly for me, however if I use request, the profile terminates prematurely.

You can run this and see:

var AsyncProfile = require('async-profile'),
    request = require("request");

function someEndpoint() {

    var profiler = new AsyncProfile({
        callback: function(results) {
            results.print();
        }
    });

    request("http://google.com", function() {
        // profiler stops right before this callback.
        console.log("loaded google");
    });

    // wait 5 seconds and then stop
    setTimeout(function returnCallback() {
        console.log("really stop");
        profiler.stop();
    }, 5000);

}
someEndpoint();

@ConradIrwin
Copy link
Owner

That's probably because request() isn't preserving domains across async calls. This can probably be patched in a similar manner to redis/mongo etc. in the current code.

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

No branches or pull requests

4 participants