-
-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add resource detail view (#188)
This PR introduces the resoruce detail view. It also brings a couple of additional changes: - we now rely on context of entered spans rather than explicit parent - child relationships - we expose internal resources (`BatchSempahore`) - we show the relationships between resources (`Mutex` -> `BatchSemaphore`) - we show the async ops that are live on a specific resource - we also show the tasks that are awaiting on these async ops, which allows the user to draw a relationship between tasks and resources - there are more examples added in the examples folder (semaphore and mutex) Some screenshots: <img width="1050" alt="Screenshot 2021-11-23 at 19 12 28" src="https://user-images.githubusercontent.com/4391506/143072764-f940ed45-350d-4be4-941b-95ef5650c4d8.png"> <img width="1388" alt="Screenshot 2021-11-23 at 19 12 38" src="https://user-images.githubusercontent.com/4391506/143072791-ee5d485f-ea1e-4609-8946-16a61bf5776f.png"> <img width="1371" alt="Screenshot 2021-11-23 at 19 12 50" src="https://user-images.githubusercontent.com/4391506/143072807-4b577d3f-17d6-4ade-8dcc-006b44fc1014.png"> Signed-off-by: Zahari Dichev <zaharidichev@gmail.com>
- Loading branch information
1 parent
a79c505
commit 1aa9b59
Showing
25 changed files
with
1,423 additions
and
222 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ members = [ | |
"console-subscriber", | ||
"console-api" | ||
] | ||
resolver = "2" | ||
resolver = "2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use std::sync::Arc; | ||
use std::time::Duration; | ||
use tokio::sync::Barrier; | ||
use tokio::task; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> { | ||
console_subscriber::init(); | ||
task::Builder::default() | ||
.name("main-task") | ||
.spawn(async move { | ||
let mut handles = Vec::with_capacity(30); | ||
let barrier = Arc::new(Barrier::new(30)); | ||
for i in 0..30 { | ||
let c = barrier.clone(); | ||
let task_name = format!("task-{}", i); | ||
handles.push(task::Builder::default().name(&task_name).spawn(async move { | ||
tokio::time::sleep(Duration::from_secs(i)).await; | ||
let wait_result = c.wait().await; | ||
wait_result | ||
})); | ||
} | ||
|
||
// Will not resolve until all "after wait" messages have been printed | ||
let mut num_leaders = 0; | ||
for handle in handles { | ||
let wait_result = handle.await.unwrap(); | ||
if wait_result.is_leader() { | ||
num_leaders += 1; | ||
} | ||
} | ||
|
||
tokio::time::sleep(Duration::from_secs(10)).await; | ||
// Exactly one barrier will resolve as the "leader" | ||
assert_eq!(num_leaders, 1); | ||
}) | ||
.await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::sync::Arc; | ||
use std::time::Duration; | ||
use tokio::{sync::Mutex, task}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> { | ||
console_subscriber::init(); | ||
task::Builder::default() | ||
.name("main-task") | ||
.spawn(async move { | ||
let count = Arc::new(Mutex::new(0)); | ||
for i in 0..5 { | ||
let my_count = Arc::clone(&count); | ||
let task_name = format!("increment-{}", i); | ||
tokio::task::Builder::default() | ||
.name(&task_name) | ||
.spawn(async move { | ||
for _ in 0..10 { | ||
let mut lock = my_count.lock().await; | ||
*lock += 1; | ||
tokio::time::sleep(Duration::from_secs(1)).await; | ||
} | ||
}); | ||
} | ||
|
||
while *count.lock().await < 50 {} | ||
}) | ||
.await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use std::sync::Arc; | ||
use std::time::Duration; | ||
use tokio::{sync::RwLock, task}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> { | ||
console_subscriber::init(); | ||
task::Builder::default() | ||
.name("main-task") | ||
.spawn(async move { | ||
let count = Arc::new(RwLock::new(0)); | ||
for i in 0..5 { | ||
let my_count = Arc::clone(&count); | ||
let task_name = format!("increment-{}", i); | ||
tokio::task::Builder::default() | ||
.name(&task_name) | ||
.spawn(async move { | ||
for _ in 0..10 { | ||
let mut lock = my_count.write().await; | ||
*lock += 1; | ||
tokio::time::sleep(Duration::from_secs(1)).await; | ||
} | ||
}); | ||
} | ||
|
||
loop { | ||
let c = count.read().await; | ||
tokio::time::sleep(Duration::from_secs(1)).await; | ||
if *c >= 50 { | ||
break; | ||
} | ||
} | ||
}) | ||
.await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use std::sync::Arc; | ||
use std::time::Duration; | ||
use tokio::task; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> { | ||
console_subscriber::init(); | ||
task::Builder::default() | ||
.name("main-task") | ||
.spawn(async move { | ||
let sem = Arc::new(tokio::sync::Semaphore::new(0)); | ||
let mut tasks = Vec::default(); | ||
for i in 0..5 { | ||
let acquire_sem = Arc::clone(&sem); | ||
let add_sem = Arc::clone(&sem); | ||
let acquire_task_name = format!("acquire-{}", i); | ||
let add_task_name = format!("add-{}", i); | ||
tasks.push( | ||
tokio::task::Builder::default() | ||
.name(&acquire_task_name) | ||
.spawn(async move { | ||
let _permit = acquire_sem.acquire_many(i).await.unwrap(); | ||
tokio::time::sleep(Duration::from_secs(i as u64 * 2)).await; | ||
}), | ||
); | ||
tasks.push(tokio::task::Builder::default().name(&add_task_name).spawn( | ||
async move { | ||
tokio::time::sleep(Duration::from_secs(i as u64 * 5)).await; | ||
add_sem.add_permits(i as usize); | ||
}, | ||
)); | ||
} | ||
|
||
let all_tasks = futures::future::try_join_all(tasks); | ||
all_tasks.await.unwrap(); | ||
}) | ||
.await?; | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.