tracers: snapshot: Add an option to add pipeline pts in file names

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1889>
This commit is contained in:
Thibault Saunier 2024-03-22 17:44:28 -03:00 committed by GStreamer Marge Bot
parent 6551a4631c
commit f6d550d571

View file

@ -101,6 +101,7 @@ pub enum CleanupMode {
struct Settings { struct Settings {
dot_prefix: Option<String>, dot_prefix: Option<String>,
dot_ts: bool, dot_ts: bool,
dot_pipeline_ptr: bool,
dot_dir: Option<String>, dot_dir: Option<String>,
cleanup_mode: CleanupMode, cleanup_mode: CleanupMode,
} }
@ -112,10 +113,10 @@ impl Default for Settings {
dot_prefix: Some("pipeline-snapshot-".to_string()), dot_prefix: Some("pipeline-snapshot-".to_string()),
dot_ts: true, dot_ts: true,
cleanup_mode: CleanupMode::None, cleanup_mode: CleanupMode::None,
dot_pipeline_ptr: false,
} }
} }
} }
impl Settings { impl Settings {
fn set_dot_dir(&mut self, dot_dir: Option<String>) { fn set_dot_dir(&mut self, dot_dir: Option<String>) {
if let Some(dot_dir) = dot_dir { if let Some(dot_dir) = dot_dir {
@ -155,6 +156,11 @@ impl Settings {
self.dot_ts = dot_ts; self.dot_ts = dot_ts;
} }
if let Ok(dot_pipeline_ptr) = s.get("dot-pipeline-ptr") {
gst::log!(CAT, imp = imp, "dot-pipeline-ptr = {}", dot_pipeline_ptr);
self.dot_pipeline_ptr = dot_pipeline_ptr;
}
if let Ok(cleanup_mod) = s.get::<String>("cleanup-mode") { if let Ok(cleanup_mod) = s.get::<String>("cleanup-mode") {
gst::log!(CAT, imp = imp, "cleanup-mode = {:?}", cleanup_mod); gst::log!(CAT, imp = imp, "cleanup-mode = {:?}", cleanup_mod);
self.cleanup_mode = match cleanup_mod.as_str() { self.cleanup_mode = match cleanup_mod.as_str() {
@ -176,6 +182,7 @@ pub struct PipelineSnapshot {
#[property(name="dot-dir", get, set = Self::set_dot_dir, construct_only, type = String, member = dot_dir, blurb = "Directory where to place dot files")] #[property(name="dot-dir", get, set = Self::set_dot_dir, construct_only, type = String, member = dot_dir, blurb = "Directory where to place dot files")]
#[property(name="dot-prefix", get, set, type = String, member = dot_prefix, blurb = "Prefix for dot files")] #[property(name="dot-prefix", get, set, type = String, member = dot_prefix, blurb = "Prefix for dot files")]
#[property(name="dot-ts", get, set, type = bool, member = dot_ts, blurb = "Add timestamp to dot files")] #[property(name="dot-ts", get, set, type = bool, member = dot_ts, blurb = "Add timestamp to dot files")]
#[property(name="dot-pipeline-ptr", get, set, type = bool, member = dot_pipeline_ptr, blurb = "Add pipeline ptr value to dot files")]
#[property(name="cleanup-mode", get = |s: &Self| s.settings.read().unwrap().cleanup_mode, set, type = CleanupMode, member = cleanup_mode, blurb = "Cleanup mode", builder(CleanupMode::None))] #[property(name="cleanup-mode", get = |s: &Self| s.settings.read().unwrap().cleanup_mode, set, type = CleanupMode, member = cleanup_mode, blurb = "Cleanup mode", builder(CleanupMode::None))]
settings: RwLock<Settings>, settings: RwLock<Settings>,
pipelines: Arc<Mutex<HashMap<ElementPtr, glib::WeakRef<gst::Element>>>>, pipelines: Arc<Mutex<HashMap<ElementPtr, glib::WeakRef<gst::Element>>>>,
@ -292,27 +299,29 @@ impl PipelineSnapshot {
self.cleanup_dots(); self.cleanup_dots();
} }
let ts = if settings.dot_ts {
format!("{:?}-", gst::get_timestamp() - *START_TIME)
} else {
"".to_string()
};
for pipeline in pipelines.into_iter() { for pipeline in pipelines.into_iter() {
let pipeline = pipeline.downcast::<gst::Pipeline>().unwrap(); let pipeline = pipeline.downcast::<gst::Pipeline>().unwrap();
gst::debug!(CAT, imp = self, "dump {}", pipeline.name()); gst::debug!(CAT, imp = self, "dump {}", pipeline.name());
let dump_name = if settings.dot_ts { let pipeline_ptr = if settings.dot_pipeline_ptr {
format!( let pipeline_ptr: *const gst::ffi::GstPipeline = pipeline.to_glib_none().0;
"{}-{}{}",
gst::get_timestamp() - *START_TIME,
settings.dot_prefix.as_ref().map_or("", |s| s.as_str()),
pipeline.name()
)
} else {
format!(
"{}{}",
settings.dot_prefix.as_ref().map_or("", |s| s.as_str()),
pipeline.name()
)
};
let dot_path = format!("{}/{}.dot", dot_dir, dump_name); format!("-{:?}", pipeline_ptr)
gst::debug!(CAT, imp = self, "Writing {}", dot_path); } else {
"".to_string()
};
let dot_path = format!(
"{dot_dir}/{ts}{}{}{pipeline_ptr}.dot",
settings.dot_prefix.as_ref().map_or("", |s| s.as_str()),
pipeline.name(),
);
gst::debug!(CAT, im =: self, "Writing {}", dot_path);
match std::fs::File::create(&dot_path) { match std::fs::File::create(&dot_path) {
Ok(mut f) => { Ok(mut f) => {
let data = pipeline.debug_to_dot_data(gst::DebugGraphDetails::all()); let data = pipeline.debug_to_dot_data(gst::DebugGraphDetails::all());