Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
@Preference(name="shady_future") private static int[] rgba;
public static final Color shady_future;

/** When true, RTTank renders on the shared thread pool (one thread per CPU
* core) so many simultaneous Tank / ProgressBar instances update in
* parallel. When false, all renders serialise on a single global thread
* (the pre-fix behaviour). Controlled by the {@code parallel_rendering}
* preference. */
@Preference(name="parallel_rendering") public static boolean parallel_rendering;

Check warning on line 38 in app/rtplot/src/main/java/org/csstudio/javafx/rtplot/Activator.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make this "public static parallel_rendering" field final

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AZ1WdNzEiq29Pk22Vdf4&open=AZ1WdNzEiq29Pk22Vdf4&pullRequest=3766

Check warning on line 38 in app/rtplot/src/main/java/org/csstudio/javafx/rtplot/Activator.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this field "parallel_rendering" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AZ1WdNzFiq29Pk22Vdf5&open=AZ1WdNzFiq29Pk22Vdf5&pullRequest=3766

/** Thread pool for scrolling, throttling updates
*
* <p>One per CPU core allows that many plots to run updateImageBuffer in parallel.
Expand Down
35 changes: 31 additions & 4 deletions app/rtplot/src/main/java/org/csstudio/javafx/rtplot/RTTank.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.awt.image.BufferedImage;
import java.text.NumberFormat;
import java.util.Objects;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

Expand Down Expand Up @@ -166,7 +167,11 @@ public RTTank()
widthProperty().addListener(resize_listener);
heightProperty().addListener(resize_listener);

// 20Hz default throttle
// 20Hz default throttle.
// When parallel_rendering is enabled, each tank renders on the shared thread pool
// so that many tanks on a display update concurrently. The default (false) serialises
// all renders on the single global UpdateThrottle.TIMER thread — safe but slow for
// displays with many Tank / ProgressBar widgets.
update_throttle = new UpdateThrottle(50, TimeUnit.MILLISECONDS, () ->
{
if (needUpdate.getAndSet(false)){
Expand All @@ -178,7 +183,7 @@ public RTTank()
requestUpdate();
}
}
});
}, Activator.parallel_rendering ? Activator.thread_pool : UpdateThrottle.TIMER);

// Configure right-side scale — must happen after update_throttle is
// initialised because setOnRight() triggers requestUpdate() via the
Expand Down Expand Up @@ -335,12 +340,12 @@ private static NumberFormat significantDigitsFormat(final int prec)
@Override
public StringBuffer format(final double v, final StringBuffer buf, final java.text.FieldPosition pos)
{
return buf.append(String.format(java.util.Locale.ROOT, pattern, v));
return buf.append(normaliseExponent(String.format(java.util.Locale.ROOT, pattern, v)));
}
@Override
public StringBuffer format(final long v, final StringBuffer buf, final java.text.FieldPosition pos)
{
return buf.append(String.format(java.util.Locale.ROOT, pattern, (double) v));
return buf.append(normaliseExponent(String.format(java.util.Locale.ROOT, pattern, (double) v)));
}
@Override
public Number parse(final String s, final java.text.ParsePosition pos)
Expand All @@ -350,6 +355,28 @@ public Number parse(final String s, final java.text.ParsePosition pos)
};
}

/** Pre-compiled pattern for stripping the sign and leading zeros from a
* {@code %g} exponent string such as {@code "-01"} or {@code "+02"}.
*/
private static final Pattern EXP_LEADING_ZEROS = Pattern.compile("^[+-]?0*");

/** Normalise a {@code %g}-formatted string to match Phoebus axis convention:
* uppercase {@code E}, no leading zeros on the exponent, no {@code +} sign.
* Examples: {@code "1.0e-01"} &rarr; {@code "1.0E-1"},
* {@code "2.5e+02"} &rarr; {@code "2.5E2"}.
*/
private static String normaliseExponent(final String s)
{
final int e = s.indexOf('e');
if (e < 0)
return s; // decimal notation — no exponent to fix
final String mantissa = s.substring(0, e);
final String raw = s.substring(e + 1); // e.g. "-01", "+02"
final boolean neg = raw.startsWith("-");
final String digits = EXP_LEADING_ZEROS.matcher(raw).replaceFirst("");
return mantissa + "E" + (neg ? "-" : "") + (digits.isEmpty() ? "0" : digits);
}

/** Set alarm and warning limit values to display as horizontal lines on the tank.
* Pass {@link Double#NaN} for any limit that should not be shown.
* @param lolo LOLO (major alarm) lower limit
Expand Down
10 changes: 10 additions & 0 deletions app/rtplot/src/main/resources/rt_plot_preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@
#
# shady_future=128, 128, 128, 0
shady_future=128, 128, 128, 128

# Use a thread pool for RTTank rendering so that many simultaneous RTTank
# instances (Tank widget, ProgressBar with scale) render in parallel rather
# than serialising on a single global thread.
#
# Set to false only on severely resource-constrained systems where you want
# to limit background CPU usage at the cost of slower widget refresh.
#
# :default: false
parallel_rendering=false
Loading