-
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 #25 from 191220029/record-compiled-binary-size
BinaryPlot: Plot change rate
- Loading branch information
Showing
9 changed files
with
1,453 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use std::{collections::HashMap, fs::File, io::BufReader, path::PathBuf}; | ||
|
||
use crate::{benchmark::profile::Profile, compile_time::result::CompileTimeBenchResult}; | ||
|
||
use super::BINARY_SIZE_LABEL; | ||
|
||
/// Compare changes of binary sizes between 2 input files. | ||
/// Step1. Read in 2 input files. | ||
/// Step2. Calculate the change rate. | ||
pub fn compare_binary_size( | ||
binary_size_a: &PathBuf, | ||
binary_size_b: &PathBuf, | ||
profile: Profile, | ||
) -> HashMap<String, f64> { | ||
let read_binary_size = |p: &PathBuf| { | ||
let data: Vec<CompileTimeBenchResult> = | ||
serde_json::from_reader(BufReader::new(File::open(p).unwrap())).unwrap(); | ||
data.into_iter() | ||
.map(move |i| { | ||
( | ||
i.get_benchmark(), | ||
*i.get_stats_ref_by_profile(&profile) | ||
.first() | ||
.unwrap() | ||
.stats | ||
.get(BINARY_SIZE_LABEL) | ||
.unwrap(), | ||
) | ||
}) | ||
.collect::<HashMap<_, _>>() | ||
}; | ||
|
||
let binary_size_a = read_binary_size(binary_size_a); | ||
let binary_size_b = read_binary_size(binary_size_b); | ||
|
||
// Calculate differences of 2 inputs. | ||
let difference: HashMap<String, f64> = binary_size_a | ||
.clone() | ||
.iter() | ||
.map(|(b, lhs)| (b.clone(), lhs - binary_size_b.get(b).unwrap())) | ||
.collect(); | ||
|
||
// Calculate change ratio. | ||
difference | ||
.iter() | ||
.map(|(b, d)| (b.clone(), { (d / binary_size_a.get(b).unwrap()) * 100. })) | ||
.collect() | ||
} | ||
|
||
#[cfg(test)] | ||
mod test_compare { | ||
use std::path::PathBuf; | ||
|
||
use crate::benchmark::profile::Profile; | ||
|
||
use super::compare_binary_size; | ||
|
||
#[test] | ||
fn test_compare_binary_size() { | ||
let binary_size_a = PathBuf::from("test/binary_size/compare/binary_size_1.json"); | ||
let binary_size_b = PathBuf::from("test/binary_size/compare/binary_size_2.json"); | ||
|
||
assert_ne!( | ||
0, | ||
compare_binary_size(&binary_size_a, &binary_size_b, Profile::Release).len() | ||
); | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
collector/src/compile_time/binary_size/plot/plotter_cmp.py
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 @@ | ||
import matplotlib.pyplot as plt | ||
import sys | ||
|
||
if __name__ == '__main__': | ||
args = sys.argv | ||
assert(len(args) > 2) | ||
|
||
raw_data = args[1].split(";") | ||
out_file = args[2] | ||
|
||
names = [item.split(',')[0] for item in raw_data] | ||
values = [float(item.split(',')[1]) for item in raw_data] | ||
colors = ['grey' if value >= 0 else '#A7E6BF' for value in values] | ||
|
||
plt.figure(dpi=800, figsize=(4, 3)) | ||
plt.bar(names, values, color=colors) | ||
plt.ylabel('Change rate of binary size (%)', fontsize=7) | ||
plt.yticks(fontsize=7) | ||
plt.xticks(rotation=90, fontsize=7) | ||
|
||
plt.tight_layout() | ||
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
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.