How can we help you today? How can we help you today?

application does not shut down normally

I had a problem with the previous release that I still have with the v3 Beta. Whenever I stop the (big) application that I am profiling, I receive the following message: "The application that you are profiling has exited without shutting down normally. Profiling will now stop".
I have then no result set at all. The only way I can work is by taking snapshots, which is working alright.
On a more positive way, we appreciate the "fast mode" very much here, which is very usefull when you work on a big application. Without this mode, the application is not really usable, and therefore hard to profile.

keep on the good work!
fca
0

Comments

4 comments

  • Robert C
    Hi,

    Thanks for the comments.

    Is your application a console application by any chance? With some console applications and a few others (particularly when the CLR is hosted inside a non-.NET environment), we aren't able to obtain a final snapshot. This is because the host container terminates before we have chance to retrieve the data from the process. As you say, using the "Take snapshot" button before closing your application will enable you to obtain results, but this does need you to remember to do so - not always ideal!

    Another thing you may wish to try is the profiling API - you could add an Api.TakeSnapshot() call to your application's exit code, at which point it would cause a snapshot to be taken. Have a look here for more details on how to use the API.

    Hope that helps,
    Robert
    Robert C
    0
  • fca
    Thanks Robert,

    I tried you API and it just works fine. Beside of letting me close my profiling session when I shut down our application, it also helps reproduce similar results. Well, as similar as a statistical sampling might be (-; ), but still, the idea is nice.
    You could maybe even add a static boolean in your API indicating if the profiler is running?
    (I am lazy and do not want to check programmatically every process running when I launch the appli, and do not like a code like:

    try
    {//called when appli is closing
    RedGate.Profiler.Api.TakeSnapshot();
    RedGate.Profiler.Api.Disable();
    }
    catch (RedGate.Profiler.ProfilerNotRunningException e)
    {
    //do nothing but takes time and ressource...
    }
    fca
    0
  • Robert C
    Hi,

    Good idea - I'll add that to the list of suggestions, though I'm afraid it probably won't make it into version 3 due to time constraints.

    There is a way of determining whether the profiler is running or not, though as with all things it isn't entirely free. You can use the Process.GetCurrentProcess().Modules property to get a list of all the DLLs currently loaded in your process.

    You can then check for the existance of RedGate.Profiler.Core2.dll in that collection (I used a quick test on the FileName of each module), which will tell you if the process is currently being profiled.

    If you're making this call several times, you might want to cache the result in a static variable somewhere - the profiler DLL is always loaded before your program starts executing, so it's safe to only check once.

    Here's a really quick and dirty piece of code I came up with. I don't promise that it's the quickest, best, or anything else way of doing it!
    private static int m_ProfilerRunningState = 0;
    static bool ProfilerRunning
    {
        get
        {
            if (m_ProfilerRunningState == 0)
            {
                foreach (ProcessModule module in Process.GetCurrentProcess().Modules)
                {
                    if (module.FileName.EndsWith("RedGate.Profiler.Core2.dll", StringComparison.CurrentCultureIgnoreCase))
                    {
                        m_ProfilerRunningState = 1;
                        return true;
                    }
                }
                m_ProfilerRunningState = 2;
                return false;
            }
            else
            {
                return (m_ProfilerRunningState == 1);
            }
        }
    }
    
    Robert C
    0
  • fca
    Yes,

    this is probably what I will do. (An alternative could be a command line argument which tells if we want to run a profiling session or not. Simple, solid, and ... safe).

    cheers,

    François
    fca
    0

Add comment

Please sign in to leave a comment.