Skip to content

Assorted fixes and improvements #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[workspace]

members = [
"analyzeme",
"crox",
"flamegraph",
"measureme",
"mmview",
"stack_collapse",
"summarize",
"analyzeme",
"flamegraph",
]
2 changes: 2 additions & 0 deletions analyzeme/src/stringtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ impl<'st> StringRef<'st> {
Some(&addr) => Ok(addr),
None => Err(()),
}
} else if self.id == StringId::INVALID {
Err(())
} else {
Ok(self.id.to_addr())
}
Expand Down
2 changes: 1 addition & 1 deletion measureme/src/file_serialization_sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct Inner {
}

impl SerializationSink for FileSerializationSink {
fn from_path(path: &Path) -> Result<Self, Box<dyn Error>> {
fn from_path(path: &Path) -> Result<Self, Box<dyn Error + Send + Sync>> {
fs::create_dir_all(path.parent().unwrap())?;

let file = fs::File::create(path)?;
Expand Down
2 changes: 1 addition & 1 deletion measureme/src/mmap_serialization_sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct MmapSerializationSink {
}

impl SerializationSink for MmapSerializationSink {
fn from_path(path: &Path) -> Result<Self, Box<dyn Error>> {
fn from_path(path: &Path) -> Result<Self, Box<dyn Error + Send + Sync>> {
// Lazily allocate 1 GB :O
let file_size = 1 << 30;

Expand Down
16 changes: 8 additions & 8 deletions measureme/src/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ pub struct ProfilerFiles {
}

impl ProfilerFiles {
pub fn new(path_stem: &Path) -> ProfilerFiles {
pub fn new<P: AsRef<Path>>(path_stem: P) -> ProfilerFiles {
ProfilerFiles {
events_file: path_stem.with_extension("events"),
string_data_file: path_stem.with_extension("string_data"),
string_index_file: path_stem.with_extension("string_index"),
events_file: path_stem.as_ref().with_extension("events"),
string_data_file: path_stem.as_ref().with_extension("string_data"),
string_index_file: path_stem.as_ref().with_extension("string_index"),
}
}
}
Expand All @@ -31,8 +31,9 @@ pub struct Profiler<S: SerializationSink> {
}

impl<S: SerializationSink> Profiler<S> {
pub fn new(path_stem: &Path) -> Result<Profiler<S>, Box<dyn Error>> {
let paths = ProfilerFiles::new(path_stem);
pub fn new<P: AsRef<Path>>(path_stem: P)
-> Result<Profiler<S>, Box<dyn Error + Send + Sync>> {
let paths = ProfilerFiles::new(path_stem.as_ref());
let event_sink = Arc::new(S::from_path(&paths.events_file)?);

// The first thing in every file we generate must be the file header.
Expand Down Expand Up @@ -126,8 +127,7 @@ impl<S: SerializationSink> Profiler<S> {
}

fn nanos_since_start(&self) -> u64 {
let duration_since_start = self.start_time.elapsed();
duration_since_start.as_secs() * 1_000_000_000 + duration_since_start.subsec_nanos() as u64
self.start_time.elapsed().as_nanos() as _
}
}

Expand Down
4 changes: 2 additions & 2 deletions measureme/src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl Addr {
}

pub trait SerializationSink: Sized + Send + Sync + 'static {
fn from_path(path: &Path) -> Result<Self, Box<dyn Error>>;
fn from_path(path: &Path) -> Result<Self, Box<dyn Error + Send + Sync>>;

/// Atomically write `num_bytes` to the sink. The implementation must ensure
/// that concurrent invocations of `write_atomic` do not conflict with each
Expand Down Expand Up @@ -53,7 +53,7 @@ impl ByteVecSink {
}

impl SerializationSink for ByteVecSink {
fn from_path(_path: &Path) -> Result<Self, Box<dyn Error>> {
fn from_path(_path: &Path) -> Result<Self, Box<dyn Error + Send + Sync>> {
unimplemented!()
}

Expand Down
17 changes: 9 additions & 8 deletions mmview/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ 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;
if let Some(global_start_time) = data.iter().map(|e| e.timestamp.start()).min() {
for event in data.iter() {
if let Some(thread_id) = opt.thread_id {
if event.thread_id != thread_id {
continue;
}
}
print_event(&event.to_event(), global_start_time);
}

print_event(&event.to_event(), global_start_time);
} else {
eprintln!("No events.");
}

Ok(())
Expand Down