|
1 | 1 | mod benchmark;
|
2 | 2 |
|
3 | 3 | use crate::toolchain::LocalToolchain;
|
| 4 | +use std::future::Future; |
4 | 5 | use std::io::{BufRead, BufReader};
|
5 | 6 | use std::path::{Path, PathBuf};
|
6 | 7 | use std::process::{Command, Stdio};
|
7 | 8 | use thousands::Separable;
|
8 | 9 |
|
9 | 10 | use benchlib::comm::messages::{BenchmarkMessage, BenchmarkResult, BenchmarkStats};
|
10 | 11 | pub use benchmark::BenchmarkFilter;
|
11 |
| -use database::{ArtifactId, ArtifactIdNumber, Connection, Pool}; |
| 12 | +use database::{ArtifactId, ArtifactIdNumber, CollectionId, Connection, Pool}; |
12 | 13 |
|
13 | 14 | use crate::utils::git::get_rustc_perf_commit;
|
14 | 15 |
|
15 | 16 | /// Perform a series of runtime benchmarks using the provided `rustc` compiler.
|
16 | 17 | /// The runtime benchmarks are looked up in `benchmark_dir`, which is expected to be a path
|
17 |
| -/// to a Cargo crate. All binaries built by that crate will are expected to be runtime benchmark |
18 |
| -/// groups that leverage `benchlib`. |
| 18 | +/// to a Cargo crate. All binaries built by that crate are expected to be runtime benchmark |
| 19 | +/// groups that use `benchlib`. |
19 | 20 | pub async fn bench_runtime(
|
20 |
| - db: Pool, |
| 21 | + db: &Pool, |
21 | 22 | artifact_id: ArtifactId,
|
22 | 23 | toolchain: LocalToolchain,
|
23 | 24 | filter: BenchmarkFilter,
|
@@ -80,19 +81,76 @@ async fn record_stats(
|
80 | 81 | rustc_perf_version: &str,
|
81 | 82 | result: BenchmarkResult,
|
82 | 83 | ) {
|
83 |
| - for stat in result.stats { |
| 84 | + fn record<'a>( |
| 85 | + conn: &'a Box<dyn Connection>, |
| 86 | + artifact_id: ArtifactIdNumber, |
| 87 | + collection_id: CollectionId, |
| 88 | + result: &'a BenchmarkResult, |
| 89 | + value: Option<u64>, |
| 90 | + metric: &'a str, |
| 91 | + ) -> impl Future<Output = ()> + 'a { |
| 92 | + async move { |
| 93 | + if let Some(value) = value { |
| 94 | + conn.record_runtime_statistic( |
| 95 | + collection_id, |
| 96 | + artifact_id, |
| 97 | + &result.name, |
| 98 | + metric, |
| 99 | + value as f64, |
| 100 | + ) |
| 101 | + .await; |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + for stat in &result.stats { |
84 | 107 | let collection_id = conn.collection_id(rustc_perf_version).await;
|
85 | 108 |
|
86 |
| - if let Some(value) = stat.instructions { |
87 |
| - conn.record_runtime_statistic( |
88 |
| - collection_id, |
89 |
| - artifact_id, |
90 |
| - &result.name, |
91 |
| - "instructions:u", |
92 |
| - value as f64, |
93 |
| - ) |
94 |
| - .await; |
95 |
| - } |
| 109 | + record( |
| 110 | + conn, |
| 111 | + artifact_id, |
| 112 | + collection_id, |
| 113 | + &result, |
| 114 | + stat.instructions, |
| 115 | + "instructions:u", |
| 116 | + ) |
| 117 | + .await; |
| 118 | + record( |
| 119 | + conn, |
| 120 | + artifact_id, |
| 121 | + collection_id, |
| 122 | + &result, |
| 123 | + stat.cycles, |
| 124 | + "cycles:u", |
| 125 | + ) |
| 126 | + .await; |
| 127 | + record( |
| 128 | + conn, |
| 129 | + artifact_id, |
| 130 | + collection_id, |
| 131 | + &result, |
| 132 | + stat.branch_misses, |
| 133 | + "branch-misses", |
| 134 | + ) |
| 135 | + .await; |
| 136 | + record( |
| 137 | + conn, |
| 138 | + artifact_id, |
| 139 | + collection_id, |
| 140 | + &result, |
| 141 | + stat.cache_misses, |
| 142 | + "cache-misses", |
| 143 | + ) |
| 144 | + .await; |
| 145 | + record( |
| 146 | + conn, |
| 147 | + artifact_id, |
| 148 | + collection_id, |
| 149 | + &result, |
| 150 | + Some(stat.wall_time.as_nanos() as u64), |
| 151 | + "wall-time", |
| 152 | + ) |
| 153 | + .await; |
96 | 154 | }
|
97 | 155 | }
|
98 | 156 |
|
|
0 commit comments