-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path内存统计.ps1
105 lines (66 loc) · 2.03 KB
/
内存统计.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
Add-Type @"
using System.Collections.Generic;
public class DataInfo
{
public DataInfo()
{}
public string Name { get; set; }
public string Company { get; set; }
public long VirtualMemorySize { get; set; }
public long PrivateMemorySize { get; set; }
public long WorkingSet { get; set; }
public long num { get; set; }
}
"@
$filters=("七星工作室","uChrome Studio","FlashPeak Inc.")
#$filters=("7chrome","chrome","slimjet")
Add-Type -AssemblyName System.Core
$dict = new-object "System.Collections.Generic.Dictionary[string,DataInfo]"
$time= [System.DateTime]::Now
$allProcess=Get-Process
foreach($proc in $allProcess )
{
if($dict.ContainsKey($proc.Name))
{
$pinfo= $dict[$proc.Name]
$pinfo.num +=1
$pinfo.PrivateMemorySize +=$proc.PrivateMemorySize64
$pinfo.VirtualMemorySize += $proc.VirtualMemorySize64
$pinfo.WorkingSet += $proc.WorkingSet64
}
else
{
$pinfo= New-Object "DataInfo"
$pinfo.Name = $proc.Name
$pinfo.Company = $proc.Company
$pinfo.num =1
$pinfo.PrivateMemorySize =$proc.PrivateMemorySize64
$pinfo.VirtualMemorySize =$proc.VirtualMemorySize64
$pinfo.WorkingSet =$proc.WorkingSet64
$dict.Add($proc.Name,$pinfo)
}
}
$titlestr="Time"
$str = "$time"
foreach($f in $filters )
{
foreach($key in $dict.Keys )
{
$pinfo= $dict[$key]
if($pinfo.Company -eq $f)
{
$titlestr += ",$($pinfo.Name) PrivateMemorySize(GB),$($pinfo.Name) WorkingSet(GB)"
$str += ",$(($pinfo.PrivateMemorySize)/1GB),$(($pinfo.WorkingSet)/1GB)"
}
}
}
$file= Join-Path -ChildPath "ProcessMemory.csv" -Path ([System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::DesktopDirectory))
if(Test-Path -Path $file)
{
}
else
{
#添加标题
Out-File -FilePath $file -InputObject $titlestr -Encoding utf8 -Append
}
Out-File -FilePath $file -InputObject $str -Encoding utf8 -Append