Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve reported statistics #553

Merged
merged 16 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/telemetry_core/src/feed_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,5 @@ pub struct ChainStats {
pub memory_memcpy_score: Ranking<(u32, Option<u32>)>,
pub disk_sequential_write_score: Ranking<(u32, Option<u32>)>,
pub disk_random_write_score: Ranking<(u32, Option<u32>)>,
pub cpu_vendor: Ranking<String>,
}
30 changes: 29 additions & 1 deletion backend/telemetry_core/src/state/chain_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,27 @@ fn bucket_memory(memory: u64) -> (u32, Option<u32>) {
48,
56,
64,
128,
}
}

fn kernel_version_number(version: &Box<str>) -> &str {
&version[0..version.find('-').unwrap_or(version.len())]
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved
}

#[test]
fn test_kernel_version_number() {
assert_eq!(kernel_version_number(&"5.10.0-8-amd64".into()), "5.10.0");
assert_eq!(kernel_version_number(&"5.10.0".into()), "5.10.0");
}

fn cpu_vendor(cpu: &Box<str>) -> &str {
if cpu.contains("Intel") || cpu.contains("intel") {
lexnv marked this conversation as resolved.
Show resolved Hide resolved
"Intel"
} else if cpu.contains("AMD") || cpu.contains("amd") {
"AMD"
} else {
"Other"
}
}

Expand All @@ -114,6 +135,7 @@ pub struct ChainStatsCollator {
memory_memcpy_score: Counter<(u32, Option<u32>)>,
disk_sequential_write_score: Counter<(u32, Option<u32>)>,
disk_random_write_score: Counter<(u32, Option<u32>)>,
cpu_vendor: Counter<String>,
}

impl ChainStatsCollator {
Expand Down Expand Up @@ -155,7 +177,7 @@ impl ChainStatsCollator {
self.linux_distro.modify(
sysinfo
.and_then(|sysinfo| sysinfo.linux_distro.as_ref())
.map(|value| &**value),
.map(kernel_version_number),
op,
);

Expand All @@ -164,6 +186,11 @@ impl ChainStatsCollator {
op,
);

self.cpu_vendor.modify(
sysinfo.and_then(|sysinfo| sysinfo.cpu.as_ref().map(cpu_vendor)),
op,
);

self.update_hwbench(hwbench, op);
}

Expand Down Expand Up @@ -220,6 +247,7 @@ impl ChainStatsCollator {
.disk_sequential_write_score
.generate_ranking_ordered(),
disk_random_write_score: self.disk_random_write_score.generate_ranking_ordered(),
cpu_vendor: self.cpu_vendor.generate_ranking_top(10),
}
}
}
6 changes: 3 additions & 3 deletions backend/telemetry_core/src/state/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
use crate::feed_message::Ranking;
use std::collections::HashMap;

/// A data structure which counts how many occurences of a given key we've seen.
/// A data structure which counts how many occurrences of a given key we've seen.
#[derive(Default)]
pub struct Counter<K> {
/// A map containing the number of occurences of a given key.
/// A map containing the number of occurrences of a given key.
///
/// If there are none then the entry is removed.
map: HashMap<K, u64>,

/// The number of occurences where the key is `None`.
/// The number of occurrences where the key is `None`.
empty: u64,
}

Expand Down
Loading
Loading