コンテンツへスキップ

ストレステスト windows

・メモリ

# Memory Stress test
$maxMemoryUsed = 75 # percentage
while($true){
    $p = Get-WmiObject Win32_OperatingSystem | %{(($_.TotalVisibleMemorySize - $_.FreePhysicalMemory)/$_.TotalVisibleMemorySize) * 100}
    if($p -le $maxMemoryUsed){
        try{
            $a += "m" * 100MB
        } catch [Exception]{
            $b += "m" * 100MB
        }
    }
    write-host("memory used [{0}]" -f $p.toString())
    sleep 1
}

・CPU

while($true){ echo $i;$i++ }

複数powershellを起動(start-process powershell )し上のコマンドを実行する。

・ディスク 1Gバイトのダミーファイルを作成する。

fsutil file createnew testfile (1024*1024*1024)

・stressTest.ps1 作成中
# Memory Stress test
param(
    [parameter(mandatory=$false)][string]$type,
    [parameter(mandatory=$false)][int]$percent,
    [parameter(mandatory=$false)][string]$driveLetter,
    [parameter(mandatory=$false)][string]$dummyFileName = "dummyFile",
    [parameter(mandatory=$false)][switch]$help
)

function memoryTest($percent) {
    while($true){
        $p = Get-WmiObject Win32_OperatingSystem | ForEach-Object {(($_.TotalVisibleMemorySize - $_.FreePhysicalMemory)/$_.TotalVisibleMemorySize) * 100}
        if($p -le $percent){
            try{
                $a += "m" * 100MB
            } catch [Exception]{
                $b += "m" * 100MB
            }
        }
        write-host("memory used [{0}]" -f $p.toString())
        sleep 1
    }
}

function cpuTest($percent){
    while($true){
        $newestJobId = ""
        $p = (Get-WmiObject Win32_PerfFormattedData_PerfOS_Processor | where-object name -eq "_Total").PercentProcessorTime
        if($p -le $percent){
            Start-Job -ScriptBlock {
                write-host($i)
                $i++
            } | Out-Null
            $job = "Start-job"
            sleep 1
        } else {
            $id =(get-job).id
            $newestJobId=$id[-1]
            stop-job $newestJobId
            $job = "Stop-job"
            
        }
        write-host("cpu used [{0}]%, [{1}] {2}" -f $p, $job, $newestJobId)
    }
}

function diskCapacity($percent,$driveLetter){
    $dummyFilePath = join-path ($driveLetter + ":\") $dummyFileName
    fsutil file createnew $dummyFilePath (1024*1024*1024)
}

function usage(){
    write-host("usage:")
    write-host("stressTest.ps1")
    write-host("    -type memory -percent %")
    write-host("    -type cpu -percent %")
    write-host("    -type diskCapacity -percent % -driveLetter (c|d|e...)")
}

if(($type -eq "memory") -And ($percent)){
    memoryTest $percent
} elseif(($type -eq "cpu") -And ($percent)){
    cpuTest $percent
} elseif(($type -eq "diskCapacity") -And ($driveLetter -ne "") -And ($percent)){
    diskCapacity $percent $driveLetter
} elseif($help){
    usage
} else {
    usage
}