1use client::telemetry;
2use gpui::{AppContext, Task};
3use human_bytes::human_bytes;
4use release_channel::{AppCommitSha, AppVersion, ReleaseChannel};
5use serde::Serialize;
6use std::{env, fmt::Display};
7use sysinfo::{MemoryRefreshKind, RefreshKind, System};
8
9#[derive(Clone, Debug, Serialize)]
10pub struct SystemSpecs {
11 app_version: String,
12 release_channel: &'static str,
13 os_name: String,
14 os_version: String,
15 memory: u64,
16 architecture: &'static str,
17 commit_sha: Option<String>,
18}
19
20impl SystemSpecs {
21 pub fn new(cx: &AppContext) -> Task<Self> {
22 let app_version = AppVersion::global(cx).to_string();
23 let release_channel = ReleaseChannel::global(cx);
24 let os_name = telemetry::os_name();
25 let system = System::new_with_specifics(
26 RefreshKind::new().with_memory(MemoryRefreshKind::everything()),
27 );
28 let memory = system.total_memory();
29 let architecture = env::consts::ARCH;
30 let commit_sha = match release_channel {
31 ReleaseChannel::Dev | ReleaseChannel::Nightly => {
32 AppCommitSha::try_global(cx).map(|sha| sha.0.clone())
33 }
34 _ => None,
35 };
36
37 cx.background_executor().spawn(async move {
38 let os_version = telemetry::os_version();
39 SystemSpecs {
40 app_version,
41 release_channel: release_channel.display_name(),
42 os_name,
43 os_version,
44 memory,
45 architecture,
46 commit_sha,
47 }
48 })
49 }
50}
51
52impl Display for SystemSpecs {
53 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
54 let os_information = format!("OS: {} {}", self.os_name, self.os_version);
55 let app_version_information = format!(
56 "Zed: v{} ({})",
57 self.app_version,
58 match &self.commit_sha {
59 Some(commit_sha) => format!("{} {}", self.release_channel, commit_sha),
60 None => self.release_channel.to_string(),
61 }
62 );
63 let system_specs = [
64 app_version_information,
65 os_information,
66 format!("Memory: {}", human_bytes(self.memory as f64)),
67 format!("Architecture: {}", self.architecture),
68 ]
69 .into_iter()
70 .collect::<Vec<String>>()
71 .join("\n");
72
73 write!(f, "{system_specs}")
74 }
75}