Skip to content

Commit b82f0a6

Browse files
committed
refactor(prof): remove unnecessary pub, remove dead code
1 parent cde5dfb commit b82f0a6

File tree

1 file changed

+40
-45
lines changed

1 file changed

+40
-45
lines changed

profiling/src/internal/profile/fuzz_tests.rs

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,22 @@ use bolero::generator::TypeGenerator;
66
use core::cmp::Ordering;
77
use core::hash::Hasher;
88
use core::ops::Deref;
9-
use std::collections::HashSet;
109

1110
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash, TypeGenerator)]
12-
pub struct Function {
11+
struct Function {
1312
/// Name of the function, in human-readable form if available.
14-
pub name: Box<str>,
13+
name: Box<str>,
1514

1615
/// Name of the function, as identified by the system.
1716
/// For instance, it can be a C++ mangled name.
18-
pub system_name: Box<str>,
17+
system_name: Box<str>,
1918

2019
/// Source file containing the function.
21-
pub filename: Box<str>,
20+
filename: Box<str>,
2221
}
2322

2423
impl Function {
25-
pub fn new(name: Box<str>, system_name: Box<str>, filename: Box<str>) -> Self {
24+
fn new(name: Box<str>, system_name: Box<str>, filename: Box<str>) -> Self {
2625
Self {
2726
name,
2827
system_name,
@@ -42,7 +41,7 @@ impl<'a> From<&'a Function> for api::Function<'a> {
4241
}
4342

4443
#[derive(Clone, Debug, TypeGenerator)]
45-
pub enum LabelValue {
44+
enum LabelValue {
4645
Str(Box<str>),
4746
Num { num: i64, num_unit: Box<str> },
4847
}
@@ -53,10 +52,18 @@ impl Default for LabelValue {
5352
}
5453
}
5554

55+
// Note that Hash, Eq, Ord, etc. are implemented manually by converting the
56+
// Label into an api::Label calling its hash, eq, cmp, etc. functions. This
57+
// is a convenient way to have a consistent implementation while also taking
58+
// into account that these should be considered the same:
59+
// LabelValue::Num { LabelValue::Str(Box::from(""))
60+
// num: 0,
61+
// num_unit: Box::from(""),
62+
// }
5663
#[derive(Clone, Debug, Default, TypeGenerator)]
57-
pub struct Label {
58-
pub key: Box<str>,
59-
pub value: LabelValue,
64+
struct Label {
65+
key: Box<str>,
66+
value: LabelValue,
6067
}
6168

6269
impl From<(Box<str>, LabelValue)> for Label {
@@ -119,12 +126,12 @@ impl core::hash::Hash for Label {
119126
}
120127

121128
#[derive(Clone, Debug, Eq, PartialEq, TypeGenerator)]
122-
pub struct Line {
129+
struct Line {
123130
/// The corresponding profile.Function for this line.
124-
pub function: Function,
131+
function: Function,
125132

126133
/// Line number in source code.
127-
pub line: i64,
134+
line: i64,
128135
}
129136

130137
impl<'a> From<&'a Line> for api::Line<'a> {
@@ -137,21 +144,21 @@ impl<'a> From<&'a Line> for api::Line<'a> {
137144
}
138145

139146
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash, TypeGenerator)]
140-
pub struct Location {
141-
pub mapping: Mapping,
142-
pub function: Function,
147+
struct Location {
148+
mapping: Mapping,
149+
function: Function,
143150

144151
/// The instruction address for this location, if available. It
145152
/// should be within [Mapping.memory_start...Mapping.memory_limit]
146153
/// for the corresponding mapping. A non-leaf address may be in the
147154
/// middle of a call instruction. It is up to display tools to find
148155
/// the beginning of the instruction if necessary.
149-
pub address: u64,
150-
pub line: i64,
156+
address: u64,
157+
line: i64,
151158
}
152159

153160
impl Location {
154-
pub fn new(mapping: Mapping, function: Function, address: u64, line: i64) -> Self {
161+
fn new(mapping: Mapping, function: Function, address: u64, line: i64) -> Self {
155162
Self {
156163
mapping,
157164
function,
@@ -173,29 +180,29 @@ impl<'a> From<&'a Location> for api::Location<'a> {
173180
}
174181

175182
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash, TypeGenerator)]
176-
pub struct Mapping {
183+
struct Mapping {
177184
/// Address at which the binary (or DLL) is loaded into memory.
178-
pub memory_start: u64,
185+
memory_start: u64,
179186

180187
/// The limit of the address range occupied by this mapping.
181-
pub memory_limit: u64,
188+
memory_limit: u64,
182189

183190
/// Offset in the binary that corresponds to the first mapped address.
184-
pub file_offset: u64,
191+
file_offset: u64,
185192

186193
/// The object this entry is loaded from. This can be a filename on
187194
/// disk for the main binary and shared libraries, or virtual
188195
/// abstractions like "[vdso]".
189-
pub filename: Box<str>,
196+
filename: Box<str>,
190197

191198
/// A string that uniquely identifies a particular program version
192199
/// with high probability. E.g., for binaries generated by GNU tools,
193200
/// it could be the contents of the .note.gnu.build-id field.
194-
pub build_id: Box<str>,
201+
build_id: Box<str>,
195202
}
196203

197204
impl Mapping {
198-
pub fn new(
205+
fn new(
199206
memory_start: u64,
200207
memory_limit: u64,
201208
file_offset: u64,
@@ -225,30 +232,30 @@ impl<'a> From<&'a Mapping> for api::Mapping<'a> {
225232
}
226233

227234
#[derive(Clone, Debug)]
228-
pub struct Sample {
235+
struct Sample {
229236
/// The leaf is at locations[0].
230-
pub locations: Vec<Location>,
237+
locations: Vec<Location>,
231238

232239
/// The type and unit of each value is defined by the corresponding
233240
/// entry in Profile.sample_type. All samples must have the same
234241
/// number of values, the same as the length of Profile.sample_type.
235242
/// When aggregating multiple samples into a single sample, the
236243
/// result has a list of values that is the element-wise sum of the
237244
/// lists of the originals.
238-
pub values: Vec<i64>,
245+
values: Vec<i64>,
239246

240247
/// label includes additional context for this sample. It can include
241248
/// things like a thread id, allocation size, etc
242-
pub labels: Vec<Label>,
249+
labels: Vec<Label>,
243250
}
244251

245252
/// Since [Sample] needs a Vec<Label> which have unique keys, we generate
246253
/// samples using this parallel struct, and then map it to the [Sample].
247254
#[derive(Clone, Debug, TypeGenerator)]
248255
struct FuzzSample {
249-
pub locations: Vec<Location>,
250-
pub values: Vec<i64>,
251-
pub labels: HashMap<Box<str>, LabelValue>,
256+
locations: Vec<Location>,
257+
values: Vec<i64>,
258+
labels: HashMap<Box<str>, LabelValue>,
252259
}
253260

254261
impl From<FuzzSample> for Sample {
@@ -271,18 +278,6 @@ impl From<&FuzzSample> for Sample {
271278
}
272279
}
273280

274-
#[cfg(test)]
275-
impl Sample {
276-
/// Checks if the sample is well-formed. Useful in testing.
277-
pub fn is_well_formed(&self) -> bool {
278-
let labels_are_unique = {
279-
let mut uniq = HashSet::new();
280-
self.labels.iter().map(|l| &l.key).all(|x| uniq.insert(x))
281-
};
282-
labels_are_unique
283-
}
284-
}
285-
286281
impl<'a> From<&'a Sample> for api::Sample<'a> {
287282
fn from(value: &'a Sample) -> Self {
288283
Self {

0 commit comments

Comments
 (0)