Skip to content

Commit

Permalink
refactor: add tracing data for make phase
Browse files Browse the repository at this point in the history
  • Loading branch information
hardfist committed Sep 29, 2024
1 parent b2ee5d1 commit 918adbd
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 4 deletions.
5 changes: 5 additions & 0 deletions crates/rspack_core/src/compiler/make/repair/add.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use rspack_error::Result;
use tracing::instrument;

use super::{build::BuildTask, MakeTaskContext};
use crate::{
Expand All @@ -17,9 +18,13 @@ pub struct AddTask {
}

impl Task<MakeTaskContext> for AddTask {
fn name(&self) -> &'static str {
"add_task"
}
fn get_task_type(&self) -> TaskType {
TaskType::Sync
}
#[instrument("add_task_run")]
fn sync_run(self: Box<Self>, context: &mut MakeTaskContext) -> TaskResult<MakeTaskContext> {
let module_identifier = self.module.identifier();
let artifact = &mut context.artifact;
Expand Down
8 changes: 8 additions & 0 deletions crates/rspack_core/src/compiler/make/repair/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{collections::VecDeque, sync::Arc};
use derivative::Derivative;
use rspack_error::{Diagnostic, IntoTWithDiagnosticArray};
use rspack_fs::ReadableFileSystem;
use tracing::instrument;

use super::{process_dependencies::ProcessDependenciesTask, MakeTaskContext};
use crate::{
Expand All @@ -27,6 +28,9 @@ pub struct BuildTask {

#[async_trait::async_trait]
impl Task<MakeTaskContext> for BuildTask {
fn name(&self) -> &'static str {
"build_task"
}
fn get_task_type(&self) -> TaskType {
TaskType::Async
}
Expand Down Expand Up @@ -106,9 +110,13 @@ struct BuildResultTask {
}

impl Task<MakeTaskContext> for BuildResultTask {
fn name(&self) -> &'static str {
"build_result"
}
fn get_task_type(&self) -> TaskType {
TaskType::Sync
}
#[instrument("build_result_task_run")]
fn sync_run(self: Box<Self>, context: &mut MakeTaskContext) -> TaskResult<MakeTaskContext> {
let BuildResultTask {
mut module,
Expand Down
8 changes: 8 additions & 0 deletions crates/rspack_core/src/compiler/make/repair/factorize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{path::PathBuf, sync::Arc};
use rspack_error::Diagnostic;
use rspack_sources::BoxSource;
use rustc_hash::FxHashSet as HashSet;
use tracing::instrument;

use super::{add::AddTask, MakeTaskContext};
use crate::{
Expand All @@ -29,6 +30,9 @@ pub struct FactorizeTask {

#[async_trait::async_trait]
impl Task<MakeTaskContext> for FactorizeTask {
fn name(&self) -> &'static str {
"factorize_task"
}
fn get_task_type(&self) -> TaskType {
TaskType::Async
}
Expand Down Expand Up @@ -198,9 +202,13 @@ impl FactorizeResultTask {
}

impl Task<MakeTaskContext> for FactorizeResultTask {
fn name(&self) -> &'static str {
"factorize_result"
}
fn get_task_type(&self) -> TaskType {
TaskType::Sync
}
#[instrument("factorize_result_task_run")]
fn sync_run(self: Box<Self>, context: &mut MakeTaskContext) -> TaskResult<MakeTaskContext> {
let FactorizeResultTask {
original_module_identifier,
Expand Down
6 changes: 4 additions & 2 deletions crates/rspack_core/src/compiler/make/repair/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ pub mod add;
pub mod build;
pub mod factorize;
pub mod process_dependencies;

use std::sync::Arc;

use derivative::Derivative;
use rspack_error::Result;
use rspack_fs::ReadableFileSystem;
use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet};
Expand All @@ -18,11 +18,13 @@ use crate::{
BuildDependency, Compilation, CompilerOptions, DependencyType, Module, ModuleFactory,
ModuleProfile, NormalModuleSource, ResolverFactory, SharedPluginDriver,
};

#[derive(Derivative)]
#[derivative(Debug)]
pub struct MakeTaskContext {
// compilation info
pub plugin_driver: SharedPluginDriver,
pub buildtime_plugin_driver: SharedPluginDriver,
#[derivative(Debug = "ignore")]
pub fs: Arc<dyn ReadableFileSystem>,
pub compiler_options: Arc<CompilerOptions>,
pub resolver_factory: Arc<ResolverFactory>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::borrow::Cow;

use rustc_hash::FxHashMap as HashMap;
use tracing::instrument;

use super::{factorize::FactorizeTask, MakeTaskContext};
use crate::{
Expand All @@ -15,10 +16,13 @@ pub struct ProcessDependenciesTask {
}

impl Task<MakeTaskContext> for ProcessDependenciesTask {
fn name(&self) -> &'static str {
"process_dependencies_task"
}
fn get_task_type(&self) -> TaskType {
TaskType::Sync
}

#[instrument("process_dependencies_task_run")]
fn sync_run(self: Box<Self>, context: &mut MakeTaskContext) -> TaskResult<MakeTaskContext> {
let Self {
original_module_identifier,
Expand Down
6 changes: 6 additions & 0 deletions crates/rspack_core/src/compiler/module_executor/ctrl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ impl CtrlTask {

#[async_trait::async_trait]
impl Task<MakeTaskContext> for CtrlTask {
fn name(&self) -> &'static str {
"control_task"
}
fn get_task_type(&self) -> TaskType {
TaskType::Async
}
Expand Down Expand Up @@ -162,6 +165,9 @@ struct FinishModuleTask {
}

impl Task<MakeTaskContext> for FinishModuleTask {
fn name(&self) -> &'static str {
"finish_module_task"
}
fn get_task_type(&self) -> TaskType {
TaskType::Sync
}
Expand Down
3 changes: 3 additions & 0 deletions crates/rspack_core/src/compiler/module_executor/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pub struct EntryTask {
}

impl Task<MakeTaskContext> for EntryTask {
fn name(&self) -> &'static str {
"entry_task"
}
fn get_task_type(&self) -> TaskType {
TaskType::Sync
}
Expand Down
3 changes: 3 additions & 0 deletions crates/rspack_core/src/compiler/module_executor/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ pub struct ExecuteTask {
}

impl Task<MakeTaskContext> for ExecuteTask {
fn name(&self) -> &'static str {
"execute_task"
}
fn get_task_type(&self) -> TaskType {
TaskType::Sync
}
Expand Down
3 changes: 3 additions & 0 deletions crates/rspack_core/src/compiler/module_executor/overwrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ pub struct OverwriteTask {

#[async_trait::async_trait]
impl Task<MakeTaskContext> for OverwriteTask {
fn name(&self) -> &'static str {
"overwrite_task"
}
fn get_task_type(&self) -> TaskType {
self.origin_task.get_task_type()
}
Expand Down
11 changes: 10 additions & 1 deletion crates/rspack_core/src/utils/task_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ pub trait Task<Ctx>: Send + Any + AsAny {
/// Return `TaskType::Sync` will run `self::sync_run`
/// Return `TaskType::Async` will run `self::async_run`
fn get_task_type(&self) -> TaskType;

/// get task name for monitor
fn name(&self) -> &'static str;
/// Sync task process
///
/// The context is shared with all tasks
Expand Down Expand Up @@ -94,6 +95,8 @@ pub fn run_task_loop_with_event<Ctx: 'static>(
}
TaskType::Sync => {
// merge sync task result directly
let span = tracing::info_span!("sync_run", name = task.name());
let _enter = span.enter();
match task.sync_run(ctx) {
Ok(r) => queue.extend(r),
Err(e) => {
Expand Down Expand Up @@ -150,6 +153,9 @@ mod test {

struct SyncTask;
impl Task<Context> for SyncTask {
fn name(&self) -> &'static str {
"sync_task"
}
fn get_task_type(&self) -> TaskType {
TaskType::Sync
}
Expand All @@ -175,6 +181,9 @@ mod test {
}
#[async_trait::async_trait]
impl Task<Context> for AsyncTask {
fn name(&self) -> &'static str {
"async_task"
}
fn get_task_type(&self) -> TaskType {
TaskType::Async
}
Expand Down

0 comments on commit 918adbd

Please sign in to comment.