From 52eb5d66149e7549e4151c5ed0872fdda2f2c89a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=96R=C3=96K=20Attila?= Date: Thu, 22 Aug 2024 15:04:44 +0200 Subject: [PATCH] avm2: Add new feature tracy_avm, which emits tracy spans for AVM2 methods --- Cargo.lock | 1 + core/Cargo.toml | 2 ++ core/src/avm2/function.rs | 29 +++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index e371ff442..004dd1d65 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4269,6 +4269,7 @@ dependencies = [ "symphonia", "thiserror", "tracing", + "tracy-client", "ttf-parser", "unic-segment", "url", diff --git a/core/Cargo.toml b/core/Cargo.toml index d154e07c6..fbf2b5da0 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -68,6 +68,7 @@ unic-segment = "0.9.0" id3 = "1.14.0" either = "1.13.0" chardetng = "0.1.17" +tracy-client = { version = "0.17.1", optional = true, default-features = false } [target.'cfg(not(target_family = "wasm"))'.dependencies.futures] workspace = true @@ -79,6 +80,7 @@ version = "0.4.43" default = [] lzma = ["lzma-rs", "swf/lzma"] avm_debug = [] +tracy_avm = ["dep:tracy-client"] deterministic = [] timeline_debug = [] mp3 = ["symphonia"] diff --git a/core/src/avm2/function.rs b/core/src/avm2/function.rs index af143973b..d0ebb1fe5 100644 --- a/core/src/avm2/function.rs +++ b/core/src/avm2/function.rs @@ -184,6 +184,18 @@ pub fn exec<'gc>( resolved_signature, bound_class, )?; + + #[cfg(feature = "tracy_avm")] + let _span = { + let mut name = WString::new(); + display_function(&mut name, &method, bound_class); + let span = tracy_client::Client::running() + .expect("tracy_client should be running") + .span_alloc(None, &name.to_utf8_lossy(), "rust", 0, 0); + span.emit_color(0x2c4980); + span + }; + activation .context .avm2 @@ -210,6 +222,23 @@ pub fn exec<'gc>( bound_class, callee, )?; + + #[cfg(feature = "tracy_avm")] + let _span = { + let mut name = WString::new(); + display_function(&mut name, &method, bound_class); + let option = tracy_client::Client::running(); + let span = option.expect("tracy_client should be running").span_alloc( + None, + &name.to_utf8_lossy(), + bm.owner_movie().url(), + line!(), + 0, + ); + span.emit_color(0x425fa1); + span + }; + activation .context .avm2