Skip to content

Commit

Permalink
Merge branch 'repo' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcc0nn3ll committed Nov 3, 2023
2 parents b621faa + c5909c5 commit 6d61936
Show file tree
Hide file tree
Showing 6 changed files with 998 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>jetty-toolchain</artifactId>
<groupId>org.eclipse.jetty.toolchain</groupId>
<version>1.7</version>
<relativePath>../jetty-toolchain</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>jetty-perf-helper</artifactId>
<packaging>jar</packaging>
<version>1.0.8-SNAPSHOT</version>
<name>Jetty Toolchain :: Performance Helper</name>
<description>Performance/Benchmark Support for Jetty</description>

<scm>
<connection>scm:git:git://github.com/eclipse/jetty.toolchain.git</connection>
<developerConnection>scm:git:ssh://[email protected]/eclipse/jetty.toolchain.git</developerConnection>
<url>https://github.com/eclipse/jetty.toolchain/tree/master/jetty-perf-helper</url>
</scm>

<dependencies>
<dependency>
<groupId>org.hdrhistogram</groupId>
<artifactId>HdrHistogram</artifactId>
<version>2.1.12</version>
</dependency>
</dependencies>

</project>

122 changes: 122 additions & 0 deletions src/main/java/org/eclipse/jetty/toolchain/perf/HistogramSnapshot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
//
// ========================================================================
// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//

package org.eclipse.jetty.toolchain.perf;

import java.util.concurrent.TimeUnit;
import org.HdrHistogram.Histogram;
import org.HdrHistogram.HistogramIterationValue;

public class HistogramSnapshot implements MeasureConverter
{
private final Histogram histogram;
private final long buckets;
private final String name;
private final String unit;
private final MeasureConverter converter;

public HistogramSnapshot(Histogram histogram)
{
this(histogram, 32);
}

public HistogramSnapshot(Histogram histogram, long buckets)
{
this(histogram, buckets, "Measures", "ms", null);
}

public HistogramSnapshot(Histogram histogram, long buckets, String name, String unit, MeasureConverter converter)
{
this.histogram = histogram;
this.buckets = buckets;
this.name = name;
this.unit = unit;
this.converter = converter == null ? this : converter;
}

@Override
public long convert(long measure)
{
return TimeUnit.NANOSECONDS.toMillis(measure);
}

@Override
public String toString()
{
StringBuilder builder = new StringBuilder();

long range = histogram.getMaxValue();

long maxBucketCount = 0;
for (HistogramIterationValue value : histogram.linearBucketValues(range / buckets))
{
long bucketCount = value.getCountAddedInThisIterationStep();
if (bucketCount > maxBucketCount)
maxBucketCount = bucketCount;
}

double previousPercentile = 0;
for (HistogramIterationValue value : histogram.linearBucketValues(range / buckets))
{
long bucketCount = value.getCountAddedInThisIterationStep();

// Draw the ASCII "gaussian" point.
long point = maxBucketCount == 0 ? 0 : Math.round((double)bucketCount / maxBucketCount * buckets);
if (point == buckets)
--point;
for (long j = 0; j < point; ++j)
builder.append(" ");
builder.append("@");
for (long j = point + 1; j < buckets; ++j)
builder.append(" ");

// Print the measure and its frequency.
builder.append(" _ ");
builder.append(String.format("%,d %s (%d, %.2f%%)",
converter.convert(value.getValueIteratedTo()),
unit,
bucketCount,
100D * bucketCount / histogram.getTotalCount()));
double percentile = value.getPercentile();
if (previousPercentile < 50D && percentile >= 50D)
builder.append(" ^50%");
if (previousPercentile < 85D && percentile >= 85D)
builder.append(" ^85%");
if (previousPercentile < 95D && percentile >= 95D)
builder.append(" ^95%");
if (previousPercentile < 99D && percentile >= 99D)
builder.append(" ^99%");
if (previousPercentile < 99.9D && percentile >= 99.9D)
builder.append(" ^99.9%");
previousPercentile = percentile;
builder.append(System.lineSeparator());
}

builder.append(String.format("%s: %d samples | min/avg/50th%%/99th%%/max = %,d/%,d/%,d/%,d/%,d %s",
name,
histogram.getTotalCount(),
converter.convert(histogram.getMinValue()),
converter.convert(Math.round(histogram.getMean())),
converter.convert(histogram.getValueAtPercentile(50D)),
converter.convert(histogram.getValueAtPercentile(99D)),
converter.convert(histogram.getMaxValue()),
unit));

return builder.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// ========================================================================
// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//

package org.eclipse.jetty.toolchain.perf;

public interface MeasureConverter
{
public long convert(long measure);
}
Loading

0 comments on commit 6d61936

Please sign in to comment.