Skip to content

Commit

Permalink
rename stack to threadInfos
Browse files Browse the repository at this point in the history
  • Loading branch information
Haim Yadid committed Dec 2, 2022
1 parent 5842d60 commit 6b409d4
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 38 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/performizeit/mjprof/parser/ThreadContainer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.performizeit.mjprof.parser;

import java.util.ArrayList;

public class ThreadContainer {
String name;
String parent;
String owner;
ArrayList<ThreadInfo> threads = new ArrayList<>();
}
20 changes: 9 additions & 11 deletions src/main/java/com/performizeit/mjprof/parser/ThreadDump.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/* Thread dump consists of a header and a list ThreadInfo */
public class ThreadDump {
protected JStackHeader header;
ArrayList<ThreadInfo> stacks = new ArrayList<>();
ArrayList<ThreadInfo> threadInfos = new ArrayList<>();
int JNIglobalReferences = -1;

public static String JNI_GLOBAL_REFS = "JNI global references:";
Expand All @@ -47,7 +47,7 @@ public ThreadDump(String stringRep) {
}

} else {
stacks.add(new ThreadInfo("\"" + splitTraces[i]));
threadInfos.add(new ThreadInfo("\"" + splitTraces[i]));
}
}
}
Expand All @@ -56,24 +56,24 @@ public ThreadDump() {
super();
}

