-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathtask.rs
More file actions
68 lines (61 loc) · 1.89 KB
/
task.rs
File metadata and controls
68 lines (61 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Recording metrics related to tasks.
use prometheus_client::encoding::{EncodeLabelSet, EncodeLabelValue};
/// Metric label that indicates the type of task spawned.
#[derive(Clone, Debug, Hash, PartialEq, Eq, EncodeLabelSet)]
pub struct Label {
/// The name of the task.
name: String,
/// The type of task (root, async, or blocking).
kind: Kind,
/// Whether the task runs on a dedicated thread or the shared runtime.
execution: Execution,
}
impl Label {
/// Create a new label for the root task.
pub const fn root() -> Self {
Self {
name: String::new(),
kind: Kind::Root,
execution: Execution::Shared,
}
}
/// Create a new label for a future task.
pub const fn task(name: String, execution: crate::Execution) -> Self {
Self {
name,
kind: Kind::Task,
execution: match execution {
crate::Execution::Dedicated(_) => Execution::Dedicated,
crate::Execution::Shared(blocking) => {
if blocking {
Execution::SharedBlocking
} else {
Execution::Shared
}
}
},
}
}
/// Get the name of the task.
pub fn name(&self) -> String {
self.name.clone()
}
}
/// Metric label that indicates the type of task spawned.
#[derive(Clone, Debug, Hash, PartialEq, Eq, EncodeLabelValue)]
pub enum Kind {
/// The root task.
Root,
/// An async task.
Task,
}
/// Metric label describing whether a task runs on a dedicated thread.
#[derive(Clone, Debug, Hash, PartialEq, Eq, EncodeLabelValue)]
pub enum Execution {
/// Task runs on the shared runtime.
Shared,
/// Task runs on a shared runtime but is blocking.
SharedBlocking,
/// Task runs on a dedicated thread.
Dedicated,
}