Skip to content

Commit

Permalink
Merge pull request #102 from michaelwoerister/bump-to-0.7.0
Browse files Browse the repository at this point in the history
Bump to 0.7.0
  • Loading branch information
wesleywiser authored Dec 18, 2019
2 parents 560162a + 788438e commit f35928f
Show file tree
Hide file tree
Showing 16 changed files with 153 additions and 73 deletions.
2 changes: 1 addition & 1 deletion analyzeme/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "analyzeme"
version = "0.6.0"
version = "0.7.0"
authors = ["Wesley Wiser <[email protected]>", "Michael Woerister <michaelwoerister@posteo>"]
edition = "2018"
license = "MIT OR Apache-2.0"
Expand Down
16 changes: 12 additions & 4 deletions analyzeme/benches/serialization_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use measureme::{FileSerializationSink, MmapSerializationSink};
fn bench_file_serialization_sink(bencher: &mut test::Bencher) {
bencher.iter(|| {
testing_common::run_serialization_bench::<FileSerializationSink>(
"file_serialization_sink_test", 500_000, 1
"file_serialization_sink_test",
500_000,
1,
);
});
}
Expand All @@ -18,7 +20,9 @@ fn bench_file_serialization_sink(bencher: &mut test::Bencher) {
fn bench_mmap_serialization_sink(bencher: &mut test::Bencher) {
bencher.iter(|| {
testing_common::run_serialization_bench::<MmapSerializationSink>(
"mmap_serialization_sink_test", 500_000, 1
"mmap_serialization_sink_test",
500_000,
1,
);
});
}
Expand All @@ -27,7 +31,9 @@ fn bench_mmap_serialization_sink(bencher: &mut test::Bencher) {
fn bench_file_serialization_sink_8_threads(bencher: &mut test::Bencher) {
bencher.iter(|| {
testing_common::run_serialization_bench::<FileSerializationSink>(
"file_serialization_sink_test", 50_000, 8
"file_serialization_sink_test",
50_000,
8,
);
});
}
Expand All @@ -36,7 +42,9 @@ fn bench_file_serialization_sink_8_threads(bencher: &mut test::Bencher) {
fn bench_mmap_serialization_sink_8_threads(bencher: &mut test::Bencher) {
bencher.iter(|| {
testing_common::run_serialization_bench::<MmapSerializationSink>(
"mmap_serialization_sink_test", 50_000, 8
"mmap_serialization_sink_test",
50_000,
8,
);
});
}
8 changes: 4 additions & 4 deletions analyzeme/src/lightweight_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ impl<'a> PartialEq for LightweightEvent<'a> {
timestamp: other_timestamp,
} = *other;

std::ptr::eq(data, other_data) &&
event_index == other_event_index &&
thread_id == other_thread_id &&
timestamp == other_timestamp
std::ptr::eq(data, other_data)
&& event_index == other_event_index
&& thread_id == other_thread_id
&& timestamp == other_timestamp
}
}

Expand Down
1 change: 1 addition & 0 deletions analyzeme/src/profiling_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ fn event_index_to_addr(event_index: usize) -> usize {
FILE_HEADER_SIZE + event_index * mem::size_of::<RawEvent>()
}

#[rustfmt::skip]
#[cfg(test)]
mod tests {
use super::*;
Expand Down
4 changes: 3 additions & 1 deletion analyzeme/src/stack_collapse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ pub fn collapse_stacks<'a>(profiling_data: &ProfilingData) -> FxHashMap<String,

// Add this event to the stack_id
thread.stack_id.push(';');
thread.stack_id.push_str(&current_event.to_event().label[..]);
thread
.stack_id
.push_str(&current_event.to_event().label[..]);

// Update current events self time
let self_time = counters.entry(thread.stack_id.clone()).or_default();
Expand Down
14 changes: 5 additions & 9 deletions analyzeme/src/stringtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,13 @@ pub struct StringRef<'st> {
const UNKNOWN_STRING: &str = "<unknown>";

impl<'st> StringRef<'st> {

/// Expands the StringRef into an actual string. This method will
/// avoid allocating a `String` if it can instead return a `&str` pointing
/// into the raw string table data.
pub fn to_string(&self) -> Cow<'st, str> {

let addr = match self.get_addr() {
Ok(addr) => addr,
Err(_) => {
return Cow::from(UNKNOWN_STRING)
}
Err(_) => return Cow::from(UNKNOWN_STRING),
};

// Try to avoid the allocation, which we can do if this is
Expand All @@ -60,11 +56,12 @@ impl<'st> StringRef<'st> {
let first_byte = self.table.string_data[pos];
const STRING_ID_SIZE: usize = std::mem::size_of::<StringId>();
if terminator_pos == pos + STRING_ID_SIZE && is_utf8_continuation_byte(first_byte) {
let id = decode_string_id_from_data(&self.table.string_data[pos..pos+STRING_ID_SIZE]);
let id = decode_string_id_from_data(&self.table.string_data[pos..pos + STRING_ID_SIZE]);
return StringRef {
id,
table: self.table,
}.to_string();
}
.to_string();
}

// Decode the bytes until the terminator. If there is a string id in
Expand All @@ -84,12 +81,11 @@ impl<'st> StringRef<'st> {
}

pub fn write_to_string(&self, output: &mut String) {

let addr = match self.get_addr() {
Ok(addr) => addr,
Err(_) => {
output.push_str(UNKNOWN_STRING);
return
return;
}
};

Expand Down
82 changes: 51 additions & 31 deletions analyzeme/src/testing_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,39 +68,44 @@ fn generate_profiling_data<S: SerializationSink>(
ExpectedEvent::new("QueryWithArg", "AQueryWithArg", &["some_arg"]),
];

let threads: Vec<_> = (0.. num_threads).map(|thread_id| {
let event_ids = event_ids.clone();
let profiler = profiler.clone();
let expected_events_templates = expected_events_templates.clone();

std::thread::spawn(move || {
let mut expected_events = Vec::new();

for i in 0..num_stacks {
// Allocate some invocation stacks

pseudo_invocation(
&profiler,
i,
thread_id as u32,
4,
&event_ids[..],
&expected_events_templates,
&mut expected_events,
);
}

expected_events
let threads: Vec<_> = (0..num_threads)
.map(|thread_id| {
let event_ids = event_ids.clone();
let profiler = profiler.clone();
let expected_events_templates = expected_events_templates.clone();

std::thread::spawn(move || {
let mut expected_events = Vec::new();

for i in 0..num_stacks {
// Allocate some invocation stacks

pseudo_invocation(
&profiler,
i,
thread_id as u32,
4,
&event_ids[..],
&expected_events_templates,
&mut expected_events,
);
}

expected_events
})
})
}).collect();
.collect();

let expected_events: Vec<_> = threads.into_iter().flat_map(|t| t.join().unwrap()).collect();
let expected_events: Vec<_> = threads
.into_iter()
.flat_map(|t| t.join().unwrap())
.collect();

// An example of allocating the string contents of an event id that has
// already been used
profiler.map_virtual_to_concrete_string(
event_id_virtual.to_string_id(),
profiler.alloc_string("SomeQuery")
profiler.alloc_string("SomeQuery"),
);

expected_events
Expand Down Expand Up @@ -140,7 +145,10 @@ fn check_profiling_data(
let expected_events_per_thread = collect_events_per_thread(expected_events);

let thread_ids: Vec<_> = actual_events_per_thread.keys().collect();
assert_eq!(thread_ids, expected_events_per_thread.keys().collect::<Vec<_>>());
assert_eq!(
thread_ids,
expected_events_per_thread.keys().collect::<Vec<_>>()
);

for thread_id in thread_ids {
let actual_events = &actual_events_per_thread[thread_id];
Expand All @@ -164,22 +172,34 @@ fn check_profiling_data(
assert_eq!(count, num_expected_events);
}

fn collect_events_per_thread<'a>(events: &mut dyn Iterator<Item = Event<'a>>) -> FxHashMap<u32, Vec<Event<'a>>> {
fn collect_events_per_thread<'a>(
events: &mut dyn Iterator<Item = Event<'a>>,
) -> FxHashMap<u32, Vec<Event<'a>>> {
let mut per_thread: FxHashMap<_, _> = Default::default();

for event in events {
per_thread.entry(event.thread_id).or_insert(Vec::new()).push(event);
per_thread
.entry(event.thread_id)
.or_insert(Vec::new())
.push(event);
}

per_thread
}

pub fn run_serialization_bench<S: SerializationSink>(file_name_stem: &str, num_events: usize, num_threads: usize) {
pub fn run_serialization_bench<S: SerializationSink>(
file_name_stem: &str,
num_events: usize,
num_threads: usize,
) {
let filestem = mk_filestem(file_name_stem);
generate_profiling_data::<S>(&filestem, num_events, num_threads);
}

pub fn run_end_to_end_serialization_test<S: SerializationSink>(file_name_stem: &str, num_threads: usize) {
pub fn run_end_to_end_serialization_test<S: SerializationSink>(
file_name_stem: &str,
num_threads: usize,
) {
let filestem = mk_filestem(file_name_stem);
let expected_events = generate_profiling_data::<S>(&filestem, 10_000, num_threads);
process_profiling_data(&filestem, &expected_events);
Expand Down
20 changes: 16 additions & 4 deletions analyzeme/tests/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,32 @@ use measureme::{FileSerializationSink, MmapSerializationSink};

#[test]
fn test_file_serialization_sink_1_thread() {
run_end_to_end_serialization_test::<FileSerializationSink>("file_serialization_sink_test_1_thread", 1);
run_end_to_end_serialization_test::<FileSerializationSink>(
"file_serialization_sink_test_1_thread",
1,
);
}

#[test]
fn test_file_serialization_sink_8_threads() {
run_end_to_end_serialization_test::<FileSerializationSink>("file_serialization_sink_test_8_threads", 8);
run_end_to_end_serialization_test::<FileSerializationSink>(
"file_serialization_sink_test_8_threads",
8,
);
}

#[test]
fn test_mmap_serialization_sink_1_thread() {
run_end_to_end_serialization_test::<MmapSerializationSink>("mmap_serialization_sink_test_1_thread", 1);
run_end_to_end_serialization_test::<MmapSerializationSink>(
"mmap_serialization_sink_test_1_thread",
1,
);
}

#[test]
fn test_mmap_serialization_sink_8_threads() {
run_end_to_end_serialization_test::<MmapSerializationSink>("mmap_serialization_sink_test_8_threads", 8);
run_end_to_end_serialization_test::<MmapSerializationSink>(
"mmap_serialization_sink_test_8_threads",
8,
);
}
2 changes: 1 addition & 1 deletion crox/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "crox"
version = "0.6.0"
version = "0.7.0"
authors = ["Wesley Wiser <[email protected]>"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion flamegraph/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "flamegraph"
version = "0.6.0"
version = "0.7.0"
authors = ["Wesley Wiser <[email protected]>", "Michael Woerister <michaelwoerister@posteo>"]
edition = "2018"
license = "MIT OR Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion measureme/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "measureme"
version = "0.6.0"
version = "0.7.0"
authors = ["Wesley Wiser <[email protected]>", "Michael Woerister <michaelwoerister@posteo>"]
edition = "2018"
description = "Support crate for rustc's self-profiling feature"
Expand Down
4 changes: 2 additions & 2 deletions mmview/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "mmview"
version = "0.6.0"
version = "0.7.0"
authors = ["Wesley Wiser <[email protected]>", "Michael Woerister <michaelwoerister@posteo>"]
edition = "2018"
license = "MIT OR Apache-2.0"

[dependencies]
measureme = { path = "../measureme" }
analyzeme = { path = "../analyzeme" }
measureme = { path = "../measureme" }
structopt = "0.2"
40 changes: 37 additions & 3 deletions mmview/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use analyzeme::ProfilingData;
use analyzeme::{Event, ProfilingData, Timestamp};
use std::error::Error;
use std::path::PathBuf;

use std::time::{Duration, SystemTime};
use structopt::StructOpt;

#[derive(StructOpt, Debug)]
Expand All @@ -18,15 +18,49 @@ fn main() -> Result<(), Box<dyn Error>> {

let data = ProfilingData::new(&opt.file_prefix)?;

let global_start_time = data.iter().map(|e| e.timestamp.start()).min().unwrap();

for event in data.iter() {
if let Some(thread_id) = opt.thread_id {
if event.thread_id != thread_id {
continue;
}
}

println!("{:?}", event);
print_event(&event.to_event(), global_start_time);
}

Ok(())
}

fn system_time_to_micros_since(t: SystemTime, since: SystemTime) -> u128 {
t.duration_since(since)
.unwrap_or(Duration::from_nanos(0))
.as_micros()
}

fn print_event(event: &Event<'_>, global_start_time: SystemTime) {
let additional_data = event.additional_data.join(",");

let timestamp = match event.timestamp {
Timestamp::Instant(t) => {
format!("{} μs", system_time_to_micros_since(t, global_start_time))
}
Timestamp::Interval { start, end } => format!(
"{} μs - {} μs",
system_time_to_micros_since(start, global_start_time),
system_time_to_micros_since(end, global_start_time)
),
};

println!(
r#"{{
kind: {},
label: {},
additional_data: [{}],
timestamp: {},
thread_id: {},
}}"#,
event.event_kind, event.label, additional_data, timestamp, event.thread_id
);
}
2 changes: 1 addition & 1 deletion stack_collapse/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "stack_collapse"
version = "0.6.0"
version = "0.7.0"
authors = ["Wesley Wiser <[email protected]>", "Michael Woerister <michaelwoerister@posteo>"]
edition = "2018"
license = "MIT OR Apache-2.0"
Expand Down
Loading

0 comments on commit f35928f

Please sign in to comment.