Skip to content

Commit

Permalink
refactor the flame graph view
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardWarburton committed Sep 6, 2015
1 parent 995893b commit 2d9cd10
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 19 deletions.
Expand Up @@ -50,6 +50,11 @@ public List<Method> getMethods()
return methods;
}

public Method at(final int row)
{
return methods.size() > row ? methods.get(row) : null;
}

public void incrementWeight()
{
weight++;
Expand Down
Expand Up @@ -39,10 +39,12 @@
/**
* .
*/
// TODO: compress together method squares if they are the same.
public class FlameGraphCanvas extends Canvas
{
private static final Color START_COLOR = Color.BISQUE.deriveColor(0, 1.2, 1.0, 1.0);

public static final int TEXT_WIDTH = 7;
public static final int ROW_WRAP = 4;
private final Tooltip tooltip = new Tooltip();
private final Window window;

Expand Down Expand Up @@ -99,34 +101,70 @@ public void display(FlameGraph graph)

columnWidth = getWidth() / totalWeight;
rowHeight = getHeight() / maxHeight;
double x = 0;
initialY = getHeight() - rowHeight;

for (FlameTrace stack : traces)
for (int row = 0; row < maxHeight; row++)
{
double stackWidth = stack.getWeight() * columnWidth;
initialY = getHeight() - rowHeight;
double y = initialY;
Color colour = Color.BISQUE;
double y = initialY - (row * rowHeight);
final Color colour = colorAt(row);

for (Method method : stack.getMethods())
for (int col = 0; col < traces.size();)
{
y -= rowHeight;
FlameTrace stack = traces.get(col);
final double stackWidth = stack.getWeight() * columnWidth;

colour = colour.deriveColor(0, 1.05, 1.0, 1.0);
graphics.setFill(colour);
graphics.fillRect(x, y, stackWidth, rowHeight);
Method method = stack.at(row);
final int numberOfConsecutiveTraces = numberOfConsecutiveTracesWith(method, col, row);
double methodWidth = stackWidth * numberOfConsecutiveTraces;

final String title = renderShortMethod(method);
if (title.length() * 7 < stackWidth)
if (method != null)
{
graphics.setFill(Color.ROYALBLUE);
graphics.fillText(title, x, y + 0.75 * rowHeight);
final double x = col * stackWidth;
graphics.setFill(colour);
graphics.fillRect(x, y, methodWidth, rowHeight);

final String title = renderShortMethod(method);
if (!renderText(graphics, x, y, methodWidth, title))
{
renderText(graphics, x, y, methodWidth, method.getMethodName());
}
}

col += numberOfConsecutiveTraces;
}
}
}

private Color colorAt(final int row)
{
return START_COLOR.deriveColor(0, 1.15 * (1 + row % ROW_WRAP), 1.0, 1.0);
}

x += stackWidth;
private boolean renderText(final GraphicsContext graphics,
final double x, final double y,
final double methodWidth,
final String title)
{
if (title.length() * TEXT_WIDTH < methodWidth)
{
graphics.setFill(Color.ROYALBLUE);
graphics.fillText(title, x, y + 0.75 * rowHeight);

return true;
}

return false;
}

private int numberOfConsecutiveTracesWith(
final Method method, final int initialCol, final int row)
{
int col = initialCol;
while (col < traces.size() && traces.get(col).at(row) == method)
{
col++;
}
;
return col - initialCol;
}

public Tooltip getTooltip()
Expand Down
Expand Up @@ -42,7 +42,7 @@ public void start(Stage stage) throws Exception
stage.setWidth(1920);
stage.setHeight(1000);

FlameGraph data = readFlamegraph(new FileLogSource(new File("log-10401-1439827661223.hpl")));
FlameGraph data = readFlamegraph(new FileLogSource(new File("log-7283-1441385361763.hpl")));
Group root = new Group();
FlameGraphCanvas canvas = new FlameGraphCanvas(stage);
canvas.setWidth(1920);
Expand Down

0 comments on commit 2d9cd10

Please sign in to comment.