mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-11-22 03:21:00 +00:00
tracers: pipeline_snapshot: Allow passing dot-dir as a parameter
Overriding the default GST_DEBUG_DUMP_DOT_DIR env var Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1889>
This commit is contained in:
parent
d9ed642057
commit
27b02445d0
3 changed files with 80 additions and 4 deletions
49
Cargo.lock
generated
49
Cargo.lock
generated
|
@ -1606,6 +1606,27 @@ dependencies = [
|
|||
"subtle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "5.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225"
|
||||
dependencies = [
|
||||
"dirs-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs-sys"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"option-ext",
|
||||
"redox_users",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dssim-core"
|
||||
version = "3.2.10"
|
||||
|
@ -3062,6 +3083,7 @@ version = "0.14.0-alpha.1"
|
|||
dependencies = [
|
||||
"anyhow",
|
||||
"atomic_refcell",
|
||||
"dirs",
|
||||
"etherparse",
|
||||
"gst-plugin-version-helper",
|
||||
"gstreamer",
|
||||
|
@ -4439,6 +4461,16 @@ version = "0.2.8"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058"
|
||||
|
||||
[[package]]
|
||||
name = "libredox"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "librespot-audio"
|
||||
version = "0.5.0"
|
||||
|
@ -5126,6 +5158,12 @@ dependencies = [
|
|||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "option-ext"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
|
||||
|
||||
[[package]]
|
||||
name = "option-operations"
|
||||
version = "0.5.0"
|
||||
|
@ -5906,6 +5944,17 @@ dependencies = [
|
|||
"bitflags 2.6.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"libredox",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.11.0"
|
||||
|
|
|
@ -15,6 +15,7 @@ regex = "1"
|
|||
atomic_refcell = "0.1"
|
||||
pcap-file = "1.1.1"
|
||||
etherparse = "0.16.0"
|
||||
dirs = "5.0.1"
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
signal-hook = "0.3"
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
* ```
|
||||
*
|
||||
* Parameters can be passed to configure the tracer:
|
||||
* - `dot-dir` (string, default: None): directory where to place dot files (overriding `GST_DEBUG_DUMP_DOT_DIR`). Set to `xdg-cache` to use the XDG cache directory.
|
||||
* - `dot-prefix` (string, default: "pipeline-snapshot-"): when dumping pipelines to a `dot` file each file is named `$prefix$pipeline_name.dot`.
|
||||
* - `dot-ts` (boolean, default: "true"): if the current timestamp should be added as a prefix to each pipeline `dot` file.
|
||||
*
|
||||
|
@ -38,8 +39,9 @@
|
|||
* ```
|
||||
*/
|
||||
use std::collections::HashMap;
|
||||
use std::io::Write;
|
||||
use std::str::FromStr;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::{Arc, Mutex, RwLock};
|
||||
|
||||
use gst::glib;
|
||||
use gst::glib::translate::ToGlibPtr;
|
||||
|
@ -55,6 +57,8 @@ static CAT: LazyLock<gst::DebugCategory> = LazyLock::new(|| {
|
|||
)
|
||||
});
|
||||
|
||||
static START_TIME: LazyLock<gst::ClockTime> = LazyLock::new(gst::get_timestamp);
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
struct ElementPtr(std::ptr::NonNull<gst::ffi::GstElement>);
|
||||
|
||||
|
@ -75,20 +79,36 @@ impl ElementPtr {
|
|||
|
||||
#[derive(Debug)]
|
||||
struct Settings {
|
||||
dot_prefix: String,
|
||||
dot_prefix: Option<String>,
|
||||
dot_ts: bool,
|
||||
dot_dir: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for Settings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
dot_prefix: "pipeline-snapshot-".to_string(),
|
||||
dot_dir: None,
|
||||
dot_prefix: Some("pipeline-snapshot-".to_string()),
|
||||
dot_ts: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
fn set_dot_dir(&mut self, dot_dir: Option<String>) {
|
||||
if let Some(dot_dir) = dot_dir {
|
||||
if dot_dir == "xdg-cache" {
|
||||
let mut path = dirs::cache_dir().expect("Failed to find cache directory");
|
||||
path.push("gstreamer-dots");
|
||||
self.dot_dir = path.to_str().map(|s| s.to_string());
|
||||
} else {
|
||||
self.dot_dir = Some(dot_dir);
|
||||
}
|
||||
} else {
|
||||
self.dot_dir = std::env::var("GST_DEBUG_DUMP_DOT_DIR").ok();
|
||||
}
|
||||
}
|
||||
|
||||
fn update_from_params(&mut self, imp: &PipelineSnapshot, params: String) {
|
||||
let s = match gst::Structure::from_str(&format!("pipeline-snapshot,{params}")) {
|
||||
Ok(s) => s,
|
||||
|
@ -98,8 +118,13 @@ impl Settings {
|
|||
}
|
||||
};
|
||||
|
||||
if let Ok(dot_dir) = s.get("dot-dir") {
|
||||
self.set_dot_dir(dot_dir);
|
||||
gst::log!(CAT, imp: imp, "dot-dir = {:?}", self.dot_dir);
|
||||
}
|
||||
|
||||
if let Ok(dot_prefix) = s.get("dot-prefix") {
|
||||
gst::log!(CAT, imp = imp, "dot-prefix = {}", dot_prefix);
|
||||
gst::log!(CAT, imp = imp, "dot-prefix = {:?}", dot_prefix);
|
||||
self.dot_prefix = dot_prefix;
|
||||
}
|
||||
|
||||
|
@ -131,6 +156,7 @@ impl ObjectSubclass for PipelineSnapshot {
|
|||
|
||||
impl ObjectImpl for PipelineSnapshot {
|
||||
fn constructed(&self) {
|
||||
let _ = START_TIME.as_ref();
|
||||
self.parent_constructed();
|
||||
|
||||
let mut settings = Settings::default();
|
||||
|
|
Loading…
Reference in a new issue