forked from apache/lucenenet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReportTask.cs
More file actions
184 lines (173 loc) · 7.36 KB
/
Copy pathReportTask.cs
File metadata and controls
184 lines (173 loc) · 7.36 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
using Lucene.Net.Benchmarks.ByTask.Stats;
using Lucene.Net.Benchmarks.ByTask.Utils;
using System;
using System.Collections.Generic;
using System.Text;
using JCG = J2N.Collections.Generic;
namespace Lucene.Net.Benchmarks.ByTask.Tasks
{
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/// <summary>
/// Report (abstract) task - all report tasks extend this task.
/// </summary>
public abstract class ReportTask : PerfTask
{
protected ReportTask(PerfRunData runData) // LUCENENET: CA1012: Abstract types should not have constructors (marked protected)
: base(runData)
{
}
/// <seealso cref="PerfTask.ShouldNeverLogAtStart"/>
protected override bool ShouldNeverLogAtStart => true;
/// <seealso cref="PerfTask.ShouldNotRecordStats"/>
protected override bool ShouldNotRecordStats => true;
/// <summary>
/// From here start the code used to generate the reports.
/// Subclasses would use this part to generate reports.
/// </summary>
protected static readonly string newline = Environment.NewLine;
/// <summary>
/// Get a textual summary of the benchmark results, average from all test runs.
/// </summary>
protected const string OP = "Operation ";
protected const string ROUND = " round";
protected const string RUNCNT = " runCnt";
protected const string RECCNT = " recsPerRun";
protected const string RECSEC = " rec/s";
protected const string ELAPSED = " elapsedSec";
protected const string USEDMEM = " avgUsedMem";
protected const string TOTMEM = " avgTotalMem";
protected static readonly string[] COLS = {
RUNCNT,
RECCNT,
RECSEC,
ELAPSED,
USEDMEM,
TOTMEM
};
/// <summary>
/// Compute a title line for a report table.
/// </summary>
/// <param name="longestOp">Size of longest op name in the table.</param>
/// <returns>The table title line.</returns>
protected virtual string TableTitle(string longestOp)
{
StringBuilder sb = new StringBuilder();
sb.Append(Formatter.Format(OP, longestOp));
sb.Append(ROUND);
sb.Append(RunData.Config.GetColsNamesForValsByRound());
for (int i = 0; i < COLS.Length; i++)
{
sb.Append(COLS[i]);
}
return sb.ToString();
}
/// <summary>
/// Find the longest op name out of completed tasks.
/// </summary>
/// <param name="taskStats">Completed tasks to be considered.</param>
/// <returns>The longest op name out of completed tasks.</returns>
protected virtual string LongestOp(IEnumerable<TaskStats> taskStats)
{
string longest = OP;
foreach (TaskStats stat in taskStats)
{
if (stat.Elapsed >= 0)
{ // consider only tasks that ended
string name = stat.Task.GetName();
if (name.Length > longest.Length)
{
longest = name;
}
}
}
return longest;
}
/// <summary>
/// Compute a report line for the given task stat.
/// </summary>
/// <param name="longestOp">Size of longest op name in the table.</param>
/// <param name="stat">Task stat to be printed.</param>
/// <returns>The report line.</returns>
protected virtual string TaskReportLine(string longestOp, TaskStats stat)
{
PerfTask task = stat.Task;
StringBuilder sb = new StringBuilder();
sb.Append(Formatter.Format(task.GetName(), longestOp));
string round = (stat.Round >= 0 ? "" + stat.Round : "-");
sb.Append(Formatter.FormatPaddLeft(round, ROUND));
sb.Append(RunData.Config.GetColsValuesForValsByRound(stat.Round));
sb.Append(Formatter.Format(stat.NumRuns, RUNCNT));
sb.Append(Formatter.Format(stat.Count / stat.NumRuns, RECCNT));
long elapsed = (stat.Elapsed > 0 ? stat.Elapsed : 1); // assume at least 1ms
sb.Append(Formatter.Format(2, (float)(stat.Count * 1000.0 / elapsed), RECSEC));
sb.Append(Formatter.Format(2, (float)stat.Elapsed / 1000, ELAPSED));
sb.Append(Formatter.Format(0, (float)stat.MaxUsedMem / stat.NumRuns, USEDMEM));
sb.Append(Formatter.Format(0, (float)stat.MaxTotMem / stat.NumRuns, TOTMEM));
return sb.ToString();
}
// LUCENENET specific: OrderedDictionary<TKey, TValue> is a replacement for LinkedHashMap<K, V> in the JDK
protected virtual Report GenPartialReport(int reported, JCG.OrderedDictionary<string, TaskStats> partOfTasks, int totalSize)
{
string longetOp = LongestOp(partOfTasks.Values);
bool first = true;
StringBuilder sb = new StringBuilder();
sb.Append(TableTitle(longetOp));
sb.Append(newline);
int lineNum = 0;
foreach (TaskStats stat in partOfTasks.Values)
{
if (!first)
{
sb.Append(newline);
}
first = false;
string line = TaskReportLine(longetOp, stat);
lineNum++;
if (partOfTasks.Count > 2 && lineNum % 2 == 0)
{
line = line.Replace(" ", " - ");
}
sb.Append(line);
int[] byTime = stat.GetCountsByTime();
if (byTime != null)
{
sb.Append(newline);
int end = -1;
for (int i = byTime.Length - 1; i >= 0; i--)
{
if (byTime[i] != 0)
{
end = i;
break;
}
}
if (end != -1)
{
sb.Append(" by time:");
for (int i = 0; i < end; i++)
{
sb.Append(' ').Append(byTime[i]);
}
}
}
}
string reptxt = (reported == 0 ? "No Matching Entries Were Found!" : sb.ToString());
return new Report(reptxt, partOfTasks.Count, reported, totalSize);
}
}
}