Skip to content

Commit 016f0f5

Browse files
stepanchegfacebook-github-bot
authored andcommitted
NetworkStatisticsResponse -> RemoteExecutionClientStats
Summary: Following diff D39319605 adds more fields to `RemoteExecutionClientStats`. Reviewed By: krallin Differential Revision: D39311890 fbshipit-source-id: d63f12e527a08add20f604d560b2ee404c809842
1 parent 1937f7f commit 016f0f5

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

buck2_execute/src/re/client.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ impl RemoteExecutionStaticMetadata {
138138
}
139139
}
140140

141+
pub struct RemoteExecutionClientStats {
142+
/// In bytes.
143+
pub uploaded: u64,
144+
/// In bytes.
145+
pub downloaded: u64,
146+
}
147+
141148
#[derive(Clone, Dupe)]
142149
pub struct RemoteExecutionClient {
143150
data: Arc<RemoteExecutionClientData>,
@@ -350,18 +357,27 @@ impl RemoteExecutionClient {
350357
self.data.client.client().get_experiment_name()
351358
}
352359

353-
pub fn get_network_stats(&self) -> anyhow::Result<NetworkStatisticsResponse> {
360+
pub fn get_network_stats(&self) -> anyhow::Result<RemoteExecutionClientStats> {
354361
let updated = self
355362
.data
356363
.client
357364
.client()
358365
.get_network_stats()
359366
.context("Error getting updated network stats")?;
360367

361-
Ok(NetworkStatisticsResponse {
362-
uploaded: updated.uploaded - self.data.initial_network_stats.uploaded,
363-
downloaded: updated.downloaded - self.data.initial_network_stats.downloaded,
364-
..Default::default()
368+
let uploaded = updated
369+
.uploaded
370+
.checked_sub(self.data.initial_network_stats.uploaded)
371+
.and_then(|d| u64::try_from(d).ok())
372+
.context("Overflow calculating uploaded bytes")?;
373+
let downloaded = updated
374+
.downloaded
375+
.checked_sub(self.data.initial_network_stats.downloaded)
376+
.and_then(|d| u64::try_from(d).ok())
377+
.context("Overflow calculating downloaded bytes")?;
378+
Ok(RemoteExecutionClientStats {
379+
uploaded,
380+
downloaded,
365381
})
366382
}
367383
}

buck2_execute/src/re/manager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use remote_execution::ExecuteResponse;
3131
use remote_execution::InlinedBlobWithDigest;
3232
use remote_execution::NamedDigest;
3333
use remote_execution::NamedDigestWithPermissions;
34-
use remote_execution::NetworkStatisticsResponse;
3534
use remote_execution::TActionResult2;
3635
use remote_execution::TDigest;
3736

@@ -42,6 +41,7 @@ use crate::execute::manager::CommandExecutionManager;
4241
use crate::materialize::materializer::Materializer;
4342
use crate::re::action_identity::ReActionIdentity;
4443
use crate::re::client::RemoteExecutionClient;
44+
use crate::re::client::RemoteExecutionClientStats;
4545
use crate::re::client::RemoteExecutionStaticMetadata;
4646
use crate::re::knobs::ReExecutorGlobalKnobs;
4747
use crate::re::re_get_session_id::ReGetSessionId;
@@ -222,7 +222,7 @@ impl ReConnectionManager {
222222
}
223223
}
224224

225-
pub fn get_network_stats(&self) -> anyhow::Result<Option<NetworkStatisticsResponse>> {
225+
pub fn get_network_stats(&self) -> anyhow::Result<Option<RemoteExecutionClientStats>> {
226226
let conn = self.data.read().unwrap().upgrade();
227227
conn.as_ref()
228228
.and_then(|lazy_client| lazy_client.with_client(|client| client.get_network_stats()))

buck2_server/src/snapshot.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,8 @@ impl SnapshotCollector {
7171
None => return Ok(()),
7272
};
7373

74-
snapshot.re_download_bytes = stats
75-
.downloaded
76-
.try_into()
77-
.with_context(|| format!("Invalid downloaded bytes: `{}`", stats.downloaded))?;
78-
79-
snapshot.re_upload_bytes = stats
80-
.uploaded
81-
.try_into()
82-
.with_context(|| format!("Invalid uploaded bytes: `{}`", stats.uploaded))?;
74+
snapshot.re_download_bytes = stats.downloaded;
75+
snapshot.re_upload_bytes = stats.uploaded;
8376

8477
Ok(())
8578
}

0 commit comments

Comments
 (0)