Skip to content

Commit

Permalink
begin seperation of parser from model
Browse files Browse the repository at this point in the history
  • Loading branch information
Haim Yadid committed Dec 8, 2022
1 parent 89ff079 commit c66c4f2
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
import java.util.ArrayList;

public class ThreadContainer {
public ThreadContainer(String name, String parent, String owner) {
this.name = name;
this.parent = parent;
this.owner = owner;
}


String name;
String parent;
String owner;
Expand Down
27 changes: 10 additions & 17 deletions src/main/java/com/performizeit/mjprof/parser/ThreadDump.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,19 @@ public JStackHeader getHeader() {
return header;
}

public ThreadDump(String stringRep) {
String[] splitTraces = stringRep.split("\n\""); // Assuming that thread stack trace starts with a new line followed by "

header = new JStackHeader(splitTraces[0]);
for (int i = 1; i < splitTraces.length; i++) {
if (splitTraces[i].startsWith(JNI_GLOBAL_REFS)) {
try {
JNIglobalReferences = Integer.parseInt(splitTraces[i].substring(splitTraces[i].indexOf(":") + 2).trim());
} catch (NumberFormatException e) {
// do nothing so we missed the JNI global references I do not know what to do with it.
}

} else {
threadInfos.add(new ThreadInfo("\"" + splitTraces[i]));
}
}
public ThreadDump(JStackHeader header, ArrayList<ThreadInfo> threadInfos, int JNIglobalReferences) {
this.header = header;
this.threadInfos = threadInfos;
this.JNIglobalReferences = JNIglobalReferences;
}
public ThreadDump(JStackHeader header, ArrayList<ThreadInfo> threadInfos) {
this.header = header;
this.threadInfos = threadInfos;

}


public ThreadDump() {
super();
}

public ArrayList<ThreadInfo> getThreadInfos() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.performizeit.mjprof.parser;

import com.performizeit.mjprof.model.JStackHeader;

import java.util.ArrayList;

public class ThreadDumpTextualParser {
public static String JNI_GLOBAL_REFS = "JNI global references:";

public static ThreadDump parseStringRepresentation (String stringRep) {
String[] splitTraces = stringRep.split("\n\""); // Assuming that thread stack trace starts with a new line followed by "
int JNIglobalReferences = -1;
JStackHeader header = new JStackHeader(splitTraces[0]);
ArrayList<ThreadInfo> threadInfos = new ArrayList<>();
for (int i = 1; i < splitTraces.length; i++) {
if (splitTraces[i].startsWith(JNI_GLOBAL_REFS)) {
try {
JNIglobalReferences = Integer.parseInt(splitTraces[i].substring(splitTraces[i].indexOf(":") + 2).trim());
} catch (NumberFormatException e) {
// do nothing so we missed the JNI global references I do not know what to do with it.
}

} else {
threadInfos.add(new ThreadInfo("\"" + splitTraces[i]));
}
}
return new ThreadDump(header,threadInfos,JNIglobalReferences);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.performizeit.mjprof.api.Param;
import com.performizeit.mjprof.api.Plugin;
import com.performizeit.mjprof.api.PluginCategory;
import com.performizeit.mjprof.model.JStackHeader;
import com.performizeit.mjprof.model.ThreadInfoAggregator;
import com.performizeit.mjprof.parser.ThreadDump;
import com.performizeit.mjprof.parser.ThreadInfo;
Expand Down Expand Up @@ -48,19 +49,12 @@ public void reduce(ThreadDump td) {
tidAggr.accumulateThreadInfo(ti);
}
countDumps++;


}

public ThreadDump getResult() {
ThreadDump td = new ThreadDump();
td.setHeader("Profiling session number of dumps is " + countDumps);

td.setThreadInfos(tidAggr.getAggrInfos());
return td;
return new ThreadDump(new JStackHeader("Profiling session number of dumps is " + countDumps), tidAggr.getAggrInfos());
}


@Override
public ThreadDump handleMsg(ThreadDump msg) {
reduce(msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.IOException;
import java.util.regex.Pattern;

import com.performizeit.mjprof.parser.ThreadDumpTextualParser;
import com.performizeit.mjprof.plugin.types.DataSource;
import com.performizeit.mjprof.parser.ThreadDump;
import com.performizeit.plumbing.GeneratorHandler;
Expand Down Expand Up @@ -58,7 +59,7 @@ public ThreadDump generate() {
isDoneFlag = true;
return null;
}
return new ThreadDump(nextDump);
return ThreadDumpTextualParser.parseStringRepresentation(nextDump);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


import com.performizeit.mjprof.parser.ThreadDump;
import com.performizeit.mjprof.parser.ThreadDumpTextualParser;
import org.junit.jupiter.api.Test;

public class MergedCalleesTest {
Expand All @@ -20,7 +21,7 @@ public void testName() throws Exception {

// GroupByProp g = new GroupByProp("org.eclipse.core.internal.jobs.WorkerPool.test");
// ThreadDump dump = new ThreadDump(readFromFile("src/test/res/test1.txt"));
ThreadDump dump = new ThreadDump(readFromFile("src/test/res/test2.txt"));
ThreadDump dump = ThreadDumpTextualParser.parseStringRepresentation(readFromFile("src/test/res/test2.txt"));
// ThreadDump resDump = new ThreadDump(readFromFile("src/test/res/resTest2.txt"));

//System.out.println(g.map(dump).getStacks());
Expand Down

0 comments on commit c66c4f2

Please sign in to comment.