Skip to content

Commit

Permalink
moved profiler interface to dataset module
Browse files Browse the repository at this point in the history
  • Loading branch information
ennerf committed Aug 20, 2023
1 parent 6dca43e commit 55df734
Show file tree
Hide file tree
Showing 14 changed files with 227 additions and 199 deletions.
6 changes: 3 additions & 3 deletions chartfx-chart/src/main/java/io/fair_acc/chartfx/Chart.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import java.util.function.Consumer;
import java.util.stream.Collectors;

import io.fair_acc.chartfx.profiler.DurationMeasure;
import io.fair_acc.chartfx.profiler.Profileable;
import io.fair_acc.chartfx.profiler.Profiler;
import io.fair_acc.dataset.profiler.DurationMeasure;
import io.fair_acc.dataset.profiler.Profileable;
import io.fair_acc.dataset.profiler.Profiler;
import io.fair_acc.chartfx.ui.css.*;
import io.fair_acc.chartfx.ui.layout.TitleLabel;
import io.fair_acc.chartfx.ui.layout.ChartPane;
Expand Down
10 changes: 2 additions & 8 deletions chartfx-chart/src/main/java/io/fair_acc/chartfx/axes/Axis.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
package io.fair_acc.chartfx.axes;

import java.util.List;

import io.fair_acc.chartfx.profiler.Profileable;
import io.fair_acc.chartfx.profiler.Profiler;
import io.fair_acc.dataset.profiler.Profileable;
import io.fair_acc.dataset.profiler.Profiler;
import io.fair_acc.chartfx.ui.css.LineStyle;
import io.fair_acc.chartfx.ui.css.TextStyle;
import io.fair_acc.dataset.events.BitState;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.ObservableList;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.util.StringConverter;

import io.fair_acc.chartfx.axes.spi.AxisRange;
import io.fair_acc.chartfx.axes.spi.MetricPrefix;
import io.fair_acc.chartfx.axes.spi.TickMark;
import io.fair_acc.chartfx.ui.geometry.Side;
import io.fair_acc.dataset.AxisDescription;
import io.fair_acc.dataset.event.UpdateEvent;

