If a service takes too long to start the service control manager kills the service.
The way to stop this is for a service to call ReportStatusToSCMgr() to tell the service control manager that the service is still OK.
Performance Validator can't do this for you as the call requires some data from any earlier call you have made.
The solution is that you provide a callback using svlPVStub_SetServiceCallback() that Performance Validator can call during the process of attaching to the service, and you can call the appropriate function.
Example code to set the callback:
errCode = svlPVStub_SetServiceCallback(serviceCallback, // the callback
NULL); // some user data (we don't have any, so set NULL)
if (bLogging)
{
if (errCode != SVL_OK)
{
svlPVStub_writeToLogFileW(L"Setting service callback failed. \r\n");
svlPVStub_writeToLogFile(errCode);
}
svlPVStub_writeToLogFileW(L"Starting Performance Validator\r\n");
}
Example callback:
static void serviceCallback(void *userParam)
{
// just tell the Service Control Manager that we are still busy
// in this example userParam is not used
//
// note that prior to the Validator loading it's DLL ssStatus.dwCurrentState must have been initialised, most likely to SERVICE_START_PENDING
// you could pass a fixed value here, but it would need to change once the service has finished starting up so that you don't unintentionally change the service state
// when this callback is called. This callback is called whenever instrumentation happens (when a DLL is loaded). Thus you can't assume this is only called during service startup,
// it may also get called later in the service lifetime.
ReportStatusToSCMgr(ssStatus.dwCurrentState, // service state
NO_ERROR, // exit code
3000); // wait hint
}
We strongly recommend that you set a service callback. It won't harm your program and it will remove any likelihood of your service being killed by the service control manager.
If you have problems getting Performance Validator to monitor your service you'll need to find out what's failing.
Until Performance Validator loads correctly and successfully connects to the graphical user interface you have no way of knowing what is happening.
The solution is to set a log file that Performance Validator can write status messages to. You can also write your own status messages to this log file.
Set the log file using svlPVStub_setLogFileName. Write to it using svlPVStub_writeToLogFile(), svlPVStub_writeToLogFileA(), svlPVStub_writeToLogFileW().
Then when things are not working as expected take a look at the log file to see the errors. The Performance Validator will often suggest what the problem is.
We strongly recommend that you configure the log file and use it when working with services. It has saved us a lot of time.