Windows Tool: Perfmon / Logman

Perfmon is a gui tool on windows to start/stop a performance collection and then view the results. It is natively available on windows. Logman is a command line tool that also can start/stop performance collection and create counters. Both tools invoke the same underlying code but logman is useful for using inside scripts.

Perfmon: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/perfmon

Logman: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/logman

Basic steps for a performance gathering activity:
1. Create a “User defined” “Data Collector Set”. Name it and add some “counters”

2. Start the collecter set and let it run for a period, say 10 minutes.

3. Stop the set

4. parse, transform the results and view them

The steps for perfmon are pretty intuitive. Here is an excellent blog for the above steps: https://knowledge.ni.com/KnowledgeArticleDetails?id=kA03q000000YHEICA4&l=en-US

The same steps in logmon are listed below:

From dos administrator command prompt:
1. Select a name, for e.g my_perf
2. query if that user defined data collector set exists:
logman query my_perf > NUL 2>&1

3. If it exists, stop and delete it

if errorlevel 0 (
logman stop my_perf > NUL 2>&1
logman delete my_perf > NUL 2>&1
)

4. Create a set of performance counters you are interested in a text file, for e.g my_counters.txt with some counters as in the example below:
“\Processor(_Total)\% Privileged Time”
“\Processor(_Total)\% Processor Time”
“\Processor(_Total)\% User Time”
“\PhysicalDisk(_Total)\Disk Transfers/sec”
“\PhysicalDisk(_Total)\Disk Writes/sec”
“\PhysicalDisk(_Total)\Disk Reads/sec”
“\PhysicalDisk(_Total)\Disk Bytes/sec”

5. Select a stat interval, for example 10 seconds

set STAT_INTERVAL=10

6. Create a directory to store the results:
set OUTPUT_DIR=c:\my_perf
cmd /c mkdir %OUTPUT_DIR% > NUL 2>&1

7. Optionally set codepage to utf-8. This is useful if you want to use your scripts to parse the results and show a specific value. Scripts work better if the results are in utf-8 codepage.

chcp 65001  > NUL 2>&1

8. Create data collector set:
logman create counter my_perf -f bin -si %STAT_INTERVAL% -o %OUTPUT_DIR%\\my_perf -cf  my_counters.txt > NUL 2>&1

9. Start the collector set: This creates a file with a .blg extension.
logman start my_perf > NUL 2>&1

10. Wait 10 minutes or so and stop the collector

logman stop my_perf > NUL 2>&1

11. View the results. You can use perfmon for this step or convert the blg file to a csv file and then write a script to split the one csv file into multiple csv files by process, counter etc. Then create an html graph or table using each individual csv file

for %%f in (%OUTPUT_DIR%\*.blg) do (
relog %%f /f csv /o %OUTPUT_DIR%\%%~nf.csv > NUL 2>&1)

Leave a Reply

Your email address will not be published. Required fields are marked *