File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
datafusion/execution/src/memory_pool Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -302,6 +302,34 @@ impl TrackedConsumer {
302302 }
303303}
304304
305+
306+ /// A point-in-time snapshot of a tracked memory consumer's state.
307+ ///
308+ /// Returned by [`TrackConsumersPool::metrics()`].
309+ #[ derive( Debug , Clone ) ]
310+ pub struct MemoryConsumerMetrics {
311+ /// The name of the memory consumer
312+ pub name : String ,
313+ /// Whether this consumer can spill to disk
314+ pub can_spill : bool ,
315+ /// The number of bytes currently reserved by this consumer
316+ pub reserved : usize ,
317+ /// The peak number of bytes reserved by this consumer
318+ pub peak : usize ,
319+ }
320+
321+ impl From < & TrackedConsumer > for MemoryConsumerMetrics {
322+ fn from ( tracked : & TrackedConsumer ) -> Self {
323+ Self {
324+ name : tracked. name . clone ( ) ,
325+ can_spill : tracked. can_spill ,
326+ reserved : tracked. reserved ( ) ,
327+ peak : tracked. peak ( ) ,
328+ }
329+ }
330+ }
331+
332+
305333/// A [`MemoryPool`] that tracks the consumers that have
306334/// reserved memory within the inner memory pool.
307335///
@@ -381,6 +409,11 @@ impl<I: MemoryPool> TrackConsumersPool<I> {
381409 }
382410 }
383411
412+ /// Returns a snapshot of all currently tracked consumers.
413+ pub fn metrics ( & self ) -> Vec < MemoryConsumerMetrics > {
414+ self . tracked_consumers . lock ( ) . values ( ) . map ( Into :: into) . collect ( )
415+ }
416+
384417 /// Returns a formatted string with the top memory consumers.
385418 pub fn report_top ( & self , top : usize ) -> String {
386419 let mut consumers = self
You can’t perform that action at this time.
0 commit comments