Skip to content

Commit bd7018e

Browse files
committed
add dir parameter to crox
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
1 parent 1971851 commit bd7018e

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
## Unreleased
44
### Added
55
- `flamegraph`: new tool that uses the `inferno` crate to generate flamegraph svg files ([GH-73])
6+
- `crox`: Added the `--dir` parameter to merge all events files in dir in to one trace file ([GH-84])
7+
- `crox`: Added possibility to add multiple `file_prefix` parameters to merge all them to one trace file ([GH-84])
68

79
### Changed
810
- `measureme`: Events are recorded in a more compact format ([GH-76])
@@ -47,3 +49,4 @@
4749
[GH-70]: https://github.com/rust-lang/measureme/pull/70
4850
[GH-73]: https://github.com/rust-lang/measureme/pull/73
4951
[GH-76]: https://github.com/rust-lang/measureme/pull/76
52+
[GH-84]: https://github.com/rust-lang/measureme/pull/84

crox/src/main.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ struct Event {
4444

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

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

123-
for file_prefix in opt.file_prefix.iter() {
127+
let dir_paths = file_prefixes_in_dir(&opt)?;
128+
129+
for file_prefix in opt.file_prefix.iter().chain(dir_paths.iter()) {
124130
let data = ProfilingData::new(&file_prefix)?;
125131

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

200+
fn file_prefixes_in_dir(opt: &Opt) -> Result<Vec<PathBuf>, std::io::Error> {
201+
let mut result = Vec::new();
202+
if let Some(dir_path) = &opt.dir {
203+
for entry in fs::read_dir(dir_path)? {
204+
let entry = entry?;
205+
let path = entry.path();
206+
if path.extension().filter(|e| *e == "events").is_some() {
207+
result.push(path)
208+
}
209+
}
210+
}
211+
Ok(result)
212+
}
213+
194214
fn timestamp_to_min_max(timestamp: Timestamp) -> (SystemTime, SystemTime) {
195215
match timestamp {
196216
Timestamp::Instant(t) => (t, t),

0 commit comments

Comments
 (0)