-
Notifications
You must be signed in to change notification settings - Fork 147
/
ReportUtil.java
290 lines (239 loc) · 8.47 KB
/
ReportUtil.java
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
package com.insightfullogic.honest_profiler.ports.javafx.util.report;
import static com.insightfullogic.honest_profiler.ports.javafx.util.report.Table.Alignment.LEFT;
import static com.insightfullogic.honest_profiler.ports.javafx.util.report.Table.Alignment.RIGHT;
import java.io.PrintWriter;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import com.insightfullogic.honest_profiler.core.collector.FlatProfileEntry;
import com.insightfullogic.honest_profiler.core.profiles.ProfileNode;
import com.insightfullogic.honest_profiler.core.profiles.ProfileTree;
import com.insightfullogic.honest_profiler.ports.javafx.model.diff.FlatProfileDiff;
public final class ReportUtil
{
private static char BOX_HORIZONTAL = 0x2500;
private static char BOX_VERTICAL = 0x2502;
private static char BOX_UPANDRIGHT = 0x2514;
private static char BOX_VERTICALANDRIGHT = 0x251C;
private static String DROP_STRAIGHT = new String(new char[]
{ BOX_VERTICAL, ' ' });
private static String DROP_NONLAST = new String(new char[]
{ BOX_VERTICALANDRIGHT, BOX_HORIZONTAL });
private static String DROP_LAST = new String(new char[]
{ BOX_UPANDRIGHT, BOX_HORIZONTAL });
private static NumberFormat FMT_PERCENT;
static
{
FMT_PERCENT = NumberFormat.getPercentInstance();
FMT_PERCENT.setMinimumFractionDigits(2);
FMT_PERCENT.setMaximumFractionDigits(2);
}
public static enum Mode
{
TEXT("", " ", ""),
CSV("\"", "\",\"", "\"");
private String start;
private String middle;
private String end;
private Mode(String start, String middle, String end)
{
this.start = start;
this.middle = middle;
this.end = end;
}
private PrintWriter start(PrintWriter out)
{
out.print(start);
return out;
}
private PrintWriter middle(PrintWriter out)
{
out.print(middle);
return out;
}
private PrintWriter end(PrintWriter out)
{
out.println(end);
return out;
}
}
public static void writeStack(PrintWriter out, ProfileNode node)
{
Table table = new Table();
table.addColumn("Method", obj -> obj.toString(), LEFT);
table.addColumn("Self Time Share", object -> FMT_PERCENT.format(object), RIGHT);
table.addColumn("Total Time Share", object -> FMT_PERCENT.format(object), RIGHT);
buildStackTable(node, 0, table, new ArrayList<>());
table.print(out);
}
private static void buildStackTable(ProfileNode node, int level, Table table,
List<DropLine> dropLines)
{
table.addRow(
indent(dropLines, level)
+ node.getFrameInfo().getClassName()
+ "."
+ node.getFrameInfo().getMethodName(),
node.getSelfTimeShare(),
node.getTotalTimeShare());
if (level > 0)
{
dropLines.get(level - 1).decrement();
}
List<ProfileNode> children = node.getChildren();
if (children.size() > 0)
{
dropLines.add(new DropLine(children.size()));
children.forEach(child -> buildStackTable(child, level + 1, table, dropLines));
dropLines.remove(level);
}
}
public static void writeThread(PrintWriter out, ProfileTree thread, Mode mode)
{
// TODO Implement
}
public static void writeFlatProfileCsv(PrintWriter out, List<FlatProfileEntry> entries,
Mode mode)
{
mode.start(out);
out.print("Method");
mode.middle(out);
out.print("Self Time %");
mode.middle(out);
out.print("Total Time %");
mode.middle(out);
out.print("Self Sample #");
mode.middle(out);
out.print("Total Sample #");
mode.middle(out);
out.print("Profile Sample #");
mode.end(out);
entries.forEach(entry ->
{
mode.start(out);
out.print(entry.getFrameInfo().getClassName());
out.print(".");
out.print(entry.getFrameInfo().getMethodName());
mode.middle(out);
out.printf("%.4f", entry.getSelfTimeShare());
mode.middle(out);
out.printf("%.4f", entry.getTotalTimeShare());
mode.middle(out);
out.printf("%d", entry.getSelfCount());
mode.middle(out);
out.printf("%d", entry.getTotalCount());
mode.middle(out);
out.printf("%d", entry.getTraceCount());
mode.end(out);
});
out.flush();
}
public static void writeFlatProfileDiffCsv(PrintWriter out, FlatProfileDiff diff, Mode mode)
{
mode.start(out);
out.print("Method");
mode.middle(out);
out.print("Base Self Time %");
mode.middle(out);
out.print("New Self Time %");
mode.middle(out);
out.print("Self Time % Diff");
mode.middle(out);
out.print("Base Total Time %");
mode.middle(out);
out.print("New Total Time %");
mode.middle(out);
out.print("Total Time % Diff");
mode.middle(out);
out.print("Base Self Sample #");
mode.middle(out);
out.print("New Self Sample #");
mode.middle(out);
out.print("Self Sample # Diff");
mode.middle(out);
out.print("Base Total Sample #");
mode.middle(out);
out.print("New Total Sample #");
mode.middle(out);
out.print("Total Sample # Diff");
mode.middle(out);
out.print("Base Profile Sample #");
mode.middle(out);
out.print("New Profile Sample #");
mode.middle(out);
out.print("Profile Sample # Diff");
mode.end(out);
diff.getEntries().forEach(entry ->
{
mode.start(out);
out.write(entry.getFullName());
mode.middle(out);
out.printf("%.4f", entry.baseSelfTimeShareProperty().get());
mode.middle(out);
out.printf("%.4f", entry.newSelfTimeShareProperty().get());
mode.middle(out);
out.printf("%.4f", entry.pctSelfChangeProperty().get());
mode.middle(out);
out.printf("%.4f", entry.baseTotalTimeShareProperty().get());
mode.middle(out);
out.printf("%.4f", entry.newTotalTimeShareProperty().get());
mode.middle(out);
out.printf("%.4f", entry.pctTotalChangeProperty().get());
mode.middle(out);
out.printf("%d", entry.baseSelfCountProperty().get());
mode.middle(out);
out.printf("%d", entry.newSelfCountProperty().get());
mode.middle(out);
out.printf(
"%d",
entry.newSelfCountProperty().get() - entry.baseSelfCountProperty().get());
mode.middle(out);
out.printf("%d", entry.baseTotalCountProperty().get());
mode.middle(out);
out.printf("%d", entry.newTotalCountProperty().get());
mode.middle(out);
out.printf(
"%d",
entry.newTotalCountProperty().get() - entry.baseTotalCountProperty().get());
mode.middle(out);
out.printf("%d", entry.baseTraceCountProperty().get());
mode.middle(out);
out.printf("%d", entry.newTraceCountProperty().get());
mode.middle(out);
out.printf(
"%d",
entry.newTraceCountProperty().get() - entry.baseTraceCountProperty().get());
mode.end(out);
});
out.flush();
}
private static String indent(List<DropLine> dropLines, int level)
{
StringBuilder result = new StringBuilder();
for (int i = 0; i < level - 1; i++)
{
result.append(dropLines.get(i).childrenLeft > 0 ? DROP_STRAIGHT : " ");
}
if (level > 0)
{
result.append(dropLines.get(level - 1).childrenLeft > 1 ? DROP_NONLAST : DROP_LAST);
}
return result.toString();
}
private static class DropLine
{
private int childrenLeft;
private DropLine(int childrenLeft)
{
this.childrenLeft = childrenLeft;
}
private void decrement()
{
childrenLeft--;
}
}
private ReportUtil()
{
// Empty Constructor for utility class
}
}