-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from 191220029/data-manage
Data manage: impl merge_stats
- Loading branch information
Showing
17 changed files
with
202 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
pub mod benchmark; | ||
pub(crate) mod benchmark; | ||
pub mod profile; | ||
pub mod scenario; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
pub mod benchmark; | ||
pub mod compile_time; | ||
mod execute; | ||
mod runtime; | ||
pub mod statistics; | ||
pub mod toolchain; | ||
mod utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "manager" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
anyhow = "1" | ||
collector = { path = "../collector" } | ||
clap = { version = "3.0.9", features = ["derive"] } | ||
serde = { version = "1", features = ["derive"] } | ||
serde_json = "1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use collector::benchmark::profile::Profile; | ||
use std::path::PathBuf; | ||
|
||
#[derive(Debug, clap::Parser)] | ||
#[clap(about, version, author)] | ||
pub struct Cli { | ||
#[clap(subcommand)] | ||
pub command: Commands, | ||
} | ||
|
||
#[derive(Debug, clap::Subcommand)] | ||
#[clap(rename_all = "snake_case")] | ||
pub enum Commands { | ||
/// Merge Data of the same rustc version from different benchmark groups | ||
/// and calculate their statistics. | ||
MergeStats { | ||
/// Path to root of Stats dir | ||
#[clap(long = "root-dir")] | ||
root_dir: PathBuf, | ||
|
||
/// `debug` or `release` or someother profiles of rustc. | ||
#[clap(long = "profile")] | ||
profile: Profile, | ||
|
||
/// Version of rustc | ||
#[clap(long = "rust-ver")] | ||
rustc: String, | ||
|
||
/// The path of output file | ||
#[clap(long = "out-path", default_value = "results")] | ||
out_path: PathBuf, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use clap::Parser; | ||
use commannds::Cli; | ||
use merge_stat::merge_compile_time_stats; | ||
|
||
mod commannds; | ||
mod merge_stat; | ||
|
||
fn main() { | ||
let cli = Cli::parse(); | ||
|
||
match cli.command { | ||
commannds::Commands::MergeStats { | ||
root_dir, | ||
profile, | ||
rustc, | ||
out_path, | ||
} => match merge_compile_time_stats(&root_dir, profile, rustc, out_path) { | ||
Ok(p) => println!("Write merged stats to {}", p.to_str().unwrap()), | ||
Err(e) => eprintln!("{}", e), | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
use std::{ | ||
fs::{read_dir, File}, | ||
io::{BufReader, BufWriter}, | ||
path::PathBuf, | ||
}; | ||
|
||
use collector::{ | ||
benchmark::profile::Profile, | ||
compile_time::result::{CompileTimeResultSet, CompileTimeStatistics}, | ||
}; | ||
|
||
pub fn merge_compile_time_stats( | ||
root_dir: &PathBuf, | ||
profile: Profile, | ||
rustc: String, | ||
out_path: PathBuf, | ||
) -> anyhow::Result<PathBuf> { | ||
let mut merged_stats = CompileTimeStatistics::new(); | ||
|
||
// Iterate each benchmark group under root dir. | ||
for bench_group in read_dir(root_dir)? { | ||
let bench_group = bench_group?; | ||
// Iterate each rustc stats dir under root dir. | ||
if bench_group.metadata()?.is_dir() { | ||
for rustc_dir in read_dir(bench_group.path())? { | ||
let rustc_dir = rustc_dir?; | ||
// Find wanted rustc version. | ||
if rustc_dir.metadata()?.is_dir() | ||
&& rustc_dir.file_name().to_str().unwrap().to_string() == rustc | ||
{ | ||
// Find statistics file | ||
for f in read_dir(rustc_dir.path())? { | ||
let f = f?; | ||
if f.file_name().to_str().unwrap().contains("results.json") { | ||
let data: CompileTimeResultSet = | ||
serde_json::from_reader(BufReader::new(File::open(f.path())?))?; | ||
|
||
merged_stats.append( | ||
&mut data | ||
.calculate_statistics() | ||
.into_iter() | ||
.filter(|s| s.profile == profile) | ||
.collect(), | ||
); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
merged_stats.sort_by(|a, b| a.name.to_lowercase().cmp(&b.name.to_lowercase())); | ||
|
||
serde_json::to_writer(BufWriter::new(File::create(&out_path)?), &merged_stats)?; | ||
|
||
Ok(out_path) | ||
} | ||
|
||
#[cfg(test)] | ||
mod test_merge_stat { | ||
use std::{ | ||
fs::{remove_file, File}, | ||
io::BufReader, | ||
path::PathBuf, | ||
}; | ||
|
||
use collector::{benchmark::profile::Profile, compile_time::result::CompileTimeStatistics}; | ||
|
||
use super::merge_compile_time_stats; | ||
|
||
/// test for merge_stat | ||
/// | ||
/// Step1. merge stats in `test/merge_stat/stat` for `rustc_A`. | ||
/// | ||
/// Step2. verify length of merged stats. | ||
/// | ||
/// Step3. clean up. | ||
#[test] | ||
fn test_merge_stat() { | ||
let root_dir = PathBuf::from("test/merge_stat/stat"); | ||
let profile = Profile::Release; | ||
let rustc = String::from("rustc_A"); | ||
let out_path = PathBuf::from("test/merge_stat/merge.json"); | ||
|
||
assert_eq!( | ||
merge_compile_time_stats(&root_dir, profile, rustc, out_path.clone()).unwrap(), | ||
out_path, | ||
); | ||
|
||
let stats: CompileTimeStatistics = | ||
serde_json::from_reader(BufReader::new(File::open(&out_path).unwrap())).unwrap(); | ||
|
||
assert_eq!(12, stats.len()); | ||
|
||
remove_file(out_path).unwrap(); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
data_manage/test/merge_stat/stat/bench_group_1/rustc_A/compile_time_results.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
data_manage/test/merge_stat/stat/bench_group_1/rustc_B/compile_time_results.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
data_manage/test/merge_stat/stat/bench_group_2/rustc_A/compile_time_results.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
data_manage/test/merge_stat/stat/bench_group_2/rustc_B/compile_time_results.json
Large diffs are not rendered by default.
Oops, something went wrong.