Skip to content

Commit

Permalink
Improved decompilation highlighting in chart
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswhocodes committed Aug 27, 2015
1 parent 22c6568 commit 41a19ab
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 76 deletions.
Expand Up @@ -70,7 +70,7 @@ private void processParseTag(Tag parseTag, CompileNode parentNode, IParseDiction
for (Tag child : parseTag.getChildren()) for (Tag child : parseTag.getChildren())
{ {
String tagName = child.getName(); String tagName = child.getName();
Map<String, String> tagAttrs = child.getAttrs(); Map<String, String> tagAttrs = child.getAttributes();


switch (tagName) switch (tagName)
{ {
Expand Down
Expand Up @@ -669,8 +669,8 @@ private void renameCompilationCompletedTimestamp(Tag tag)


if (compilationCompletedStamp != null) if (compilationCompletedStamp != null)
{ {
tag.getAttrs().remove(ATTR_STAMP); tag.getAttributes().remove(ATTR_STAMP);
tag.getAttrs().put(ATTR_STAMP_COMPLETED, compilationCompletedStamp); tag.getAttributes().put(ATTR_STAMP_COMPLETED, compilationCompletedStamp);
} }
} }


Expand Down Expand Up @@ -721,7 +721,7 @@ private void handleTagTask(Tag tag)
// copy timestamp from parent <task> tag used for graphing code // copy timestamp from parent <task> tag used for graphing code
// cache // cache
String stamp = tag.getAttribute(ATTR_STAMP); String stamp = tag.getAttribute(ATTR_STAMP);
tagCodeCache.getAttrs().put(ATTR_STAMP, stamp); tagCodeCache.getAttributes().put(ATTR_STAMP, stamp);


model.addCodeCacheTag(tagCodeCache); model.addCodeCacheTag(tagCodeCache);
} }
Expand All @@ -736,7 +736,7 @@ private void handleTagTask(Tag tag)


private void handleMethodLine(Tag tag, EventType eventType) private void handleMethodLine(Tag tag, EventType eventType)
{ {
Map<String, String> attrs = tag.getAttrs(); Map<String, String> attrs = tag.getAttributes();


String attrMethod = attrs.get(ATTR_METHOD); String attrMethod = attrs.get(ATTR_METHOD);


Expand Down Expand Up @@ -798,7 +798,7 @@ private IMetaMember handleMember(String signature, Map<String, String> attrs, Ev


private void handleTaskDone(Tag tag) private void handleTaskDone(Tag tag)
{ {
Map<String, String> attrs = tag.getAttrs(); Map<String, String> attrs = tag.getAttributes();


if (attrs.containsKey("nmsize")) if (attrs.containsKey("nmsize"))
{ {
Expand Down
Expand Up @@ -68,7 +68,7 @@ public void visitTag(Tag parseTag, IParseDictionary parseDictionary) throws LogP
for (Tag childTag : allChildren) for (Tag childTag : allChildren)
{ {
String tagName = childTag.getName(); String tagName = childTag.getName();
Map<String, String> attrs = childTag.getAttrs(); Map<String, String> attrs = childTag.getAttributes();


switch (tagName) switch (tagName)
{ {
Expand Down
Expand Up @@ -70,7 +70,7 @@ private void processParseTag(Tag parseTag, IParseDictionary parseDictionary)
for (Tag child : parseTag.getChildren()) for (Tag child : parseTag.getChildren())
{ {
String tagName = child.getName(); String tagName = child.getName();
Map<String, String> attrs = child.getAttrs(); Map<String, String> attrs = child.getAttributes();


switch (tagName) switch (tagName)
{ {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/adoptopenjdk/jitwatch/model/Journal.java
Expand Up @@ -43,8 +43,8 @@ public List<Tag> getEntryList()
@Override @Override
public int compare(Tag tag1, Tag tag2) public int compare(Tag tag1, Tag tag2)
{ {
long ts1 = ParseUtil.getStamp(tag1.getAttrs()); long ts1 = ParseUtil.getStamp(tag1.getAttributes());
long ts2 = ParseUtil.getStamp(tag2.getAttrs()); long ts2 = ParseUtil.getStamp(tag2.getAttributes());


return Long.compare(ts1, ts2); return Long.compare(ts1, ts2);
} }
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/org/adoptopenjdk/jitwatch/model/Tag.java
Expand Up @@ -107,7 +107,7 @@ public List<Tag> getNamedChildrenWithAttribute(String tagName, String attrName,
{ {
if (child.getName().equals(tagName)) if (child.getName().equals(tagName))
{ {
if (child.getAttrs().containsKey(attrName) && child.getAttribute(attrName).equals(attrValue)) if (child.containsAttribute(attrName) && child.getAttribute(attrName).equals(attrValue))
{ {
result.add(child); result.add(child);
} }
Expand All @@ -131,8 +131,13 @@ public String getName()
{ {
return name; return name;
} }

public boolean containsAttribute(String name)
{
return attrs.containsKey(name);
}


public Map<String, String> getAttrs() public Map<String, String> getAttributes()
{ {
return attrs; return attrs;
} }
Expand Down
Expand Up @@ -314,7 +314,7 @@ private void buildParseTagAnnotations(Tag parseTag, BytecodeAnnotations annotati
for (Tag child : children) for (Tag child : children)
{ {
String name = child.getName(); String name = child.getName();
Map<String, String> tagAttrs = child.getAttrs(); Map<String, String> tagAttrs = child.getAttributes();


if (DEBUG_LOGGING) if (DEBUG_LOGGING)
{ {
Expand Down
Expand Up @@ -172,7 +172,7 @@ private void processParseTag(Tag parseTag, IMetaMember caller, IParseDictionary
for (Tag child : parseTag.getChildren()) for (Tag child : parseTag.getChildren())
{ {
String tagName = child.getName(); String tagName = child.getName();
Map<String, String> attrs = child.getAttrs(); Map<String, String> attrs = child.getAttributes();


switch (tagName) switch (tagName)
{ {
Expand Down
Expand Up @@ -51,7 +51,7 @@ private void processParseTag(Tag parseTag)
for (Tag child : parseTag.getChildren()) for (Tag child : parseTag.getChildren())
{ {
String tagName = child.getName(); String tagName = child.getName();
Map<String, String> attrs = child.getAttrs(); Map<String, String> attrs = child.getAttributes();


logger.info("processParseTag {}", child.toString(false)); logger.info("processParseTag {}", child.toString(false));


Expand Down
Expand Up @@ -228,7 +228,7 @@ private void drawYAxis()


protected double getApproximateStringWidth(String text) protected double getApproximateStringWidth(String text)
{ {
return text.length() * gc.getFont().getSize() * 0.5; return text.length() * gc.getFont().getSize() * 0.6;
} }


protected double getStringHeight() protected double getStringHeight()
Expand Down
Expand Up @@ -124,14 +124,14 @@ else if (freeCodeCache < minY)


private long getStampFromTag(Tag tag) private long getStampFromTag(Tag tag)
{ {
Map<String, String> attrs = tag.getAttrs(); Map<String, String> attrs = tag.getAttributes();
return ParseUtil.parseStamp(attrs.get(JITWatchConstants.ATTR_STAMP)); return ParseUtil.parseStamp(attrs.get(JITWatchConstants.ATTR_STAMP));


} }


private long getFreeCodeCacheFromTag(Tag tag) private long getFreeCodeCacheFromTag(Tag tag)
{ {
Map<String, String> attrs = tag.getAttrs(); Map<String, String> attrs = tag.getAttributes();
return Long.parseLong(attrs.get(JITWatchConstants.ATTR_FREE_CODE_CACHE)); return Long.parseLong(attrs.get(JITWatchConstants.ATTR_FREE_CODE_CACHE));
} }
} }
102 changes: 62 additions & 40 deletions src/main/java/org/adoptopenjdk/jitwatch/ui/graphing/TimeLineStage.java
Expand Up @@ -30,7 +30,6 @@
import org.adoptopenjdk.jitwatch.model.Tag; import org.adoptopenjdk.jitwatch.model.Tag;
import org.adoptopenjdk.jitwatch.ui.JITWatchUI; import org.adoptopenjdk.jitwatch.ui.JITWatchUI;
import org.adoptopenjdk.jitwatch.util.ParseUtil; import org.adoptopenjdk.jitwatch.util.ParseUtil;
import org.adoptopenjdk.jitwatch.util.StringUtil;
import org.adoptopenjdk.jitwatch.util.UserInterfaceUtil; import org.adoptopenjdk.jitwatch.util.UserInterfaceUtil;


public class TimeLineStage extends AbstractGraphStage public class TimeLineStage extends AbstractGraphStage
Expand All @@ -40,7 +39,7 @@ public class TimeLineStage extends AbstractGraphStage
private int selectedTagIndex = 0; private int selectedTagIndex = 0;
private static final double MARKET_DIAMETER = 10; private static final double MARKET_DIAMETER = 10;
private boolean labelLeft = true; private boolean labelLeft = true;

public TimeLineStage(final JITWatchUI parent) public TimeLineStage(final JITWatchUI parent)
{ {
super(parent, JITWatchUI.WINDOW_WIDTH, JITWatchUI.WINDOW_HEIGHT, true); super(parent, JITWatchUI.WINDOW_WIDTH, JITWatchUI.WINDOW_HEIGHT, true);
Expand Down Expand Up @@ -122,8 +121,8 @@ public int compare(JITEvent e1, JITEvent e2)


minX = 0; minX = 0;
maxX = events.get(events.size() - 1).getStamp(); maxX = events.get(events.size() - 1).getStamp();
maxX *= 1.1; maxX *= 1.2;

minY = 0; minY = 0;


calculateMaxCompiles(events); calculateMaxCompiles(events);
Expand Down Expand Up @@ -154,7 +153,7 @@ private void drawMemberEvents(long stamp, double yPos)


Tag nextJournalEvent = selectedMemberJournalTags.get(selectedTagIndex); Tag nextJournalEvent = selectedMemberJournalTags.get(selectedTagIndex);


long journalEventTime = ParseUtil.getStamp(nextJournalEvent.getAttrs()); long journalEventTime = ParseUtil.getStamp(nextJournalEvent.getAttributes());


if (journalEventTime == stamp) if (journalEventTime == stamp)
{ {
Expand All @@ -176,21 +175,46 @@ private void drawMemberEvents(long stamp, double yPos)


if (labelLeft) if (labelLeft)
{ {
labelX = blobX - getApproximateStringWidth(label) - 8; labelX = blobX - getApproximateStringWidth(label) - 16;
labelY = Math.min(blobY - getStringHeight() - 8, graphGapTop + chartHeight - 32); labelY = Math.min(blobY - getStringHeight(), graphGapTop + chartHeight - 32);


} }
else else
{ {
labelX = blobX + 16; labelX = blobX + 16;
labelY = Math.min(blobY, graphGapTop + chartHeight - 32); labelY = Math.min(blobY, graphGapTop + chartHeight - 32);
} }

labelLeft = !labelLeft; labelLeft = !labelLeft;


drawLabel(label, labelX, labelY); drawLabel(label, labelX, labelY, getLabelColour(nextJournalEvent));
} }
} }

private Color getLabelColour(Tag tag)
{
Color result = Color.WHITE;

String tagName = tag.getName();

if (TAG_NMETHOD.equals(tagName))
{
if (tag.containsAttribute(ATTR_DECOMPILES))
{
result = Color.ORANGERED;
}
else
{
result = Color.LIMEGREEN;
}
}
else if (TAG_TASK_QUEUED.equals(tagName))
{
result = Color.YELLOW;
}

return result;
}


private void showSelectedMemberLabel() private void showSelectedMemberLabel()
{ {
Expand All @@ -202,13 +226,18 @@ private void showSelectedMemberLabel()
} }


private void drawLabel(String text, double xPos, double yPos) private void drawLabel(String text, double xPos, double yPos)
{
drawLabel(text, xPos, yPos, Color.WHITE);
}

private void drawLabel(String text, double xPos, double yPos, Color backgroundColour)
{ {
double boxPad = 4; double boxPad = 4;


double boxWidth = getApproximateStringWidth(text) + boxPad * 2; double boxWidth = getApproximateStringWidth(text) + boxPad * 2;
double boxHeight = getStringHeight() + boxPad * 2; double boxHeight = getStringHeight() + boxPad * 2;


gc.setFill(Color.WHITE); gc.setFill(backgroundColour);


setStrokeForAxis(); setStrokeForAxis();
gc.fillRect(fix(xPos), fix(yPos), fix(boxWidth), fix(boxHeight)); gc.fillRect(fix(xPos), fix(yPos), fix(boxWidth), fix(boxHeight));
Expand All @@ -226,40 +255,37 @@ private String buildLabel(Tag nextJournalEvent, long journalEventTime)


if (TAG_TASK_QUEUED.equals(tagName)) if (TAG_TASK_QUEUED.equals(tagName))
{ {
selectedItemBuilder.append("Queued at "); selectedItemBuilder.append("Queued");
selectedItemBuilder.append(StringUtil.formatTimestamp((long) journalEventTime, true));
} }
else else
{ {
if (nextJournalEvent.getAttribute(ATTR_DECOMPILES) != null) if (nextJournalEvent.getAttribute(ATTR_DECOMPILES) != null)
{ {
selectedItemBuilder.append("Recompiled at "); selectedItemBuilder.append("Recompiled");
} }
else else
{ {
selectedItemBuilder.append("Compiled at "); selectedItemBuilder.append("Compiled");
} }


selectedItemBuilder.append(StringUtil.formatTimestamp((long) journalEventTime, true));

String compiler = nextJournalEvent.getAttribute(ATTR_COMPILER); String compiler = nextJournalEvent.getAttribute(ATTR_COMPILER);

if (compiler == null) if (compiler == null)
{ {
compiler = "unknown!"; compiler = "unknown!";
} }

selectedItemBuilder.append(" by ").append(compiler); selectedItemBuilder.append(" by ").append(compiler);

String compileKind = nextJournalEvent.getAttribute(ATTR_COMPILE_KIND); String compileKind = nextJournalEvent.getAttribute(ATTR_COMPILE_KIND);

if (compileKind != null) if (compileKind != null)
{ {
selectedItemBuilder.append(C_OPEN_PARENTHESES).append(compileKind.toUpperCase()).append(C_CLOSE_PARENTHESES); selectedItemBuilder.append(C_SPACE).append(C_OPEN_PARENTHESES).append(compileKind.toUpperCase()).append(C_CLOSE_PARENTHESES);
} }

String level = nextJournalEvent.getAttribute(ATTR_LEVEL); String level = nextJournalEvent.getAttribute(ATTR_LEVEL);

if (level != null) if (level != null)
{ {
selectedItemBuilder.append(" (Level ").append(level).append(C_CLOSE_PARENTHESES); selectedItemBuilder.append(" (Level ").append(level).append(C_CLOSE_PARENTHESES);
Expand Down Expand Up @@ -287,29 +313,25 @@ private void drawEvents(List<JITEvent> events)


for (JITEvent event : events) for (JITEvent event : events)
{ {
// if (event.getEventType() != EventType.QUEUE) long stamp = event.getStamp();
{

long stamp = event.getStamp();


cumC++; cumC++;


double x = graphGapLeft + normaliseX(stamp); double x = graphGapLeft + normaliseX(stamp);


double y = graphGapTop + normaliseY(cumC); double y = graphGapTop + normaliseY(cumC);


if (selectedMemberJournalTags.size() > 0) if (selectedMemberJournalTags.size() > 0)
{ {
drawMemberEvents(stamp, y); drawMemberEvents(stamp, y);
} }


gc.setStroke(colourMarker); gc.setStroke(colourMarker);
gc.setLineWidth(2); gc.setLineWidth(2);
gc.strokeLine(fix(lastCX), fix(lastCY), fix(x), fix(y)); gc.strokeLine(fix(lastCX), fix(lastCY), fix(x), fix(y));


lastCX = x; lastCX = x;
lastCY = y; lastCY = y;
}
} }


showStatsLegend(gc); showStatsLegend(gc);
Expand Down
Expand Up @@ -11,6 +11,7 @@
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.text.Font;


import org.adoptopenjdk.jitwatch.model.bytecode.BCAnnotationType; import org.adoptopenjdk.jitwatch.model.bytecode.BCAnnotationType;
import org.slf4j.Logger; import org.slf4j.Logger;
Expand All @@ -34,7 +35,7 @@ private UserInterfaceUtil()
{ {
IMAGE_TICK = loadResource("/images/tick.png"); IMAGE_TICK = loadResource("/images/tick.png");


FONT_MONOSPACE_FAMILY = System.getProperty("monospaceFontFamily", "monospace"); FONT_MONOSPACE_FAMILY = System.getProperty("monospaceFontFamily", Font.font(java.awt.Font.MONOSPACED, 12).getName());
FONT_MONOSPACE_SIZE = System.getProperty("monospaceFontSize", "12"); FONT_MONOSPACE_SIZE = System.getProperty("monospaceFontSize", "12");
} }


Expand Down

0 comments on commit 41a19ab

Please sign in to comment.