Skip to content

Commit

Permalink
JIT timeline shows all compile events per method including recompiles
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswhocodes committed Aug 26, 2015
1 parent 23d69b6 commit 22c6568
Show file tree
Hide file tree
Showing 18 changed files with 417 additions and 161 deletions.
19 changes: 16 additions & 3 deletions src/main/java/org/adoptopenjdk/jitwatch/core/HotSpotLogParser.java
Expand Up @@ -10,6 +10,7 @@
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_METHOD;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_NAME;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_STAMP;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_STAMP_COMPLETED;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.C1;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.C2;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.C2N;
Expand Down Expand Up @@ -662,9 +663,22 @@ private void handleTagQueued(Tag tag)
handleMethodLine(tag, EventType.QUEUE);
}

private void renameCompilationCompletedTimestamp(Tag tag)
{
String compilationCompletedStamp = tag.getAttribute(ATTR_STAMP);

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

private void handleTagNMethod(Tag tag)
{
String attrCompiler = tag.getAttribute(ATTR_COMPILER);

renameCompilationCompletedTimestamp(tag);

if (attrCompiler != null)
{
Expand Down Expand Up @@ -742,9 +756,8 @@ private void handleMethodLine(Tag tag, EventType eventType)
private IMetaMember handleMember(String signature, Map<String, String> attrs, EventType type)
{
IMetaMember metaMember = findMemberWithSignature(signature);

String stampAttr = attrs.get(ATTR_STAMP);
long stampTime = ParseUtil.parseStamp(stampAttr);

long stampTime = ParseUtil.getStamp(attrs);

if (metaMember != null)
{
Expand Down
Expand Up @@ -106,10 +106,12 @@ private JITWatchConstants()
public static final String ATTR_COMPILE_ID = "compile_id";
public static final String ATTR_COMPILE_KIND = "compile_kind";
public static final String ATTR_STAMP = "stamp";
public static final String ATTR_STAMP_COMPLETED = "stamp_completed";
public static final String ATTR_NAME = "name";
public static final String ATTR_BCI = "bci";
public static final String ATTR_CODE = "code";
public static final String ATTR_COMPILER = "compiler";
public static final String ATTR_LEVEL = "level";
public static final String ATTR_FREE_CODE_CACHE = "free_code_cache";
public static final String ATTR_NMSIZE = "nmsize";
public static final String ATTR_BYTES = "bytes";
Expand Down
17 changes: 5 additions & 12 deletions src/main/java/org/adoptopenjdk/jitwatch/model/IMetaMember.java
Expand Up @@ -14,8 +14,6 @@

public interface IMetaMember
{
List<String> getQueuedAttributes();

MetaClass getMetaClass();

MemberBytecode getMemberBytecode();
Expand All @@ -26,21 +24,16 @@ public interface IMetaMember
Journal getJournal();

String getQueuedAttribute(String key);

List<String> getCompiledAttributes();

String getCompiledAttribute(String key);

void addCompiledAttribute(String key, String value);

List<String> getQueuedAttributes();
void setQueuedAttributes(Map<String, String> queuedAttributes);

boolean isQueued();

//TODO split task and nmethod attrs?
void setCompiledAttributes(Map<String, String> compiledAttributes);

void addCompiledAttributes(Map<String, String> additionalAttrs);

String getCompiledAttribute(String key);
List<String> getCompiledAttributes();
void addCompiledAttribute(String key, String value);
boolean isCompiled();

String toStringUnqualifiedMethodName(boolean fqParamTypes);
Expand Down
Expand Up @@ -98,15 +98,15 @@ public JITStats getJITStats()

// ugly but better than using COWAL with so many writes
public void addEvent(JITEvent event)
{
{
synchronized (jitEvents)
{
jitEvents.add(event);
}
}

@Override
public synchronized List<JITEvent> getEventListCopy()
public List<JITEvent> getEventListCopy()
{
synchronized (jitEvents)
{
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/adoptopenjdk/jitwatch/model/JITEvent.java
Expand Up @@ -5,9 +5,10 @@
*/
package org.adoptopenjdk.jitwatch.model;

import org.adoptopenjdk.jitwatch.util.StringUtil;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.C_COLON;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.C_SPACE;

import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.*;
import org.adoptopenjdk.jitwatch.util.StringUtil;

public class JITEvent
{
Expand Down
Expand Up @@ -258,7 +258,7 @@ public long getTotalCompileTime()

public long getTotalCompiledMethods()
{
return countC1 + countC2 + countC2N + countOSR;
return countC1 + countC2 + countC2N;
}

public long getNativeBytes()
Expand Down
25 changes: 19 additions & 6 deletions src/main/java/org/adoptopenjdk/jitwatch/model/Journal.java
Expand Up @@ -5,10 +5,14 @@
*/
package org.adoptopenjdk.jitwatch.model;

import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.C_NEWLINE;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.adoptopenjdk.jitwatch.core.JITWatchConstants;
import org.adoptopenjdk.jitwatch.util.ParseUtil;

public class Journal
{
Expand All @@ -34,6 +38,18 @@ public List<Tag> getEntryList()
{
List<Tag> copy = new ArrayList<>(entryList);

Collections.sort(copy, new Comparator<Tag>()
{
@Override
public int compare(Tag tag1, Tag tag2)
{
long ts1 = ParseUtil.getStamp(tag1.getAttrs());
long ts2 = ParseUtil.getStamp(tag2.getAttrs());

return Long.compare(ts1, ts2);
}
});

return copy;
}
}
Expand All @@ -43,12 +59,9 @@ public String toString()
{
StringBuilder builder = new StringBuilder();

synchronized (entryList)
for (Tag tag : getEntryList())
{
for (Tag tag : entryList)
{
builder.append(tag.toString(true)).append(JITWatchConstants.C_NEWLINE);
}
builder.append(tag.toString(true)).append(C_NEWLINE);
}

return builder.toString();
Expand Down
Expand Up @@ -32,7 +32,7 @@ public InliningFailReasonTopListVisitable(IReadOnlyJITDataModel model, boolean s

@Override
public void visit(IMetaMember metaMember)
{
{
if (metaMember != null && metaMember.isCompiled())
{
try
Expand All @@ -52,6 +52,9 @@ private void processParseTag(Tag parseTag)
{
String tagName = child.getName();
Map<String, String> attrs = child.getAttrs();

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


switch (tagName)
{
Expand Down
Expand Up @@ -17,7 +17,7 @@ public AttributeTableRow(String type, String name, String value)
{
this.type = type;
this.name = name;
this.value = StringUtil.formatThousands(value);
this.value = StringUtil.replaceXMLEntities(value);
}

public String getType()
Expand Down
Expand Up @@ -50,7 +50,7 @@ public void handle(WindowEvent arg0)
int maxLineLength = 0;

List<Label> labels = new ArrayList<>();

for (Tag tag : journal.getEntryList())
{
String[] tagLines = tag.toString().split(S_NEWLINE);
Expand Down
Expand Up @@ -8,25 +8,28 @@
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.EventHandler;
import javafx.geometry.VPos;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.WindowEvent;

import org.adoptopenjdk.jitwatch.ui.JITWatchUI;
import org.adoptopenjdk.jitwatch.util.StringUtil;
import org.adoptopenjdk.jitwatch.util.UserInterfaceUtil;

public abstract class AbstractGraphStage extends Stage
{
protected Canvas canvas;
protected GraphicsContext gc;
protected JITWatchUI parent;

protected static double graphGapLeft = 20.5;
protected static final double graphGapRight = 20.5;
protected static final double graphGapTop = 20.5;
protected double graphGapLeft = 20.5;
protected final double graphGapRight = 20.5;
protected final double graphGapTop = 20.5;

protected static final int[] Y_SCALE = new int[21];

Expand All @@ -46,6 +49,12 @@ public abstract class AbstractGraphStage extends Stage
protected long maxYQ;

private boolean xAxisTime = false;

protected static final Font STANDARD_FONT = new Font(UserInterfaceUtil.FONT_MONOSPACE_FAMILY,
Double.valueOf(UserInterfaceUtil.FONT_MONOSPACE_SIZE));

protected static final Font MEMBER_FONT = new Font(UserInterfaceUtil.FONT_MONOSPACE_FAMILY,
Double.valueOf(UserInterfaceUtil.FONT_MONOSPACE_SIZE) * 2.0);

static
{
Expand Down Expand Up @@ -101,15 +110,21 @@ public void changed(ObservableValue<? extends Number> arg0, Number arg1, Number

protected void baseRedraw()
{
gc.setFont(STANDARD_FONT);

width = canvas.getWidth();
height = canvas.getHeight();
chartWidth = width - graphGapLeft - graphGapRight;
chartHeight = height - graphGapTop * 2;

setStrokeForAxis();

gc.setFill(Color.WHITE);
gc.fillRect(0, 0, width, height);

gc.setFill(Color.rgb(210, 255, 255));
gc.fillRect(graphGapLeft, graphGapTop, chartWidth, chartHeight);

gc.setStroke(Color.BLACK);
gc.strokeRect(graphGapLeft, graphGapTop, chartWidth, chartHeight);
}
Expand Down Expand Up @@ -141,11 +156,14 @@ private void drawXAxisTime()
while (gridX <= maxX)
{
double x = graphGapLeft + normaliseX(gridX);

setStrokeForAxis();
gc.strokeLine(fix(x), fix(graphGapTop), fix(x), fix(graphGapTop + chartHeight));

boolean showMillis = maxX < 5000;

gc.strokeText(StringUtil.formatTimestamp(gridX, showMillis), fix(x), fix(graphGapTop + chartHeight + 12));
setStrokeForText();
gc.fillText(StringUtil.formatTimestamp(gridX, showMillis), fix(x), fix(graphGapTop + chartHeight + 2));

gridX += xInc;
}
Expand All @@ -164,8 +182,12 @@ private void drawXAxis()
while (gridX <= maxX)
{
double x = graphGapLeft + normaliseX(gridX);

setStrokeForAxis();
gc.strokeLine(fix(x), fix(graphGapTop), fix(x), fix(graphGapTop + chartHeight));
gc.strokeText(StringUtil.formatThousands(Long.toString(gridX)), fix(x), fix(graphGapTop + chartHeight + 12));

setStrokeForText();
gc.fillText(StringUtil.formatThousands(Long.toString(gridX)), fix(x), fix(graphGapTop + chartHeight + 2));

gridX += xInc;
}
Expand All @@ -192,13 +214,27 @@ private void drawYAxis()
if (gridY >= minYQ)
{
double y = graphGapTop + normaliseY(gridY);

setStrokeForAxis();
gc.strokeLine(fix(graphGapLeft), fix(y), fix(graphGapLeft + chartWidth), fix(y));
gc.strokeText(StringUtil.formatThousands(Long.toString(gridY)), fix(yLabelX), fix(y + 2));

setStrokeForText();
gc.fillText(StringUtil.formatThousands(Long.toString(gridY)), fix(yLabelX), fix(y - getStringHeight() / 2));
}

gridY += yInc;
}
}

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

protected double getStringHeight()
{
return gc.getFont().getSize();
}

private long getXStepTime()
{
Expand Down Expand Up @@ -279,4 +315,18 @@ protected double fix(double pixel)
{
return 0.5 + (int) pixel;
}

protected void setStrokeForAxis()
{
gc.setStroke(Color.BLACK);
gc.setLineWidth(0.5);
}

protected void setStrokeForText()
{
gc.setStroke(Color.BLACK);
gc.setFill(Color.BLACK);
gc.setLineWidth(1.0);
gc.setTextBaseline(VPos.TOP);
}
}
Expand Up @@ -19,7 +19,6 @@
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.StageStyle;

public class CodeCacheStage extends AbstractGraphStage
Expand Down Expand Up @@ -94,7 +93,6 @@ else if (freeCodeCache < minY)
double lastCY = graphGapTop + normaliseY(getFreeCodeCacheFromTag(firstTag));

gc.setStroke(Color.BLACK);
gc.setFont(new Font("monospace", 10));

Color colourLine = Color.BLUE;

Expand All @@ -120,7 +118,7 @@ else if (freeCodeCache < minY)
}
else
{
gc.strokeText("No code cache information in log", fix(10), fix(10));
gc.fillText("No code cache information in log", fix(10), fix(10));
}
}

Expand Down

0 comments on commit 22c6568

Please sign in to comment.