Skip to content

Commit

Permalink
add dir parameter to crox
Browse files Browse the repository at this point in the history
if dir is added all events files will be located in that dir
and then all event will be merged to one chrome_profiler.json file
  • Loading branch information
andjo403 committed Nov 11, 2019
1 parent 6397c52 commit 6d3a912
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## Unreleased
### Added
- `flamegraph`: new tool that uses the `inferno` crate to generate flamegraph svg files ([GH-73])
- `crox`: Added the `--dir` parameter to merge all events files in dir in to one trace file ([GH-84])
- `crox`: Added possibility to add multiple `file_prefix` parameters to merge all them to one trace file ([GH-84])

### Changed
- `measureme`: Events are recorded in a more compact format ([GH-76])
Expand Down Expand Up @@ -47,3 +49,4 @@
[GH-70]: https://github.com/rust-lang/measureme/pull/70
[GH-73]: https://github.com/rust-lang/measureme/pull/73
[GH-76]: https://github.com/rust-lang/measureme/pull/76
[GH-84]: https://github.com/rust-lang/measureme/pull/84
22 changes: 21 additions & 1 deletion crox/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ struct Event {

#[derive(StructOpt, Debug)]
struct Opt {
#[structopt(required_unless = "dir")]
file_prefix: Vec<PathBuf>,
/// all event trace files in dir will be merged to one chrome_profiler.json file
#[structopt(long = "dir")]
dir: Option<PathBuf>,
/// collapse threads without overlapping events
#[structopt(long = "collapse-threads")]
collapse_threads: bool,
Expand Down Expand Up @@ -120,7 +124,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

let mut seq = serializer.serialize_seq(None)?;

for file_prefix in opt.file_prefix.iter() {
let dir_paths = file_prefixes_in_dir(&opt)?;

for file_prefix in opt.file_prefix.iter().chain(dir_paths.iter()) {
let data = ProfilingData::new(&file_prefix)?;

let thread_to_collapsed_thread = generate_thread_to_collapsed_thread_mapping(&opt, &data);
Expand Down Expand Up @@ -191,6 +197,20 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}

fn file_prefixes_in_dir(opt: &Opt) -> Result<Vec<PathBuf>, std::io::Error> {
let mut result = Vec::new();
if let Some(dir_path) = &opt.dir {
for entry in fs::read_dir(dir_path)? {
let entry = entry?;
let path = entry.path();
if path.extension().filter(|e| *e == "events").is_some() {
result.push(path)
}
}
}
Ok(result)
}

fn timestamp_to_min_max(timestamp: Timestamp) -> (SystemTime, SystemTime) {
match timestamp {
Timestamp::Instant(t) => (t, t),
Expand Down

0 comments on commit 6d3a912

Please sign in to comment.