Soak sampler: add atomic nMatchLag freshness monitoring; add lag sampling script
This commit is contained in:
parent
253f4b3cf7
commit
d95973ab68
23
scripts/tc-ads-lag.ps1
Normal file
23
scripts/tc-ads-lag.ps1
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
param([int]$Samples = 20, [int]$IntervalMs = 500)
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
$adsDll = 'C:\Program Files (x86)\Beckhoff\TwinCAT\3.1\Components\Base\v170\TwinCAT.Ads.dll'
|
||||||
|
Add-Type -Path $adsDll
|
||||||
|
$c = New-Object TwinCAT.Ads.TcAdsClient
|
||||||
|
$c.Connect('169.254.176.217.1.1', 851)
|
||||||
|
function ReadSym($name, $type) {
|
||||||
|
$h = $c.CreateVariableHandle($name)
|
||||||
|
$v = $c.ReadAny($h, $type)
|
||||||
|
$c.DeleteVariableHandle($h)
|
||||||
|
return $v
|
||||||
|
}
|
||||||
|
$lags = New-Object System.Collections.Generic.List[int]
|
||||||
|
for ($k = 0; $k -lt $Samples; $k++) {
|
||||||
|
$lag = ReadSym 'GVL_Sync.nMatchLag' ([int])
|
||||||
|
$bs = ReadSym 'GVL_Sync.bSync' ([bool])
|
||||||
|
$lags.Add($lag)
|
||||||
|
Write-Host ("{0} lag={1,4} cyc bSync={2}" -f (Get-Date -Format 'HH:mm:ss'), $lag, $bs)
|
||||||
|
if ($k -lt $Samples - 1) { Start-Sleep -Milliseconds $IntervalMs }
|
||||||
|
}
|
||||||
|
$s = $lags | Sort-Object
|
||||||
|
Write-Host ("min={0} p50={1} max={2} mean={3:F2}" -f $s[0], $s[[int]($Samples/2)], $s[$Samples-1], (($lags | Measure-Object -Average).Average))
|
||||||
|
$c.Dispose()
|
||||||
32
scripts/tc-ads-soak.ps1
Normal file
32
scripts/tc-ads-soak.ps1
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
param([int]$Minutes = 190, [string]$LogFile = "$env:TEMP\soak.log")
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
$adsDll = 'C:\Program Files (x86)\Beckhoff\TwinCAT\3.1\Components\Base\v170\TwinCAT.Ads.dll'
|
||||||
|
Add-Type -Path $adsDll
|
||||||
|
$c = New-Object TwinCAT.Ads.TcAdsClient
|
||||||
|
$c.Connect('169.254.176.217.1.1', 851)
|
||||||
|
function ReadSym($name, $type) {
|
||||||
|
$h = $c.CreateVariableHandle($name)
|
||||||
|
$v = $c.ReadAny($h, $type)
|
||||||
|
$c.DeleteVariableHandle($h)
|
||||||
|
return $v
|
||||||
|
}
|
||||||
|
$prevMism = $null
|
||||||
|
$prevCyc = $null
|
||||||
|
for ($k = 0; $k -lt $Minutes; $k++) {
|
||||||
|
try {
|
||||||
|
$nc = ReadSym 'GVL_Sync.nCycles' ([uint64])
|
||||||
|
$bs = ReadSym 'GVL_Sync.bSync' ([bool])
|
||||||
|
$nm = ReadSym 'GVL_Sync.nMismatch' ([int])
|
||||||
|
$lag = ReadSym 'GVL_Sync.nMatchLag' ([int])
|
||||||
|
$dmism = if ($null -ne $prevMism) { $nm - $prevMism } else { 0 }
|
||||||
|
$rate = if ($null -ne $prevCyc) { ([int64]$nc - $prevCyc) / 60.0 } else { 0 }
|
||||||
|
$prevMism = $nm
|
||||||
|
$prevCyc = [int64]$nc
|
||||||
|
$line = "{0} k={1,3} nCycles={2,-9} rate={3,7:F1}/s bSync={4} lag={5,4} nMismatch={6} dMism={7}" -f (Get-Date -Format 'HH:mm:ss'), $k, $nc, $rate, $bs, $lag, $nm, $dmism
|
||||||
|
} catch {
|
||||||
|
$line = "{0} k={1,3} ADS ERROR: {2}" -f (Get-Date -Format 'HH:mm:ss'), $k, $_.Exception.Message
|
||||||
|
}
|
||||||
|
Add-Content -Path $LogFile -Value $line
|
||||||
|
Start-Sleep -Seconds 60
|
||||||
|
}
|
||||||
|
$c.Dispose()
|
||||||
Loading…
Reference in New Issue
Block a user