Skip to content

Commit 136e141

Browse files
committed
feat(monitor): add monitoring and resize throttling
1 parent 699bdb8 commit 136e141

File tree

8 files changed

+225
-129
lines changed

8 files changed

+225
-129
lines changed

trame_rca/widgets/rca.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
"""RCA Widgets support both vue2 and vue3."""
22

3-
from trame_client.widgets.core import AbstractElement
4-
from trame_rca.utils import RcaViewAdapter, RcaRenderScheduler
53
import warnings
4+
5+
from trame_client.widgets.core import AbstractElement
6+
7+
from trame_rca.utils import RcaRenderScheduler, RcaViewAdapter
8+
69
from .. import module
710

811
__all__ = [
@@ -40,6 +43,11 @@ def __init__(self, **kwargs):
4043
("image_style", "imageStyle"),
4144
("send_mouse_move", "sendMouseMove"),
4245
("event_throttle_ms", "eventThrottleMs"),
46+
"monitor",
47+
("resize_throttle_ms", "resizeThrottleMs"),
48+
]
49+
self._event_names += [
50+
"stats",
4351
]
4452

4553
self.name = kwargs.get("name") or f"trame_rca_{RemoteControlledArea._next_id}"
@@ -111,6 +119,10 @@ def __init__(self, **kwargs):
111119
"origin",
112120
"display",
113121
("image_style", "imageStyle"),
122+
"monitor",
123+
]
124+
self._event_names += [
125+
"stats",
114126
]
115127

116128

@@ -142,6 +154,10 @@ def __init__(self, **kwargs):
142154
"origin",
143155
("pool_size", "poolSize"),
144156
("image_style", "imageStyle"),
157+
"monitor",
158+
]
159+
self._event_names += [
160+
"stats",
145161
]
146162

147163

vue-components/package-lock.json

Lines changed: 34 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vue-components/src/components/DisplayArea.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ export default {
2727
type: Object,
2828
default: () => ({ width: '100%' }),
2929
},
30+
monitor: {
31+
type: Number,
32+
default: 0,
33+
},
3034
},
3135
template: `
3236
<div style="width: 100%; height: 100%; display: flex; justify-content: center; align-items: center;">
33-
<image-display-area v-if="display === 'image'" :name="name" :origin="origin" :poolSize="4" :imageStyle="imageStyle" />
37+
<image-display-area v-if="display === 'image'" :name="name" :origin="origin" :poolSize="4" :imageStyle="imageStyle" :monitor="monitor" @stats="$emit('stats', $event)" />
3438
<media-source-display-area v-if="display === 'media-source'" :name="name" :origin="origin" />
3539
<video-decoder-display-area v-if="display === 'video-decoder'" :name="name" :origin="origin" />
3640
<raw-image-display-area v-if="display === 'raw-image'" :name="name" :origin="origin" :imageStyle="imageStyle" />

vue-components/src/components/ImageDisplayArea.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { FPSMonitor } from '../utils/FpsMonitor';
2+
13
class ImageFrame {
24
constructor(vueComponent) {
35
this.vueComponent = vueComponent;
@@ -37,11 +39,18 @@ export default {
3739
type: Object,
3840
default: () => ({ width: '100%' }),
3941
},
42+
monitor: {
43+
type: Number,
44+
default: 0,
45+
},
4046
},
4147
watch: {
4248
poolSize() {
4349
this.updatePoolSize();
4450
},
51+
monitor() {
52+
this.updateMonitorWindow();
53+
},
4554
},
4655
data() {
4756
return {
@@ -74,7 +83,14 @@ export default {
7483
}
7584
},
7685
},
86+
updateMonitorWindow() {
87+
const bufferSize = Math.max(10, this.monitor);
88+
this.fpsMonitor.windowSize = bufferSize;
89+
this.fpsMonitor.windowStatSize = bufferSize;
90+
},
7791
created() {
92+
// Monitoring
93+
this.fpsMonitor = new FPSMonitor(10, 10);
7894
// Image decoding
7995
this.frames = [];
8096
this.nextFrameIndex = 0;
@@ -97,6 +113,19 @@ export default {
97113
this.nextFrameIndex = (this.nextFrameIndex + 1) % this.frames.length;
98114
const frame = this.frames[this.nextFrameIndex];
99115
frame.update(meta.type, content);
116+
if (this.monitor) {
117+
const serverTime = meta.st;
118+
const contentSize = content.length;
119+
const stats = this.fpsMonitor.addEntry(serverTime, contentSize);
120+
if (stats) {
121+
const { avgFps, totalSize } = stats;
122+
this.$emit('stats', {
123+
fps: Math.round(avgFps),
124+
bps: Math.floor(totalSize),
125+
st: serverTime,
126+
});
127+
}
128+
}
100129
} else {
101130
this.hasContent = false;
102131
}

vue-components/src/components/RemoteControlledArea.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import vtkRenderWindowInteractor from '@kitware/vtk.js/Rendering/Core/RenderWindowInteractor';
22
import vtkInteractorStyleRemoteMouse from '../utils/interactorStyle';
33

4-
const { inject, provide, ref, toRefs, onMounted, onBeforeUnmount } = window.Vue;
5-
import { EventThrottle } from '../utils/EventThrottle';
4+
const { inject, provide, ref, toRefs, onMounted, onBeforeUnmount, watch } =
5+
window.Vue;
6+
import { FunctionThrottle, EventThrottle } from '../utils/EventThrottle';
67

78
const RESOLVED_PROMISED = Promise.resolve(true);
89

@@ -28,15 +29,30 @@ export default {
2829
type: Number,
2930
default: 25,
3031
},
32+
resizeThrottleMs: {
33+
type: Number,
34+
default: 100,
35+
},
3136
imageStyle: {
3237
type: Object,
3338
default: () => ({ width: '100%' }),
3439
},
40+
monitor: {
41+
type: Number,
42+
default: 0,
43+
},
3544
},
3645
setup(props) {
3746
const rootElem = ref(null);
3847
const trame = inject('trame');
3948

49+
// Resizing throttle
50+
const throttleSize = new FunctionThrottle(
51+
_pushSize,
52+
props.resizeThrottleMs
53+
);
54+
watch(props.resizeThrottleMs, (v) => (throttleSize.delay = v));
55+
4056
// Event throttle
4157
const throttle = new EventThrottle((event) => {
4258
return trame.client
@@ -147,6 +163,10 @@ export default {
147163
});
148164

149165
function pushSize(addOn) {
166+
throttleSize.run(addOn);
167+
}
168+
169+
function _pushSize(addOn) {
150170
if (trame) {
151171
if (readySizeUpdate) {
152172
readySizeUpdate = false;
@@ -194,7 +214,7 @@ export default {
194214
template: `
195215
<div ref="rootElem" style="margin: 0; padding: 0; position: relative; width: 100%; height: 100%;">
196216
<div style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;">
197-
<display-area :display="display" :name="name" :origin="origin" :imageStyle="imageStyle" />
217+
<display-area :display="display" :name="name" :origin="origin" :imageStyle="imageStyle" :monitor="monitor" @stats="$emit('stats', $event)" />
198218
<slot></slot>
199219
</div>
200220
</div>

0 commit comments

Comments
 (0)