Skip to content

Commit 3479256

Browse files
authored
Merge pull request #52 from Atul9/cargo-fmt
Format code using 'cargo fmt'
2 parents 8bd1782 + 4b83002 commit 3479256

File tree

16 files changed

+269
-250
lines changed

16 files changed

+269
-250
lines changed

crox/src/main.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,21 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
6262
//create an iterator so we can avoid allocating a Vec with every Event for serialization
6363
let json_event_iterator = std::iter::from_fn(|| {
6464
while let Some(event) = event_iterator.next() {
65-
let event_type =
66-
match event.timestamp_kind {
67-
TimestampKind::Start => EventType::Begin,
68-
TimestampKind::End => EventType::End,
69-
//Chrome does not seem to like how many QueryCacheHit events we generate
70-
TimestampKind::Instant => continue,
71-
};
65+
let event_type = match event.timestamp_kind {
66+
TimestampKind::Start => EventType::Begin,
67+
TimestampKind::End => EventType::End,
68+
// Chrome does not seem to like how many QueryCacheHit events we generate
69+
TimestampKind::Instant => continue,
70+
};
7271

7372
return Some(Event {
7473
name: event.label.clone().into_owned(),
7574
category: event.event_kind.clone().into_owned(),
7675
event_type,
77-
timestamp: event.timestamp.duration_since(first_event_timestamp).unwrap(),
76+
timestamp: event
77+
.timestamp
78+
.duration_since(first_event_timestamp)
79+
.unwrap(),
7880
process_id: 0,
7981
thread_id: event.thread_id,
8082
args: None,
Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
#![feature(test)]
2-
3-
extern crate test;
4-
5-
use measureme::{
6-
FileSerializationSink, MmapSerializationSink, testing_common
7-
};
8-
9-
#[bench]
10-
fn bench_file_serialization_sink(bencher: &mut test::Bencher) {
11-
bencher.iter(|| {
12-
testing_common::run_end_to_end_serialization_test::<FileSerializationSink>("file_serialization_sink_test");
13-
});
14-
}
15-
16-
#[bench]
17-
fn bench_mmap_serialization_sink(bencher: &mut test::Bencher) {
18-
bencher.iter(|| {
19-
testing_common::run_end_to_end_serialization_test::<MmapSerializationSink>("mmap_serialization_sink_test");
20-
});
21-
}
1+
#![feature(test)]
2+
3+
extern crate test;
4+
5+
use measureme::{testing_common, FileSerializationSink, MmapSerializationSink};
6+
7+
#[bench]
8+
fn bench_file_serialization_sink(bencher: &mut test::Bencher) {
9+
bencher.iter(|| {
10+
testing_common::run_end_to_end_serialization_test::<FileSerializationSink>(
11+
"file_serialization_sink_test",
12+
);
13+
});
14+
}
15+
16+
#[bench]
17+
fn bench_mmap_serialization_sink(bencher: &mut test::Bencher) {
18+
bencher.iter(|| {
19+
testing_common::run_end_to_end_serialization_test::<MmapSerializationSink>(
20+
"mmap_serialization_sink_test",
21+
);
22+
});
23+
}

measureme/src/file_header.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
//! consists of a 4 byte file magic string and a 4 byte little-endian version
33
//! number.
44
5-
use byteorder::{ByteOrder, LittleEndian};
65
use crate::serialization::SerializationSink;
6+
use byteorder::{ByteOrder, LittleEndian};
77
use std::error::Error;
88

99
pub const CURRENT_FILE_FORMAT_VERSION: u32 = 0;
@@ -21,28 +21,24 @@ pub fn write_file_header<S: SerializationSink>(s: &S, file_magic: &[u8; 4]) {
2121
assert_eq!(FILE_HEADER_SIZE, 8);
2222

2323
s.write_atomic(FILE_HEADER_SIZE, |bytes| {
24-
bytes[0 .. 4].copy_from_slice(file_magic);
24+
bytes[0..4].copy_from_slice(file_magic);
2525
LittleEndian::write_u32(&mut bytes[4..8], CURRENT_FILE_FORMAT_VERSION);
2626
});
2727
}
2828

29-
pub fn read_file_header(
30-
bytes: &[u8],
31-
expected_magic: &[u8; 4]
32-
) -> Result<u32, Box<dyn Error>> {
29+
pub fn read_file_header(bytes: &[u8], expected_magic: &[u8; 4]) -> Result<u32, Box<dyn Error>> {
3330
// The implementation here relies on FILE_HEADER_SIZE to have the value 8.
3431
// Let's make sure this assumption cannot be violated without being noticed.
3532
assert_eq!(FILE_HEADER_SIZE, 8);
3633

37-
let actual_magic = &bytes[0 .. 4];
34+
let actual_magic = &bytes[0..4];
3835

3936
if actual_magic != expected_magic {
4037
// FIXME: The error message should mention the file path in order to be
4138
// more useful.
4239
let msg = format!(
4340
"Unexpected file magic `{:?}`. Expected `{:?}`",
44-
actual_magic,
45-
expected_magic,
41+
actual_magic, expected_magic,
4642
);
4743

4844
return Err(From::from(msg));
@@ -52,10 +48,9 @@ pub fn read_file_header(
5248
}
5349

5450
pub fn strip_file_header(data: &[u8]) -> &[u8] {
55-
&data[FILE_HEADER_SIZE ..]
51+
&data[FILE_HEADER_SIZE..]
5652
}
5753

58-
5954
#[cfg(test)]
6055
mod tests {
6156
use super::*;
@@ -69,8 +64,10 @@ mod tests {
6964

7065
let data = data_sink.into_bytes();
7166

72-
assert_eq!(read_file_header(&data, FILE_MAGIC_EVENT_STREAM).unwrap(),
73-
CURRENT_FILE_FORMAT_VERSION);
67+
assert_eq!(
68+
read_file_header(&data, FILE_MAGIC_EVENT_STREAM).unwrap(),
69+
CURRENT_FILE_FORMAT_VERSION
70+
);
7471
}
7572

7673
#[test]
@@ -97,7 +94,9 @@ mod tests {
9794
data[5] = 0xFF;
9895
data[6] = 0xFF;
9996
data[7] = 0xFF;
100-
assert_eq!(read_file_header(&data, FILE_MAGIC_STRINGTABLE_INDEX).unwrap(),
101-
0xFFFF_FFFF);
97+
assert_eq!(
98+
read_file_header(&data, FILE_MAGIC_STRINGTABLE_INDEX).unwrap(),
99+
0xFFFF_FFFF
100+
);
102101
}
103102
}

measureme/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
mod event;
22
mod file_header;
3-
#[cfg(any(not(target_arch="wasm32"), target_os="wasi"))]
3+
#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))]
44
mod file_serialization_sink;
5-
#[cfg(not(target_arch="wasm32"))]
5+
#[cfg(not(target_arch = "wasm32"))]
66
mod mmap_serialization_sink;
77
mod profiler;
88
mod profiling_data;
@@ -14,12 +14,12 @@ pub mod rustc;
1414
pub mod testing_common;
1515

1616
pub use crate::event::Event;
17-
#[cfg(any(not(target_arch="wasm32"), target_os="wasi"))]
17+
#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))]
1818
pub use crate::file_serialization_sink::FileSerializationSink;
19-
#[cfg(not(target_arch="wasm32"))]
19+
#[cfg(not(target_arch = "wasm32"))]
2020
pub use crate::mmap_serialization_sink::MmapSerializationSink;
2121
pub use crate::profiler::{Profiler, ProfilerFiles};
22-
pub use crate::profiling_data::{ProfilingData, MatchingEvent};
22+
pub use crate::profiling_data::{MatchingEvent, ProfilingData};
2323
pub use crate::raw_event::{RawEvent, Timestamp, TimestampKind};
2424
pub use crate::serialization::{Addr, SerializationSink};
2525
pub use crate::stringtable::{

measureme/src/mmap_serialization_sink.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::serialization::{Addr, SerializationSink};
2-
use memmap::{MmapMut};
2+
use memmap::MmapMut;
33
use std::error::Error;
4-
use std::io::{Write, BufWriter};
5-
use std::fs::{File};
4+
use std::fs::File;
5+
use std::io::{BufWriter, Write};
66
use std::path::{Path, PathBuf};
77
use std::sync::atomic::{AtomicUsize, Ordering};
88

@@ -60,14 +60,14 @@ impl Drop for MmapSerializationSink {
6060
Ok(file) => file,
6161
Err(e) => {
6262
eprintln!("Error opening file for writing: {:?}", e);
63-
return
63+
return;
6464
}
6565
};
6666

6767
let mut file = BufWriter::new(file);
6868

69-
if let Err(e) = file.write_all(&self.mapped_file[0 .. actual_size]) {
69+
if let Err(e) = file.write_all(&self.mapped_file[0..actual_size]) {
7070
eprintln!("Error writing file: {:?}", e);
7171
}
7272
}
73-
}
73+
}

measureme/src/profiling_data.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::file_header::FILE_HEADER_SIZE;
21
use crate::event::Event;
2+
use crate::file_header::FILE_HEADER_SIZE;
33
use crate::{ProfilerFiles, RawEvent, StringTable, TimestampKind};
44
use std::error::Error;
55
use std::fs;
@@ -17,7 +17,8 @@ impl ProfilingData {
1717
let paths = ProfilerFiles::new(path_stem);
1818

1919
let string_data = fs::read(paths.string_data_file).expect("couldn't read string_data file");
20-
let index_data = fs::read(paths.string_index_file).expect("couldn't read string_index file");
20+
let index_data =
21+
fs::read(paths.string_index_file).expect("couldn't read string_index file");
2122
let event_data = fs::read(paths.events_file).expect("couldn't read events file");
2223

2324
let string_table = StringTable::new(string_data, index_data)?;
@@ -55,8 +56,7 @@ impl<'a> Iterator for ProfilerEventIterator<'a> {
5556
type Item = Event<'a>;
5657

5758
fn next(&mut self) -> Option<Event<'a>> {
58-
let event_start_addr = FILE_HEADER_SIZE +
59-
self.curr_event_idx * mem::size_of::<RawEvent>();
59+
let event_start_addr = FILE_HEADER_SIZE + self.curr_event_idx * mem::size_of::<RawEvent>();
6060
let event_end_addr = event_start_addr + mem::size_of::<RawEvent>();
6161
if event_end_addr > self.data.event_data.len() {
6262
return None;
@@ -70,7 +70,7 @@ impl<'a> Iterator for ProfilerEventIterator<'a> {
7070
unsafe {
7171
let raw_event = std::slice::from_raw_parts_mut(
7272
&mut raw_event as *mut RawEvent as *mut u8,
73-
std::mem::size_of::<RawEvent>()
73+
std::mem::size_of::<RawEvent>(),
7474
);
7575
raw_event.copy_from_slice(raw_event_bytes);
7676
};
@@ -121,21 +121,22 @@ impl<'a> Iterator for MatchingEventsIterator<'a> {
121121
let thread_id = event.thread_id as usize;
122122
if thread_id >= self.thread_stacks.len() {
123123
let growth_size = (thread_id + 1) - self.thread_stacks.len();
124-
self.thread_stacks.append(
125-
&mut vec![vec![]; growth_size]
126-
)
124+
self.thread_stacks.append(&mut vec![vec![]; growth_size])
127125
}
128126

129127
self.thread_stacks[thread_id].push(event);
130-
},
128+
}
131129
TimestampKind::Instant => {
132130
return Some(MatchingEvent::Instant(event));
133-
},
131+
}
134132
TimestampKind::End => {
135133
let thread_id = event.thread_id as usize;
136-
let previous_event = self.thread_stacks[thread_id].pop().expect("no previous event");
137-
if previous_event.event_kind != event.event_kind ||
138-
previous_event.label != event.label {
134+
let previous_event = self.thread_stacks[thread_id]
135+
.pop()
136+
.expect("no previous event");
137+
if previous_event.event_kind != event.event_kind
138+
|| previous_event.label != event.label
139+
{
139140
panic!("previous event on thread wasn't the start event");
140141
}
141142

measureme/src/stringtable.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
//! UTF-8 bytes. The content of a `TAG_STR_REF` is the contents of the entry
1313
//! it references.
1414
15-
use crate::file_header::{write_file_header, read_file_header, strip_file_header,
16-
FILE_MAGIC_STRINGTABLE_DATA, FILE_MAGIC_STRINGTABLE_INDEX};
15+
use crate::file_header::{
16+
read_file_header, strip_file_header, write_file_header, FILE_MAGIC_STRINGTABLE_DATA,
17+
FILE_MAGIC_STRINGTABLE_INDEX,
18+
};
1719
use crate::serialization::{Addr, SerializationSink};
1820
use byteorder::{ByteOrder, LittleEndian};
1921
use rustc_hash::FxHashMap;
@@ -120,7 +122,6 @@ fn deserialize_index_entry(bytes: &[u8]) -> (StringId, Addr) {
120122

121123
impl<S: SerializationSink> StringTableBuilder<S> {
122124
pub fn new(data_sink: Arc<S>, index_sink: Arc<S>) -> StringTableBuilder<S> {
123-
124125
// The first thing in every file we generate must be the file header.
125126
write_file_header(&*data_sink, FILE_MAGIC_STRINGTABLE_DATA);
126127
write_file_header(&*index_sink, FILE_MAGIC_STRINGTABLE_INDEX);
@@ -239,7 +240,6 @@ pub struct StringTable {
239240

240241
impl<'data> StringTable {
241242
pub fn new(string_data: Vec<u8>, index_data: Vec<u8>) -> Result<StringTable, Box<dyn Error>> {
242-
243243
let string_data_format = read_file_header(&string_data, FILE_MAGIC_STRINGTABLE_DATA)?;
244244
let index_data_format = read_file_header(&index_data, FILE_MAGIC_STRINGTABLE_INDEX)?;
245245

@@ -248,8 +248,11 @@ impl<'data> StringTable {
248248
}
249249

250250
if string_data_format != 0 {
251-
Err(format!("StringTable file format version '{}' is not supported
252-
by this version of `measureme`.", string_data_format))?;
251+
Err(format!(
252+
"StringTable file format version '{}' is not supported
253+
by this version of `measureme`.",
254+
string_data_format
255+
))?;
253256
}
254257

255258
assert!(index_data.len() % 8 == 0);

0 commit comments

Comments
 (0)