Skip to content

Commit

Permalink
Better format on connection age.
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoffranca committed Oct 6, 2024
1 parent 0591dc5 commit 510be97
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions node/actors/network/src/debug_page/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,11 +598,12 @@ impl Server {
.load(Ordering::Relaxed)
.human_count_bytes()
.to_string(),
SystemTime::now()
.duration_since(connection.stats.established)
.unwrap_or_default()
.human_duration()
.to_string(),
Self::human_readable_duration(
SystemTime::now()
.duration_since(connection.stats.established)
.unwrap_or_default()
.as_secs(),
),
])
}

Expand Down Expand Up @@ -641,14 +642,26 @@ impl Server {
.load(Ordering::Relaxed)
.human_count_bytes()
.to_string(),
SystemTime::now()
.duration_since(stats.established)
.unwrap_or_default()
.human_duration()
.to_string(),
Self::human_readable_duration(
SystemTime::now()
.duration_since(stats.established)
.unwrap_or_default()
.as_secs(),
),
])
}

table.to_html_string()
}

/// Returns human readable duration. We use this function instead of `Duration::human_duration` because
/// we want to show days as well.
fn human_readable_duration(seconds: u64) -> String {
let days = seconds / 86400;
let hours = (seconds % 86400) / 3600;
let minutes = (seconds % 3600) / 60;
let seconds = seconds % 60;

format!("{}d {}h {}m {}s", days, hours, minutes, seconds)
}
}

0 comments on commit 510be97

Please sign in to comment.