]> git.proxmox.com Git - proxmox-backup.git/blame - examples/download-speed.rs
ui: drop id field from verify/sync add window
[proxmox-backup.git] / examples / download-speed.rs
CommitLineData
17243003
DM
1use std::io::Write;
2
f7d4e4b5 3use anyhow::{Error};
b9203d87 4
e7cb4dc5 5use proxmox_backup::api2::types::Userid;
d59dbeca 6use proxmox_backup::client::{HttpClient, HttpClientOptions, BackupReader};
17243003
DM
7
8pub struct DummyWriter {
9 bytes: usize,
10}
11
12impl Write for DummyWriter {
13
14 fn write(&mut self, data: &[u8]) -> Result<usize, std::io::Error> {
15 self.bytes += data.len();
16 Ok(data.len())
17 }
18
19 fn flush(&mut self) -> Result<(), std::io::Error> {
20 Ok(())
21 }
22}
23
24
b9203d87 25async fn run() -> Result<(), Error> {
17243003
DM
26
27 let host = "localhost";
28
e7cb4dc5 29 let username = Userid::root_userid();
17243003 30
d59dbeca
DM
31 let options = HttpClientOptions::new()
32 .interactive(true)
33 .ticket_cache(true);
34
b19b4bfc 35 let client = HttpClient::new(host, 8007, username, options)?;
17243003 36
6a7be83e 37 let backup_time = proxmox::tools::time::parse_rfc3339("2019-06-28T10:49:48Z")?;
17243003 38
296c50ba 39 let client = BackupReader::start(client, None, "store2", "host", "elsa", backup_time, true)
b9203d87 40 .await?;
17243003
DM
41
42 let start = std::time::SystemTime::now();
43
b9203d87
WB
44 let mut bytes = 0;
45 for _ in 0..100 {
3d571d55
WB
46 let mut writer = DummyWriter { bytes: 0 };
47 client.speedtest(&mut writer).await?;
b9203d87
WB
48 println!("Received {} bytes", writer.bytes);
49 bytes += writer.bytes;
50 }
17243003 51
b9203d87
WB
52 let elapsed = start.elapsed().unwrap();
53 let elapsed = (elapsed.as_secs() as f64) +
54 (elapsed.subsec_millis() as f64)/1000.0;
17243003 55
b9203d87 56 println!("Downloaded {} bytes, {} MB/s", bytes, (bytes as f64)/(elapsed*1024.0*1024.0));
17243003 57
b9203d87
WB
58 Ok(())
59}
17243003 60
29c55e5f 61fn main() {
d973aa82 62 if let Err(err) = proxmox_backup::tools::runtime::main(run()) {
b9203d87
WB
63 eprintln!("ERROR: {}", err);
64 }
65 println!("DONE");
17243003 66}