Skip to content

Commit 3b72d04

Browse files
authored
Merge pull request #191 from RReverser/master
Fix directory name escaping
2 parents b3b0c88 + 6af097e commit 3b72d04

File tree

4 files changed

+26
-22
lines changed

4 files changed

+26
-22
lines changed

src/html/mod.rs

+23-17
Original file line numberDiff line numberDiff line change
@@ -264,25 +264,27 @@ impl Report for Html {
264264
.collect::<Vec<_>>();
265265

266266
let mut all_plots = vec![];
267-
let group_id = &all_ids[0].group_id;
267+
let group_id = all_ids[0].group_id.clone();
268+
269+
let data: Vec<(BenchmarkId, Vec<f64>)> =
270+
self.load_summary_data(&context.output_directory, &all_ids);
268271

269272
let mut function_ids = BTreeSet::new();
270-
for id in &all_ids {
271-
if let Some(ref function_id) = id.function_id {
273+
for id in all_ids {
274+
if let Some(function_id) = id.function_id {
272275
function_ids.insert(function_id);
273276
}
274277
}
275278

276-
let data: Vec<(BenchmarkId, Vec<f64>)> =
277-
self.load_summary_data(&context.output_directory, &all_ids);
278-
279279
for function_id in function_ids {
280280
let samples_with_function: Vec<_> = data.iter()
281281
.by_ref()
282-
.filter(|&&(ref id, _)| id.function_id.as_ref() == Some(function_id))
282+
.filter(|&&(ref id, _)| id.function_id.as_ref() == Some(&function_id))
283283
.collect();
284+
284285
if samples_with_function.len() > 1 {
285-
let subgroup_id = format!("{}/{}", group_id, function_id);
286+
let subgroup_id = BenchmarkId::new(group_id.clone(), Some(function_id), None, None);
287+
286288
all_plots.extend(self.generate_summary(
287289
&subgroup_id,
288290
&*samples_with_function,
@@ -293,7 +295,7 @@ impl Report for Html {
293295
}
294296

295297
all_plots.extend(self.generate_summary(
296-
group_id,
298+
&BenchmarkId::new(group_id, None, None, None),
297299
&*(data.iter().by_ref().collect::<Vec<_>>()),
298300
context,
299301
true,
@@ -586,7 +588,7 @@ impl Html {
586588

587589
fn generate_summary(
588590
&self,
589-
group_id: &str,
591+
id: &BenchmarkId,
590592
data: &[&(BenchmarkId, Vec<f64>)],
591593
report_context: &ReportContext,
592594
full_summary: bool,
@@ -596,17 +598,19 @@ impl Html {
596598
try_else_return!(
597599
fs::mkdirp(&format!(
598600
"{}/{}/report/",
599-
report_context.output_directory, group_id
601+
report_context.output_directory,
602+
id.as_directory_name()
600603
)),
601604
|| gnuplots
602605
);
603606

604607
let violin_path = format!(
605608
"{}/{}/report/violin.svg",
606-
report_context.output_directory, group_id
609+
report_context.output_directory,
610+
id.as_directory_name()
607611
);
608612
gnuplots.push(plot::summary::violin(
609-
group_id,
613+
id.id(),
610614
data,
611615
&violin_path,
612616
report_context.plot_config.summary_scale,
@@ -622,11 +626,12 @@ impl Html {
622626
if let Some(value_type) = value_types[0] {
623627
let path = format!(
624628
"{}/{}/report/lines.svg",
625-
report_context.output_directory, group_id
629+
report_context.output_directory,
630+
id.as_directory_name()
626631
);
627632

628633
gnuplots.push(plot::summary::line_comparison(
629-
group_id,
634+
id.id(),
630635
data,
631636
&path,
632637
value_type,
@@ -643,7 +648,7 @@ impl Html {
643648
.collect();
644649

645650
let context = SummaryContext {
646-
group_id: group_id.to_owned(),
651+
group_id: id.id().to_owned(),
647652

648653
thumbnail_width: THUMBNAIL_SIZE.0,
649654
thumbnail_height: THUMBNAIL_SIZE.1,
@@ -662,7 +667,8 @@ impl Html {
662667
&text,
663668
&format!(
664669
"{}/{}/report/index.html",
665-
report_context.output_directory, group_id
670+
report_context.output_directory,
671+
id.as_directory_name()
666672
),
667673
),
668674
|| gnuplots

src/plot/summary.rs

-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ pub fn line_comparison(
7979
.group_by(|&&&(ref id, _)| &id.function_id)
8080
{
8181
let mut tuples: Vec<_> = group
82-
.into_iter()
8382
.map(|&&(ref id, ref sample)| {
8483
// Unwrap is fine here because it will only fail if the assumptions above are not true
8584
// ie. programmer error.

src/report.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ impl BenchmarkId {
7575
.replace("\"", "_")
7676
.replace("/", "_")
7777
.replace("\\", "_")
78-
.replace(".", "_")
7978
.replace("*", "_")
8079
}
8180

@@ -92,7 +91,7 @@ impl BenchmarkId {
9291
(&None, &Some(ref val)) => {
9392
format!("{}/{}", directory_safe(&group_id), directory_safe(val))
9493
}
95-
(&None, &None) => group_id.clone(),
94+
(&None, &None) => directory_safe(&group_id),
9695
};
9796

9897
BenchmarkId {

tests/criterion_tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -407,15 +407,15 @@ fn test_output_files() {
407407
"test_output",
408408
Benchmark::new("output_1", |b| b.iter(|| 10))
409409
.with_function("output_2", |b| b.iter(|| 20))
410-
.with_function("output_\\/.*\"?", |b| b.iter(|| 30)),
410+
.with_function("output_\\/*\"?", |b| b.iter(|| 30)),
411411
);
412412
}
413413

414414
// For each benchmark, assert that the expected files are present.
415415
for x in 0..3 {
416416
let dir = if x == 2 {
417417
// Check that certain special characters are replaced with underscores
418-
tempdir.path().join(format!("test_output/output_______"))
418+
tempdir.path().join(format!("test_output/output______"))
419419
} else {
420420
tempdir.path().join(format!("test_output/output_{}", x + 1))
421421
};

0 commit comments

Comments
 (0)