public interface Axis extends AxisDescription, Profileable {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import java.util.Objects;

import io.fair_acc.chartfx.axes.AxisLabelOverlapPolicy;
import io.fair_acc.chartfx.profiler.DurationMeasure;
import io.fair_acc.chartfx.profiler.Profileable;
import io.fair_acc.chartfx.profiler.Profiler;
import io.fair_acc.dataset.profiler.DurationMeasure;
import io.fair_acc.dataset.profiler.Profileable;
import io.fair_acc.dataset.profiler.Profiler;
import io.fair_acc.chartfx.ui.css.LineStyle;
import io.fair_acc.chartfx.ui.css.TextStyle;
import io.fair_acc.chartfx.utils.FXUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
import io.fair_acc.chartfx.XYChart;
import io.fair_acc.chartfx.marker.DefaultMarker;
import io.fair_acc.chartfx.plugins.Zoomer;
import io.fair_acc.chartfx.profiler.DurationMeasure.SimpleDurationMeasure;
import io.fair_acc.dataset.profiler.DurationMeasure;
import io.fair_acc.dataset.profiler.SimpleDurationMeasure;
import io.fair_acc.chartfx.renderer.LineStyle;
import io.fair_acc.chartfx.renderer.Renderer;
import io.fair_acc.chartfx.renderer.spi.AbstractRendererXY;
import io.fair_acc.chartfx.renderer.spi.ErrorDataSetRenderer;
import io.fair_acc.dataset.DataSet;
import io.fair_acc.dataset.events.BitState;
import io.fair_acc.dataset.events.ChartBits;
import io.fair_acc.dataset.profiler.Profiler;
import io.fair_acc.dataset.spi.AbstractDataSet;
import io.fair_acc.dataset.spi.fastutil.DoubleArrayList;
import io.fair_acc.dataset.utils.DoubleCircularBuffer;
Expand All @@ -29,15 +31,15 @@
*/
public class ChartProfiler implements Profiler {

public static Profiler showInNewStage(String title) {
public static ChartProfiler showInNewStage(String title) {
return createChart(title, chart -> {
var stage = new Stage();
stage.setScene(new Scene(chart));
stage.show();
});
}

private static Profiler createChart(String title, Consumer<XYChart> onChart) {
private static ChartProfiler createChart(String title, Consumer<XYChart> onChart) {
var chart = new XYChart();
chart.setTitle("Profiler: " + title);
chart.getXAxis().setTimeAxis(false);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.fair_acc.chartfx.profiler;

import io.fair_acc.dataset.profiler.DurationMeasure;
import io.fair_acc.dataset.profiler.Profiler;
import io.fair_acc.dataset.profiler.SimpleDurationMeasure;
import io.fair_acc.dataset.utils.AssertUtils;
import org.HdrHistogram.Histogram;
import org.HdrHistogram.HistogramLogWriter;
Expand Down Expand Up @@ -111,7 +114,7 @@ public void close() {
private final ScheduledFuture<?> task;
private final ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);

static class HdrHistogramMeasure extends DurationMeasure.SimpleDurationMeasure {
static class HdrHistogramMeasure extends SimpleDurationMeasure {

HdrHistogramMeasure(final String tag) {
super(System::nanoTime);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.fair_acc.chartfx.profiler;

import io.fair_acc.dataset.profiler.Profiler;

import java.util.concurrent.TimeUnit;

/**
* Convenience methods for creating commonly used profilers
*
* @author ennerf
*/
public interface Profilers {

/**
* A low-overhead hdr histogram recorder that writes an aggregate histogram to disk once a second.
* Check <a href="http://hdrhistogram.org/">hdrhistogram.org</a> for more information
*
* @param fileName the disk file
* @return hdr histogram profiler
*/
static HdrHistogramProfiler hdrHistogramProfiler(String fileName) {
return HdrHistogramProfiler.createStarted(fileName, 1, TimeUnit.SECONDS);
}

/**
* A profiler that creates a new stage and renders the measures in real time
*
* @param title title of the chart
* @return a chart profiler
*/
static ChartProfiler chartProfiler(String title) {
return ChartProfiler.showInNewStage(title);
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.fair_acc.chartfx.renderer;

import io.fair_acc.chartfx.Chart;
import io.fair_acc.chartfx.profiler.Profileable;
import io.fair_acc.chartfx.profiler.Profiler;
import io.fair_acc.dataset.profiler.Profileable;
import io.fair_acc.dataset.profiler.Profiler;
import io.fair_acc.chartfx.ui.css.DataSetNode;
import javafx.beans.property.BooleanProperty;
import javafx.collections.ObservableList;
Expand All @@ -12,9 +12,6 @@
import io.fair_acc.chartfx.axes.Axis;
import io.fair_acc.dataset.DataSet;

import java.util.ArrayList;
import java.util.List;

/**
* -- generic renderer interface --
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import io.fair_acc.chartfx.Chart;
import io.fair_acc.chartfx.XYChart;
import io.fair_acc.chartfx.axes.Axis;
import io.fair_acc.chartfx.profiler.DurationMeasure;
import io.fair_acc.chartfx.profiler.Profileable;
import io.fair_acc.chartfx.profiler.Profiler;
import io.fair_acc.dataset.profiler.DurationMeasure;
import io.fair_acc.dataset.profiler.Profileable;
import io.fair_acc.dataset.profiler.Profiler;
import io.fair_acc.chartfx.ui.css.DataSetNode;
import io.fair_acc.dataset.DataSet;
import io.fair_acc.dataset.utils.AssertUtils;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.fair_acc.dataset.profiler;

/**
* Gets called before and after an action. May record time.
*
* @author ennerf
*/
public interface DurationMeasure {

/**
* Called when an action begins. Sets the start timestamp.
*/
void start();

/**
* Called when an action is done. Records delta from the start timestamp.
*/
void stop();

/**
* Calling stop without start is typically an invalid call that may throw an
* error. This method explicitly allows it and simply ignores bad measurements.
*
* @return this
*/
default DurationMeasure ignoreMissingStart() {
return this;
}

/**
* A default implementation that does nothing and may be eliminated at runtime
*/
public static final DurationMeasure DISABLED = new DurationMeasure() {
@Override
public void start() {
//no-op
}

@Override
public void stop() {
// no-op
}
};

}
Loading

0 comments on commit 55df734

Please sign in to comment.