-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
172 lines (149 loc) · 4.26 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
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
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.IO;
namespace MemCompare
{ // test change for automatic build test
// a second change to test.
class Program
{// yet yet another change!
class Allocation : IComparable
{ // yet another change
public string name;
public string pool;
public int size;
public int ptr;
int IComparable.CompareTo(object x)
{
Allocation a = (Allocation)x;
return a.size - size;
}
}
class Category
{
public Category()
{
name = "";
size = 0;
count = 0;
}
public string name;
public int size;
public int count;
}
class TextFileInfo
{
public string filename;
public List<Allocation> allocations = new List<Allocation>();
public Dictionary<String, Category> categories = new Dictionary<String, Category>();
public Dictionary<String, Category> blocks = new Dictionary<String, Category>();
}
TextFileInfo ReadTextFile(string filename)
{
Console.WriteLine("ReadTextFile " + filename);
char[] seperatorTab = {'\t'};
char[] seperatorColon = {':'};
TextFileInfo fi = new TextFileInfo();
fi.filename = filename;
string currentPool = "";
StreamReader re = File.OpenText(filename);
string input = null;
while ((input = re.ReadLine()) != null)
{
input.Trim();
if (input.StartsWith("MemPool:"))
currentPool = input.Substring(8);
else
{
string[] line = input.Split(seperatorTab);
int size = int.Parse(line[2]);
Allocation a = new Allocation();
a.name = line[0];
a.ptr = Int32.Parse(line[1], System.Globalization.NumberStyles.AllowHexSpecifier);
a.pool = currentPool;
a.size = size;
fi.allocations.Add(a);
// Handle blocks (identically named allocations)
Category c;
if (fi.blocks.ContainsKey(line[0]))
c = fi.blocks[line[0]];
else
c = new Category();
c.name = line[0];
c.size += size;
++c.count;
fi.blocks[line[0]] = c;
// Handle categories
string catString = "NO CATEGORY";
if (line[0].Contains(":"))
catString = line[0].Split(seperatorColon)[0];
if (fi.categories.ContainsKey(catString))
c = fi.categories[catString];
else
c = new Category();
c.name = catString;
c.size += size;
++c.count;
fi.categories[catString] = c;
}
}
re.Close();
return fi;
}
void Run(string[] args)
{
int lastAllocation = 0;
if (args.Length == 0)
{
Console.WriteLine("usage: memcompare input1.txt [input2.txt]");
return;
}
TextFileInfo f1 = null;
TextFileInfo f2 = null;
f1 = ReadTextFile(args[0]);
if (args.Length > 1)
f2 = ReadTextFile(args[1]);
Console.WriteLine("CATEGORIES SIZE COUNT");
string[] allKeys = new string[f1.categories.Keys.Count];
f1.categories.Keys.CopyTo(allKeys, 0);
Array.Sort(allKeys);
foreach (string cName in allKeys)
{
Category c = f1.categories[cName];
Console.WriteLine(String.Format("{0,-15} {1, 8} {2,5}", c.name, c.size, c.count));
}
Console.WriteLine("\n\nBLOCKS >20k SIZE COUNT");
allKeys = new string[f1.blocks.Keys.Count];
f1.blocks.Keys.CopyTo(allKeys, 0);
Array.Sort(allKeys);
foreach (string cName in allKeys)
{
Category c = f1.blocks[cName];
if (c.size > 20 * 1024)
Console.WriteLine(String.Format("{0,-30} {1, 8} {2,5}", c.name, c.size, c.count));
}
int totalAllocations = 0;
Console.WriteLine("\n\nALLOCATIONS >20k SIZE");
ArrayList topAllocations = new ArrayList();
foreach (Allocation a in f1.allocations)
{
if (a.size > 20 * 1024)
topAllocations.Add(a);
totalAllocations += a.size;
}
topAllocations.Sort();
foreach (Allocation a in topAllocations)
{
Console.WriteLine(String.Format("{0,-30} {1, 8}", a.name, a.size));
}
Console.WriteLine("\n\nTOTAL ALLOCATIONS : " + totalAllocations);
Console.WriteLine("\nFINAL ALLOCATION : " + lastAllocation);
}
static void Main(string[] args)
{
Program app = new Program();
app.Run(args);
}
}
}