Example #1
0
 public ColorPane() {
   super();
   Font font = new Font("Monospaced", Font.PLAIN, 12);
   FontMetrics fm = getFontMetrics(font);
   lineHeight = fm.getHeight();
   setFont(font);
   setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
 }
 private void plotSubset(
     final Graphics2D g,
     final int start,
     final int end,
     final String title,
     final double startX,
     final double width,
     final double stepY,
     final double mean) {
   final FontMetrics fm = g.getFontMetrics();
   final Color color = g.getColor();
   g.setColor(Color.black);
   g.drawString(title, (int) (startX + width / 2 - fm.stringWidth(title) / 2), 975);
   final String tmp = String.format("Mean: %.3fus", mean);
   g.drawString(tmp, (int) (startX + width / 2 - fm.stringWidth(tmp) / 2), 990);
   g.setColor(color);
   final double stepX = width / (end - start);
   for (int i = start; i < end; i++) {
     final int posX = (int) (startX + stepX * (i - start));
     final int posY = 960 - ((int) (stepY * (timestamps[i] / 1000.0)) + 1);
     g.drawLine(posX, posY, posX, 960);
   }
 }
  private void generateScatterPlot() throws IOException {
    final BufferedImage image = new BufferedImage(1800, 1000, BufferedImage.TYPE_INT_ARGB);
    final Graphics2D g2 = image.createGraphics();
    final FontMetrics fm = g2.getFontMetrics();
    final String filename = "throughputency.png";
    final File imageFile = new File(filename);

    final int height = 940;
    double min = Double.MAX_VALUE;
    double max = Double.MIN_VALUE;
    for (final long timestamp : timestamps) {
      final double ts = timestamp / 1000.0;
      if (ts < min) {
        min = ts;
      }
      if (ts > max) {
        max = ts;
      }
    }
    final double stepY = height / max;

    g2.setColor(Color.white);
    g2.fillRect(0, 0, 1800, 1000);
    g2.setColor(Color.black);
    g2.setRenderingHint(
        RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2.drawString(
        "Latency ScatterPlot (microseconds)",
        900 - fm.stringWidth("Latency ScatterPlot (microseconds)") / 2,
        20);
    g2.drawString("" + max, 10, 20);
    g2.drawLine(100, 20, 100, 960);
    g2.drawLine(100, 960, 1790, 960);
    int start = 0;
    int end = 100;
    final double width = 1690.0 / 7.0;
    g2.setColor(Color.red);
    plotSubset(g2, start, end, "10 msgs/sec", 100, width, stepY, means[0]);

    start = 100;
    end = 1100;
    g2.setColor(Color.green);
    plotSubset(g2, start, end, "100 msgs/sec", 100 + width, width, stepY, means[1]);

    start = 1100;
    end = 11100;
    g2.setColor(Color.blue);
    plotSubset(g2, start, end, "1K msgs/sec", 100 + width * 2, width, stepY, means[2]);

    start = 11100;
    end = 111100;
    g2.setColor(Color.cyan);
    plotSubset(g2, start, end, "10K msgs/sec", 100 + width * 3, width, stepY, means[3]);

    start = 111100;
    end = 1111100;
    g2.setColor(Color.magenta);
    plotSubset(g2, start, end, "100K msgs/sec", 100 + width * 4, width, stepY, means[4]);

    start = 1111100;
    end = 11111100;
    g2.setColor(Color.yellow);
    plotSubset(g2, start, end, "1M msgs/sec", 100 + width * 5, width, stepY, means[5]);

    start = 11111100;
    end = 41111100;
    g2.setColor(Color.orange);
    plotSubset(g2, start, end, "3M msgs/sec", 100 + width * 6, width, stepY, means[6]);

    ImageIO.write(image, "png", imageFile);
  }