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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//! Profiling configuration.
use crate::IndexSet;
/// Configuration for the profiling layer.
///
/// By default all metric collection is disabled.
#[derive(Debug, Clone)]
#[must_use]
pub struct ProfileConfig {
pub(crate) track_allocations: bool,
pub(crate) track_heap: bool,
pub(crate) track_cpu_time: bool,
pub(crate) track_wall_time: bool,
pub(crate) max_samples: usize,
pub(crate) heap_snapshot_interval: std::time::Duration,
pub(crate) record_labels: IndexSet<String>,
pub(crate) max_closed_heap_spans: usize,
}
impl Default for ProfileConfig {
fn default() -> Self {
Self {
track_allocations: false,
track_heap: false,
track_cpu_time: false,
track_wall_time: false,
max_samples: 1000,
heap_snapshot_interval: std::time::Duration::from_secs(10),
record_labels: IndexSet::default(),
max_closed_heap_spans: 1000,
}
}
}
impl ProfileConfig {
/// Creates a new `ProfileConfig` with default settings.
pub fn new() -> Self {
Self::default()
}
/// Enable/disable tracking of allocations.
///
/// In order to track allocations, the global allocator must be
/// set to [`TrackingAllocator`](crate::allocator::TrackingAllocator).
///
/// By default, this is disabled.
pub fn track_allocations(mut self, enable: bool) -> Self {
self.track_allocations = enable;
self
}
/// Enable/disable tracking of heap usage.
///
/// Implicitly enables tracking of allocations.
///
/// By default, this is disabled.
pub fn track_heap(mut self, enable: bool) -> Self {
self.track_heap = enable;
if enable {
self.track_allocations = true;
}
self
}
/// Enable/disable tracking of CPU time.
///
/// By default, this is disabled.
pub fn track_cpu(mut self, enable: bool) -> Self {
self.track_cpu_time = enable;
self
}
/// Enable/disable tracking of wall time.
///
/// By default, this is disabled.
pub fn track_wall(mut self, enable: bool) -> Self {
self.track_wall_time = enable;
self
}
/// Enable all profiling features.
pub fn track_all(mut self) -> Self {
self.track_allocations = true;
self.track_heap = true;
self.track_cpu_time = true;
self.track_wall_time = true;
self
}
/// Use the given fields as labels for all spans.
///
/// By default, no labels are recorded as this is an expensive operation.
pub fn record_labels(mut self, labels: &[&str]) -> Self {
self.record_labels = labels.iter().map(ToString::to_string).collect();
self
}
/// Set the heap snapshot interval for the reporter.
///
/// Pyroscope will sum snapshot values if they are too frequent,
/// this is a (hopefully) temporary workaround to avoid that.
///
/// Set this to 0 to send heap snapshots on every poll.
///
/// By default, this is 10 seconds.
pub fn heap_snapshot_interval(mut self, interval: std::time::Duration) -> Self {
self.heap_snapshot_interval = interval;
self
}
/// Set the maximum number of samples to accumulate before flushing.
///
/// Note that this is a soft limit, the reporter may flush more often
/// or less often depending on the load.
///
/// By default, this is 1000.
pub fn max_samples(mut self, max_samples: usize) -> Self {
self.max_samples = max_samples;
self
}
/// Set the maximum number of closed spans to keep in the heap tracker.
/// If this is exceeded, closed spans will be dropped from heap tracking.
///
/// Spans with the lowest amount of allocated bytes still in use will be dropped first.
///
/// By default, this is 1000.
pub fn max_closed_heap_spans(mut self, max_closed_heap_spans: usize) -> Self {
self.max_closed_heap_spans = max_closed_heap_spans;
self
}
}