Integrating with the metrics
crate
#11738
Replies: 4 comments 3 replies
-
This seems like a sensible idea. Questions:
|
Beta Was this translation helpful? Give feedback.
-
One thing we want to do with diagnostics is to allow them to be nested/have paths. So for example take measurements of how long various render passes take to execute. Presumably we could do this by convention in the key of the metric. So like “view/pass name” or so? |
Beta Was this translation helpful? Give feedback.
-
I see that metrics has a Prometheus exporter. That’s cool, and useful for longer-term measurement given that Prometheus would request metric values from the exposed Prometheus endpoint quite sparsely, like every 30s for example. One thing that Prometheus recommends is that measurements not be aggregated up front and that totals are logged for counts of things. So instead of measuring a rate of something, you measure the total of it instead. This allows Prometheus to do correct aggregation and if for some reason fetching measurements is missed, you can still calculate a rate across a gap in measurements because you know how long it was between measurements and you know what the totals were either side. So you only lose resolution of measurements rather than having a gap. I’m not sure how we would reconcile the low frequency and high frequency observation of measurements through just the metrics crate. Measuring the frame time of a frame once every 30s doesn’t give much insight as there were lots of other frames during that period. But maybe summing frame times during the proof doesn’t make sense either. However, maybe tracking the quantity of allocations and the amount of data allocated during a 30s period is interesting. Not suggesting these thoughts are blockers necessarily, rather exploring whether/what we might want to do for fine, high frequency metrics to be visualised rapidly/in real time and coarse, low frequency metrics that we’d want to observe for longer runs of a bevy application - imagine someone playing through an entire scene that takes 30 minutes or an hour and you want to record what they did and measure metrics to later analyse and identify where problem areas were or something. |
Beta Was this translation helpful? Give feedback.
-
I would suggest https://github.com/madesroches/micromegas for this issue. It is a telemetry stack (in early stages) focus on game engines. So it is definitely targeted for what we may need. |
Beta Was this translation helpful? Give feedback.
-
In the interest of making it easier to debug Bevy apps, I think we should consider adding metrics directly inside of the
bevy_*
crates that can be consumed by an arbitrary monitoring backend. This is precisely the design of themetrics
crate (and ecosystem).While much can be done with
metrics
outside of Bevy proper (see bevy_metrics_dashboard), we can have a much richer set of metrics by adding instrumentation within Bevy. For example, there is probably no way to define a counter for how many commands are being run, or how many systems are being run, outside of the Bevy source code. The cost of adding and maintaining metrics is very low; because there is no plumbing involved. All metrics are written into a global recorder that is invisible to the code being instrumented (similar to howlog
andtracing
work). Recorders can be defined arbitrarily and installed on-demand. It should also be possible to "compile out" metrics in builds that don't need them by using cargo features; though it remains to be seen that metrics are even heavy enough to necessitate this.I believe this approach would be strictly better than the existing
bevy_diagnostic
option. For one,bevy_diagnostic
only supports writing metrics from within the Bevy ECS.metrics
allows writing metrics from anywhere; which means that you get access to all metrics in your dependency tree, regardless of if they have access to the ECS. You just have to take the lightweightmetrics
dependency (under 2K LOC); it's mostly just a set of facade macros for updating metrics by key/label and describing them to the recorder.Let me know what you think! I want to start using
metrics
more in Bevy apps that I work on, and if this proposal seems agreeable, I would be willing to make contributions for defining metrics inside Bevy.Beta Was this translation helpful? Give feedback.
All reactions