Profiling windows service

I cannot profile a windows service.
If I start profiling it when the service is started, the the profiler stops it and that's it. If I start profiling it when the service is stopped then nothing happens.
The only thing I see is a message on the lower left corner of the screen saying: "Starting service 'ServiceName'".
The "Stop Profiling" button is grayed out at well...

Comments

  • Does the service show up as running when you refresh the service list? The profiler does have to restart the service in order to profile it, and the 'starting service' message is usually displayed while the service is running but is not providing any profiling data yet.

    Depending on how the service and security is set up on your system, it is possible that the profiler isn't starting because of a permissions issue. The cheapest way to get around it is to reconfigure the service to run as LocalSystem. If you don't want to do that, there are a couple of things to check:

    * The service must be able to read from the ANTS Profiler directory in Program Files in order to load in the ProfilerCore DLL.
    * The service and the profiler must be able to agree upon a place where they can both read and write files. Normally, ANTS will use whatever the service has configured as a temp directory, but you can configure a specific location by setting the RGTEMP variable in your environment before starting the profiler. Set it to a directory that both your user and the user that the service runs as can write to.
    Andrew Hunter
    Software Developer
    Red Gate Software Ltd.
  • 1) The service does not show up as running.
    2) I cannot run the service as LocalSystem since it needs access to network resources.
    3) The service is configured to run as a user which is an admin on my computer, it's the same user I load the profiler with. Is there still a chance of permission issues?

    Thanks,
    Guy
  • I am having the exact same issue: the UI is stuck in "Starting service" and there is no profiling.

    Andrew, when you say
    The cheapest way to get around it is to reconfigure the service to run as LocalSystem
    do you mean "service" as in the ANTS profiler service or "service" as in the service we are running?
  • gpeszek wrote:
    I am having the exact same issue: the UI is stuck in "Starting service" and there is no profiling.

    Andrew, when you say
    The cheapest way to get around it is to reconfigure the service to run as LocalSystem
    do you mean "service" as in the ANTS profiler service or "service" as in the service we are running?

    I mean the service you are running. LocalSystem has the most rights of any user so it's guaranteed not to have a problem writing out profiler results anywhere and most services should run OK as this user. You could also configure it to run as your user if you have the log on as a service right granted.

    If you are profiling a network service there are some serious security concerns with doing this, so I can understand wanting to keep the service running as one of the users with fewer permissions. This is possible, but you'll need to create a new folder with the appropriate permissions and tell the profiler to use that instead. Here's how:

    * Create a new folder to store temporary profiler files in. It's probably easiest to put this in the root folder of a drive (I tried this out with a folder called 'D:\Profiler')
    * Grant full control permissions to this folder for the user you are running as and the user that the service runs as (generally Local Service or Network Service)
    * Set the RGTEMP environment variable to point at this folder before launching the profiler. You can do this by setting the variable then launching the profiler from the command line, or by editing the environment variables in the advanced tab of the System control panel and logging off and back on again.

    We don't grant these permissions automatically as it would cause a change to the security surface of the system - Local Service and Network Service processes are limited in what they can communicate with by design, and profiling requires a (slight) decrease in this security.

    This should work in all versions of the profiler, but I've just tried this on a version of 4.3 and seen it fail so you may wish to try the 5.0 beta version that's now available if you run into difficulties.

    You can download them from here:
    http://www.red-gate.com/messageboard/viewforum.php?f=92
    Andrew Hunter
    Software Developer
    Red Gate Software Ltd.
  • Thanks for your quick reply, Andrew.

    I have had no luck with the 4.3 profiler so I attempted to use the 5.0.0.801 profiler with the same results. The service I am attempting to profile is running as Local System and the profiler UI is stuck at "Starting application..." with "Preparing session" in the status bar. Any suggestions?
  • guy.marom wrote:
    1) The service does not show up as running.
    3) The service is configured to run as a user which is an admin on my computer, it's the same user I load the profiler with. Is there still a chance of permission issues?

    This doesn't seem to be a problem with permissions to me, like I said I am running the service with a user that is an administrator
  • The service not showing up as running is odd. Normally ANTS will get an error back from the service controller when the service fails to start and will report this back to you. The status that ANTS is showing indicates that it has sent the start request, hasn't received an error and hasn't yet received a request to start profiling. An early crash generally gets reported back to the profiler as an error, and a later crash ought to happen after the profiler has connected so the UI status will have changed.

    There are a couple of cases where I know this can get stuck, but neither appear to apply here:

    * if the service is unmanaged, ANTS will stay at this screen until the first time it executes managed code (but the service should start with no problem)
    * if the service is managed but the profiler fails to load into the process, ANTS can't tell the difference from the first case and will stick at this screen as well. A 'failed to CoCreate profiler' message will be placed in the event log.
    * If the service starts up and then shuts down in an orderly manner without running any unmanaged code, ANTS might not notice it has gone away.

    The second case most commonly occurs with services when they don't have permission to read the profiler DLL, but doesn't stop the service from starting in all the cases I've seen.

    Can you profile successfully with the new memory profiler?

    Does the service process appear in task manager? It's possible it's stuck in some sort of limbo where it can't complete startup. Additionally, does it appear briefly and then disappear again?

    Do any errors or warnings appear in the system event log when ANTS tries to restart the service?

    ANTS puts a log file in the local app data directory (whose location varies on different editions of Windows: on XP these should be in Documents and Settings\<user>\Local Settings\Application Data\Red Gate\ANTS Performance Profiler 5). Are there any warnings or errors in there?

    Are you using a config file or security policy that could be violated by the profiler with your service? I'd expect that to produce an error, but I've never tried with a service. The profiler is an unmanaged DLL and might not be permitted to load at some trust levels, and line-level timing requires full trust.
    Andrew Hunter
    Software Developer
    Red Gate Software Ltd.
  • AndrewH wrote:
    There are a couple of cases where I know this can get stuck, but neither appear to apply here
    I agree, none of these seem to apply to this case.
    AndrewH wrote:
    Can you profile successfully with the new memory profiler
    I am using version 4.0.0.861, can I use the same license for the new profiler?
    AndrewH wrote:
    Does the service process appear in task manager? It's possible it's stuck in some sort of limbo where it can't complete startup. Additionally, does it appear briefly and then disappear again?
    It doesn't appear in the task manager even briefly. What more, while the profiler was waiting for the service to start, I went ahead and started it manually and it didn't seem to make any difference.

    Also, the log didn't say anything except for 2 startup lines:
    21 May 2009 09:09:32.750 [1] INFO RedGate.Profiler.Logging.LogService - Starting new ANTS Performance Profiler 4 session
    21 May 2009 09:09:32.765 [1] INFO RedGate.Profiler.Logging.LogService - Assembly version: 4.0.0.861


    Regarding the policy, I asked our IT guys and they didn't find anything, maybe if you were more specific on what we should look they will find it. They did however dig this from the event log:
    .NET Runtime version 2.0.50727.3053 - Profiling flag set, but required environment (COR_PROFILER) was not set.

    I have to say that I expect better service (Meaning, faster answers) from a company whose product I purchased.

    Guy Marom
  • We have located what the issue is and a fix will be available very shortly in the RC releases for the V5 Performance and Memory profilers.

    Regards,

    Stephen
  • I had the same error. It happened when other user killed the login process of a job I launched.

    My job freezed for that reason
Sign In or Register to comment.