Cette révision appartient à :
ili101 2016-07-24 21:26:03 +03:00
Parent 17706536cb
révision 5a650f3082
8 fichiers modifiés avec 173 ajouts et 61 suppressions

Voir le fichier

Voir le fichier

BIN
Bin/iperf3.exe Fichier normal

Fichier binaire non affiché.

Fichier binaire non affiché.

Avant

Largeur:  |  Hauteur:  |  Taille: 71 Kio

Après

Largeur:  |  Hauteur:  |  Taille: 63 Kio

234
PPerf.ps1
Voir le fichier

@ -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">
<Grid>
<GroupBox x:Name="CsvFileGroupBox" Header="CSV File" Height="65" Margin="10,10,10,0" VerticalAlignment="Top">
<Grid Margin="0">
@ -291,25 +386,31 @@ $UiPowerShell = [PowerShell]::Create().AddScript(
</Grid>
</GroupBox>
<RichTextBox x:Name="IperfJobOutputTextBox" Margin="10,0,10,10" VerticalScrollBarVisibility="Auto" Height="52" VerticalAlignment="Bottom"/>
<GroupBox x:Name="iPerfGroupBox" Header="iPerf" Height="131" Margin="10,80,10,0" VerticalAlignment="Top">
<GroupBox x:Name="iPerfGroupBox" Header="iPerf" Height="145" Margin="10,80,10,0" VerticalAlignment="Top">
<Grid Margin="0">
<GroupBox x:Name="ModeGroupBox" Header="Server or Client" Height="88" Margin="0,0,10,0" VerticalAlignment="Top" HorizontalAlignment="Right" Width="121">
<GroupBox x:Name="ModeGroupBox" Header="Server or Client" Height="82" Margin="0,0,10,0" VerticalAlignment="Top" HorizontalAlignment="Right" Width="100">
<Grid Margin="0">
<RadioButton x:Name="ClientRadio" Content="Client" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" IsChecked="True"/>
<RadioButton x:Name="ServerRadio" Content="Server" HorizontalAlignment="Left" Margin="10,40,0,0" VerticalAlignment="Top"/>
</Grid>
</GroupBox>
<Label x:Name="CommandLabel" Content="_Command" HorizontalAlignment="Left" Height="25" Margin="10,0,0,8" VerticalAlignment="Bottom" Width="68" Target="{Binding ElementName=CommandTextBox, Mode=OneWay}"/>
<TextBox x:Name="CommandTextBox" HorizontalAlignment="Left" Margin="83,0,0,10" TextWrapping="Wrap" Width="300" Height="23" VerticalAlignment="Bottom"/>
<TextBox x:Name="CommandTextBox" Margin="83,0,10,10" TextWrapping="Wrap" Height="23" VerticalAlignment="Bottom"/>
<Button x:Name="StartIperfButton" Content="Start Iperf" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="75"/>
<Button x:Name="StopIperfButton" Content="Stop Iperf" HorizontalAlignment="Left" Margin="10,35,0,0" VerticalAlignment="Top" Width="75"/>
<Label x:Name="IpLabel" Content="IP" HorizontalAlignment="Left" Margin="100,10,0,0" Width="20" Target="{Binding ElementName=IpTextBox, Mode=OneWay}" Height="23" VerticalAlignment="Top"/>
<TextBox x:Name="IpTextBox" HorizontalAlignment="Left" Margin="145,10,0,0" TextWrapping="Wrap" Width="97" Height="23" VerticalAlignment="Top"/>
<Label x:Name="TimeLabel" Content="Time" HorizontalAlignment="Left" Margin="100,38,0,0" Width="40" Target="{Binding ElementName=TimeTextBox, Mode=OneWay}" Height="23" VerticalAlignment="Top"/>
<TextBox x:Name="TimeTextBox" HorizontalAlignment="Left" Margin="145,38,0,0" TextWrapping="Wrap" Width="97" Height="23" VerticalAlignment="Top"/>
<GroupBox x:Name="VersionGroupBox" Header="iPerf Version" Height="82" Margin="0,0,115,0" VerticalAlignment="Top" HorizontalAlignment="Right" Width="100">
<Grid Margin="0">
<RadioButton x:Name="Version2Radio" Content="Version 2" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" IsChecked="True"/>
<RadioButton x:Name="Version3Radio" Content="Version 3" HorizontalAlignment="Left" Margin="10,40,0,0" VerticalAlignment="Top"/>
</Grid>
</GroupBox>
</Grid>
</GroupBox>
<GroupBox x:Name="AnalyzerGroupBox" Header="Analyzer" Height="85" Margin="10,216,10,0" VerticalAlignment="Top">
<GroupBox x:Name="AnalyzerGroupBox" Header="Analyzer" Height="85" Margin="10,230,10,0" VerticalAlignment="Top">
<Grid Margin="0">
<Button x:Name="StartAnalyzerButton" Content="Start Analyzer" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="85"/>
<Button x:Name="StopAnalyzerButton" Content="Stop Analyzer" HorizontalAlignment="Left" Margin="10,35,0,0" VerticalAlignment="Top" Width="85"/>
@ -320,7 +421,7 @@ $UiPowerShell = [PowerShell]::Create().AddScript(
<CheckBox x:Name="MaxScaleCheckBox" Content="Auto" HorizontalAlignment="Left" Margin="234,16,0,0" VerticalAlignment="Top" IsChecked="True"/>
</Grid>
</GroupBox>
<WindowsFormsHost x:Name="FormWfa" Margin="10,306,10,67"/>
<WindowsFormsHost x:Name="FormWfa" Margin="10,320,10,67"/>
</Grid>
</Window>
"@
@ -411,12 +512,23 @@ $UiPowerShell = [PowerShell]::Create().AddScript(
Set-IperfCommand
})
$SyncHash.Version2Radio.add_Checked({
Set-IperfCommand
})
$SyncHash.Version3Radio.add_Checked({
Set-IperfCommand
})
# Csv SaveFileDialog
$CsvSaveFileDialog = New-Object -TypeName System.Windows.Forms.SaveFileDialog
$CsvSaveFileDialog.Filter = 'Comma Separated|*.csv|All files|*.*'
$CsvSaveFileDialog.FileName = ([Environment]::GetFolderPath('Desktop') + '\iperf.csv')
$SyncHash.CsvFilePathTextBox.Text = $CsvSaveFileDialog.FileName
$SyncHash.CsvFilePathTextBox.add_TextChanged({
Set-IperfCommand
})
$SyncHash.CsvFilePathButton.Add_Click({
$CsvSaveFileDialog.ShowDialog()
@ -446,7 +558,7 @@ $UiPowerShell = [PowerShell]::Create().AddScript(
Set-IperfCommand
Write-Status -Text 'PPerf Version 3.0' -Colore 'Blue'
Write-Status -Text 'PPerf Version 3.1' -Colore 'Blue'
# Shows the form
$null = $SyncHash.Form.ShowDialog()