Skip to content

Commit

Permalink
added profileable interface to Axis and Renderer directly to reduce c…
Browse files Browse the repository at this point in the history
…asting
  • Loading branch information
ennerf committed Aug 20, 2023
1 parent 5ac1d50 commit c7c7512
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
5 changes: 2 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 @@ -486,10 +486,8 @@ public void invalidate() {
}

protected void runPreLayout() {
hasRunPreLayout = true;
state.setDirty(dataSetState.clear());
if (state.isClean()) {
benchCssAndLayout.start();
return;
}
benchPreLayout.start();
Expand Down Expand Up @@ -529,6 +527,8 @@ protected void runPreLayout() {
}

benchPreLayout.stop();

hasRunPreLayout = true;
benchCssAndLayout.start();
}

Expand Down Expand Up @@ -573,7 +573,6 @@ protected void runPostLayout() {
benchCssAndLayout.stop();
hasRunPreLayout = false;
}

// nothing to do
if (state.isClean() && !hasLocked) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.List;

import io.fair_acc.chartfx.profiler.Profileable;
import io.fair_acc.chartfx.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;
Expand All @@ -23,7 +25,7 @@
import io.fair_acc.dataset.AxisDescription;
import io.fair_acc.dataset.event.UpdateEvent;

public interface Axis extends AxisDescription {
public interface Axis extends AxisDescription, Profileable {
/**
* This is true when the axis determines its range from the data automatically
*
Expand Down Expand Up @@ -368,4 +370,8 @@ public interface Axis extends AxisDescription {
* transformations with the modified ranges.
*/
default void updateCachedTransforms() {};

default void setProfiler(Profiler profiler) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -406,14 +406,14 @@ private double computePrefSize(final double axisLength) {
return computeMinSize();
}

benchComputePrefSize.start();

// We can cache the existing layout if nothing has changed.
final boolean isHorizontal = getSide().isHorizontal();
if (getLength() == axisLength && state.isClean(ChartBits.AxisLayout)) {
return isHorizontal ? getHeight() : getWidth(); // secondary dimension
}

benchComputePrefSize.start();

// Compute the ticks with correctly placed labels to determine the
// overlap. The initial estimate is usually correct, so later changes
// happen very rarely, e.g., at a point where y axes labels switch to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ public interface DurationMeasurement {

/**
* Called when an action begins. Sets the start timestamp.
*
* @return start time in the used clock
*/
long start();

/**
* Called when an action is done. Records delta from the start timestamp.
*
* @return end time in the used clock
*/
long stop();

/**
* Records the delta from now to the specified start time generated by this measurement.
*
* @return end time in the used clock
*/
long stop(long startTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;

/**
* Creates time traces for benchmarking purposes.
Expand All @@ -24,18 +22,29 @@ public interface Profiler {
/**
* A debug profiler that prints start/stop information and timestamps
*/
/**
* @param logger log output
* @return debug printer
*/
public static Profiler debugPrinter(Consumer<String> logger) {
return tag -> new MeasurementDebugPrinter(tag, logger);
}

/**
* @return debug printer that prints on System.out
*/
public static Profiler debugPrinter() {
return debugPrinter(System.out::println);
}

/**
* 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
*/
public static Profiler newHdrHistogramProfiler(String fileName) {
public static Profiler hdrHistogramProfiler(String fileName) {
return HdrHistogramProfiler.createStarted(fileName, 1, TimeUnit.SECONDS);
}

Expand All @@ -45,7 +54,7 @@ public static Profiler newHdrHistogramProfiler(String fileName) {
* @param title title of the chart
* @return a chart profiler
*/
public static Profiler newChartProfiler(String title) {
public static Profiler chartProfiler(String title) {
return LiveChartProfiler.showInNewStage(title);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +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.chartfx.ui.css.DataSetNode;
import javafx.beans.property.BooleanProperty;
import javafx.collections.ObservableList;
Expand All @@ -19,7 +21,7 @@
* @author braeun
* @author rstein
*/
public interface Renderer {
public interface Renderer extends Profileable {
/**
* @param dataSet the data set for which the representative icon should be generated
* @param canvas the canvas in which the representative icon should be drawn
Expand Down Expand Up @@ -131,4 +133,7 @@ default Node getNode() {
return null;
}

default void setProfiler(Profiler profiler) {
}

}

0 comments on commit c7c7512

Please sign in to comment.