-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathNetwork-Performance-Visualization.psm1
More file actions
394 lines (320 loc) · 14.2 KB
/
Network-Performance-Visualization.psm1
File metadata and controls
394 lines (320 loc) · 14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
$NTTTCPPivots = @("sessions", "bufferLen", "bufferCount", "none")
$LATTEPivots = @("protocol", "sendMethod", "none")
$CTSPivots = @("sessions", "none")
$CPSPivots = @("none")
$LagScopePivots = @("none")
$DEFAULT_SAVEPATH = ".\visualization.xlsx"
$DEFAULT_JSONPATH = ".\stats.xlsx"
#
# Define atrribute that dynamically tab completes pivot params.
# This is not a form of validation like [ValidateScript()]
#
[ScriptBlock] $Global:PACScript = {
param($CommandName, $ParameterName, $WordToComplete, $CommandAst, $FakeBoundParameters)
if ($FakeBoundParameters.ContainsKey("NTTTCP")) {
return $NTTTCPPivots | where {$_ -like "$WordToComplete*"}
}
elseif ($FakeBoundParameters.ContainsKey("LATTE")) {
return $LATTEPivots | where {$_ -like "$WordToComplete*"}
}
elseif ($FakeBoundParameters.ContainsKey("CTStraffic")) {
return $CTSPivots | where {$_ -like "$WordToComplete*"}
}
elseif ($FakeBoundParameters.ContainsKey("LagScope")) {
return $LagScopePivots | where {$_ -like "$WordsToComplete*"}
}
elseif ($FakeBoundParameters.ContainsKey("CPS")) {
return $CPSPivots | where {$_ -like "$WordsToComplete*"}
}
else {
return @("")
}
}
class PivotArgumentCompleter : ArgumentCompleter {
PivotArgumentCompleter() : base($Global:PACScript) {
}
}
function processing_end {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)] [String] $Output,
[Parameter()] $Starttime
)
# Collect statistics
# $timestamp = $start | Get-Date -f yyyy.MM.dd_hh.mm.ss
# Display version and file save location
$endtime = (Get-Date)
$delta = $endtime - $Starttime
Clear-Host
Write-Host "$(get-date): xcvEnd"
Write-Host "---------------`nTime: $($delta.Minutes) Min $($delta.Seconds) Sec"
Write-Host "Report: $OutPut"
Write-Host " "
}
<#
.SYNOPSIS
Visualizes network performance data via excel tables and charts
.Description
This cmdlet parses raw data files produced from various network performance monitoring tools, processes them, and produces
visualizations of the data. This tool is capable of visualizing data from the following tools:
NTTTCP
LATTE
CTStraffic
CPS
Lagscope
This tool can aggregate data over several iterations of test runs, and can be used to visualize comparisons
between a baseline and test set of data.
.PARAMETER NTTTCP
Flag that sets New-Visualization command to run in NTTTCP mode
.PARAMETER LATTE
Flag that sets New-Visualization command to run in LATTE mode
.PARAMETER CTStraffic
Flag that sets New-Visualization command to run in CTStraffic mode
.PARAMETER BaselineDir
Path to directory containing network performance data files to be consumed as baseline data.
.PARAMETER TestDir
Path to directory containing network performance data files to be consumed as test data. Providing
this parameter runs the tool in comparison mode.
.PARAMETER InnerPivot
Name of the property to use as a pivot variable. Valid values for this parameter are:
NTTTCP: sessions, bufferLen, bufferCount, none
LATTE: protocol, sendMethod, none
CTSTraffic: sessions, none
LagScope: protocol, none
CPS: none
The default for all cases is none.
The inner pivot varies in value within each worksheet; the different pivot values are used as table column labels.
.PARAMETER OuterPivot
Name of the property to use as a pivot variable. This parameter has the same valid values as InnerPivot.
The outer pivot varies in value across different worksheets and remains constant within each worksheet.
.PARAMETER SavePath
Full path to excel output file (with extension) where the report should be generated. ex: C:\TempDirName\Filename.xlsx
.PARAMETER SubsampleRate
Only relevant when run running tool in LATTE context. Sets the subsampling rate used to create the raw
data chart displaying the latency distribution over time.
.LINK
https://github.com/microsoft/Network-Performance-Visualization
#>
function New-NetworkVisualization {
[CmdletBinding()]
[Alias("New-NetVis")]
param (
[Parameter(Mandatory=$true, ParameterSetName="NTTTCP")]
[Switch] $NTTTCP,
[Parameter(Mandatory=$true, ParameterSetName="LATTE")]
[Switch] $LATTE,
[Parameter(Mandatory=$true, ParameterSetName="CTStraffic")]
[Switch] $CTStraffic,
[Parameter(Mandatory=$true, ParameterSetName="CPS")]
[Switch] $CPS,
[Parameter(Mandatory=$true, ParameterSetName="LagScope")]
[Switch] $LagScope,
[Parameter(Mandatory=$false, ParameterSetName="LagScope")]
[Parameter(Mandatory=$false, ParameterSetName="LATTE")]
[Int] $NumHistogramBuckets = 50,
[Parameter(Mandatory=$false)]
[String] $BaselineDir = "",
[Parameter(Mandatory=$false)]
[String] $BaselineDatasetName = "",
[Parameter(Mandatory=$false)]
[String] $TestDir = "",
[Parameter(Mandatory=$false)]
[String] $TestDatasetName = "",
[Parameter(Mandatory=$false)]
[String] $JsonInputPath = "",
[Parameter(Mandatory=$false)]
[PivotArgumentCompleter()]
[String] $InnerPivot = "none",
[Parameter(Mandatory=$false)]
[PivotArgumentCompleter()]
[String] $OuterPivot = "none",
[Parameter(Mandatory=$false)]
[ValidatePattern('[.]*\.xl[txms]+')]
[String] $SavePath=$DEFAULT_SAVEPATH,
[Parameter(Mandatory=$false)]
[string] $JsonSavePath = "",
[Parameter(Mandatory=$false)]
[Int] $Warmup = 0,
[Parameter(Mandatory=$false)]
[Int] $Cooldown = 0,
[Parameter(Mandatory=$false, ParameterSetName = "LATTE")]
[Parameter(Mandatory=$false, ParameterSetName = "CPS")]
[Parameter(Mandatory=$false, ParameterSetName = "LagScope")]
[Int] $SubsampleRate = -1,
[Parameter(Mandatory=$false)]
[Switch] $NoExcel
)
$ErrorActionPreference = "Stop"
Confirm-Parameters -BaselineDir $BaselineDir -TestDir $TestDir -JsonInputPath $JsonInputPath -NoExcel $NoExcel -JsonSavePath $JsonSavePath
if ($NoExcel -and ($JsonSavePath -eq "")) {
$JsonSavePath = $DEFAULT_JSONPATH
}
if ($JsonInputPath -ne "") {
$JsonSavePath = ""
}
$starttime = (Get-Date)
Clear-Host
# Normalize SavePath
$file = Split-Path $SavePath -Leaf
$dir = Convert-Path $(Split-Path $SavePath -Parent)
$fullPath = Join-Path $dir $file
# Normalize JsonSavePath
if ($JsonSavePath) {
$JsonFile = Split-Path $JsonSavePath -Leaf
$jsonDir = Convert-Path $(Split-Path $JsonSavePath -Parent)
$jsonFullPath = Join-Path $jsonDir $JsonFile
}
$tool = $PSCmdlet.ParameterSetName
Confirm-Pivots -Tool $tool -InnerPivot $InnerPivot -OuterPivot $OuterPivot
# Temporarily replace "none" with empty string to ensure compat.
$InnerPivot = if ($InnerPivot -eq "none") {""} else {$InnerPivot}
$OuterPivot = if ($OuterPivot -eq "none") {""} else {$OuterPivot}
if (-not $NoExcel) {
Add-ExcelTypes
}
if ($JsonInputPath) {
$jsonInputObj = Get-Content -Path $JsonInputPath | ConvertFrom-Json
$processedData = Parse-RestructedData -DataObj $jsonInputObj
} else {
# Parse Data
$baselineRaw = Get-RawData -Tool $tool -DirName $BaselineDir -InnerPivot $InnerPivot -OuterPivot $OuterPivot -Warmup $Warmup -Cooldown $Cooldown
$testRaw = $null
if ($TestDir) {
$testRaw = Get-RawData -Tool $tool -DirName $TestDir -Mode "Test" -InnerPivot $InnerPivot -OuterPivot $OuterPivot -Warmup $Warmup -Cooldown $Cooldown
}
$processedData = Process-Data -BaselineRawData $baselineRaw -TestRawData $testRaw -InnerPivot $InnerPivot -OuterPivot $OuterPivot -NumHistogramBuckets $NumHistogramBuckets
$processedData.meta.datasetNames = @{}
$processedData.meta.datasetNames["baseline"] = "baseline"
$processedData.meta.datasetNames["test"] = "test"
$processedData.meta.usedCustomNames = @{
"baseline" = $false
"test" = $false
}
if ($BaselineDatasetName) {
$processedData.meta.datasetNames["baseline"] = $BaselineDatasetName
$processedData.meta.usedCustomNames["baseline"] = $true
}
if ($TestDatasetName) {
$processedData.meta.datasetNames["test"] = $TestDatasetName
$processedData.meta.usedCustomNames["test"] = $true
}
}
if ($JsonSavePath) {
$output = Restructure-Data -DataObj $processedData
($output | ConvertTo-Json -Depth 100) | Out-File -FilePath $jsonFullPath
}
if ($NoExcel) {
$endtime = (Get-Date)
$delta = $endtime - $starttime
Write-Host "Time: $($delta.Minutes) Min $($delta.Seconds) Sec"
Write-Host "Json File: $jsonFullPath `n`n"
return
}
$tables = @()
foreach ($oPivotKey in $processedData.data.Keys) {
$tables += Format-Stats -DataObj $processedData -OPivotKey $oPivotKey -Tool $tool
if ($tool -in @("NTTTCP", "CTStraffic")) {
#$tables += Format-RawData -DataObj $processedData -OPivotKey $oPivotKey -Tool $tool
$tables += Format-Quartiles -DataObj $processedData -OPivotKey $oPivotKey -Tool $tool -NoNewWorksheets
$tables += Format-MinMaxChart -DataObj $processedData -OPivotKey $oPivotKey -Tool $tool -NoNewWorksheets
} elseif ($tool -in @("LATTE", "LagScope")) {
#$tables += Format-Distribution -DataObj $processedData -OPivotKey $oPivotKey -Tool $tool -Prop "latency" -SubSampleRate $SubsampleRate
$tables += Format-Histogram -DataObj $processedData -OPivotKey $oPivotKey -Tool $tool
#$tables += Format-Percentiles -DataObj $processedData -OPivotKey $oPivotKey -Tool $tool
} elseif ($tool -in @("CPS")) {
$tables += Format-Distribution -DataObj $processedData -OPivotKey $oPivotKey -Tool $tool -Prop "conn/s" -SubSampleRate $SubsampleRate
$tables += Format-Distribution -DataObj $processedData -OPivotKey $oPivotKey -Tool $tool -Prop "close/s" -SubSampleRate $SubsampleRate
$tables += Format-Histogram -DataObj $processedData -OPivotKey $oPivotKey -Tool $tool
}
$tables += Format-Percentiles -DataObj $processedData -OPivotKey $oPivotKey -Tool $tool
}
Create-ExcelFile -Tables $tables -SavePath $fullPath
for ($i = 0; $i -lt 4; $i++)
{
if ( (-not $processedData.meta.comparison) -and ($i -eq 1)) {
continue
}
Write-Progress -Activity "Processing" -Id $i -Completed
}
$endtime = (Get-Date)
$delta = $endtime - $starttime
# Powershell wont print more than two lines here
Write-Host "Time: $($delta.Minutes) Min $($delta.Seconds) Sec"
Write-Host "Report: $fullPath"
Write-Host "Json File: $jsonFullPath `n`n"
#processing_end -OutPut $fullPath -Starttime $starttime
if ($JsonSavePath) {
($output | ConvertTo-Json -Depth 100) | Out-File -FilePath $JsonSavePath
}
}
<#
.SYNOPSIS
This function loads Microsoft.Office.Interop.Excel.dll
from the GAC so exported enums can be accessed.
#>
function Add-ExcelTypes {
$gac = "$env:WINDIR\assembly\GAC_MSIL"
$version = (Get-ChildItem "$gac\office" | select -Last 1).Name # e.g. 15.0.0.0__71e9bce111e9429c
Add-Type -Path "$gac\office\$version\office.dll"
Add-Type -Path "$gac\Microsoft.Office.Interop.Excel\$version\Microsoft.Office.Interop.Excel.dll"
}
<#
.SYNOPSIS
Check if user-provided pivots are valid pivots given the
chosen context, and that the two pivots are not the same.
.PARAMETER Tool
Name of the tool that
.PARAMETER InnerPivot
Property to be used as the inner pivot variable
.PARAMETER OuterPivot
Property to be used as the outer pivot variable
#>
function Confirm-Pivots ($Tool, $InnerPivot, $OuterPivot) {
$validPivots = switch ($Tool) {
"NTTTCP" {
$NTTTCPPivots
break
}
"LATTE" {
$LATTEPivots
break
}
"CTSTraffic" {
$CTSPivots
break
}
"CPS" {
$CPSPivots
break
}
"LagScope" {
$LagScopePivots
break
}
}
foreach ($curPivot in @($InnerPivot, $OuterPivot)) {
if ($curPivot -notin $validPivots) {
Write-Error "Invalid pivot property '$curPivot'. Supported pivots for $Tool are: $($validPivots -join ", ")." -ErrorAction "Stop"
}
}
if (($InnerPivot -eq $OuterPivot) -and ($InnerPivot -ne "none")) {
Write-Error "Cannot use the same property for both inner and outer pivots." -ErrorAction "Stop"
}
}
function Confirm-Parameters($BaselineDir, $TestDir, $JsonInputPath, $NoExcel, $JsonSavePath) {
if ($TestDir -and ($BaselineDir -eq "")) {
Write-Error "TestDir should only be used if BaselineDir is non-null"
}
if (($BaselineDir -ne "") -and ($JsonInputPath -ne "")) {
Write-Error "Cannot injest raw data and pre-processed data at the same time. Use either BaselineDir+TestDir OR JsonInputPath"
}
if (($BaselineDir -eq "") -and ($JsonInputPath -eq "")) {
Write-Error "Must provide a non-null value to either BaselineDir or InputJsonPath parameters"
}
if (($JsonInputPath -ne "") -and ($JsonSavePath -ne "")) {
Write-Warning "Ignoring JsonSavePath parameter since JsonInputPath was used to provide input (input is already pre-processed json file)"
}
if (($JsonInputPath -ne "") -and ($NoExcel)) {
Write-Error "Cannot run in NoExcel mode when providing input through JsonInputPath"
}
}