2010YOUY01 commented on code in PR #14142:
URL: https://github.com/apache/datafusion/pull/14142#discussion_r1921001947


##########
datafusion/core/tests/memory_limit/memory_limit_validation/utils.rs:
##########
@@ -0,0 +1,186 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use datafusion_common_runtime::SpawnedTask;
+use std::sync::atomic::{AtomicUsize, Ordering};
+use std::sync::Arc;
+use sysinfo::System;
+use tokio::time::{interval, Duration};
+
+use datafusion::prelude::{SessionConfig, SessionContext};
+use datafusion_execution::{
+    memory_pool::{human_readable_size, FairSpillPool},
+    runtime_env::RuntimeEnvBuilder,
+};
+
+/// Measures the maximum RSS (in bytes) during the execution of an async task. 
RSS
+/// will be sampled every 20ms.
+///
+/// # Arguments
+///
+/// * `f` - A closure that returns the async task to be measured.
+///
+/// # Returns
+///
+/// A tuple containing the result of the async task and the maximum RSS 
observed.
+async fn measure_max_rss<F, Fut, T>(f: F) -> (T, usize)
+where
+    F: FnOnce() -> Fut,
+    Fut: std::future::Future<Output = T>,
+{
+    // Initialize system information
+    let mut system = System::new_all();
+    system.refresh_all();
+
+    // Get the current process ID
+    let pid = sysinfo::get_current_pid().expect("Failed to get current PID");
+
+    // Shared atomic variable to store max RSS
+    let max_rss = Arc::new(AtomicUsize::new(0));
+
+    // Clone for the monitoring task
+    let max_rss_clone = Arc::clone(&max_rss);
+
+    // Spawn a monitoring task
+    let monitor_handle = SpawnedTask::spawn(async move {
+        let mut sys = System::new_all();
+        let mut interval = interval(Duration::from_millis(20));

Review Comment:
   I tried 1ms, the tests take way longer to run. 7ms seems to be the smallest 
interval that won't affect execution speed. (so we have to make sure the 
profiled queries should take >> interval time to run, all current tests are 
satisfied)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to