Skip to content

Commit bfdcf66

Browse files
committed
Multiple file paths
#618
1 parent aa89713 commit bfdcf66

File tree

25 files changed

+422
-209
lines changed

25 files changed

+422
-209
lines changed

services/cli/src/bencher/sub/run/mod.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,18 @@ impl Run {
158158
let start_time = DateTime::now();
159159
let mut results = Vec::with_capacity(self.iter);
160160
for _ in 0..self.iter {
161-
let output = self.runner.run(self.log).await?;
162-
if output.is_success() {
163-
results.push(output.result());
164-
} else if self.allow_failure {
165-
cli_eprintln_quietable!(self.log, "Skipping failure:\n{output}");
166-
} else {
167-
return Err(RunError::ExitStatus {
168-
runner: Box::new(self.runner.clone()),
169-
output,
170-
});
161+
let outputs = self.runner.run(self.log).await?;
162+
for output in outputs {
163+
if output.is_success() {
164+
results.push(output.result());
165+
} else if self.allow_failure {
166+
cli_eprintln_quietable!(self.log, "Skipping failure:\n{output}");
167+
} else {
168+
return Err(RunError::ExitStatus {
169+
runner: Box::new(self.runner.clone()),
170+
output,
171+
});
172+
}
171173
}
172174
}
173175

services/cli/src/bencher/sub/run/runner/command.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,20 @@ impl CommandOutput {
194194
Ok(self.output)
195195
}
196196

197-
pub fn build_with_file_path(mut self, file_path: &FilePath) -> Result<Output, RunError> {
197+
pub fn build_with_file_path(self, file_path: &FilePath) -> Result<Vec<Output>, RunError> {
198198
debug_assert!(
199199
self.build_command.is_none(),
200200
"Build command should not be set for file path"
201201
);
202202
let results = file_path.get_results()?;
203-
self.output.result = Some(results);
204-
Ok(self.output)
203+
let outputs = results
204+
.into_iter()
205+
.map(|result| Output {
206+
result: Some(result),
207+
..self.output.clone()
208+
})
209+
.collect();
210+
Ok(outputs)
205211
}
206212

207213
pub fn build_with_file_size(mut self, file_size: &FileSize) -> Result<Output, RunError> {

services/cli/src/bencher/sub/run/runner/file_path.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,33 @@ use camino::Utf8PathBuf;
55
use crate::RunError;
66

77
#[derive(Debug, Clone)]
8-
pub struct FilePath(Utf8PathBuf);
8+
pub struct FilePath(Vec<Utf8PathBuf>);
99

1010
impl fmt::Display for FilePath {
1111
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12-
write!(f, "{}", self.0)
12+
write!(
13+
f,
14+
"{}",
15+
self.0
16+
.iter()
17+
.map(|p| p.as_str())
18+
.collect::<Vec<&str>>()
19+
.join(", ")
20+
)
1321
}
1422
}
1523

1624
impl FilePath {
17-
pub fn new(file_path: Utf8PathBuf) -> Self {
18-
Self(file_path)
25+
pub fn new(file_paths: Vec<Utf8PathBuf>) -> Self {
26+
Self(file_paths)
1927
}
2028

21-
pub fn get_results(&self) -> Result<String, RunError> {
22-
std::fs::read_to_string(&self.0).map_err(RunError::OutputFileRead)
29+
pub fn get_results(&self) -> Result<Vec<String>, RunError> {
30+
let mut results = Vec::new();
31+
for path in &self.0 {
32+
let result = std::fs::read_to_string(path).map_err(RunError::OutputFileRead)?;
33+
results.push(result);
34+
}
35+
Ok(results)
2336
}
2437
}

services/cli/src/bencher/sub/run/runner/mod.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ impl TryFrom<CliRunCommand> for Runner {
5050
Command::new_exec(program, arguments)
5151
};
5252
let build_time = cmd.build_time.then_some(BuildTime);
53-
Ok(if let Some(file_path) = cmd.file {
54-
Self::CommandToFile(command, FilePath::new(file_path))
53+
Ok(if let Some(file_paths) = cmd.file {
54+
Self::CommandToFile(command, FilePath::new(file_paths))
5555
} else if let Some(file_paths) = cmd.file_size {
5656
Self::CommandToFileSize(command, build_time, FileSize::new(file_paths))
5757
} else {
5858
Self::Command(command, build_time)
5959
})
60-
} else if let Some(file_path) = cmd.file {
61-
Ok(Self::File(FilePath::new(file_path)))
60+
} else if let Some(file_paths) = cmd.file {
61+
Ok(Self::File(FilePath::new(file_paths)))
6262
} else if let Some(file_paths) = cmd.file_size {
6363
Ok(Self::FileSize(FileSize::new(file_paths)))
6464
} else if let Some(pipe) = Pipe::new() {
@@ -103,20 +103,25 @@ impl fmt::Display for Runner {
103103
}
104104

105105
impl Runner {
106-
pub async fn run(&self, log: bool) -> Result<Output, RunError> {
106+
pub async fn run(&self, log: bool) -> Result<Vec<Output>, RunError> {
107107
match self {
108-
Self::Pipe(pipe) => Ok(pipe.output()),
109-
Self::Command(command, build_time) => command.run(log, *build_time).await?.build(),
108+
Self::Pipe(pipe) => Ok(pipe.output().into()),
109+
Self::Command(command, build_time) => {
110+
command.run(log, *build_time).await?.build().map(Into::into)
111+
},
110112
Self::CommandToFile(command, file_path) => command
111113
.run(log, None)
112114
.await?
113115
.build_with_file_path(file_path),
114116
Self::CommandToFileSize(command, build_time, file_size) => command
115117
.run(log, *build_time)
116118
.await?
117-
.build_with_file_size(file_size),
119+
.build_with_file_size(file_size)
120+
.map(Into::into),
118121
Self::File(file_path) => CommandOutput::default().build_with_file_path(file_path),
119-
Self::FileSize(file_size) => CommandOutput::default().build_with_file_size(file_size),
122+
Self::FileSize(file_size) => CommandOutput::default()
123+
.build_with_file_size(file_size)
124+
.map(Into::into),
120125
}
121126
}
122127
}

services/cli/src/bencher/sub/run/runner/output.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ impl fmt::Display for ExitStatus {
3838
}
3939
}
4040

41+
impl From<Output> for Vec<Output> {
42+
fn from(output: Output) -> Self {
43+
vec![output]
44+
}
45+
}
46+
4147
impl Output {
4248
pub fn is_success(&self) -> bool {
4349
self.status.is_success()

services/cli/src/parser/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ pub struct CliRunCommand {
140140

141141
/// Benchmark command output file path
142142
#[clap(long, conflicts_with = "file_size")]
143-
pub file: Option<Utf8PathBuf>,
143+
pub file: Option<Vec<Utf8PathBuf>>,
144144

145145
/// Track the size of a file at the given file path
146146
#[clap(long, conflicts_with = "file")]

services/console/src/chunks/docs-explanation/bencher-run/de/benchmark-command.mdx

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,59 @@ import ExecForm from "../exec-form.mdx";
33

44
## Benchmark-Befehl
55

6-
Das erste Argument für `bencher run` ist der optionale Benchmark-Befehl.
7-
Dies ist der Befehl, der ausgeführt wird, um Ihr Benchmark-Harness zu starten.
6+
Das erste Argument von `bencher run` ist der optionale Benchmark-Befehl.
7+
Dies ist der Befehl, der ausgeführt wird und Ihr Benchmark-Harness aufruft.
88
Er kann auch über die Umgebungsvariable `BENCHER_CMD` gesetzt werden.
99
Standardmäßig wird dieser Befehl in einer Shell ausgeführt,
1010
die mit den Optionen [`--shell`][shell option] und [`--flag`][flag option] konfiguriert werden kann.
1111
Seine Ausgabe wird von einem [Benchmark-Harness-Adapter][benchmark harness adapters] geparst,
12-
der mit der Option [`--adapter`][adapter option] festgelegt werden kann.
13-
Wenn das Benchmark-Harness jedoch in eine Datei schreibt, dann muss auch die Option [`--file`][file option] verwendet werden, um den Pfad der Ausgabedatei anzugeben.
14-
Alternative, um die Größe der Ausgabedatei (z. B. Binärgröße) anstelle ihres Inhalts zu verfolgen,
12+
der mit der Option [`--adapter`][adapter option] gesetzt werden kann.
13+
Wenn das Benchmark-Harness jedoch in eine Datei schreibt, muss außerdem die Option [`--file`][file option] verwendet werden,
14+
um den Pfad der Ausgabedatei anzugeben.
15+
Alternativ, um die Größe der Ausgabedatei (z. B. Binärgröße) statt ihres Inhalts zu erfassen,
1516
verwenden Sie die Option [`--file-size`][file size option], um den Pfad der Ausgabedatei anzugeben.
1617

17-
Wenn Sie bevorzugen, dass der Befehl nicht in einer Shell ausgeführt wird, können Sie den `--exec` Flag verwenden oder einfach zusätzliche Argumente zu Ihrem Befehl als zusätzliche Argumente zu `bencher run` hinzufügen.
18+
Wenn Sie nicht möchten, dass der Befehl in einer Shell ausgeführt wird, können Sie das Flag `--exec` verwenden oder zusätzliche Argumente für Ihren Befehl einfach als zusätzliche Argumente an `bencher run` übergeben.
1819

19-
Shell-Formular:
20+
Shell-Form:
2021
<ShellForm />
2122

22-
Ausführungsformular:
23+
Exec-Form:
2324
<ExecForm />
2425

25-
Der Benchmark-Befehl kann mehrmals mit der Option [`--iter`][iter option] ausgeführt werden,
26+
Der Benchmark-Befehl kann mehrfach mit der Option [`--iter`][iter option] ausgeführt werden,
2627
und diese Ergebnisse können mit der Option [`--fold`][fold option] zu einem einzigen Ergebnis zusammengefasst werden.
2728
Wenn eine der Iterationen fehlschlägt, gilt der gesamte Befehl als fehlgeschlagen,
28-
es sei denn, der Flag [`--allow-failure`][allow failure flag] wird gesetzt.
29+
es sei denn, das Flag [`--allow-failure`][allow failure flag] ist gesetzt.
2930

30-
Wenn der Benchmark-Befehl nicht angegeben ist, aber die Option [`--file`][file option] verwendet wird,
31-
dann wird `bencher run` stattdessen einfach den Pfad der Ausgabedatei lesen.
32-
Ähnlich, wenn der Benchmark-Befehl nicht angegeben ist, aber die Option [`--file-size`][file size option] verwendet wird,
33-
dann wird `bencher run` einfach die Größe der Datei am angegebenen Dateipfad lesen.
34-
Wenn weder der Benchmark-Befehl, die Option [`--file`][file option],
31+
Wenn der Benchmark-Befehl nicht angegeben ist, aber die Option [`--file`][file option],
32+
dann wird `bencher run` stattdessen einfach aus dem angegebenen Ausgabedateipfad lesen.
33+
Ähnlich, wenn der Benchmark-Befehl nicht angegeben ist, aber die Option [`--file-size`][file size option],
34+
dann liest `bencher run` stattdessen nur die Größe der Datei am angegebenen Pfad.
35+
Beide Optionen `--file` und `--file-size` können mehrfach angegeben werden, um aus mehreren Dateien zu lesen.
36+
37+
<blockquote>
38+
<details>
39+
<summary>🐰 Tipps zur Verwendung der <code>-&#8288;-file</code> Option</summary>
40+
Die <code>-&#8288;-file</code>-Option kann verwendet werden, um Benchmark-Ergebnisse aus einer Datei zu lesen.
41+
Sie können die <code>-&#8288;-file</code>-Option mehrfach angeben, um aus mehreren Dateien zu lesen.
42+
Wenn Sie die <code>-&#8288;-file</code>-Option mehrfach angeben,
43+
wird jede Datei als separate <code>iteration</code> des Benchmark-Befehls betrachtet.
44+
Beim Anzeigen werden diese Ergebnisse in separaten Tabellen dargestellt.
45+
46+
Wenn Sie diese Ergebnisse zu einer einzigen <code>iteration</code> zusammenfassen möchten,
47+
können Sie die Option <code>-&#8288;-iter</code> auf <code>1</code> setzen
48+
und die Option <code>-&#8288;-fold</code> auf eine der Aggregatfunktionen <code>min</code>, <code>max</code> oder <code>median</code> setzen.
49+
Dadurch werden die Ergebnisse zu einer einzigen <code>iteration</code> zusammengefasst
50+
und in einer einzigen Tabelle angezeigt.
51+
Setzen Sie die Option <code>-&#8288;-fold</code> <b>nicht</b> auf <code>mean</code>.
52+
</details>
53+
</blockquote>
54+
55+
Wenn weder der Benchmark-Befehl noch die Option [`--file`][file option]
3556
noch die Option [`--file-size`][file size option] angegeben sind,
36-
wird `bencher run` stattdessen von `stdin` lesen.
37-
Dies ermöglicht es Ihnen, die Ausgabe eines anderen Befehls in eine Datei zu speichern oder in `bencher run` zu pipen.
57+
dann liest `bencher run` stattdessen von `stdin`.
58+
Das ermöglicht es Ihnen, die Ausgabe eines anderen Befehls in eine Datei zu speichern oder sie in `bencher run` zu pipen.
3859

3960
[benchmark harness adapters]: /de/docs/explanation/adapters/
4061

services/console/src/chunks/docs-explanation/bencher-run/en/benchmark-command.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@ If the benchmark command is not specified but the [`--file`][file option] option
3232
then `bencher run` will just read from output file path instead.
3333
Similarly, if the the benchmark command is not specified but the [`--file-size`][file size option] option is,
3434
then `bencher run` will just read the size of the file at the given file path instead.
35+
Both `--file` and `--file-size` options can be specified multiple times to read from multiple files.
36+
37+
<blockquote>
38+
<details>
39+
<summary>🐰 Tips for using the <code>-&#8288;-file</code> option</summary>
40+
The <code>-&#8288;-file</code> option can be used to read benchmark results from a file.
41+
You can specify the <code>-&#8288;-file</code> option multiple times to read from multiple files.
42+
If you do specify the <code>-&#8288;-file</code> option multiple times,
43+
then each file will be considered a separate <code>iteration</code> of the benchmark command.
44+
When displayed, these results will be shown in separate tables.
45+
46+
If you wish to combined these results into a single <code>iteration</code>,
47+
then you can set the <code>-&#8288;-iter</code> option to <code>1</code>
48+
and set the <code>-&#8288;-fold</code> option to either the <code>min</code>, <code>max</code>, or <code>median</code> aggregate functions.
49+
This will fold the results into a single <code>iteration</code>
50+
and display them in a single table.
51+
Do <b>not</b> set the <code>-&#8288;-fold</code> option to <code>mean</code>.
52+
</details>
53+
</blockquote>
54+
3555
If neither the benchmark command, [`--file`][file option] option,
3656
nor [`--file-size`][file size option] option are specified,
3757
then `bencher run` will read from `stdin` instead.

services/console/src/chunks/docs-explanation/bencher-run/es/benchmark-command.mdx

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,61 @@
11
import ShellForm from "../shell-form.mdx";
22
import ExecForm from "../exec-form.mdx";
33

4-
## Comando de Benchmark
5-
6-
El primer argumento para `bencher run` es el comando de benchmark opcional.
7-
Este es el comando que se ejecutará, invocando tu arnés de referencia.
8-
También se puede establecer usando la variable de entorno `BENCHER_CMD`.
9-
Por defecto, este comando se ejecuta en una shell,
10-
que se puede configurar con las opciones [`--shell`][shell option] y [`--flag`][flag option].
11-
Su salida es analizada por un [adaptador del arnés de referencia][benchmark harness adapters],
12-
que se puede establecer usando la opción [`--adapter`][adapter option].
13-
Sin embargo, si el arnés de referencia genera salida a un archivo, entonces la opción [`--file`][file option]
14-
también debe usarse para especificar la ruta del archivo de salida.
15-
Alternativamente, para rastrear el tamaño del archivo de salida (es decir, tamaño binario) en lugar de su contenido,
4+
## Comando de benchmark
5+
6+
El primer argumento de `bencher run` es el comando de benchmark opcional.
7+
Este es el comando que se ejecutará para invocar tu harness de benchmark.
8+
También puede establecerse mediante la variable de entorno `BENCHER_CMD`.
9+
Por defecto este comando se ejecuta en un shell,
10+
el cual puede configurarse con las opciones [`--shell`][shell option] y [`--flag`][flag option].
11+
Su salida es analizada por un [benchmark harness adapter][benchmark harness adapters],
12+
que puede establecerse usando la opción [`--adapter`][adapter option].
13+
Sin embargo, si el harness de benchmark escribe en un archivo entonces también debe usarse la opción [`--file`][file option]
14+
para especificar la ruta del archivo de salida.
15+
Alternativamente, para rastrear el tamaño del archivo de salida (por ejemplo, el tamaño del binario) en lugar de su contenido,
1616
usa la opción [`--file-size`][file size option] para especificar la ruta del archivo de salida.
1717

18-
Si prefieres que el comando no se ejecute en una shell, puedes usar la bandera `--exec` o simplemente proporcionar argumentos adicionales a tu comando como argumentos adicionales a `bencher run`.
18+
Si prefieres que el comando no se ejecute en un shell, puedes usar la bandera `--exec` o simplemente proporcionar argumentos adicionales a tu comando como argumentos adicionales a `bencher run`.
1919

2020
Forma Shell:
2121
<ShellForm />
2222

2323
Forma Exec:
2424
<ExecForm />
2525

26-
El comando de benchmark se puede ejecutar múltiples veces usando la opción [`--iter`][iter option],
27-
y esos resultados pueden ser combinados en un solo resultado usando la opción [`--fold`][fold option].
26+
El comando de benchmark puede ejecutarse múltiples veces usando la opción [`--iter`][iter option],
27+
y esos resultados pueden combinarse en un único resultado usando la opción [`--fold`][fold option].
2828
Si alguna de las iteraciones falla, entonces se considera que todo el comando ha fallado
29-
a menos que la bandera [`--allow-failure`][allow failure flag] esté establecida.
30-
31-
Si el comando de benchmark no se especifica pero la opción [`--file`][file option] sí,
32-
entonces `bencher run` simplemente leerá de la ruta del archivo de salida en su lugar.
33-
De manera similar, si el comando de benchmark no se especifica pero la opción [`--file-size`][file size option] sí,
34-
entonces `bencher run` simplemente leerá el tamaño del archivo en la ruta de archivo dada en su lugar.
35-
Si ni el comando de benchmark, la opción [`--file`][file option],
36-
ni la opción [`--file-size`][file size option] están especificados,
37-
entonces `bencher run` leerá desde `stdin` en su lugar.
38-
Esto te permite guardar la salida de otro comando en un archivo o canalizarlo a `bencher run`.
29+
a menos que se haya establecido la bandera [`--allow-failure`][allow failure flag].
30+
31+
Si no se especifica el comando de benchmark pero sí la opción [`--file`][file option],
32+
entonces `bencher run` simplemente leerá desde la ruta del archivo de salida.
33+
De forma similar, si no se especifica el comando de benchmark pero sí la opción [`--file-size`][file size option],
34+
entonces `bencher run` simplemente leerá el tamaño del archivo en la ruta indicada.
35+
Las opciones `--file` y `--file-size` pueden especificarse varias veces para leer desde múltiples archivos.
36+
37+
<blockquote>
38+
<details>
39+
<summary>🐰 Consejos para usar la opción <code>-&#8288;-file</code></summary>
40+
La opción <code>-&#8288;-file</code> se puede usar para leer resultados de benchmark desde un archivo.
41+
Puedes especificar la opción <code>-&#8288;-file</code> varias veces para leer desde múltiples archivos.
42+
Si especificas la opción <code>-&#8288;-file</code> varias veces,
43+
entonces cada archivo se considerará una <code>iteración</code> separada del comando de benchmark.
44+
Cuando se muestren, estos resultados aparecerán en tablas separadas.
45+
46+
Si deseas combinar estos resultados en una sola <code>iteración</code>,
47+
puedes establecer la opción <code>-&#8288;-iter</code> en <code>1</code>
48+
y establecer la opción <code>-&#8288;-fold</code> en una de las funciones de agregación <code>min</code>, <code>max</code> o <code>median</code>.
49+
Esto plegará los resultados en una sola <code>iteración</code>
50+
y los mostrará en una única tabla.
51+
No establezcas la opción <code>-&#8288;-fold</code> en <code>mean</code>.
52+
</details>
53+
</blockquote>
54+
55+
Si no se especifican ni el comando de benchmark, ni la opción [`--file`][file option],
56+
ni la opción [`--file-size`][file size option],
57+
entonces `bencher run` leerá desde `stdin`.
58+
Esto te permite guardar la salida de otro comando en un archivo o encadenarla (pipe) a `bencher run`.
3959

4060
[benchmark harness adapters]: /es/docs/explanation/adapters/
4161

0 commit comments

Comments
 (0)