Skip to content

Commit 88522bb

Browse files
authored
Merge pull request #119 from nagisa/nagisa/assorted-fixes
Assorted fixes and improvements
2 parents 7ff08df + 75758ca commit 88522bb

File tree

7 files changed

+25
-22
lines changed

7 files changed

+25
-22
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[workspace]
22

33
members = [
4+
"analyzeme",
45
"crox",
6+
"flamegraph",
57
"measureme",
68
"mmview",
79
"stack_collapse",
810
"summarize",
9-
"analyzeme",
10-
"flamegraph",
1111
]

analyzeme/src/stringtable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ impl<'st> StringRef<'st> {
120120
Some(&addr) => Ok(addr),
121121
None => Err(()),
122122
}
123+
} else if self.id == StringId::INVALID {
124+
Err(())
123125
} else {
124126
Ok(self.id.to_addr())
125127
}

measureme/src/file_serialization_sink.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct Inner {
1717
}
1818

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

2323
let file = fs::File::create(path)?;

measureme/src/mmap_serialization_sink.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub struct MmapSerializationSink {
1313
}
1414

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

measureme/src/profiler.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ pub struct ProfilerFiles {
1515
}
1616

1717
impl ProfilerFiles {
18-
pub fn new(path_stem: &Path) -> ProfilerFiles {
18+
pub fn new<P: AsRef<Path>>(path_stem: P) -> ProfilerFiles {
1919
ProfilerFiles {
20-
events_file: path_stem.with_extension("events"),
21-
string_data_file: path_stem.with_extension("string_data"),
22-
string_index_file: path_stem.with_extension("string_index"),
20+
events_file: path_stem.as_ref().with_extension("events"),
21+
string_data_file: path_stem.as_ref().with_extension("string_data"),
22+
string_index_file: path_stem.as_ref().with_extension("string_index"),
2323
}
2424
}
2525
}
@@ -31,8 +31,9 @@ pub struct Profiler<S: SerializationSink> {
3131
}
3232

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

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

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

measureme/src/serialization.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl Addr {
1212
}
1313

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

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

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

mmview/src/main.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ fn main() -> Result<(), Box<dyn Error>> {
1818

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

21-
let global_start_time = data.iter().map(|e| e.timestamp.start()).min().unwrap();
22-
23-
for event in data.iter() {
24-
if let Some(thread_id) = opt.thread_id {
25-
if event.thread_id != thread_id {
26-
continue;
21+
if let Some(global_start_time) = data.iter().map(|e| e.timestamp.start()).min() {
22+
for event in data.iter() {
23+
if let Some(thread_id) = opt.thread_id {
24+
if event.thread_id != thread_id {
25+
continue;
26+
}
2727
}
28+
print_event(&event.to_event(), global_start_time);
2829
}
29-
30-
print_event(&event.to_event(), global_start_time);
30+
} else {
31+
eprintln!("No events.");
3132
}
3233

3334
Ok(())

0 commit comments

Comments
 (0)