perf report -t output as object

by on ‎2014-02-10 08:12 AM

just ran across "perf report -t" and wanted to be able to get the same format from powershell.

these are quick (and probably inefficient) functions that format the cpu_disk_util_matrix counter as a table like the output from "perf report -t"

cluster version returns a hash.

. .\get-naperfreport.ps1

Get-NaPerfReport -Controller <filer> | out-gridview

. .\get-ncperfreport.ps1

$results = Get-NcPerfReport -Controller <cluster>

$results.item("<node>") | out-gridview

7-mode:

Function Get-NaPerfReport{

    [CmdletBinding()]

    Param(

        [Parameter(Mandatory=$False,

                    ValueFromPipeline=$true)]

        [String]$Controller

    )

    Begin{

        if($Controller){

            connect-nacontroller $Controller > $null

        }

        $results = @()

    }

    Process{

        $raw = (get-naperfdata perf -Counters  cpu_disk_util_matrix).counters.Value

        $matrix = $raw.split(',')

        foreach($i in 0..9){

            $cpulabel = "$($i*10) to $(($i+1)*10)% CPU"

            $total = ($matrix[($i*10)..((($i+1)*10)-1)] | Measure-Object -sum).sum -as [int64]

            $Prop=[ordered]@{

                'CPU bucket' = $cpulabel

                '10disk' = $matrix[(($i)*10)] -as [int64]

                '20disk' = $matrix[(($i)*10)+1] -as [int64]

                '30disk' = $matrix[(($i)*10)+2] -as [int64]

                '40disk' = $matrix[(($i)*10)+3] -as [int64]

                '50disk' = $matrix[(($i)*10)+4] -as [int64]

                '60disk' = $matrix[(($i)*10)+5] -as [int64]

                '70disk' = $matrix[(($i)*10)+6] -as [int64]

                '80disk' = $matrix[(($i)*10)+7] -as [int64]

                '90disk' = $matrix[(($i)*10)+8] -as [int64]

                '100disk' = $matrix[(($i)*10)+9] -as [int64]

                'total' = $total

            }

            $Obj=New-Object -TypeName PSObject -Property $Prop

            $Results += $Obj

        }

        $prop=[ordered]@{}

        $prop.'CPU bucket'="total"

        $prop.'10disk'=($results.'10disk' | measure-object -sum).sum -as [int64]

        $prop.'20disk'=($results.'20disk' | measure-object -sum).sum -as [int64]

        $prop.'30disk'=($results.'30disk' | measure-object -sum).sum -as [int64]

        $prop.'40disk'=($results.'40disk' | measure-object -sum).sum -as [int64]

        $prop.'50disk'=($results.'50disk' | measure-object -sum).sum -as [int64]

        $prop.'60disk'=($results.'60disk' | measure-object -sum).sum -as [int64]

        $prop.'70disk'=($results.'70disk' | measure-object -sum).sum -as [int64]

        $prop.'80disk'=($results.'80disk' | measure-object -sum).sum -as [int64]

        $prop.'90disk'=($results.'90disk' | measure-object -sum).sum -as [int64]

        $prop.'100disk'=($results.'100disk' | measure-object -sum).sum -as [int64]

        $prop.'total'=($results.'total' | measure-object -sum).sum -as [int64]

        $Obj=New-Object -TypeName PSObject -Property $Prop

        $results += $Obj

    }

    End{

        Write-Output $results

    }

}

cDOT:

Function Get-NcPerfReport{

    [CmdletBinding()]

    Param(

        [Parameter(Mandatory=$False,

                    ValueFromPipeline=$true)]

        [String]$Controller

    )

    Begin{

        if($Controller){

            connect-nccontroller $Controller > $null

        }

        $results = @()

        $hash = @{}

    }

    Process{

        $raw = get-ncperfdata perf -Instance perf -Counter cpu_disk_util_matrix

       

        foreach($r in $raw){

            $results = @()

            $node = $r.uuid.split(':')[0]

            $matrix = $r.Counters.value.split(',')

            foreach($i in 0..9){

                $cpulabel = "$($i*10) to $(($i+1)*10)% CPU"

                $total = ($matrix[($i*10)..((($i+1)*10)-1)] | Measure-Object -sum).sum -as [int64]

                $Prop=[ordered]@{

                    'CPU bucket' = $cpulabel

                    '10disk' = $matrix[(($i)*10)] -as [int64]

                    '20disk' = $matrix[(($i)*10)+1] -as [int64]

                    '30disk' = $matrix[(($i)*10)+2] -as [int64]

                    '40disk' = $matrix[(($i)*10)+3] -as [int64]

                    '50disk' = $matrix[(($i)*10)+4] -as [int64]

                    '60disk' = $matrix[(($i)*10)+5] -as [int64]

                    '70disk' = $matrix[(($i)*10)+6] -as [int64]

                    '80disk' = $matrix[(($i)*10)+7] -as [int64]

                    '90disk' = $matrix[(($i)*10)+8] -as [int64]

                    '100disk' = $matrix[(($i)*10)+9] -as [int64]

                    'total' = $total

                }

                $Obj=New-Object -TypeName PSObject -Property $Prop

                $Results += $Obj

            }

            $prop=[ordered]@{}

            $prop.'CPU bucket'="total"

            $prop.'10disk'=($results.'10disk' | measure-object -sum).sum -as [int64]

            $prop.'20disk'=($results.'20disk' | measure-object -sum).sum -as [int64]

            $prop.'30disk'=($results.'30disk' | measure-object -sum).sum -as [int64]

            $prop.'40disk'=($results.'40disk' | measure-object -sum).sum -as [int64]

            $prop.'50disk'=($results.'50disk' | measure-object -sum).sum -as [int64]

            $prop.'60disk'=($results.'60disk' | measure-object -sum).sum -as [int64]

            $prop.'70disk'=($results.'70disk' | measure-object -sum).sum -as [int64]

            $prop.'80disk'=($results.'80disk' | measure-object -sum).sum -as [int64]

            $prop.'90disk'=($results.'90disk' | measure-object -sum).sum -as [int64]

            $prop.'100disk'=($results.'100disk' | measure-object -sum).sum -as [int64]

            $prop.'total'=($results.'total' | measure-object -sum).sum -as [int64]

            $Obj=New-Object -TypeName PSObject -Property $Prop

            $results += $Obj

            $hash.add($node,$results)

        }

    }

    End{

        Write-Output $hash

    }

}

Warning!

This NetApp Community is public and open website that is indexed by search engines such as Google. Participation in the NetApp Community is voluntary. All content posted on the NetApp Community is publicly viewable and available. This includes the rich text editor which is not encrypted for https.

In accordance to our Code of Conduct and Community Terms of Use DO NOT post or attach the following:

  • Software files (compressed or uncompressed)
  • Files that require an End User License Agreement (EULA)
  • Confidential information
  • Personal data you do not want publicly available
  • Another’s personally identifiable information
  • Copyrighted materials without the permission of the copyright owner

Files and content that do not abide by the Community Terms of Use or Code of Conduct will be removed. Continued non-compliance may result in NetApp Community account restrictions or termination.