-
Notifications
You must be signed in to change notification settings - Fork 0
/
Report.cs
269 lines (235 loc) · 11.7 KB
/
Report.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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.IO;
using System.Web.UI.WebControls;
using System.Web.UI;
using MongoBench.Benchmarks;
using GoogleChartSharp;
namespace MongoBench {
/// <summary>
/// Report
/// </summary>
public class Report {
/// <summary>
/// Output Filename
/// </summary>
public string OutputFileName { get; set; }
/// <summary>
/// Template Filename
/// </summary>
public string TemplateFileName { get; set; }
/// <summary>
/// Report data
/// </summary>
private StringBuilder ReportData;
/// <summary>
/// Initializes a new instance of the <see cref="Report"/> class.
/// </summary>
/// <param name="templateFileName">Name of the template file.</param>
/// <param name="outputFileName">Name of the output file.</param>
public Report(string templateFileName, string outputFileName) {
this.TemplateFileName = templateFileName;
this.OutputFileName = outputFileName;
}
/// <summary>
/// Print Report
/// </summary>
/// <param name="benchmarks"></param>
public void PrintReport(params MultiRunBenchmark[] benchmarks) {
//Initialize output file
this.ReportData = new StringBuilder().Append(File.ReadAllText(this.TemplateFileName));
//Print Servers
PrintServers(benchmarks);
//Print Stats
PrintStats(benchmarks);
//Print Data
PrintData(benchmarks);
//Print Log
PrintLog();
//Write report data
File.WriteAllText(this.OutputFileName, this.ReportData.ToString());
}
/// <summary>
/// Prints the servers.
/// </summary>
/// <param name="benchmarks">The benchmarks.</param>
private void PrintServers(params MultiRunBenchmark[] benchmarks) {
StringBuilder str = new StringBuilder();
str.Append("<table><tr><th>Name</th><th>Connection String</th></tr>");
foreach (var b in benchmarks) {
str.AppendFormat("<tr><td>{0}</td><td><code>{1}</code></td></tr>",
b.ServerBenchmark[0].ServerName,
b.ServerBenchmark[0].ConnectionString);
}
str.Append("</table><br/>");
//Print benchmark options
str.Append("<table><tr><th>Type</th><th>Value</th></tr>");
str.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", "Database Name", Settings.DATABASE_NAME);
str.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", "Collection Name", Settings.COLLECTION_NAME);
str.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", "Safe Mode", Settings.INSERT_SAFE_MODE);
str.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", "Index Fields", string.Join(",", Settings.INDEX_FIELDS));
str.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", "Number Of Runs", benchmarks[0].NumOfRuns);
str.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", "Number Of Threads", benchmarks[0].ServerBenchmark[0].NumOfThreads);
str.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", "Number Of Reecords/Thread", benchmarks[0].ServerBenchmark[0].NumOfRecords);
str.AppendLine("</table>");
this.ReportData.Replace("<%SERVERS%>", str.ToString());
}
/// <summary>
/// Prints the stats.
/// </summary>
/// <param name="benchmarks">The benchmarks.</param>
private void PrintStats(params MultiRunBenchmark[] benchmarks) {
StringBuilder str = new StringBuilder();
//Global Average
str.Append("<table><tr><th></th><th>")
.Append(string.Join("</th><th>",
Array.ConvertAll<MultiRunBenchmark, string>(benchmarks,
b => b.ServerBenchmark[0].ServerName)))
.Append("</th></tr>");
//AvgInsertsPerThreadSecond
str.Append("<tr><td>AvgInsertsPerThreadSecond</td><td>")
.Append(string.Join("</td><td>",
Array.ConvertAll<MultiRunBenchmark, string>(benchmarks,
b => b.AvgInsertsPerThreadSecond.ToString())))
.Append("</td></tr>");
//AvgInsertsPerSecond
str.Append("<tr><td>AvgInsertsPerSecond</td><td>")
.Append(string.Join("</td><td>",
Array.ConvertAll<MultiRunBenchmark, string>(benchmarks,
b => b.AvgInsertsPerSecond.ToString())))
.Append("</td></tr>");
//AvgSimpleSelectDuration
str.Append("<tr><td>AvgSimpleSelectDuration</td><td>")
.Append(string.Join("</td><td>",
Array.ConvertAll<MultiRunBenchmark, string>(benchmarks,
b => b.AvgSimpleSelectDuration.ToString())))
.Append("</td></tr>");
//AvgSimpleFilterDuration
str.Append("<tr><td>AvgSimpleFilterDuration</td><td>")
.Append(string.Join("</td><td>",
Array.ConvertAll<MultiRunBenchmark, string>(benchmarks,
b => b.AvgSimpleFilterDuration.ToString())))
.Append("</td></tr>");
//AvgMapReduceTagsDuration
str.Append("<tr><td>AvgMapReduceTagsDuration</td><td>")
.Append(string.Join("</td><td>",
Array.ConvertAll<MultiRunBenchmark, string>(benchmarks,
b => b.AvgMapReduceTagsDuration.ToString())))
.Append("</td></tr>");
//AvgMapReduceCommentsDuration
str.Append("<tr><td>AvgMapReduceCommentsDuration</td><td>")
.Append(string.Join("</td><td>",
Array.ConvertAll<MultiRunBenchmark, string>(benchmarks,
b => b.AvgMapReduceCommentsDuration.ToString())))
.Append("</td></tr>");
//AvgCreateIndexDuration
str.Append("<tr><td>AvgCreateIndexDuration</td><td>")
.Append(string.Join("</td><td>",
Array.ConvertAll<MultiRunBenchmark, string>(benchmarks,
b => b.AvgCreateIndexDuration.ToString())))
.Append("</td></tr>");
//AvgIndexedSimpleSelectDuration
str.Append("<tr><td>AvgIndexedSimpleSelectDuration</td><td>")
.Append(string.Join("</td><td>",
Array.ConvertAll<MultiRunBenchmark, string>(benchmarks,
b => b.AvgIndexedSimpleSelectDuration.ToString() )))
.Append("</td></tr>");
//AvgIndexedSimpleFilterDuration
str.Append("<tr><td>AvgIndexedSimpleFilterDuration</td><td>")
.Append(string.Join("</td><td>",
Array.ConvertAll<MultiRunBenchmark, string>(benchmarks,
b => b.AvgIndexedSimpleFilterDuration.ToString())))
.Append("</td></tr>");
//AvgIndexedMapReduceTagsDuration
str.Append("<tr><td>AvgIndexedMapReduceTagsDuration</td><td>")
.Append(string.Join("</td><td>",
Array.ConvertAll<MultiRunBenchmark, string>(benchmarks,
b => b.AvgIndexedMapReduceTagsDuration.ToString())))
.Append("</td></tr>");
//AvgIndexedMapReduceCommentsDuration
str.Append("<tr><td>AvgIndexedMapReduceCommentsDuration</td><td>")
.Append(string.Join("</td><td>",
Array.ConvertAll<MultiRunBenchmark, string>(benchmarks,
b => b.AvgIndexedMapReduceCommentsDuration.ToString())))
.Append("</td></tr>");
str.Append("</table>");
this.ReportData.Replace("<%STATS%>", str.ToString());
}
/// <summary>
/// Prints the data.
/// </summary>
private void PrintData(params MultiRunBenchmark[] benchmarks) {
DataTable data = new DataTable();
data.Columns.Add("Server");
data.Columns.Add("Run");
data.Columns.Add("Type");
data.Columns.Add("Time (seconds)");
//Populate data table
foreach (var m in benchmarks) {
Dictionary<string, List<int[]>> graphData = new Dictionary<string, List<int[]>>();
for (int i = 0; i < m.NumOfRuns; i++) {
for (int j = 0; j < m.ServerBenchmark[i].Results.Length; j++) {
BenchmarkBase b = m.ServerBenchmark[i].Results[j];
AppendDataTable(data, m.ServerBenchmark[i].ServerName, i + 1, b);
}
}
}
//Insert Graph
BarChart insertBarChart = new BarChart(320, 220, BarChartOrientation.Vertical, BarChartStyle.Grouped);
insertBarChart.SetTitle("Inserts");
insertBarChart.AddAxis(new ChartAxis(ChartAxisType.Bottom));
var c = new ChartAxis(ChartAxisType.Left);
c.SetRange(0, 60000);
insertBarChart.AddAxis(c);
insertBarChart.SetData(benchmarks[0].Results
.Where(b => b.Type == "Insert")
.ToList()
.ConvertAll<float>(b => b.Time.ElapsedMilliseconds)
.ToArray());
//Print table
using (GridView table = new GridView()) {
table.CellPadding = 5;
table.CellSpacing = 5;
table.DataSource = data;
table.DataBind();
StringBuilder text = new StringBuilder();
text.AppendFormat("<img src=\"{0}\" /><br/>", insertBarChart.GetUrl());
using (StringWriter wr = new StringWriter(text))
using (HtmlTextWriter htmlWr = new HtmlTextWriter(wr)) {
table.RenderControl(htmlWr);
this.ReportData.Replace("<%DATA%>", text.ToString());
}
}
}
/// <summary>
/// Appends the data table.
/// </summary>
/// <param name="table">The table.</param>
/// <param name="benchmark">The benchmark.</param>
private void AppendDataTable(DataTable data, string serverName, int run, BenchmarkBase benchmark) {
if (benchmark.GetType() == typeof(CompositeQueries)) {
AppendDataTable(data, serverName, run, ((CompositeQueries)benchmark).SimpleQuery);
AppendDataTable(data, serverName, run, ((CompositeQueries)benchmark).FilterQuery);
AppendDataTable(data, serverName, run, ((CompositeQueries)benchmark).TagCountMapReduce);
AppendDataTable(data, serverName, run, ((CompositeQueries)benchmark).CommentAuthorMapReduce);
}
else {
DataRow row = data.NewRow();
row["Server"] = serverName;
row["Run"] = run;
row["Type"] = benchmark.Type;
row["Time (seconds)"] = benchmark.Time.ElapsedMilliseconds / 1000.0;
data.Rows.Add(row);
}
}
/// <summary>
/// Prints the log.
/// </summary>
private void PrintLog() {
this.ReportData.Replace("<%LOG%>", Log.LOG.Replace("\n", "<br/>").ToString());
}
}
}