-
Notifications
You must be signed in to change notification settings - Fork 4k
/
cleanup_perf.ps1
118 lines (105 loc) · 2.48 KB
/
cleanup_perf.ps1
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
param (
[string]$CPCLocation = "C:/CPC",
[switch]$ShouldArchive = $false
)
set-variable -name LastExitCode 0
set-strictmode -version 2.0
$ErrorActionPreference="Stop"
# If the test runner crashes and doesn't shut down CPC, CPC could fill
# the entire disk with ETL traces.
function KillAndIgnore {
try {
taskkill /F /IM $args[0] 2>&1 | Out-Null
}
catch {}
}
KillAndIgnore Cpc.exe
KillAndIgnore msbuild.exe
KillAndIgnore csc.exe
KillAndIgnore vbc.exe
KillAndIgnore VBCSCompiler.exe
try {
& $CPCLocation/cpc.exe /Stop /SkipClean 2>&1 | Out-Null
}
catch {}
if (Test-Path ToArchive) {
Remove-Item -Recurse -Force ToArchive
}
if ($ShouldArchive) {
# Move all etl files to the a folder for archiving
echo "creating ToArchive directory"
mkdir ToArchive
if (Test-Path $CPCLocation) {
try
{
echo "moving $CPCLocation/DataBackup* to ToArchive"
mv $CPCLocation/DataBackup* ToArchive
echo "moving $CPCLocation/consumptionTempResults.xml to ToArchive"
mv $CPCLocation/consumptionTempResults.xml ToArchive
}
catch
{
echo "Copying CPC data failed"
$ExitCode = 1
}
}
if (Test-Path C:\PerfLogs)
{
try
{
mkdir ToArchive/PerfLogs
xcopy /S C:\PerfLogs ToArchive\PerfLogs
}
catch
{
echo "Copying PerfLogs failed"
$ExitCode = 1
}
}
ls ToArchive
}
# Clean CPC and related directories out of the machine
$ExitCode = 0
if (Test-Path $CPCLocation) {
try {
echo "removing $CPCLocation ..."
Remove-Item -Recurse -Force $CPCLocation
echo "done."
}
catch {
echo "Removing CPC failed, restarting the machine. THIS SHOULD NOT HAPPEN. Please email [email protected]"
shutdown /r /t 5
$ExitCode = 1
}
}
if (Test-Path C:/CPCTraces) {
try {
echo "removing C:/CPCTraces"
Remove-Item -Recurse -Force C:/CPCTraces
echo "done."
}
catch {
$ExitCode = 1
}
}
if (Test-Path C:/PerfLogs) {
try {
echo "removing C:/PerfLogs"
Remove-Item -Recurse -Force C:/PerfLogs
echo "done."
}
catch {
$ExitCode = 1
}
}
if (Test-Path C:/PerfTemp) {
try {
echo "removing C:/PerfTemp"
Remove-Item -Recurse -Force C:/PerfTemp
echo "done."
}
catch {
$ExitCode = 1
}
}
exit $ExitCode