返回 DeepSeek-Reasonix
devinfo.go
根目录 / desktop / devinfo.go
1 package main
2
3 import (
4 "runtime"
5 "strconv"
6 "strings"
7 )
8
9 // devinfo.go collects coarse machine facts attached to crash reports: OS version,
10 // CPU model, core count, RAM. Nothing here identifies a user or machine.
11
12 type deviceInfo struct {
13 OSVersion string `json:"osVersion,omitempty"`
14 CPU string `json:"cpu,omitempty"`
15 Cores int `json:"cores"`
16 RAMGB int `json:"ramGb,omitempty"`
17 }
18
19 const gib = 1 << 30
20
21 func collectDeviceInfo() deviceInfo {
22 return deviceInfo{
23 OSVersion: platformOSVersion(),
24 CPU: platformCPU(),
25 Cores: runtime.NumCPU(),
26 RAMGB: int((platformRAMBytes() + gib/2) / gib),
27 }
28 }
29
30 func parseCPUModel(cpuinfo string) string {
31 for _, line := range strings.Split(cpuinfo, "\n") {
32 if name, ok := strings.CutPrefix(line, "model name"); ok {
33 if _, v, ok := strings.Cut(name, ":"); ok {
34 return strings.TrimSpace(v)
35 }
36 }
37 }
38 return ""
39 }
40
41 func parseMemTotalBytes(meminfo string) uint64 {
42 for _, line := range strings.Split(meminfo, "\n") {
43 if rest, ok := strings.CutPrefix(line, "MemTotal:"); ok {
44 kb, err := strconv.ParseUint(strings.TrimSuffix(strings.TrimSpace(rest), " kB"), 10, 64)
45 if err != nil {
46 return 0
47 }
48 return kb * 1024
49 }
50 }
51 return 0
52 }
53
54 func parseOSReleasePrettyName(osRelease string) string {
55 for _, line := range strings.Split(osRelease, "\n") {
56 if v, ok := strings.CutPrefix(line, "PRETTY_NAME="); ok {
57 return strings.Trim(strings.TrimSpace(v), `"`)
58 }
59 }
60 return ""
61 }
62
62 lines GO