Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): add task name for tokio-console better display #7966

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading