-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
120 lines (101 loc) · 3.86 KB
/
Program.cs
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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Runner
{
class Program
{
static void Main(string[] args)
{
// Define variables to track the peak
// memory usage of the process.
memoryTester("StructsVsObjects.exe", "Class");
memoryTester("StructsVsObjects.exe", "Struct");
memoryTester("StructsVsObjects.exe", "ClassLarge");
memoryTester("StructsVsObjects.exe", "StructLarge");
memoryTester("dotnet", "netcoreapp2.0\\StructsVsObjectsCore.dll Class");
memoryTester("dotnet", "netcoreapp2.0\\StructsVsObjectsCore.dll Struct");
memoryTester("dotnet", "netcoreapp2.0\\StructsVsObjectsCore.dll ClassLarge");
memoryTester("dotnet", "netcoreapp2.0\\StructsVsObjectsCore.dll StructLarge");
Console.ReadKey();
}
private static void memoryTester(string FileName, string Arguments, bool logInProgress=false)
{
var sw = Stopwatch.StartNew();
long peakPagedMem = 0, peakWorkingSet = 0, peakVirtualMem = 0;
Process myProcess = null;
try
{
// Start the process.
myProcess = Process.Start(FileName, Arguments);
// Display the process statistics until
// the user closes the program.
do
{
if (!myProcess.HasExited)
{
// Refresh the current process property values.
myProcess.Refresh();
if (logInProgress)
{
Console.WriteLine();
// Display current process statistics.
Console.WriteLine("{0} -", myProcess.ToString());
Console.WriteLine("-------------------------------------");
Console.WriteLine(" physical memory usage: {0}",
myProcess.WorkingSet64);
Console.WriteLine(" base priority: {0}",
myProcess.BasePriority);
Console.WriteLine(" priority class: {0}",
myProcess.PriorityClass);
Console.WriteLine(" user processor time: {0}",
myProcess.UserProcessorTime);
Console.WriteLine(" privileged processor time: {0}",
myProcess.PrivilegedProcessorTime);
Console.WriteLine(" total processor time: {0}",
myProcess.TotalProcessorTime);
Console.WriteLine(" PagedSystemMemorySize64: {0}",
myProcess.PagedSystemMemorySize64);
Console.WriteLine(" PagedMemorySize64: {0}",
myProcess.PagedMemorySize64);
}
// Update the values for the overall peak memory statistics.
peakPagedMem = myProcess.PeakPagedMemorySize64;
peakVirtualMem = myProcess.PeakVirtualMemorySize64;
peakWorkingSet = myProcess.PeakWorkingSet64;
if (logInProgress)
{
if (myProcess.Responding)
{
Console.WriteLine("Status = Running");
}
else
{
Console.WriteLine("Status = Not Responding");
}}
}
}
while (!myProcess.WaitForExit(1000));
Console.WriteLine();
Console.WriteLine($"Process FileName:{FileName} Arguments:{Arguments} exit code: {myProcess.ExitCode} TIME:{sw.Elapsed}" );
// Display peak memory statistics for the process.
Console.WriteLine("Peak physical memory usage of the process: {0}",
peakWorkingSet);
Console.WriteLine("Peak paged memory usage of the process: {0}",
peakPagedMem);
Console.WriteLine("Peak virtual memory usage of the process: {0}",
peakVirtualMem);
}
finally
{
if (myProcess != null)
{
myProcess.Close();
}
}
}
}
}