Skip to content

Commit

Permalink
reverse/include/exclude support
Browse files Browse the repository at this point in the history
  • Loading branch information
apangin committed Mar 12, 2024
1 parent c244027 commit dc85d74
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/converter/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private static boolean isJfr(String fileName) throws IOException {
}

private static void usage() {
System.out.print("Usage: jfrconv [options] <input> <output>\n" +
System.out.print("Usage: jfrconv [options] <input> [<input>...] <output>\n" +
"\n" +
"Conversion options:\n" +
" -o --output FORMAT Output format: html, collapsed, pprof, pb.gz\n" +
Expand Down
34 changes: 26 additions & 8 deletions src/converter/one/convert/FlameGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@ public void parseCollapsed(Reader in) throws IOException {
}

public void parseHtml(Reader in) throws IOException {
Frame[] levels = new Frame[128];
int level = 0;
long total = 0;
boolean needRebuild = args.reverse || args.include != null || args.exclude != null;

try (BufferedReader br = new BufferedReader(in)) {
for (String line; !(line = br.readLine()).startsWith("const cpool"); ) ;
while (!br.readLine().startsWith("const cpool")) ;
br.readLine();

String s = "";
Expand All @@ -74,11 +79,7 @@ public void parseHtml(Reader in) throws IOException {
cpool.put(s, cpool.size());
}

for (String line; !(line = br.readLine()).isEmpty(); ) ;

Frame[] levels = new Frame[128];
int level = 0;
long total = 0;
while (!br.readLine().isEmpty()) ;

for (String line; !(line = br.readLine()).isEmpty(); ) {
StringTokenizer st = new StringTokenizer(line.substring(2, line.length() - 1), ",");
Expand All @@ -104,7 +105,7 @@ public void parseHtml(Reader in) throws IOException {
type = TYPE_JIT_COMPILED;
}

Frame f = level > 0 ? new Frame(titleIndex, type) : root;
Frame f = level > 0 || needRebuild ? new Frame(titleIndex, type) : root;
f.self = f.total = total;
if (st.hasMoreTokens()) f.inlined = Long.parseLong(st.nextToken());
if (st.hasMoreTokens()) f.c1 = Long.parseLong(st.nextToken());
Expand All @@ -122,6 +123,23 @@ public void parseHtml(Reader in) throws IOException {
levels[level] = f;
}
}

if (needRebuild) {
rebuild(levels[0], new CallStack(), cpool.keys());
}
}

private void rebuild(Frame frame, CallStack stack, String[] strings) {
if (frame.self > 0) {
addSample(stack, frame.self);
}
if (!frame.isEmpty()) {
for (Frame child : frame.values()) {
stack.push(strings[child.getTitleIndex()], child.getType());
rebuild(child, stack, strings);
stack.size--;
}
}
}

public void addSample(CallStack stack, long ticks) {
Expand Down Expand Up @@ -188,7 +206,7 @@ private String printTill(PrintStream out, String data, String till) {
}

private void printCpool(PrintStream out) {
String[] strings = cpool.keySet().toArray(new String[0]);
String[] strings = cpool.keys();
Arrays.sort(strings);
out.print("'all'");

Expand Down

0 comments on commit dc85d74

Please sign in to comment.