GuillaumeGomez / sysinfo

Cross-platform library to fetch system information
MIT License
2.11k stars 313 forks source link

brand() returns empty on iOS device #1386

Open dionysuzx opened 5 days ago

dionysuzx commented 5 days ago

Describe the bug

I am running it on an iPhone 15 pro. I'm on:

sysinfo = "0.32.0"

To Reproduce Try fetch the brand() on iOS device like iPhone 15 pro. For example my code snippet here returns empty:

    // Get processor details
    let cpu_name = sys
        .cpus()
        .first()
        .and_then(|cpu| {
            if cpu.brand().is_empty() {
                Some("Unknown CPU name".to_string())
            } else {
                Some(cpu.brand().to_string())
            }
        })
        .ok_or_else(|| eyre::eyre!("Failed to retrieve CPU name"))?;
GuillaumeGomez commented 5 days ago

I don't have an iphone so I can't fix this bug myself. The code to retrieve the brand of a CPU is here. From what I can see, there seems to be no way to query this information on iOS.

dionysuzx commented 5 days ago

I don't have an iphone so I can't fix this bug myself. The code to retrieve the brand of a CPU is here. From what I can see, there seems to be no way to query this information on iOS.

is there anything i can do to help, or run some diagnostics against my iphone? otherwise i can close the issue. i just assumed it worked on iOS because i saw iOS was supported under the sysinfo docs; but i understand iOS may not allow access into this.

GuillaumeGomez commented 5 days ago

You have as much information as I do. So feel free to search around. If you find a fix, please send a PR. :)

dionysuzx commented 5 days ago

adding some more info here. it seems like we cannot fetch the cpu brand() but we may be able to get the device type: and because iOS devices don't have an interchangeable CPU, we can just maintain a mapping of iOS devices to their processors, something like:

func getCPUModel(for identifier: String) -> String? {
    let mapping: [String: String] = [
        "iPhone14,2": "A16 Bionic",
        "iPhone13,2": "A15 Bionic",
        "iPad13,4": "M1",
        // Add more mappings as needed
    ]
    return mapping[identifier]
}

func getCPUName() -> String? {
    var size = 0
    sysctlbyname("hw.machine", nil, &size, nil, 0)
    var machine = [CChar](repeating: 0, count: size)
    sysctlbyname("hw.machine", &machine, &size, nil, 0)
    let identifier = String(cString: machine)
    return getCPUModel(for: identifier)
}

if let cpuName = getCPUName() {
    print("CPU Name: \(cpuName)")
} else {
    print("Unknown CPU Model")
}
GuillaumeGomez commented 5 days ago

Oh nice. A PR with this add would be greatly appreciated. :)