Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrançois Laignel <fengalin@free.fr>2022-09-08 00:10:29 +0300
committerSebastian Dröge <slomo@coaxion.net>2022-09-13 10:29:50 +0300
commit235ded35fd71082ac9ec78502ba462adb238d38f (patch)
treedc39075c68974f78f97390ab60924378a6c4aaf5 /generic/threadshare/src/runtime
parent72acbebff0147043a93abd4190e28544afa41801 (diff)
ts: add feature to add counters for performance evaluation
Add a `tuning` feature which adds counters that help with performance evaluation. The only counter added so far accumulates the duration a Scheduler has been parked, which is pretty accurate an indication of CPU usage of the Scheduler.
Diffstat (limited to 'generic/threadshare/src/runtime')
-rw-r--r--generic/threadshare/src/runtime/executor/context.rs8
-rw-r--r--generic/threadshare/src/runtime/executor/scheduler.rs19
2 files changed, 25 insertions, 2 deletions
diff --git a/generic/threadshare/src/runtime/executor/context.rs b/generic/threadshare/src/runtime/executor/context.rs
index f1555627a..325e20190 100644
--- a/generic/threadshare/src/runtime/executor/context.rs
+++ b/generic/threadshare/src/runtime/executor/context.rs
@@ -187,6 +187,14 @@ impl Context {
self.0.max_throttling()
}
+ /// Total duration the scheduler spent parked.
+ ///
+ /// This is only useful for performance evaluation.
+ #[cfg(feature = "tuning")]
+ pub fn parked_duration(&self) -> Duration {
+ self.0.parked_duration()
+ }
+
/// Returns `true` if a `Context` is running on current thread.
pub fn is_context_thread() -> bool {
Scheduler::is_scheduler_thread()
diff --git a/generic/threadshare/src/runtime/executor/scheduler.rs b/generic/threadshare/src/runtime/executor/scheduler.rs
index 53a7fab7f..958d88b3f 100644
--- a/generic/threadshare/src/runtime/executor/scheduler.rs
+++ b/generic/threadshare/src/runtime/executor/scheduler.rs
@@ -11,6 +11,8 @@ use gio::glib::clone::Downgrade;
use std::cell::RefCell;
use std::future::Future;
use std::panic;
+#[cfg(feature = "tuning")]
+use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::mpsc as sync_mpsc;
use std::sync::{Arc, Condvar, Mutex, Weak};
use std::task::Poll;
@@ -34,6 +36,8 @@ pub(super) struct Scheduler {
tasks: TaskQueue,
must_unpark: Mutex<bool>,
must_unpark_cvar: Condvar,
+ #[cfg(feature = "tuning")]
+ parked_duration: AtomicU64,
}
impl Scheduler {
@@ -104,6 +108,8 @@ impl Scheduler {
tasks: TaskQueue::new(context_name),
must_unpark: Mutex::new(false),
must_unpark_cvar: Condvar::new(),
+ #[cfg(feature = "tuning")]
+ parked_duration: AtomicU64::new(0),
}));
*cur_scheduler = Some(handle.downgrade());
@@ -201,12 +207,16 @@ impl Scheduler {
break;
}
- if let Some(wait_duration) = self.max_throttling.checked_sub(last.elapsed()) {
+ if let Some(parking_duration) = self.max_throttling.checked_sub(last.elapsed()) {
let result = self
.must_unpark_cvar
- .wait_timeout(must_unpark, wait_duration)
+ .wait_timeout(must_unpark, parking_duration)
.unwrap();
+ #[cfg(feature = "tuning")]
+ self.parked_duration
+ .fetch_add(parking_duration.subsec_nanos() as u64, Ordering::Relaxed);
+
must_unpark = result.0;
} else {
*must_unpark = false;
@@ -360,6 +370,11 @@ impl Handle {
self.0.scheduler.max_throttling
}
+ #[cfg(feature = "tuning")]
+ pub fn parked_duration(&self) -> Duration {
+ Duration::from_nanos(self.0.scheduler.parked_duration.load(Ordering::Relaxed))
+ }
+
/// Executes the provided function relatively to this [`Scheduler`]'s [`Reactor`].
///
/// Usefull to initialze i/o sources and timers from outside