This tutorial describes how to collect an execution trace for a child process of a service (or any descendant process of the service).
This tutorial covers the following:
Related tutorials:
Execution tracing in a child process.
Execution tracing in a service.
Execution tracing in an IIS ISAPI DLL.
Execution tracing for a child process from the command line.
This tutorial applies to all native applications and to mixed-mode applications where the startup code is native.
If your application is written entirely in .Net or .Net Core, or your application is mixed-mode with the startup code written in .Net or .Net core you can skip the part of this tutorial relating to the NT Service API and go straight to the collecting an execution trace from a service child process section.
Bug Validator ships with an example service and an example child process launched by the service. These can be found in the following directories in the Bug Validator installation directory:
or
or
The childProcess has already been modified to use the NT Service API. In this tutorial, we’ll describe the modifications you would make to the child process to make it work correctly with Bug Validator.
The NT Service API is a simple API that allows you to load the Bug Validator profiling DLL and start the process of collecting execution trace data.
The API also includes some debugging functions to help provide debugging information via log files (the only way to get data out of a service without a connection to the Bug Validator user interface).
static void attachToBugValidator() { if (bLogging) { // Set the log file name. // When anything goes wrong the API will write error information to this file. // You can also write to this log file any status errors you need (you'll see examples in this source file) svlBVStub_setLogFileName(SZLOGFILENAME); svlBVStub_deleteLogFile(); } if (bLogging) { svlBVStub_writeToLogFileW(L"About to load Bug Validator\r\n"); } SVL_SERVICE_ERROR errCode; #ifdef IS6432 // x86 with x64 GUI errCode = svlBVStub_LoadBugValidator6432(); #else //#ifdef IS6432 // x86 with x86 GUI // x64 with x64 GUI errCode = svlBVStub_LoadBugValidator(); #endif //#ifdef IS6432 if (bLogging) { if (errCode != SVL_OK) { DWORD lastError; lastError = GetLastError(); svlBVStub_writeToLogFileW(L"Bug Validator load failed. \r\n"); svlBVStub_writeToLogFileLastError(lastError); svlBVStub_writeToLogFile(errCode); svlBVStub_dumpPathToLogFile(); } else { svlBVStub_writeToLogFileW(L"Bug Validator load success. \r\n"); } } // DO NOT setup a service callback because this is a child application of a service, not a service // start Bug Validator errCode = svlBVStub_StartBugValidator(); if (bLogging) { if (errCode != SVL_OK) { DWORD lastError; lastError = GetLastError(); svlBVStub_writeToLogFileW(L"Starting Bug Validator failed. \r\n"); svlBVStub_writeToLogFileLastError(lastError); svlBVStub_writeToLogFile(errCode); } svlBVStub_writeToLogFileW(L"Finished loading Bug Validator\r\n"); } }
Now that the NT Service API has been implemented in your application, we can start collecting execution trace data from the service child process.
Select the application executable (the service’s child process) you are going to monitor. For this example the application is examples\serviceWithAChildProcess\serviceWithAChildProcess\Release\childProcess.exe.
There are a few things to check.
svlBVStub_setLogFileName(SZLOGFILENAME);
You have learned how to add the NT Service API to a native application that is going to be launched from a service, how to use Bug Validator to monitor a service’s child process, and what to look at to diagnose errors if things don’t work first time.