mirror of
https://github.com/facebook/sapling.git
synced 2024-10-12 01:39:21 +03:00
remotefilelog: print HTTP stats in debug output
Summary: Print out download stats when `edenapi.debug` is set. Pretty printing of the stats has been improved to make these numbers more useful to humans. Reviewed By: xavierd Differential Revision: D15466702 fbshipit-source-id: 6fac9ca5976b98874fc7a5f9b89d42975e1520ce
This commit is contained in:
parent
7b90c6c483
commit
cafacdf6b4
@ -803,6 +803,9 @@ class fileserverclient(object):
|
||||
|
||||
stats = self.repo.edenapi.get_files(fileids, dpack, progcallback)
|
||||
|
||||
if edenapi.debug(self.ui):
|
||||
self.ui.warn(_("%s\n") % stats.to_str())
|
||||
|
||||
self.ui.metrics.gauge("http_getfiles_time_ms", stats.time_in_millis())
|
||||
self.ui.metrics.gauge("http_getfiles_bytes_downloaded", stats.downloaded())
|
||||
self.ui.metrics.gauge("http_getfiles_bytes_uploaded", stats.uploaded())
|
||||
@ -827,6 +830,9 @@ class fileserverclient(object):
|
||||
|
||||
stats = self.repo.edenapi.get_history(fileids, hpack, depth, progcallback)
|
||||
|
||||
if edenapi.debug(self.ui):
|
||||
self.ui.warn(_("%s\n") % stats.to_str())
|
||||
|
||||
self.ui.metrics.gauge("http_gethistory_time_ms", stats.time_in_millis())
|
||||
self.ui.metrics.gauge("http_gethistory_bytes_downloaded", stats.downloaded())
|
||||
self.ui.metrics.gauge("http_gethistory_bytes_uploaded", stats.uploaded())
|
||||
|
@ -23,13 +23,31 @@ impl DownloadStats {
|
||||
impl fmt::Display for DownloadStats {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let rate = self.bytes_per_second() / 1_000_000.0; // Convert to MB/s.
|
||||
let time = self.time_in_seconds();
|
||||
let (time, prec, unit) = if time > 1.0 {
|
||||
(time, 2, "s")
|
||||
} else {
|
||||
(time * 1000.0, 0, "ms")
|
||||
};
|
||||
write!(
|
||||
f,
|
||||
"Downloaded {} bytes in {:.3} seconds over {} request(s) ({:.2} MB/s)",
|
||||
self.downloaded,
|
||||
self.time_in_seconds(),
|
||||
"{} downloaded in {:.*} {} over {} request{} ({:.2} MB/s)",
|
||||
fmt_num_bytes(self.downloaded),
|
||||
prec,
|
||||
time,
|
||||
unit,
|
||||
self.requests,
|
||||
if self.requests == 1 { "" } else { "s" },
|
||||
rate
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn fmt_num_bytes(n: usize) -> String {
|
||||
let mut n = n as f64;
|
||||
let i = (n.log10() / 3.0).floor() as usize;
|
||||
n /= 1000f64.powi(i as i32);
|
||||
let units = ["B", "kB", "MB", "GB"];
|
||||
let prec = if i > 0 { 2 } else { 0 };
|
||||
format!("{:.*} {}", prec, n, units[i])
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user