Use Performance Monitoring Tool (also known as Perfmon) to diagnose performance problems
Sometimes when you encounter performance related problems in your database the Profiler alone can't help you identifying the exact cause of the problems.
For example, analyzing the query execution time using the Profiler in the production server you've seen that the corresponding TSQL is executing slowly, say 10 seconds, while the same query takes a much lower time in the Test server, say 200 ms. You analyzed the query execution plans and data volume and found those to be roughly the same.
The Performance Monitoring Tool comes to your aid in these kinds of situations. Performance Monitor is a tool that gathers statistical data related to hardware and software metrics from time to time.
When you issue a TSQL to execute in the database server, there are many stakeholders participating in the actions to execute the query and return result. These include the TSQL Execution engine, Server buffer cache, SQL Optimizer, Output queue, CPU, Disk I/O and lots of other things. So, if one of these does not perform its corresponding task well and fast, the ultimate query execution time taken by the database server would be high. Using the Performance Monitoring tool you can take a microscopic look at the performance of these individual components and identify the root cause of the performance problem.
With Perfmon you can create a counter log including different built in counters that measures performance of each individual components while executing the queries and analyze the counter log with a graphical view to understand what's going on in detail. Also you can combine the Performance counter log with the SQL Profiler trace for a certain period of time to better understand the complete situation while executing a query.
  • Basic use of Performance Monitor
    Steps to create a performance counter log:
    1. Launch the Performance Monitor tool from Tools->Performance Monitor in the SQL profiler tool

    2. Create a new Performance Counter log by clicking on the Counter Logs->New Log Settings

      Specify log file name and press OK.

    3. Click on the Add Counters button to select the preferred counters in the newly created counter log.

    4. Add the preferred counters by selecting desired objects and their corresponding counters from the list. Click on Close when done.

    5. The selected counters will be displayed in the form.

    6. Click on the Log Files tab and click on the Configure tab to specify the log file location and modify log file name if required. Click OK when done.

    7. Click on the Schedule tab to specify a schedule for reading the counter information and write in the log file. Or you can also select Manually for Start log and Stop log options in which case the counter data will be logged after you start the performance counter log.

    8. Click on the General tab and specify the interval for gathering counter data.

    9. Press OK and start performance counter log by selecting the counter log and clicking start. When done stop the counter log.

    10. To view log data close and open the Performance monitor tool again. Click on the view log icon to view counter log. Click on the Source tab and select Log files radio button and add the log file to view by clicking on the Add button.

    11. By default only three default counters are selected to be shown in the counter log output. Specify other counters, that were included while creating the Coutner log, by clicking on the Data tab and selecting the desired counters by clicking on the Add button.

    12. Click OK button to view the performance counter log output in a graphical view.

  • Correlate Performance counter log and SQL Profiler trace for better investigation
    SQL Profiler can give you information about the long running queries, but it can't provide you with the context information to explain the reason for long query execution time. On the other hand, the Performance monitor tool gives you statistics regarding the individual component's performance but, it does not give you information about the query execution time. So, by combining the performance counter log with the SQL Profiler trace you can get the complete picture while diagnosing performance problems in SQL Server.
    Correlating these two things serve another important purpose also. If the same query takes longer time in production server to execute on Production server than on Test server, this indicates that the Test server may not have the same amount of load, environment and query execution context as the Production server has. So, to diagnose the performance problem, you need a way to simulate the Production server's query execution context in the Test server somehow. You can do this by correlating the SQL Profiler trace at the Test server with the Performance counter log that is taken at the Production server. Correlating these two tool's output can help you identifying the exact root cause of the performance problem.
    For example, you might find that each time the query takes 10 seconds to execute in the Production server, the CPU utilization reaches up to 100%. So, instead of trying to tune the SQL, you should investigate the reason why the CPU utilization rises up to 100% to optimize the query performance.
    Here are the steps to correlate the SQL Profiler trace with the Performance counter log:
    1. Create a Performance Counter log by incorporating the following common performance counters. Specify Manual option for starting and stopping the counter log.
      --Network Interface\Output Queue length
      --Processor\%Processor Time
      --SQL Server:Buffer Manager\Buffer Cache Hit Ratio
      --SQL Server:Buffer Manager\Page Life Expectancy
      --SQL Server:SQL Statistics\Batch Requests/Sec
      --SQL Server:SQL Statistics\SQL Compilations
      --SQL Server:SQL Statistics\SQL Re-compilations/Sec

      Create the performance counter log, but don't start it.
    2. Using the SQL Profiler create a trace using the TSQL Duration template. Add Start Time and End Time column to the trace and Start the Profiler trace and the Performance counter log created in the previous step at the same time.
    3. When enough tracing has been done, stop both SQL Profiler trace and the Performance counter log at the same time. Save the SQL Profiler trace as a .trc file in the file system.
    4. Close the SQL Profiler trace window and open the trace file again with the Profiler's .trc file. Then, you have to close the Profiler trace and open the trace file again, otherwise you will not get the Import Performance Data option enabled. Click on the File->Import Performance Data to correlate the Performance Counter log with the SQL Profiler trace. Nota, that if the Import Performance Data option is disabled, something is wrong and review your steps from the beginning. A file browser window will appear and select the Performance counter log file in the file system that is to be correlated.
    5. A window will appear to select the counters to correlate. Select all counters and press OK. You will be presented with a screen like the below that is the correlated output of SQL Profiler trace and Performance Counter log.

    6. Click on a particular TSQL in the Profiler trace output. You'll see that, a Red vertical bar will be set in the Performance counter log output to indicate the particular counter statistics when that particular query was being executed. Similarly, click on the Performance counter log output any where you see a certain performance counter's value is high or above the normal value. You'll see that the corresponding TSQL that was being executed on the database server will be highlighted in the SQL Profiler trace output.