Skip to content

Commit

Permalink
refactor(core): add task name for tokio-console better display (#7966)
Browse files Browse the repository at this point in the history
Co-authored-by: Fy <[email protected]>
  • Loading branch information
hardfist and JSerFeng authored Sep 25, 2024
1 parent 5fd46ef commit b63c0d6
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crates/rspack_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ swc_core = { workspace = true, features = [
"swc_ecma_visit",
] }
swc_node_comments = { workspace = true }
tokio = { workspace = true, features = ["rt", "rt-multi-thread", "macros", "test-util", "parking_lot"] }
tokio = { workspace = true, features = ["rt", "rt-multi-thread", "macros", "test-util", "parking_lot", "tracing"] }
tracing = { workspace = true }
url = { workspace = true }
ustr = { workspace = true }
Expand Down
3 changes: 3 additions & 0 deletions crates/rspack_core/src/compiler/make/repair/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ pub struct AddTask {
}

impl Task<MakeTaskContext> for AddTask {
fn name(&self) -> &'static str {
"add_task"
}
fn get_task_type(&self) -> TaskType {
TaskType::Sync
}
Expand Down
6 changes: 6 additions & 0 deletions crates/rspack_core/src/compiler/make/repair/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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,6 +109,9 @@ struct BuildResultTask {
}

impl Task<MakeTaskContext> for BuildResultTask {
fn name(&self) -> &'static str {
"build_result"
}
fn get_task_type(&self) -> TaskType {
TaskType::Sync
}
Expand Down
6 changes: 6 additions & 0 deletions crates/rspack_core/src/compiler/make/repair/factorize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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,6 +201,9 @@ impl FactorizeResultTask {
}

impl Task<MakeTaskContext> for FactorizeResultTask {
fn name(&self) -> &'static str {
"factorize_result"
}
fn get_task_type(&self) -> TaskType {
TaskType::Sync
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ pub struct ProcessDependenciesTask {
}

impl Task<MakeTaskContext> for ProcessDependenciesTask {
fn name(&self) -> &'static str {
"process_dependencies_task"
}
fn get_task_type(&self) -> TaskType {
TaskType::Sync
}
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
25 changes: 18 additions & 7 deletions 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 @@ -85,12 +86,16 @@ pub fn run_task_loop_with_event<Ctx: 'static>(
let tx = tx.clone();
let is_expected_shutdown = is_expected_shutdown.clone();
active_task_count += 1;
tokio::spawn(async move {
let r = task.async_run().await;
if !is_expected_shutdown.load(Ordering::Relaxed) {
tx.send(r).expect("failed to send error message");
}
});
// safe expect here since spawn always return Ok
tokio::task::Builder::new()
.name(task.name())
.spawn(async move {
let r = task.async_run().await;
if !is_expected_shutdown.load(Ordering::Relaxed) {
tx.send(r).expect("failed to send error message");
}
})
.expect("spawn task failed");
}
TaskType::Sync => {
// merge sync task result directly
Expand Down Expand Up @@ -150,6 +155,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 +183,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

2 comments on commit b63c0d6

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-09-25 5fd46ef) Current Change
10000_development-mode + exec 2.27 s ± 30 ms 2.27 s ± 36 ms +0.01 %
10000_development-mode_hmr + exec 701 ms ± 15 ms 706 ms ± 6.8 ms +0.69 %
10000_production-mode + exec 2.93 s ± 20 ms 2.92 s ± 32 ms -0.57 %
arco-pro_development-mode + exec 1.84 s ± 80 ms 1.88 s ± 62 ms +2.23 %
arco-pro_development-mode_hmr + exec 436 ms ± 2.9 ms 436 ms ± 1.4 ms 0.00 %
arco-pro_production-mode + exec 3.32 s ± 72 ms 3.34 s ± 71 ms +0.52 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.35 s ± 98 ms 3.37 s ± 101 ms +0.74 %
threejs_development-mode_10x + exec 1.7 s ± 17 ms 1.71 s ± 16 ms +0.41 %
threejs_development-mode_10x_hmr + exec 788 ms ± 9.3 ms 789 ms ± 11 ms +0.13 %
threejs_production-mode_10x + exec 5.26 s ± 11 ms 5.27 s ± 20 ms +0.13 %

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ✅ success
_selftest ✅ success
nx ❌ failure
rspress ✅ success
rslib ✅ success
rsbuild ✅ success
examples ✅ success
devserver ✅ success

Please sign in to comment.