diff --git a/iperf2/checkdelay.exe b/Bin/checkdelay.exe similarity index 100% rename from iperf2/checkdelay.exe rename to Bin/checkdelay.exe diff --git a/iperf2/cyggcc_s-seh-1.dll b/Bin/cyggcc_s-seh-1.dll similarity index 100% rename from iperf2/cyggcc_s-seh-1.dll rename to Bin/cyggcc_s-seh-1.dll diff --git a/iperf2/cygstdc++-6.dll b/Bin/cygstdc++-6.dll similarity index 100% rename from iperf2/cygstdc++-6.dll rename to Bin/cygstdc++-6.dll diff --git a/iperf2/cygwin1.dll b/Bin/cygwin1.dll similarity index 100% rename from iperf2/cygwin1.dll rename to Bin/cygwin1.dll diff --git a/iperf2/iperf.exe b/Bin/iperf.exe similarity index 100% rename from iperf2/iperf.exe rename to Bin/iperf.exe diff --git a/Bin/iperf3.exe b/Bin/iperf3.exe new file mode 100644 index 0000000..2efa342 Binary files /dev/null and b/Bin/iperf3.exe differ diff --git a/Examples/Example1.png b/Examples/Example1.png index 8358efa..f203328 100644 Binary files a/Examples/Example1.png and b/Examples/Example1.png differ diff --git a/PPerf.ps1 b/PPerf.ps1 index 36760bc..fc3a681 100644 --- a/PPerf.ps1 +++ b/PPerf.ps1 @@ -11,7 +11,7 @@ if ((!$Work) -and ($host.name -eq 'ConsoleHost')) # Set Variables $SyncHash = [hashtable]::Synchronized(@{}) $SyncHash.Host = $host -$SyncHash.IperfFolder = $PSScriptRoot + '\iperf2' +$SyncHash.IperfFolder = $PSScriptRoot + '\Bin' # UI Runspace $UiRunspace = [runspacefactory]::CreateRunspace() @@ -74,6 +74,8 @@ $UiPowerShell = [PowerShell]::Create().AddScript( $SyncHash.IperfJobMonitorRunspace.SessionStateProxy.SetVariable('syncHash',$SyncHash) $SyncHash.IperfJobMonitorRunspace.SessionStateProxy.SetVariable('CsvFilePath',$SyncHash.CsvFilePathTextBox.Text) $SyncHash.IperfJobMonitorRunspace.SessionStateProxy.SetVariable('Command',$SyncHash.CommandTextBox.Text) + $SyncHash.IperfJobMonitorRunspace.SessionStateProxy.SetVariable('IperfVersion',$IperfVersion) + $SyncHash.IperfJobMonitorRunspace.SessionStateProxy.SetVariable('IperfExe',$IperfExe) $SyncHash.IperfJobMonitorPowerShell = [PowerShell]::Create().AddScript( { trap {$SyncHash.host.ui.WriteErrorLine("$_`nError was in Line {0}`n{1}" -f ($_.InvocationInfo.ScriptLineNumber, $_.InvocationInfo.Line))} @@ -81,14 +83,28 @@ $UiPowerShell = [PowerShell]::Create().AddScript( $SyncHash.host.ui.WriteVerboseLine('Start-Iperf Running') Set-Location -Path $SyncHash.IperfFolder - try { - 'Time,localIp,localPort,RemoteIp,RemotePort,Id,Interval,Transfer,Bandwidth' | Out-File -FilePath $CsvFilePath - Write-Status -Text ((Invoke-Expression -Command '.\iperf.exe -v') 2>&1) -Colore 'Blue' - $ErrorActionPreferenceOrg = $ErrorActionPreference; $ErrorActionPreference = 'stop' - Invoke-Expression -Command $Command | Out-File -FilePath $CsvFilePath -Append + $ErrorActionPreferenceOrg = $ErrorActionPreference + if ($IperfVersion -eq 2) + { + 'Time,localIp,localPort,RemoteIp,RemotePort,Id,Interval,Transfer,Bandwidth' | Out-File -FilePath $CsvFilePath + Write-Status -Text ((Invoke-Expression -Command "$IperfExe -v") 2>&1) -Colore 'Blue' + $ErrorActionPreference = 'stop' + Invoke-Expression -Command $Command | Out-File -FilePath $CsvFilePath -Append + } + else + { + Set-Content -Path $CsvFilePath -Value $null + #Write-Status -Text ((Invoke-Expression -Command "$IperfExe -v") -join ' ') -Colore 'Blue' + Invoke-Expression -Command $Command + + if ($ErrorOut = Get-Content -Tail 5 -Path $CsvFilePath | Select-String -Pattern 'iperf3: error') + { + Write-Error -Message $ErrorOut -ErrorAction Stop + } + } } catch { @@ -143,6 +159,7 @@ $UiPowerShell = [PowerShell]::Create().AddScript( $SyncHash.AnalyzerRunspace.SessionStateProxy.SetVariable('syncHash',$SyncHash) $SyncHash.AnalyzerRunspace.SessionStateProxy.SetVariable('CsvFilePath',$SyncHash.CsvFilePathTextBox.Text) $SyncHash.AnalyzerRunspace.SessionStateProxy.SetVariable('LastX',$SyncHash.LastXTextBox.Text) + $SyncHash.AnalyzerRunspace.SessionStateProxy.SetVariable('IperfVersion',$IperfVersion) $SyncHash.AnalyzerPowerShell = [powershell]::Create() $SyncHash.AnalyzerPowerShell.Runspace = $SyncHash.AnalyzerRunspace $null = $SyncHash.AnalyzerPowerShell.AddScript($AnalyzerScript) @@ -158,85 +175,149 @@ $UiPowerShell = [PowerShell]::Create().AddScript( trap [System.Management.Automation.PipelineStoppedException] {$SyncHash.host.ui.WriteVerboseLine($_)} $First = $true + $Header = $null + $AnalyzerDataLength = 0 + + $ChartDataAction0 = [Action]{ + $SyncHash.Chart.Series['Bandwidth (Mbits/sec)'].Points.Clear() + $SyncHash.Chart.Series['Transfer (MBytes)'].Points.Clear() + $SyncHash.host.ui.WriteVerboseLine('Clear Data: ' + ($SyncHash.Chart.Series['Transfer (MBytes)'].Points.Count | Out-String)) + } + $SyncHash.Chart.Invoke($ChartDataAction0) + Get-Content -Path $CsvFilePath -ReadCount 0 -Wait | ForEach-Object { - if ($First) + trap {$SyncHash.host.ui.WriteErrorLine("$_`nError was in Line {0}`n{1}" -f ($_.InvocationInfo.ScriptLineNumber, $_.InvocationInfo.Line))} + #$SyncHash.host.ui.WriteVerboseLine('Loop Data: ' + ($_ | Out-String)) ### + $AnalyzerData = New-Object -TypeName System.Collections.Generic.List[System.Object] + + if ($IperfVersion -eq 2) { - $Header = $_[0] -split ',' - if (!$Header -contains 'Bandwidth') + foreach ($Line in $_) { - Write-Status -Text 'CSV Error' -Colore 'Red' - Stop-Analyzer + if ($Line -like '*Bandwidth*') + { + $Header = $Line -split ',' + } + else + { + if ($First -and !$Header) + { + Write-Status -Text 'CSV Error' -Colore 'Red' + Stop-Analyzer + } + else + { + $First = $false + } + + $CsvLine = $Line | ConvertFrom-Csv -Header $Header + $CsvLine.Bandwidth = $CsvLine.Bandwidth /1Mb + $CsvLine.Transfer = $CsvLine.Transfer /1Mb + if (!($CsvLine.Interval).StartsWith('0.0-') -or ($CsvLine.Interval -eq '0.0-1.0')) + { + $AnalyzerData.add($CsvLine) + } + else + { + $SyncHash.host.ui.WriteVerboseLine('Remove Total Line: ' + $CsvLine.Time) + } + } } - - $Csv = ConvertFrom-Csv $_ - $AnalyzerDataLength = 0 } else { - $Csv = ConvertFrom-Csv $_ -Header $Header - } - - $AnalyzerData = New-Object -TypeName System.Collections.Generic.List[System.Object] - foreach ($Line in $Csv) - { - $Line.Bandwidth = $Line.Bandwidth /1Mb - $Line.Transfer = $Line.Transfer /1Mb - if (!($Line.Interval).StartsWith('0.0-') -or ($Line.Interval -eq '0.0-1.0')) + $Csv = $_ | Where-Object {$_ -match '\[...\]'} + #$Csv = $a | Select-String -Pattern '\[...\]' + foreach ($Line in $Csv) { - $AnalyzerData.add($Line) - } - else - { - $SyncHash.host.ui.WriteVerboseLine('Remove Total Line: ' + $Line.Time) + $Line = $Line -replace '[][]' + if ($Line -like ' ID *') + { + $Header = $Line -split '\s+' | Where-Object {$_} + $HeaderIndex = @() + foreach ($Head in $Header) + { + $HeaderIndex += $Line.IndexOf($Head) + } + } + elseif ($Header -and $Line -notlike '*connected to*' -and $Line -notlike '*sender*' -and $Line -notlike '*receiver*') + { + $i=0 + $CsvLine = New-Object System.Object + foreach ($Head in $Header) + { + if ($i -lt $HeaderIndex.Length-1) + { + $Cell = $Line.Substring($HeaderIndex[$i],$HeaderIndex[$i + 1] - $HeaderIndex[$i]) + } + else + { + $Cell = $Line.Substring($HeaderIndex[$i]) + } + + if ($Head -eq 'Transfer') + { + $TransferData = $Cell.Trim() -split '\s+' + if ($TransferData[1] -eq 'KBytes') + { + $Cell = $TransferData[0] /1kb + } + elseif ($TransferData[1] -eq 'GBytes') + { + $Cell = $TransferData[0] *1kb + } + } + + $i++ + Add-Member -InputObject $CsvLine -NotePropertyName $Head -NotePropertyValue ("$Cell".Trim() -split '\s+')[0] + } + $AnalyzerData.add($CsvLine) + } } } - + if ($AnalyzerData.Count -gt $LastX -and $LastX -gt 0) { $SyncHash.host.ui.WriteVerboseLine('Trim Data 1') $AnalyzerData = $AnalyzerData.GetRange($AnalyzerData.Count - $LastX, $LastX) } - $SyncHash.host.ui.WriteVerboseLine('New Points: ' + ($AnalyzerData.Count | Out-String)) - $AnalyzerDataLength += $AnalyzerData.Count + $SyncHash.host.ui.WriteVerboseLine('New Points: ' + $AnalyzerData.Count) - if ($First) + if ($AnalyzerData.Count -gt 0) { - if ($AnalyzerData) + if ($AnalyzerDataLength -eq 0 -and $AnalyzerData.Count -gt 1) { $ChartDataAction1 = [Action]{ $SyncHash.Chart.Series['Bandwidth (Mbits/sec)'].Points.DataBindXY($AnalyzerData.Interval, $AnalyzerData.Bandwidth) $SyncHash.Chart.Series['Transfer (MBytes)'].Points.DataBindXY($AnalyzerData.Interval, $AnalyzerData.Transfer) $SyncHash.host.ui.WriteVerboseLine('Show Data: ' + ($SyncHash.Chart.Series['Transfer (MBytes)'].Points.Count | Out-String)) } + $SyncHash.Chart.Invoke($ChartDataAction1) } else { - $ChartDataAction1 = [Action]{ - $SyncHash.Chart.Series['Bandwidth (Mbits/sec)'].Points.Clear() - $SyncHash.Chart.Series['Transfer (MBytes)'].Points.Clear() - $SyncHash.host.ui.WriteVerboseLine('Clear Data: ' + ($SyncHash.Chart.Series['Transfer (MBytes)'].Points.Count | Out-String)) + $ChartDataAction2 = [Action]{ + while ($AnalyzerDataLength + $AnalyzerData.Count -gt $LastX -and $LastX -gt 0) + { + $SyncHash.Chart.Series['Bandwidth (Mbits/sec)'].Points.RemoveAt(0) + $SyncHash.Chart.Series['Transfer (MBytes)'].Points.RemoveAt(0) + $Global:AnalyzerDataLength -- + } + foreach ($Point in $AnalyzerData) + { + $SyncHash.Chart.Series['Bandwidth (Mbits/sec)'].Points.AddXY($Point.Interval, $Point.Bandwidth) + $SyncHash.Chart.Series['Transfer (MBytes)'].Points.AddXY($Point.Interval, $Point.Transfer) + $SyncHash.host.ui.WriteVerboseLine('Add Data Point: ' + ($SyncHash.Chart.Series['Transfer (MBytes)'].Points.Count | Out-String)) + } } + $SyncHash.Chart.Invoke($ChartDataAction2) } - $First = $false + $AnalyzerDataLength += $AnalyzerData.Count } else { - $ChartDataAction1 = [Action]{ - while ($AnalyzerDataLength -gt $LastX -and $LastX -gt 0) - { - $SyncHash.Chart.Series['Bandwidth (Mbits/sec)'].Points.RemoveAt(0) - $SyncHash.Chart.Series['Transfer (MBytes)'].Points.RemoveAt(0) - $Global:AnalyzerDataLength -- - } - foreach ($Point in $AnalyzerData) - { - $SyncHash.Chart.Series['Bandwidth (Mbits/sec)'].Points.AddXY($Point.Interval, $Point.Bandwidth) - $SyncHash.Chart.Series['Transfer (MBytes)'].Points.AddXY($Point.Interval, $Point.Transfer) - $SyncHash.host.ui.WriteVerboseLine('Add Data Point: ' + ($SyncHash.Chart.Series['Transfer (MBytes)'].Points.Count | Out-String)) - } - } + $SyncHash.host.ui.WriteVerboseLine('Point Skipped') } - $SyncHash.Chart.Invoke($ChartDataAction1) $SyncHash.host.ui.WriteVerboseLine('Analyzer Loop End: ' + ($AnalyzerDataLength | Out-String)) } } @@ -268,7 +349,21 @@ $UiPowerShell = [PowerShell]::Create().AddScript( $IperfTime = $null $SyncHash.TimeTextBox.IsEnabled = $false } - $SyncHash.CommandTextBox.Text = '.\iperf.exe' + $IperfMode + $IperfTime + ' -y c -i 1' + + if ($SyncHash.Version2Radio.IsChecked) + { + $IperfVersionParams = ' -y c' + $Global:IperfVersion = 2 + $Global:IperfExe = '.\iperf.exe' + } + else + { + $IperfVersionParams = ' -f m --logfile ' + $SyncHash.CsvFilePathTextBox.Text + $Global:IperfVersion = 3 + $Global:IperfExe = '.\iperf3.exe' + } + + $SyncHash.CommandTextBox.Text = $IperfExe + $IperfMode + $IperfTime + $IperfVersionParams + ' -i 1' } # UI @@ -282,7 +377,7 @@ $UiPowerShell = [PowerShell]::Create().AddScript( xmlns:wf="clrnamespace:System.Windows.Forms;assembly=System.Windows.Forms" xmlns:wfi="clr-namespace:System.Windows.Forms;assembly=WindowsFormsIntegration" mc:Ignorable="d" - Title="PPerf" Height="667.298" Width="641.413"> + Title="PPerf" Height="680" Width="670"> @@ -291,25 +386,31 @@ $UiPowerShell = [PowerShell]::Create().AddScript( - + - +