public ArrayList<ThreadInfo> getStacks() {
return stacks;
public ArrayList<ThreadInfo> getThreadInfos() {
return threadInfos;
}

public void addThreadInfo(ThreadInfo ti) {
stacks.add(ti);
threadInfos.add(ti);
}

public void setStacks(ArrayList<ThreadInfo> stacks) {
this.stacks = stacks;
public void setThreadInfos(ArrayList<ThreadInfo> threadInfos) {
this.threadInfos = threadInfos;
}

@Override
public String toString() {
StringBuilder s = new StringBuilder();
s.append(header).append("\n\n");

for (ThreadInfo stack : stacks) {
for (ThreadInfo stack : threadInfos) {
s.append(stack.toString()).append("\n");
}

Expand All @@ -91,9 +91,7 @@ public void setHeader(JStackHeader header) {

public ArrayList<ThreadInfo> cloneStacks() {
ArrayList<ThreadInfo> newStcks = new ArrayList<>();
for (ThreadInfo stk : getStacks()) {
newStcks.add(stk);
}
newStcks.addAll(getThreadInfos());
return newStcks;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import java.util.ArrayList;


@Plugin(name = "merge", params = {@Param(type = String.class, value = "attr", optional = true, defaultValue = "tid")},
@Plugin(name = "merge", params = {@Param(value = "attr", optional = true, defaultValue = "tid")},
category = PluginCategory.DUMP_REDUCER,
description = "Combine all dumps to a single one merge based on an attribute (thread id is the default attribute)")
public class AccumulateDumps implements DumpReducer, PipeHandler<ThreadDump, ThreadDump> {
Expand All @@ -44,7 +44,7 @@ public AccumulateDumps(String prop) {
}

public void reduce(ThreadDump td) {
for (ThreadInfo ti : td.getStacks()) {
for (ThreadInfo ti : td.getThreadInfos()) {
tidAggr.accumulateThreadInfo(ti);
}
countDumps++;
Expand All @@ -56,7 +56,7 @@ public ThreadDump getResult() {
ThreadDump td = new ThreadDump();
td.setHeader("Profiling session number of dumps is " + countDumps);

td.setStacks(tidAggr.getAggrInfos());
td.setThreadInfos(tidAggr.getAggrInfos());
return td;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
import com.performizeit.plumbing.PipeHandler;

import java.util.ArrayList;
import java.util.Collections;

public abstract class SortMapper implements ThreadInfoComparator, PipeHandler<ThreadDump, ThreadDump> {
public ThreadDump map(ThreadDump jsd) {
ThreadDump that = new ThreadDump();
that.setHeader(jsd.getHeader());
that.setJNIglobalReferences(jsd.getJNIglobalReferences());
ArrayList<ThreadInfo> stacks = jsd.cloneStacks();
Collections.sort(stacks, this);
that.setStacks(stacks);
stacks.sort(this);
that.setThreadInfos(stacks);
return that;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public ThreadDump map(ThreadDump jsd) {
that.setHeader(jsd.getHeader());
that.setJNIglobalReferences(jsd.getJNIglobalReferences());
ArrayList<ThreadInfo> stcks = new ArrayList<>();
for (ThreadInfo stk : jsd.getStacks()) {
for (ThreadInfo stk : jsd.getThreadInfos()) {
if (filter(stk))
stcks.add(stk);
}
that.setStacks(stcks);
that.setThreadInfos(stcks);
return that;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public ThreadDump map(final ThreadDump jsd) {
ArrayList<String> a = new ArrayList<>();
a.add(prop);
ThreadInfoAggregator aggr = new ThreadInfoAggregator(a);
for (ThreadInfo mss : jsd.getStacks()) {
for (ThreadInfo mss : jsd.getThreadInfos()) {
aggr.accumulateThreadInfo(mss);
}
ThreadDump jsd2 = new ThreadDump();
jsd2.setHeader(jsd.getHeader());
jsd2.setStacks(aggr.getAggrInfos());
jsd2.setThreadInfos(aggr.getAggrInfos());
jsd2.setJNIglobalReferences(jsd.getJNIglobalReferences());
return jsd2;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import com.performizeit.mjprof.api.Plugin;
import com.performizeit.mjprof.api.PluginCategory;
import com.performizeit.mjprof.model.Profile;
import com.performizeit.mjprof.model.ProfileNodeFilter;
import com.performizeit.mjprof.model.SFNode;
import com.performizeit.mjprof.model.ThreadInfoAggregator;
import com.performizeit.mjprof.parser.ThreadDump;
import com.performizeit.mjprof.parser.ThreadInfo;
Expand All @@ -48,7 +46,7 @@ public ThreadDump map(final ThreadDump jsd) {
ArrayList<String> a = new ArrayList<>();
a.add(methodName);
ThreadInfoAggregator aggr = new ThreadInfoAggregator(a);
for (ThreadInfo mss : jsd.getStacks()) {
for (ThreadInfo mss : jsd.getThreadInfos()) {
Profile p = (Profile) mss.getVal(STACK);

// p.filterUp(new ProfileNodeFilter() {
Expand All @@ -67,7 +65,7 @@ public ThreadDump map(final ThreadDump jsd) {
}
ThreadDump jsd2 = new ThreadDump();
jsd2.setHeader(jsd.getHeader());
jsd2.setStacks(aggr.getAggrInfos());
jsd2.setThreadInfos(aggr.getAggrInfos());
jsd2.setJNIglobalReferences(jsd.getJNIglobalReferences());
return jsd2;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public ThreadDump map(ThreadDump jsd) {
that.setHeader(jsd.getHeader());
that.setJNIglobalReferences(jsd.getJNIglobalReferences());
ArrayList<ThreadInfo> stcks = new ArrayList<>();
for (ThreadInfo stk : jsd.getStacks()) {
for (ThreadInfo stk : jsd.getThreadInfos()) {
stcks.add(map(stk));
}
that.setStacks(stcks);
that.setThreadInfos(stcks);
return that;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class StackTreeMerger implements Terminal, PipeHandler<ThreadDump, String
protected Profile st = new Profile();

public void addStackDump(ThreadDump jsd) {
for (ThreadInfo mss : jsd.getStacks()) {
for (ThreadInfo mss : jsd.getThreadInfos()) {
st.addMulti((Profile) mss.getVal(ThreadInfoProps.STACK)); // System.out.println();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
public class ThreadDumpGuiViewer extends JPanel implements TreeSelectionListener {
ThreadDump toDisplay;
private JTree tree;
private final JTree tree;

//Optionally play with line styles. Possible values are
//"Angled" (the default), "Horizontal", and "None".
Expand Down Expand Up @@ -77,21 +77,21 @@ public void valueChanged(TreeSelectionEvent e) {

if (node == null) return;

Object nodeInfo = node.getUserObject();
node.getUserObject();

}


private void createNodes(DefaultMutableTreeNode top) {
for (ThreadInfo ti : toDisplay.getStacks()) {
for (ThreadInfo ti : toDisplay.getThreadInfos()) {
DefaultMutableTreeNode tgui = createThreadProfile(ti);

top.add(tgui);
}

}

class Vis implements ProfileVisitor {
static class Vis implements ProfileVisitor {
HashMap<Integer, DefaultMutableTreeNode> parents = new HashMap<>();

public Vis(DefaultMutableTreeNode thread) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class CountThreads implements Terminal, PipeHandler<ThreadDump, String> {
@Override
public String handleMsg(ThreadDump msg) {
int count = 0;
for (ThreadInfo mss : msg.getStacks()) {
for (ThreadInfo mss : msg.getThreadInfos()) {
int inc = mss.getVal("count") == null ? 1 : (Integer) mss.getVal("count");

count += inc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class FlatFrames implements Terminal,PipeHandler<ThreadDump,String> {


public void addStackDump(ThreadDump jsd) {
for (ThreadInfo mss : jsd.getStacks() ) {
for (ThreadInfo mss : jsd.getThreadInfos() ) {
Profile p = (Profile) mss.getVal(STACK);
p.visit((stackframe, level) -> {
if (stackframe.getNumChildren() ==0 && stackframe.getStackFrame() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ public String toString() {

@Override
public String handleMsg(ThreadDump threadDump) {
for (ThreadInfo threadInfo : threadDump.getStacks()) {
for (String prop : threadInfo.getProps()) {
propsHash.add(prop);
}
for (ThreadInfo threadInfo : threadDump.getThreadInfos()) {
propsHash.addAll(threadInfo.getProps());
}
return null;
}
Expand Down

0 comments on commit 6b409d4

Please sign in to comment.