-
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 #21 from 191220029/record-compiled-binary-size
Impl plottor for compiled_binary_size
- Loading branch information
Showing
14 changed files
with
1,950 additions
and
13 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
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,67 @@ | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
import sys | ||
|
||
def annotate_interval(y_axis: list[float]) -> list[list[float, float]]: | ||
tolerance = 7.0 | ||
cur_offset_left = 0 | ||
cur_offset_right = 0 | ||
cur_offset = 0 | ||
intervals = [] | ||
for (i, y) in enumerate(y_axis): | ||
if i % 2 == 0: | ||
cur_offset = cur_offset_left | ||
else: | ||
cur_offset = cur_offset_right | ||
|
||
if i - 2 >= 0: | ||
interval = y - y_axis[i-2] | ||
if interval < tolerance: | ||
cur_offset += tolerance - interval | ||
else: | ||
cur_offset = max(0, cur_offset - (interval - tolerance)) | ||
|
||
if i % 2 == 0: | ||
cur_offset_left = cur_offset | ||
intervals.append([-80, cur_offset]) | ||
else: | ||
cur_offset_right = cur_offset | ||
intervals.append([20, cur_offset]) | ||
return intervals | ||
|
||
if __name__ == '__main__': | ||
args = sys.argv | ||
assert(len(args) > 3) | ||
|
||
raw_data_1 = args[1] | ||
raw_data_2 = args[2] | ||
label_1 = args[3] | ||
label_2 = args[4] | ||
out_file = args[5] | ||
|
||
data_pair_1 = [[item.split(',')[0], float(item.split(',')[1])] for item in raw_data_1.split(';')] | ||
data_pair_2 = [[item.split(',')[0], float(item.split(',')[1])] for item in raw_data_2.split(';')] | ||
data_pair_1.sort(key=lambda d: d[1]) | ||
data_pair_2.sort(key=lambda d: d[1]) | ||
|
||
data_1 = [item[1] for item in data_pair_1] | ||
data_2 = [item[1] for item in data_pair_2] | ||
interval_1 = annotate_interval(data_1) | ||
interval_2 = annotate_interval(data_2) | ||
annotate_1 = [item[0] for item in data_pair_1] | ||
annotate_2 = [item[0] for item in data_pair_2] | ||
|
||
plt.figure(dpi=500) | ||
plt.boxplot([data_1, data_2], labels=[label_1, label_2]) | ||
|
||
plt.scatter([1]*len(data_1), data_1, color='green', marker='o', s=2) | ||
plt.scatter([2]*len(data_2), data_2, color='green', marker='o', s=2) | ||
|
||
for i, d1 in enumerate(data_1): | ||
plt.annotate(annotate_1[i], (1, d1), textcoords="offset points", xytext=(interval_1[i][0], interval_1[i][1]), arrowprops=dict(headlength = 0.1, width = 0.15, headwidth = 0.1, shrink=0.99, linewidth=0.2, mutation_scale=0.1), fontsize=9) | ||
for i, d2 in enumerate(data_2): | ||
plt.annotate(annotate_2[i], (2, d2), textcoords="offset points", xytext=(interval_2[i][0], interval_2[i][1]), arrowprops=dict(headlength = 0.1, width = 0.15, headwidth = 0.1, shrink=0.99, linewidth=0.2, mutation_scale=0.1), fontsize=9) | ||
|
||
plt.ylabel('Binary Size (MB)') | ||
|
||
plt.savefig(out_file) |
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,92 @@ | ||
use std::{ | ||
fs::File, | ||
io::BufReader, | ||
path::PathBuf, | ||
process::{Command, Stdio}, | ||
}; | ||
|
||
use crate::{ | ||
benchmark::profile::Profile, | ||
compile_time::{binary_size::BINARY_SIZE_LABEL, result::CompileTimeBenchResult}, | ||
}; | ||
|
||
pub fn plot( | ||
data_file_a: PathBuf, | ||
data_file_b: PathBuf, | ||
label_a: String, | ||
label_b: String, | ||
out_path: PathBuf, | ||
profile: Profile, | ||
) -> anyhow::Result<()> { | ||
let data_a: Vec<CompileTimeBenchResult> = | ||
serde_json::from_reader(BufReader::new(File::open(data_file_a)?))?; | ||
|
||
let data_b: Vec<CompileTimeBenchResult> = | ||
serde_json::from_reader(BufReader::new(File::open(data_file_b)?))?; | ||
|
||
let get_benchmark_binary_size = |d: &Vec<CompileTimeBenchResult>| { | ||
d.iter() | ||
.map(|d| { | ||
d.get_benchmark() | ||
+ "," | ||
+ d.get_stats_ref_by_profile(&profile) | ||
.first() | ||
.unwrap() | ||
.stats | ||
.get(&BINARY_SIZE_LABEL.to_string()) | ||
.unwrap() | ||
.to_string() | ||
.as_str() | ||
}) | ||
.collect::<Vec<String>>() | ||
.join(";") | ||
}; | ||
|
||
let benchmark_binary_size_a = get_benchmark_binary_size(&data_a); | ||
let benchmark_binary_size_b = get_benchmark_binary_size(&data_b); | ||
|
||
let mut cmd = Command::new("python"); | ||
cmd.arg("src/compile_time/binary_size/plotter.py") | ||
.arg(benchmark_binary_size_a) | ||
.arg(benchmark_binary_size_b) | ||
.arg(label_a) | ||
.arg(label_b) | ||
.arg(&out_path); | ||
cmd.stdout(Stdio::inherit()); | ||
cmd.spawn().unwrap().wait().unwrap(); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[cfg(test)] | ||
mod test_binary_size_plotter { | ||
use std::{ | ||
fs::{self, remove_file}, | ||
path::PathBuf, | ||
}; | ||
|
||
use crate::benchmark::profile::Profile; | ||
|
||
use super::plot; | ||
|
||
#[test] | ||
fn test_plotter() { | ||
let data_path_a = PathBuf::from("test/binary_size/plotter/merged_binary_size.json"); | ||
let data_path_b = | ||
PathBuf::from("test/binary_size/plotter/merged_rustc_perf_binary_size.json"); | ||
let file_path = PathBuf::from("test/binary_size/plotter/merged_binary_size.jpg"); | ||
|
||
plot( | ||
data_path_a, | ||
data_path_b, | ||
"A".to_string(), | ||
"B".to_string(), | ||
file_path.clone(), | ||
Profile::Release, | ||
) | ||
.unwrap(); | ||
|
||
fs::metadata(&file_path).unwrap(); | ||
remove_file(file_path).unwrap(); | ||
} | ||
} |
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
Oops, something went wrong.