mirror of
https://github.com/swc-project/swc.git
synced 2024-12-23 05:32:09 +03:00
feat(plugin): Support tracing plugin execution (#3744)
This commit is contained in:
parent
9a4e961b2b
commit
5c29f15640
4
.gitignore
vendored
4
.gitignore
vendored
@ -52,4 +52,6 @@ pkg/
|
||||
*.tmp.js
|
||||
|
||||
# Used to see output of babel.
|
||||
/lab
|
||||
/lab
|
||||
|
||||
*.mm_profdata
|
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -3549,6 +3549,7 @@ dependencies = [
|
||||
"swc_ecma_parser",
|
||||
"swc_ecma_visit",
|
||||
"testing",
|
||||
"tracing",
|
||||
"wasmer",
|
||||
"wasmer-cache",
|
||||
"wasmer-wasi",
|
||||
|
@ -34,9 +34,11 @@ pub fn init_trace_once(
|
||||
FLUSH_GUARD.get_or_init(|| {
|
||||
if enable_chrome_trace {
|
||||
let layer = if let Some(trace_out_file) = trace_out_file {
|
||||
ChromeLayerBuilder::new().file(trace_out_file)
|
||||
} else {
|
||||
ChromeLayerBuilder::new()
|
||||
.file(trace_out_file)
|
||||
.include_args(true)
|
||||
} else {
|
||||
ChromeLayerBuilder::new().include_args(true)
|
||||
};
|
||||
|
||||
let (chrome_layer, guard) = layer.build();
|
||||
|
@ -68,6 +68,7 @@ struct RustPlugins {
|
||||
}
|
||||
|
||||
impl RustPlugins {
|
||||
#[tracing::instrument(level = "trace", skip_all, name = "apply_plugins")]
|
||||
#[cfg(feature = "plugin")]
|
||||
fn apply(&mut self, n: Program) -> Result<Program, anyhow::Error> {
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
@ -86,6 +87,13 @@ impl RustPlugins {
|
||||
// transform.
|
||||
if let Some(plugins) = &self.plugins {
|
||||
for p in plugins {
|
||||
let span = tracing::span!(
|
||||
tracing::Level::TRACE,
|
||||
"serialize_context",
|
||||
plugin_module = p.0.as_str()
|
||||
);
|
||||
let context_span_guard = span.enter();
|
||||
|
||||
let config_json = serde_json::to_string(&p.1)
|
||||
.context("Failed to serialize plugin config as json")
|
||||
.and_then(|value| Serialized::serialize(&value))?;
|
||||
@ -103,7 +111,14 @@ impl RustPlugins {
|
||||
} else {
|
||||
anyhow::bail!("Failed to resolve plugin path: {:?}", resolved_path);
|
||||
};
|
||||
drop(context_span_guard);
|
||||
|
||||
let span = tracing::span!(
|
||||
tracing::Level::TRACE,
|
||||
"execute_plugin_runner",
|
||||
plugin_module = p.0.as_str()
|
||||
);
|
||||
let transform_span_guard = span.enter();
|
||||
serialized = swc_plugin_runner::apply_js_plugin(
|
||||
&p.0,
|
||||
&path,
|
||||
@ -112,6 +127,7 @@ impl RustPlugins {
|
||||
config_json,
|
||||
context_json,
|
||||
)?;
|
||||
drop(transform_span_guard);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ swc_ecma_transforms_classes = {version = "0.50.0", path = "../swc_ecma_transform
|
||||
swc_ecma_transforms_macros = {version = "0.3.0", path = "../swc_ecma_transforms_macros"}
|
||||
swc_ecma_utils = {version = "0.68.0", path = "../swc_ecma_utils"}
|
||||
swc_ecma_visit = {version = "0.54.0", path = "../swc_ecma_visit"}
|
||||
swc_trace_macro = {versio = "0.1.0", path = "../swc_trace_macro"}
|
||||
swc_trace_macro = {version = "0.1.0", path = "../swc_trace_macro"}
|
||||
tracing = "0.1.31"
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -16,6 +16,7 @@ serde = {version = "1.0.126", features = ["derive"]}
|
||||
serde_json = "1.0.64"
|
||||
swc_common = {version = "0.17.0", path = "../swc_common", features = ["plugin-rt", "concurrent"]}
|
||||
swc_ecma_ast = {version = "0.68.0", path = "../swc_ecma_ast", features = ["rkyv-impl"]}
|
||||
tracing = "0.1.31"
|
||||
wasmer = "2.1.1"
|
||||
wasmer-cache = "2.1.1"
|
||||
wasmer-wasi = "2.1.1"
|
||||
|
@ -195,6 +195,7 @@ struct HostEnvironment {
|
||||
transform_result: Arc<Mutex<Vec<u8>>>,
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace", skip_all)]
|
||||
fn load_plugin(
|
||||
plugin_path: &Path,
|
||||
cache: &Lazy<PluginModuleCache>,
|
||||
@ -347,6 +348,7 @@ struct PluginTransformTracker {
|
||||
}
|
||||
|
||||
impl PluginTransformTracker {
|
||||
#[tracing::instrument(level = "trace", skip(cache))]
|
||||
fn new(path: &Path, cache: &Lazy<PluginModuleCache>) -> Result<PluginTransformTracker, Error> {
|
||||
let (instance, transform_result) = load_plugin(path, cache)?;
|
||||
|
||||
@ -414,6 +416,7 @@ impl PluginTransformTracker {
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace", skip_all)]
|
||||
fn transform(
|
||||
&mut self,
|
||||
program: &Serialized,
|
||||
|
Loading…
Reference in New Issue
Block a user