-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Count over time #3
Comments
When you say "over time" do you mean every second, over an undetermined period of time, or since the start of the execution? rStats is designed to calculate values per-frame, but it can be modified to accumulate values in a different manner. If it's over a frame, you can see a way of doing it in the WebGL plugin https://github.com/spite/rstats/blob/master/src/rStats.extras.js#L32 I've been thinking about adding measures over other time frames, so let's talk about how it could work best. |
Yes, I was looking at the webgl plugin when trying to figure out a way to handle this. One thing to note is that those counts are never reset and even though it's a plugin the counts are being managed manually. My use case is slightly unique: I'm trying to separate rendering from "world" updates via web workers. So I actually have a few calls to When I say "over time" I guess I mean outside of a frame context, meaning per second. Seems like Even if the measurement was just per frame, I think something like
This would then be able to give you thinks like "draw calls per frame" or "messages received per frame" without manually managing counters outside of rstats. An alternative way would be for rstats to provide a root |
If I understand correctly, you should be using .frame(), like 'FPS' in the examples. That method accumulates (+1) each call, and calculates the correct value over 1000ms (https://github.com/spite/rstats/blob/master/src/rStats.js#L228). It does linear interpolation to compensate for the time accuracy, so it might give you fractional values.
I've added a flag: var rS = new rStats( {
values: {
fps: { caption: 'Framerate (FPS)', interpolate: false }
}
} When used with: rS( 'FPS' ).frame(); the graph will show the correct value per second when calling .update(). You will still have to call it regularly: every frame, or every second at least. I would advice sticking it to the rAF callback. |
This gets me close, but still doesn't manage flow. For example: worker.addEventListener('message', function(ev) {
rs('msgs: main-recv').frame();
})
(function graph() {
requestAnimationFrame(graph);
rs().update();
}()); Once messages stop coming in (e.g. This works for me: function _flow(num) {
var t = performance.now();
var e = t - _time;
_total += (num || 0);
if( e > 1000 ) {
if( _def && _def.interpolate === false ) {
_value = _total;
} else {
_value = _total * 1000 / e;
}
_total = 0;
_time = t;
_average( _value );
}
} and then: worker.addEventListener('message', function(ev) {
rs('msgs: main-recv').flow(1);
})
(function graph() {
requestAnimationFrame(graph);
rs('msgs: main-recv').flow(0);
rs().update();
}()); |
I think I'm looking for something like:
The idea being that we want to know the "flow frequency" of how many collisions are happening over time without manually managing decay.
I could also see this being used to monitor a stream:
If I wanted to measure flow rate,
.set
is good enough, but not for frequency of flow.Perhaps this is possible today, and I'm missing something?
For context, I'm measuring both a standard game loop as well as when asynchronous messages arrive via
postMessage
from a web worker:.tick
will measure the time between calls, but I want to measure how many calls over time. Not sure how best to handle that, which is why I'm opening this ticket.The text was updated successfully, but these errors were encountered: