forked from microsoft/StorScore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStorScore.cmd
409 lines (327 loc) · 9.4 KB
/
StorScore.cmd
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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
@rem = ' vim: set filetype=perl: ';
@rem = ' --*-Perl-*-- ';
@rem = q(
@echo off
setlocal
set PATH=%~dp0\perl\bin;%~dp0\bin;%PATH%
where perl.exe >NUL 2>&1
if %ERRORLEVEL% NEQ 0 (
echo %~n0 requires Perl. Please install one of these:
echo ActiveState Perl: http://www.activestate.com/activeperl
echo Strawberry Perl: http://strawberryperl.com/
exit /B 1
)
for /F "tokens=4" %%I IN ('powercfg -getactivescheme') DO set ORIG_SCHEME=%%I
powercfg -setactive SCHEME_MIN
start /B /WAIT /HIGH perl "%~f0" %*
set PERL_ERROR_LEVEL=%ERRORLEVEL%
powercfg -setactive %ORIG_SCHEME%
exit /B %PERL_ERROR_LEVEL%
);
# StorScore
#
# Copyright (c) Microsoft Corporation
#
# All rights reserved.
#
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
use strict;
use warnings;
use English;
use Win32;
use Time::Seconds;
use POSIX 'strftime';
use Carp;
#$SIG{ __DIE__ } = sub { Carp::confess( @_ ) };
use FindBin;
use lib "$FindBin::Bin";
use lib "$FindBin::Bin\\lib";
use Util;
use CommandLine;
use Target;
use PreconditionRunner;
use SmartCtlRunner;
use Recipe;
use DiskSpdRunner;
use SqlioRunner;
use LogmanRunner;
use Power;
use WmicRunner;
use SharedVariables;
check_system_compatibility();
mkdir( $results_dir ) unless( -d $results_dir );
# See SharedVariables.pm
our $cmd_line = CommandLine->new( argv => \@ARGV );
our $target = Target->new( cmd_line => $cmd_line );
my $recipe_file = $cmd_line->recipe;
unless( defined $recipe_file )
{
if( $target->is_ssd )
{
$recipe_file = 'recipes\\turkey_test.rcp';
}
else
{
$recipe_file = 'recipes\\corners.rcp';
}
}
my $output_dir = "$results_dir\\";
$output_dir .= $cmd_line->test_id_prefix
if defined $cmd_line->test_id_prefix;
if( defined $cmd_line->test_id )
{
$output_dir .= $cmd_line->test_id;
}
else
{
# If no test_id was given, construct a sensible default
my $prefix =
make_legal_filename(
get_drive_model( $target->physical_drive ) );
$output_dir .=
"$prefix-" . strftime( "%Y-%m-%d_%H-%M-%S", localtime );
}
print "Targeting " . uc( $target->type ) . ": " . $target->model . "\n";
my $recipe = Recipe->new(
file_name => $recipe_file,
output_dir => $output_dir,
target => $target,
cmd_line => $cmd_line
);
my $num_steps = $recipe->get_num_steps();
my $num_tests = $recipe->get_num_test_steps();
die "Empty recipe. Nothing to do.\n" unless $num_steps > 0;
print "Loaded " . $recipe_file;
print " ($num_tests tests, $num_steps steps)\n\n";
$recipe->warn_expected_run_time();
detect_scep_and_warn();
if( $target->is_ssd )
{
if( $target->supports_smart and
$target->is_sata and
!$target->is_6Gbps_sata )
{
my $msg;
$msg .= "\tWarning!\n";
$msg .= "\tSSD target is not 6Gb/s SATA III.\n";
$msg .= "\tThroughput will be limited.\n\n";
warn $msg;
}
}
if( $target->do_purge )
{
my $msg;
$msg .= "\tWarning!\n";
$msg .= "\tThis will destroy \\\\.\\PHYSICALDRIVE";
$msg .= $target->physical_drive . "\n\n";
warn $msg;
}
else
{
if( $target->is_existing_file_or_volume )
{
my $msg;
$msg .= "\tWarning!\n";
$msg .= "\tTarget is an existing file/volume.\n";
$msg .= "\tCan not purge without destroying target.\n";
$msg .= "\tPurge steps will be skipped.\n\n";
warn $msg;
}
if( $target->is_ssd )
{
my $msg;
$msg .= "\tWarning!\n";
$msg .= "\tCan not eliminate SSD history effect without purge.\n";
$msg .= "\tFor best results target a physical drive and purge.\n\n";
warn $msg;
}
if( defined $target->file_name and
( $target->do_initialize or $recipe->contains_writes ) )
{
unless( -w $target->file_name or $pretend )
{
die "Target is not writable\n"
}
my $msg;
$msg .= "\tWarning!\n";
$msg .= "\tThis will destroy ";
$msg .= $target->file_name . "\n\n";
warn $msg;
}
}
exit 0 unless should_proceed();
die "Results subdirectory $output_dir already exists!\n"
if -e $output_dir;
my $overall_start = time();
mkdir( $output_dir );
if( $cmd_line->collect_smart )
{
if( $target->supports_smart )
{
print "Collecting SMART counters via SmartCtl.\n";
}
else
{
warn "SmartCtl missing or broken. SMART capture disabled.\n";
}
}
my $power;
if( $cmd_line->collect_power )
{
$power = Power->new( output_dir => $output_dir );
if( $power->is_functional() )
{
print "Collecting system power via IPMI.\n";
}
else
{
warn "Ipmiutil missing or broken. Power measurement disabled.\n";
undef $power;
}
}
if( defined $cmd_line->purge and not $cmd_line->purge )
{
print "Will skip purging as requested.\n";
}
if( defined $cmd_line->initialize and not $cmd_line->initialize )
{
print "Will skip initialization as requested.\n";
}
if( defined $cmd_line->precondition and not $cmd_line->precondition )
{
print "Will skip preconditioning as requested.\n";
}
my $wmic_runner = WmicRunner->new(
target => $target,
output_dir => $output_dir
);
$wmic_runner->collect( 'wmic.txt' );
my $smartctl_runner = undef;
if( $cmd_line->collect_smart and $target->supports_smart )
{
$smartctl_runner = SmartCtlRunner->new(
physical_drive => $target->physical_drive,
);
$smartctl_runner->collect(
file_name => "smart.txt",
output_dir => $output_dir,
do_identify => 1
)
}
my $logman_runner = LogmanRunner->new(
target => $target,
cmd_line => $cmd_line,
output_dir => $output_dir
)
if $cmd_line->collect_logman;
my %iogen_args = (
target => $target,
cmd_line => $cmd_line,
output_dir => $output_dir
);
my $iogen;
$iogen = SqlioRunner->new( %iogen_args )
if $cmd_line->io_generator =~ 'sqlio';
$iogen = DiskSpdRunner->new( %iogen_args )
if $cmd_line->io_generator =~ 'diskspd';
print "Testing...\n";
$recipe->run(
io_generator => $iogen,
smartctl_runner => $smartctl_runner,
logman_runner => $logman_runner,
power => $power
);
if( $cmd_line->auto_upload and defined $cmd_line->results_share )
{
print "Attempting upload to results share...";
my $upload_start = time();
my $success = upload_results();
my $dstr = seconds_to_human( time() - $upload_start );
print "success!" if $success;
print "failed!" if not $success;
print " (took $dstr)\n";
}
my $dstr = seconds_to_human( time() - $overall_start );
print( "Done (took $dstr)\n" );
exit( 0 );
sub upload_results
{
my $src = $output_dir;
my $share = $cmd_line->results_share;
my $dst = $output_dir =~ s/.*results/$share\\results/r;
my $user = $cmd_line->results_share_user;
my $pass = $cmd_line->results_share_pass;
my $nu_cmd = "net use $share";
$nu_cmd .= " $pass" if defined $pass;
$nu_cmd .= " /USER:$user" if defined $user;
my $failed = execute_task( $nu_cmd, quiet => 1 );
return 0 if $failed;
my $success =
execute_task(
"ROBOCOPY /E /R:10 /W:5 $src $dst",
quiet => 1
);
return 0 unless $success;
$failed = execute_task( "net use $share /DELETE /Y", quiet => 1 );
return 0 if $failed;
return 1;
}
sub check_system_compatibility
{
unless( is_windows_x64() )
{
warn "\n$script_name requires a 64-bit version of Windows\n\n";
exit( -1 );
}
# False positive on Server 2012 R2?
unless( is_vc_runtime_present( '12.0', 'x86' ) )
{
warn <<"MSG";
$script_name requires the x86 Visual C++ Redistributable Packages
for Visual Studio 2013. Please install vcredist_x86.exe from:
http://www.microsoft.com/en-us/download/details.aspx?id=40784
MSG
exit( -1 );
}
# False positive on Server 2012 R2?
unless( is_vc_runtime_present( '12.0', 'x64' ) )
{
warn <<"MSG";
$script_name requires the x64 Visual C++ Redistributable Packages
for Visual Studio 2013. Please install vcredist_x64.exe from:
http://www.microsoft.com/en-us/download/details.aspx?id=40784
MSG
exit( -1 );
}
unless( Win32::IsAdminUser() )
{
warn "\n$script_name: must run as Administrator\n\n";
exit( -1 );
}
}
BEGIN
{
# unbuffer STDERR and STDOUT
select STDERR;
$OUTPUT_AUTOFLUSH = 1;
select STDOUT;
$OUTPUT_AUTOFLUSH = 1;
}