Expose some details about introspection (#195)

* Expose some details about introspection, such that custom Stats implementations can use them

* Make the functions public

* Fix formatting
This commit is contained in:
Max Ammann 2021-06-30 14:16:36 +02:00 committed by GitHub
parent 574a274be6
commit 08263f7ade
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -688,6 +688,32 @@ impl ClientPerfStats {
// Set that the current stage is being used
self.stages_used[stage_index] = true;
}
pub fn elapsed_cycles(&self) -> u64 {
self.current_time - self.start_time
}
pub fn manager_cycles(&self) -> u64 {
self.manager
}
pub fn scheduler_cycles(&self) -> u64 {
self.scheduler
}
pub fn used_stages(
&self,
) -> impl Iterator<Item = (usize, &[u64; PerfFeature::Count as usize])> {
let used = self.stages_used.clone();
self.stages
.iter()
.enumerate()
.filter(move |(stage_index, _)| used[*stage_index as usize])
}
pub fn feedbacks(&self) -> impl Iterator<Item = (usize, &u64)> {
self.feedbacks.iter().enumerate()
}
}
#[cfg(feature = "introspection")]
@ -695,7 +721,7 @@ impl core::fmt::Display for ClientPerfStats {
#[allow(clippy::cast_precision_loss)]
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
// Calculate the elapsed time from the stats
let elapsed: f64 = (self.current_time - self.start_time) as f64;
let elapsed: f64 = self.elapsed_cycles() as f64;
// Calculate the percentages for each benchmark
let scheduler_percent = self.scheduler as f64 / elapsed;
@ -714,12 +740,8 @@ impl core::fmt::Display for ClientPerfStats {
)?;
// Calculate each stage
for (stage_index, features) in self.stages.iter().enumerate() {
// Make sure this stage is actually used before dumping its information
if !self.stages_used[stage_index as usize] {
continue;
}
// Make sure we only iterate over used stages
for (stage_index, features) in self.used_stages() {
// Write the stage header
writeln!(f, " Stage {}:", stage_index)?;
@ -742,7 +764,7 @@ impl core::fmt::Display for ClientPerfStats {
writeln!(f, " {:6.4}: {:?}", feature_percent, feature)?;
}
for (feedback_index, feedback) in self.feedbacks.iter().enumerate() {
for (feedback_index, feedback) in self.feedbacks() {
// Calculate this current stage's percentage
let feedback_percent = *feedback as f64 / elapsed;