Skip to content

Commit

Permalink
Set a performance warning flag on channels that take too much CPU time
Browse files Browse the repository at this point in the history
  • Loading branch information
mcslee committed May 5, 2022
1 parent 9c25bbd commit 0690340
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/java/heronarts/lx/LXModulatorComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public abstract class LXModulatorComponent extends LXComponent implements LXLoop

public class Profiler {
public long loopNanos;

public long renderNanos() {
return this.loopNanos;
}
}

protected Profiler constructProfiler() {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/heronarts/lx/mixer/LXAbstractChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ public enum CrossfadeGroup {
new EnumParameter<LXView.Normalization>("View Normalization", LXView.Normalization.RELATIVE)
.setDescription("Whether view coordinates are noramlized relative to the view, or absolute model");

public final BooleanParameter performanceWarning =
new BooleanParameter("Warning", false)
.setDescription("Set to true by the engine if this channel is using too many CPU resources");

/**
* Model view used on this bus
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/heronarts/lx/mixer/LXBus.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public interface ClipListener {

public class Profiler extends LXModulatorComponent.Profiler {
public long effectNanos;

@Override
public long renderNanos() {
return super.renderNanos() + this.effectNanos;
}
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/heronarts/lx/mixer/LXChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,7 @@ public void loop(double deltaMs) {
} else {
this.transitionProgress = 0;
}
this.profiler.loopNanos = System.nanoTime() - loopStart;

// Apply effects
long effectStart = System.nanoTime();
Expand All @@ -901,7 +902,6 @@ public void loop(double deltaMs) {
((LXBus.Profiler) this.profiler).effectNanos = System.nanoTime() - effectStart;

this.colors = colors;
this.profiler.loopNanos = System.nanoTime() - loopStart;
}

@Override
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/heronarts/lx/mixer/LXMixerEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,13 @@ public void loop(LXEngine.Frame render, double deltaMs) {
}
}

// Check for performance quality
long nanoLimit = (long) (1000000000 / this.lx.engine.framesPerSecond.getValuef() * .5);
for (LXAbstractChannel channel : this.channels) {
long renderNanos = channel.profiler.renderNanos();
channel.performanceWarning.setValue(renderNanos > nanoLimit);
}

// Step 3: blend the channel buffers down
boolean blendLeft = leftBusActive || this.cueA.isOn();
boolean blendRight = rightBusActive || this.cueB.isOn();
Expand Down

0 comments on commit 0690340

Please sign in to comment.