Skip to content

Commit

Permalink
Improve reported statistics (paritytech#553)
Browse files Browse the repository at this point in the history
* frontend: Update package lock

Signed-off-by: Alexandru Vasile <[email protected]>

* frontend/stats: Format linux kernel version

Signed-off-by: Alexandru Vasile <[email protected]>

* backend: Add [64; 128) RAM bucket

Signed-off-by: Alexandru Vasile <[email protected]>

* backend: Parse kernel string to include only version numbers

The linux kernel version string is parsed to include only
the kernel version, major version and minor version.
Ignoring the patch number and kernel specific info leads to
a better aggregation of data.

Signed-off-by: Alexandru Vasile <[email protected]>

* backend: Fix typo

Signed-off-by: Alexandru Vasile <[email protected]>

* core: Add CPU vendor to reported chain stats

Signed-off-by: Alexandru Vasile <[email protected]>

* frontend: Propagate CPU vendor to UI

Signed-off-by: Alexandru Vasile <[email protected]>

* backend: Parse kernel version by `+`

Signed-off-by: Alexandru Vasile <[email protected]>

* backend: Add CPU vendors and ignore ascii case

Signed-off-by: Alexandru Vasile <[email protected]>

* Revert "frontend/stats: Format linux kernel version"

This reverts commit 411b9a4.

* backend: Fix plus sign test

Signed-off-by: Alexandru Vasile <[email protected]>

* backend: Trim kernel versions

Signed-off-by: Alexandru Vasile <[email protected]>

* backend: Modify cpu_vendor

Signed-off-by: Alexandru Vasile <[email protected]>

---------

Signed-off-by: Alexandru Vasile <[email protected]>
  • Loading branch information
lexnv authored Nov 3, 2023
1 parent 1d04e4a commit 4378fd2
Show file tree
Hide file tree
Showing 6 changed files with 392 additions and 200 deletions.
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>,
}
44 changes: 43 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,41 @@ fn bucket_memory(memory: u64) -> (u32, Option<u32>) {
48,
56,
64,
128,
}
}

fn kernel_version_number(version: &Box<str>) -> &str {
let index = version
.find("-")
.or_else(|| version.find("+"))
.unwrap_or(version.len());

&version[0..index]
}

#[test]
fn test_kernel_version_number() {
assert_eq!(kernel_version_number(&"5.10.0-8-amd64".into()), "5.10.0");
// Plus sign indicates that the kernel was built from modified sources.
// This should only appear at the end of the version string.
assert_eq!(kernel_version_number(&"5.10.0+82453".into()), "5.10.0");
assert_eq!(kernel_version_number(&"5.10.0".into()), "5.10.0");
}

fn cpu_vendor(cpu: &Box<str>) -> &str {
let lowercase_cpu = cpu.to_ascii_lowercase();

if lowercase_cpu.contains("intel") {
"Intel"
} else if lowercase_cpu.contains("amd") {
"AMD"
} else if lowercase_cpu.contains("arm") {
"ARM"
} else if lowercase_cpu.contains("apple") {
"Apple"
} else {
"Other"
}
}

Expand All @@ -114,6 +149,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 @@ -148,7 +184,7 @@ impl ChainStatsCollator {
self.linux_kernel.modify(
sysinfo
.and_then(|sysinfo| sysinfo.linux_kernel.as_ref())
.map(|value| &**value),
.map(kernel_version_number),
op,
);

Expand All @@ -164,6 +200,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 +261,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

0 comments on commit 4378fd2

Please sign in to comment.