Analyzing a Perf-Counter-Log

Steps to collect PERFMON:

run the following command:
Logman.exe create counter Perf-Counter-Log3 -o “C:\perflogs\Perftest3.blg” -f bincirc -v mmddhhmm -max 250 -c “\LogicalDisk()*” “\Memory*” “\Network Interface()*” “\Paging File()*” “\PhysicalDisk()*” “\Processor()*” “\Process()*” “\Redirector*” “\Server*” “\System*” “\Thread*” -si 00:00:03
Then go to Performance Monitor
Data Collector Set>User Defined > Right Click on Perf-Counter-Log and start

Or type command in CMD
To start – Logman.exe start Perf-Counter-Log1Perf-Counter-Log1
To Stop – Logman.exe stop Perf-Counter-Log

PowerShell Script — Top 10 by Maximum % CPU (Excluding _Total and Idle)

Use this version to find which processes had the highest peak CPU usage in your PerfMon CSV:

# Path to your CSV log

$csvPath = “C:\PerfLogs\output.csv”

# Import the CSV

$csv = Import-Csv $csvPath

# Detect all process CPU % Processor Time columns

$cpuCols = ($csv |

    Get-Member -MemberType NoteProperty |

    Where-Object Name -Match ‘\\Process\(.+\)\\% Processor Time’).Name

$stats = @()

foreach ($col in $cpuCols) {

    # Extract the process name

    $procName = ($col -replace ‘.*Process\((.+)\).*’,’$1′)

    # Exclude aggregated/system counters

    if ($procName -in @(“_Total”, “Idle”)) {

        continue

    }

    # Safely collect numeric values only

    $vals = @()

    foreach ($row in $csv) {

        $value = $row.$col

        if ([double]::TryParse($value, [ref]$null)) {

            $vals += [double]$value

        }

    }

    if ($vals.Count -gt 0) {

        $stats += [PSCustomObject]@{

            Process = $procName

            Minimum = ($vals | Measure-Object -Minimum).Minimum

            Maximum = ($vals | Measure-Object -Maximum).Maximum

            Average = ($vals | Measure-Object -Average).Average

        }

    }

}

# Sort by Maximum CPU usage and show Top 10

$stats |

    Sort-Object -Property Maximum -Descending |

    Select-Object -First 10 |

    Format-Table `

        @{Label=”Process”;Expression={$_.Process}},

        @{Label=”Min”;Expression={“{0:N2}%” -f $_.Minimum}},

        @{Label=”Max”;Expression={“{0:N2}%” -f $_.Maximum}},

        @{Label=”Avg”;Expression={“{0:N2}%” -f $_.Average}} `

    -AutoSize

This entry was posted in Powershell, Windows and tagged . Bookmark the permalink.

Leave a comment