forked from microsoft/CSS_SQL_Networking_Tools
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGenerateDataSet.cs
More file actions
440 lines (430 loc) · 20.5 KB
/
GenerateDataSet.cs
File metadata and controls
440 lines (430 loc) · 20.5 KB
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
using System;
using System.Data;
using System.IO;
namespace SQLBench
{
//
// Written by the Microsoft CSS SQL Networking Team
//
// Creates a DataSet object into which goes the performance data to be displayed on the grid or written to file
//
class GenerateDataSet
{
public DataSet dsStats;
public bool mathtest;
public bool filetest;
public bool dbtest;
public GenerateDataSet()
{
//Create Dataset to store Statistical data
dsStats = new DataSet();
DataTable table1 = new DataTable("Memory");
table1.Columns.Add("Description", typeof(string));
table1.Columns.Add("IMath", typeof(double)).Caption = "Integer Math";
table1.Columns.Add("FMath", typeof(double)).Caption = "Floating Point Math";
table1.Columns.Add("DMath", typeof(double)).Caption = "Decimal Math";
table1.Columns.Add("SCat", typeof(double)).Caption = "String Concatenation";
table1.Columns.Add("TreeCreate", typeof(double)).Caption = "Object Tree Creation";
table1.Columns.Add("TraverseInOrder", typeof(double)).Caption = "Object Tree Traversal In Order";
table1.Columns.Add("TraversePreOrder", typeof(double)).Caption = "Object Tree Traversal Pre Order";
table1.Columns.Add("TraversePostOrder", typeof(double)).Caption = "Object Tree Traversal Post Order";
dsStats.Tables.Add(table1);
DataTable table2 = new DataTable("File");
table2.Columns.Add("Description", typeof(string));
table2.Columns.Add("Path", typeof(string)).Caption = "File Path";
table2.Columns.Add("Create", typeof(double)).Caption = "File Creation Time (ms)";
table2.Columns.Add("SRead", typeof(double)).Caption = "Sequential Read";
table2.Columns.Add("SWrite", typeof(double)).Caption = "Sequential Write";
table2.Columns.Add("RRead", typeof(double)).Caption = "Random Read";
table2.Columns.Add("RWrite", typeof(double)).Caption = "Random Write";
table2.Columns.Add("Total", typeof(double)).Caption = "Total Time (ms)";
dsStats.Tables.Add(table2);
DataTable table3 = new DataTable("Database");
table3.Columns.Add("Description", typeof(string));
table3.Columns.Add("Conn", typeof(string)).Caption = "Connection String";
table3.Columns.Add("Open", typeof(double)).Caption = "Connection Open";
table3.Columns.Add("Close", typeof(double)).Caption = "Connection Close";
table3.Columns.Add("Insert", typeof(double)).Caption = "Insert Row";
table3.Columns.Add("ReadRows", typeof(double)).Caption = "Read Rows";
table3.Columns.Add("ReadBLOB", typeof(double)).Caption = "Read BLOB";
table3.Columns.Add("WriteBLOB", typeof(double)).Caption = "Write BLOB";
table3.Columns.Add("Total", typeof(double)).Caption = "Total Time (ms)";
dsStats.Tables.Add(table3);
}
public void GenerateCSVFile(int numberofrows)
{
for (int a =0; a < dsStats.Tables.Count; a++)
{
switch (a)
{
case 0:
if (mathtest == true)
{
//Add Statics Rows
AddStatisticRows(a);
//Calculate Averages
calculate_MinMaxAve(numberofrows, a);
}
break;
case 1:
if (filetest == true)
{
//Add Statics Rows
AddStatisticRows(a);
//Calculate Averages
calculate_MinMaxAve(numberofrows, a);
}
break;
case 2:
if (dbtest == true)
{
//Add Statics Rows
AddStatisticRows(a);
//Calculate Averages
calculate_MinMaxAve(numberofrows, a);
}
break;
default:
break;
}
}
}
public void DataOutput(string outFile)
{
//Generate column Headers.
string MathoutFile;
string FilesoutFile;
string DBsoutFile;
if (outFile != "")
{
MathoutFile = outFile + "\\MathTests.csv";
FilesoutFile = outFile + "\\File.csv";
DBsoutFile = outFile + "\\Database.csv";
}
else
{
MathoutFile = Environment.CurrentDirectory + "\\MathTests.csv";
FilesoutFile = Environment.CurrentDirectory + "\\File.csv";
DBsoutFile = Environment.CurrentDirectory + "\\Database.csv";
}
//Math Tests
Stream myStream = new FileStream(MathoutFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
MathHeader(myStream);
MathData(MathoutFile);
//Files tests
Stream myFileStream = new FileStream(FilesoutFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
FileHeader(myFileStream);
FileData(FilesoutFile);
//DBTests
Stream myDBStream = new FileStream(DBsoutFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
DBHeader(myDBStream);
dbData(DBsoutFile);
}
private void AddStatisticRows(int a)
{
//Add the number of rows for statitics
//Set the Decription of column for each new row
//Add new rows to table
DataRow newrowmin = dsStats.Tables[a].NewRow();
DataRow newrowmax = dsStats.Tables[a].NewRow();
DataRow newrowavg = dsStats.Tables[a].NewRow();
DataRow newrowrange = dsStats.Tables[a].NewRow();
DataRow newrowstdiv = dsStats.Tables[a].NewRow();
DataRow newrowScore = dsStats.Tables[a].NewRow();
newrowmin["Description"] = "Min";
newrowmax["Description"] = "Max";
newrowavg["Description"] = "Average";
newrowstdiv["Description"] = "Std. Deviation";
newrowrange["Description"] = "Range";
newrowScore["Description"] = "Score (100 Base)";
dsStats.Tables[a].Rows.Add(newrowmin);
dsStats.Tables[a].Rows.Add(newrowmax);
dsStats.Tables[a].Rows.Add(newrowrange);
dsStats.Tables[a].Rows.Add(newrowavg);
dsStats.Tables[a].Rows.Add(newrowstdiv);
dsStats.Tables[a].Rows.Add(newrowScore);
}
private void calculate_MinMaxAve(int NumberofRows, int t)
{
//Caclulates the staticts
double Max = 0.0;
double Min = 1000000000000.0;
double Average = 0.0;
int Starting = 1;
//check if there is at least 1 row in the table
if (dsStats.Tables[t].Rows.Count > 0)
{
//if Tables are Files and Database start at column 2 else start at Column 1
if (t == 1 || t == 2)
Starting = 2;
else
Starting = 1;
for (int a = Starting; a < dsStats.Tables[t].Columns.Count; a++)
{
//Reset each column
Average = 0.0; //set the average to 0.0 before each column being calculated
if (dsStats.Tables[t].Rows[0][a] != DBNull.Value)
{
Max = Convert.ToDouble(dsStats.Tables[t].Rows[0][a]); //set the initial Minimum to the first row in the column
Min = Convert.ToDouble(dsStats.Tables[t].Rows[0][a]); //set the inital Maximum to the first row in the column
}
for (int b = 0; b < NumberofRows; b++)
{
if (dsStats.Tables[t].Rows[b][a] != DBNull.Value)
{
//Add to the total average calulation
Average += Convert.ToDouble(dsStats.Tables[t].Rows[b][a]);
if (Min > Convert.ToDouble(dsStats.Tables[t].Rows[b][a])) //Determin if the new value is smaller than the current value
Min = Convert.ToDouble(dsStats.Tables[t].Rows[b][a]); //If value is smaller set Min to the new value
if (Max < Convert.ToDouble(dsStats.Tables[t].Rows[b][a])) //Determin if the new value is larget than current value
Max = Convert.ToDouble(dsStats.Tables[t].Rows[b][a]); //If the value is larger set Max with the new value
}
}
dsStats.Tables[t].Rows[NumberofRows][a] = Min; //Add value to dataset table
dsStats.Tables[t].Rows[NumberofRows + 1][a] = Max; //Add value to dataset table
dsStats.Tables[t].Rows[NumberofRows + 2][a] = Max - Min; //Calculate the differance between Min and Max then add it to the dataset table
dsStats.Tables[t].Rows[NumberofRows + 3][a] = Average / NumberofRows; //calculate the mean then add the value to the dataset table
dsStats.Tables[t].Rows[NumberofRows + 4][a] = CalculateVeriances(t, a, NumberofRows, Average / NumberofRows); //Calculate the standard diviation then add it to the dataset table
dsStats.Tables[t].Rows[NumberofRows + 5][a] = IntmathBase(t, a, Average / NumberofRows, NumberofRows); //Calculate the weighted value against the base line machine then add the values to the dataset table
}
}
}
private double CalculateVeriances(int t, int a, int rowcount, double theAverage)
{
//Calculate the Veriance for Memory
double SumOfSquares = 0.0;
//lopps through to calculate the square of each data point
for (int c = 0; c < rowcount-1; c++)
{
SumOfSquares += (Convert.ToDouble(dsStats.Tables[t].Rows[c][a])-theAverage)* (Convert.ToDouble(dsStats.Tables[t].Rows[c][a]) - theAverage);
}
//calculates the square root of the averages
//Returns to the parent function the Standard Deviation
return Math.Sqrt(SumOfSquares/(double)(rowcount -1));
}
private int IntmathBase(int T, int myCol, double Average, int recCount)
{
//Intager Math Base is based off of a Azure VM with 8 gigs of ram and 2 processors.
//List of the Bench mark average staticstics (sample size is 4)
double intmath = 20849449.11;
double floatmath = 135920301.78;
double decmath = 9626117.54;
double strcat = 293251.36;
double Treecreate = 39940617868.12;
double treetransinorder = 12303431875.62;
double treetranspreorder = 13573329056.72;
double treetranspostorder = 13567740514.54;
double myOpen = 103.75;
double myClose = 24;
double myInsert = 377.75;
double myReadRows = 1071.5;
double myReadBlobs = 355.5;
double myWriteBlob = 1187;
double myTotal = 3149.2005;
double createtime = 242.68;
double seqread = 1939932.49;
double seqwrite = 444895.17;
double randseekread = 1032058.63;
double randseekwrite = 7309.7;
double testdurations = 3408.22;
int result = 0;
//Set the result based on the column being calculated
switch(T)
{
case 0: // CPU / Math test
switch (myCol)
{
case 1:
result = Convert.ToInt32(((Average / intmath) * 100));
break;
case 2:
result = Convert.ToInt32(((Average / floatmath) * 100));
break;
case 3:
result = Convert.ToInt32(((Average / decmath) * 100));
break;
case 4:
result = Convert.ToInt32(((Average / strcat) * 100));
break;
case 5:
result = Convert.ToInt32(((Average / Treecreate) * 100));
break;
case 6:
result = Convert.ToInt32(((Average / treetransinorder) * 100));
break;
case 7:
result = Convert.ToInt32(((Average / treetranspreorder) * 100));
break;
case 8:
result = Convert.ToInt32(((Average / treetranspostorder) * 100));
break;
default:
break;
}
break;
case 1: // File test
switch (myCol)
{
case 2:
result = Convert.ToInt32(((Average / createtime) * 100));
break;
case 3:
result = Convert.ToInt32(((Average / seqread) * 100));
break;
case 4:
result = Convert.ToInt32(((Average / seqwrite) * 100));
break;
case 5:
result = Convert.ToInt32(((Average/ randseekread) * 100));
break;
case 6:
result = Convert.ToInt32(((Average / randseekwrite) * 100));
break;
case 7:
result = Convert.ToInt32(((Average / testdurations) * 100));
break;
default:
break;
}
break;
case 2: // SQL test
switch (myCol)
{
case 2:
result = Convert.ToInt32(((Average / myOpen) * 100));
break;
case 3:
result = Convert.ToInt32(((Average / myClose) * 100));
break;
case 4:
result = Convert.ToInt32((( Average / myInsert) * 100));
break;
case 5:
result = Convert.ToInt32(((Average / myReadRows) * 100));
break;
case 6:
result = Convert.ToInt32(((Average / myReadBlobs) * 100));
break;
case 7:
result = Convert.ToInt32(((Average / myWriteBlob) * 100));
break;
case 8:
result = Convert.ToInt32(((Average / myTotal) * 100));
break;
default:
break;
}
break;
default:
break;
}
//return the wieghted score
return result;
}
private void MathHeader(Stream myStream)
{
//Set the Column Headers to print
string Header = "Description, ";
Header += "Integer Math(ops / sec),";
Header += "Floating Point(ops/ sec),";
Header += "Decimal Math(ops/ sec),";
Header += "String Concat. (ops / sec),";
Header += "Tree Creation(ops/ sec),";
Header += "Tree TransversalIn Order(ops / sec),";
Header += "Tree Transversal Pre Order(ops/ sec),";
Header += "Tree Transversal Post Order";
using (StreamWriter SW = new StreamWriter(myStream))
{
SW.WriteLine(Header);
}
}
private void MathData(string outFile)
{
//Write the dataset to a CSV File
using (StreamWriter SW = File.AppendText(outFile))
{
foreach (DataRow dr in dsStats.Tables["Memory"].Rows)
{
SW.WriteLine(dr["Description"] + "," + dr["IMath"].ToString() + "," + dr["FMath"].ToString() + "," + dr["DMath"].ToString() + "," + dr["SCat"].ToString()
+ ","+dr["TreeCreate"].ToString() + ","+dr["TraversePreOrder"].ToString() + ","+dr["TraversePreOrder"].ToString()
+ ","+dr["TraversePostOrder"].ToString());
}
}
}
private void FileHeader(Stream myStream)
{ //Set the Column Headers to print
string Header = "Description,";
Header += "File Path,";
Header += "Create Time (ms),";
Header += "Sequence Read (rows/sec),";
Header += "Sequence Write (rows/sec),";
Header += "Random Seek/Read (ops/sec),";
Header += "Random Seek/Writes (ops/sec),";
Header += "Test Duration(sec";
using (StreamWriter SW = new StreamWriter(myStream))
{
SW.WriteLine(Header);
}
}
private void FileData(string outFile)
{
//Write the dataset to a CSV File
using (StreamWriter SW = File.AppendText(outFile))
{
foreach (DataRow dr in dsStats.Tables["File"].Rows)
{
SW.WriteLine(dr["Description"] + "," +
dr["Path"].ToString() + "," +
ToFormattedDouble(dr["Create"]) + "," +
ToFormattedDouble(dr["SRead"]) + ", " +
ToFormattedDouble(dr["SWrite"]) + "," +
ToFormattedDouble(dr["RRead"]) + "," +
ToFormattedDouble(dr["RWrite"]) + "," +
ToFormattedDouble(dr["Total"]));
}
}
}
private void DBHeader(Stream myStream)
{
//Set the Column Headers to print
string Header = "Description,";
Header += "Conn,";
Header += "Open,";
Header += "Close,";
Header += "Insert,";
Header += "ReadRows,";
Header += "ReadBLOB,";
Header += "WriteBLOB,";
Header += "Total";
using (StreamWriter SW = new StreamWriter(myStream))
{
SW.WriteLine(Header);
}
}
private void dbData(string outFile)
{
//Write the dataset to a CSV File
using (StreamWriter SW = File.AppendText(outFile))
{
foreach (DataRow dr in dsStats.Tables["Database"].Rows)
{
SW.WriteLine(dr["Description"] + "," + dr["Conn"].ToString() + "," + dr["Open"].ToString() + "," + dr["Close"].ToString() + "," + dr["Insert"].ToString()
+ "," + dr["ReadRows"].ToString() + "," + dr["ReadBLOB"].ToString() + "," + dr["WriteBLOB"].ToString()
+ "," + dr["Total"].ToString());
}
}
}
private string ToFormattedDouble(object o, string Format = "#.##")
{
string s = "";
try
{
s = Convert.ToDouble(o).ToString(Format);
}
catch (Exception) { /* do nothing, return empty string */}
return s;
}
}
}