Temporarily(?) switch from heim+uom to sysinfo (#2954)

* Switch from heim to sysinfo

* WIP

* more cleanup

* fmt

* lint
This commit is contained in:
Jonathan Turner 2021-01-20 20:18:38 +13:00 committed by GitHub
parent 430da53f0b
commit b435075e09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 295 additions and 853 deletions

487
Cargo.lock generated
View file

@ -158,17 +158,6 @@ dependencies = [
"vec-arena",
]
[[package]]
name = "async-fs"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b3ca4f8ff117c37c278a2f7415ce9be55560b846b5bc4412aaa5d29c1c3dae2"
dependencies = [
"async-lock",
"blocking",
"futures-lite",
]
[[package]]
name = "async-global-executor"
version = "2.0.2"
@ -223,34 +212,6 @@ dependencies = [
"event-listener",
]
[[package]]
name = "async-net"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06de475c85affe184648202401d7622afb32f0f74e02192857d0201a16defbe5"
dependencies = [
"async-io",
"blocking",
"fastrand",
"futures-lite",
]
[[package]]
name = "async-process"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c8cea09c1fb10a317d1b5af8024eeba256d6554763e85ecd90ff8df31c7bbda"
dependencies = [
"async-io",
"blocking",
"cfg-if 0.1.10",
"event-listener",
"futures-lite",
"once_cell",
"signal-hook",
"winapi 0.3.9",
]
[[package]]
name = "async-recursion"
version = "0.3.1"
@ -396,7 +357,7 @@ dependencies = [
"lazy_static 1.4.0",
"path_abs",
"semver 0.11.0",
"serde 1.0.119",
"serde 1.0.120",
"serde_yaml",
"shell-words",
"syntect",
@ -404,23 +365,6 @@ dependencies = [
"wild",
]
[[package]]
name = "battery"
version = "0.7.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4b624268937c0e0a3edb7c27843f9e547c320d730c610d3b8e6e8e95b2026e4"
dependencies = [
"cfg-if 1.0.0",
"core-foundation 0.7.0",
"lazycell",
"libc",
"mach",
"nix 0.19.1",
"num-traits 0.2.14",
"uom",
"winapi 0.3.9",
]
[[package]]
name = "bigdecimal"
version = "0.2.0"
@ -430,7 +374,7 @@ dependencies = [
"num-bigint 0.3.1",
"num-integer",
"num-traits 0.2.14",
"serde 1.0.119",
"serde 1.0.120",
]
[[package]]
@ -440,7 +384,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f30d3a39baa26f9651f17b375061f3233dde33424a8b72b0dbe93a68a0bc896d"
dependencies = [
"byteorder",
"serde 1.0.119",
"serde 1.0.120",
]
[[package]]
@ -528,7 +472,7 @@ dependencies = [
"linked-hash-map 0.5.4",
"md5 0.6.1",
"rand 0.7.3",
"serde 1.0.119",
"serde 1.0.120",
"serde_json",
"time",
]
@ -542,7 +486,7 @@ dependencies = [
"lazy_static 1.4.0",
"memchr",
"regex-automata",
"serde 1.0.119",
"serde 1.0.120",
]
[[package]]
@ -638,7 +582,7 @@ dependencies = [
"encoding_rs",
"log 0.4.13",
"quick-xml 0.19.0",
"serde 1.0.119",
"serde 1.0.120",
"zip",
]
@ -678,7 +622,7 @@ dependencies = [
"libc",
"num-integer",
"num-traits 0.2.14",
"serde 1.0.119",
"serde 1.0.120",
"time",
"winapi 0.3.9",
]
@ -744,7 +688,7 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6ce42b8998a383572e0a802d859b1f00c79b7b7474e62fff88ee5c2845d9c13"
dependencies = [
"serde 1.0.119",
"serde 1.0.120",
"termcolor",
"unicode-width",
]
@ -784,7 +728,7 @@ dependencies = [
"lazy_static 1.4.0",
"nom 5.1.2",
"rust-ini",
"serde 1.0.119",
"serde 1.0.120",
"serde-hjson",
"serde_json",
"toml",
@ -828,32 +772,16 @@ dependencies = [
"memchr",
]
[[package]]
name = "core-foundation"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171"
dependencies = [
"core-foundation-sys 0.7.0",
"libc",
]
[[package]]
name = "core-foundation"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62"
dependencies = [
"core-foundation-sys 0.8.2",
"core-foundation-sys",
"libc",
]
[[package]]
name = "core-foundation-sys"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac"
[[package]]
name = "core-foundation-sys"
version = "0.8.2"
@ -867,7 +795,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52a67c4378cf203eace8fb6567847eb641fd6ff933c1145a115c6ee820ebb978"
dependencies = [
"bitflags",
"core-foundation 0.9.1",
"core-foundation",
"foreign-types",
"libc",
]
@ -1097,7 +1025,7 @@ dependencies = [
"csv-core",
"itoa",
"ryu",
"serde 1.0.119",
"serde 1.0.120",
]
[[package]]
@ -1115,7 +1043,7 @@ version = "3.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b57a92e9749e10f25a171adcebfafe72991d45e7ec2dcb853e8f83d9dafaeb08"
dependencies = [
"nix 0.18.0",
"nix",
"winapi 0.3.9",
]
@ -1150,26 +1078,6 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "darwin-libproc"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc629b7cf42586fee31dae31f9ab73fa5ff5f0170016aa61be5fcbc12a90c516"
dependencies = [
"darwin-libproc-sys",
"libc",
"memchr",
]
[[package]]
name = "darwin-libproc-sys"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef0aa083b94c54aa4cfd9bbfd37856714c139d1dc511af80270558c7ba3b4816"
dependencies = [
"libc",
]
[[package]]
name = "decimal"
version = "2.0.4"
@ -1333,6 +1241,12 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "doc-comment"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
[[package]]
name = "dtoa"
version = "0.4.7"
@ -1918,9 +1832,9 @@ dependencies = [
[[package]]
name = "getrandom"
version = "0.2.1"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4060f4657be78b8e766215b02b18a2e862d83745545de804638e2b545e81aee6"
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
dependencies = [
"cfg-if 1.0.0",
"libc",
@ -2037,174 +1951,6 @@ dependencies = [
"unicode-segmentation",
]
[[package]]
name = "heim"
version = "0.1.0-rc.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8a653442b9bdd11a77d3753a60443c60c4437d3acac8e6c3d4a6a9acd7cceed"
dependencies = [
"heim-common",
"heim-cpu",
"heim-disk",
"heim-host",
"heim-memory",
"heim-net",
"heim-process",
"heim-runtime",
"heim-sensors",
]
[[package]]
name = "heim-common"
version = "0.1.0-rc.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d767e6e47cf88abe7c9a5ebb4df82f180d30d9c0ba0269b6d166482461765834"
dependencies = [
"cfg-if 1.0.0",
"core-foundation 0.9.1",
"futures-core",
"futures-util",
"lazy_static 1.4.0",
"libc",
"mach",
"nix 0.19.1",
"pin-utils",
"uom",
"winapi 0.3.9",
]
[[package]]
name = "heim-cpu"
version = "0.1.0-rc.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ba5fb13a3b90581d22b4edf99e87c54316444622ae123d36816a227a7caa6df"
dependencies = [
"cfg-if 1.0.0",
"futures 0.3.12",
"glob",
"heim-common",
"heim-runtime",
"lazy_static 1.4.0",
"libc",
"mach",
"ntapi",
"smol",
"winapi 0.3.9",
]
[[package]]
name = "heim-disk"
version = "0.1.0-rc.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75603ff3868851c04954ee86bf610a6bd45be2732a0e81c35fd72b2b90fa4718"
dependencies = [
"bitflags",
"cfg-if 1.0.0",
"core-foundation 0.9.1",
"heim-common",
"heim-runtime",
"libc",
"mach",
"widestring",
"winapi 0.3.9",
]
[[package]]
name = "heim-host"
version = "0.1.0-rc.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9abf6cd02bc4f6e6aa31a7f80702a2d0e574f4f2c6156a93c3550eb036304722"
dependencies = [
"cfg-if 1.0.0",
"heim-common",
"heim-runtime",
"lazy_static 1.4.0",
"libc",
"log 0.4.13",
"mach",
"ntapi",
"platforms",
"winapi 0.3.9",
]
[[package]]
name = "heim-memory"
version = "0.1.0-rc.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fa81bccc5e81ab0c68f520ecba5cb42817bacabfc6120160de886754ad0e3e1"
dependencies = [
"cfg-if 1.0.0",
"heim-common",
"heim-runtime",
"lazy_static 1.4.0",
"libc",
"mach",
"winapi 0.3.9",
]
[[package]]
name = "heim-net"
version = "0.1.0-rc.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d13afa5e9b71c813c1e087bb27f51ae87d3a6d68a2bdd045bae4322dfae4948b"
dependencies = [
"bitflags",
"cfg-if 1.0.0",
"heim-common",
"heim-runtime",
"libc",
"macaddr",
"nix 0.19.1",
]
[[package]]
name = "heim-process"
version = "0.1.1-rc.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "386870aac75d29b817fe709f1ef4303553e0af369e3c71d04beceeb50ae2cf39"
dependencies = [
"async-trait",
"cfg-if 1.0.0",
"darwin-libproc",
"futures 0.3.12",
"heim-common",
"heim-cpu",
"heim-host",
"heim-net",
"heim-runtime",
"lazy_static 1.4.0",
"libc",
"mach",
"memchr",
"ntapi",
"ordered-float 2.0.1",
"smol",
"winapi 0.3.9",
]
[[package]]
name = "heim-runtime"
version = "0.1.0-rc.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54ec7e5238c8f0dd0cc60914d31a5a7aadd4cde74c966a76c1caed1f5224e9b8"
dependencies = [
"futures 0.3.12",
"futures-timer",
"once_cell",
"smol",
]
[[package]]
name = "heim-sensors"
version = "0.1.0-rc.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82de7f0784d3b0c53f2e8875c63f430bf6718b03ec8ddce905c12887031158f5"
dependencies = [
"cfg-if 1.0.0",
"heim-common",
"heim-runtime",
]
[[package]]
name = "hermit-abi"
version = "0.1.18"
@ -2453,7 +2199,7 @@ checksum = "4fb1fa934250de4de8aef298d81c729a7d33d8c239daa3a7575e6b92bfc7313b"
dependencies = [
"autocfg",
"hashbrown",
"serde 1.0.119",
"serde 1.0.120",
]
[[package]]
@ -2725,21 +2471,6 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4"
[[package]]
name = "macaddr"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baee0bbc17ce759db233beb01648088061bf678383130602a298e6998eedb2d8"
[[package]]
name = "mach"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa"
dependencies = [
"libc",
]
[[package]]
name = "malloc_buf"
version = "0.0.6"
@ -2758,7 +2489,7 @@ dependencies = [
"log 0.4.13",
"phf",
"phf_codegen",
"serde 1.0.119",
"serde 1.0.120",
"serde_derive",
"serde_json",
"string_cache",
@ -2961,7 +2692,7 @@ dependencies = [
"bincode",
"cfg-if 0.1.10",
"log 0.4.13",
"serde 1.0.119",
"serde 1.0.120",
"serde_derive",
"wasm-bindgen",
]
@ -3008,18 +2739,6 @@ dependencies = [
"libc",
]
[[package]]
name = "nix"
version = "0.19.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2ccba0cfe4fdf15982d1674c69b1fd80bad427d293849982668dfe454bd61f2"
dependencies = [
"bitflags",
"cc",
"cfg-if 1.0.0",
"libc",
]
[[package]]
name = "nodrop"
version = "0.1.14"
@ -3128,7 +2847,6 @@ dependencies = [
"futures_codec",
"getset",
"glob",
"heim",
"htmlescape",
"ical",
"ichwh",
@ -3168,7 +2886,7 @@ dependencies = [
"rusqlite",
"rust-embed",
"rustyline",
"serde 1.0.119",
"serde 1.0.120",
"serde_bytes",
"serde_ini",
"serde_json",
@ -3189,7 +2907,6 @@ dependencies = [
"trash",
"umask",
"unicode-segmentation",
"uom",
"url",
"users",
"uuid",
@ -3231,7 +2948,6 @@ dependencies = [
"futures_codec",
"getset",
"glob",
"heim",
"htmlescape",
"ical",
"ichwh",
@ -3270,7 +2986,7 @@ dependencies = [
"rusqlite",
"rust-embed",
"rustyline",
"serde 1.0.119",
"serde 1.0.120",
"serde_bytes",
"serde_ini",
"serde_json",
@ -3291,7 +3007,6 @@ dependencies = [
"trash",
"umask",
"unicode-segmentation",
"uom",
"url",
"users",
"uuid",
@ -3324,7 +3039,7 @@ dependencies = [
"num-traits 0.2.14",
"parking_lot 0.11.1",
"query_interface",
"serde 1.0.119",
"serde 1.0.120",
"toml",
"users",
]
@ -3362,7 +3077,7 @@ dependencies = [
"nu-value-ext",
"parking_lot 0.11.1",
"rayon",
"serde 1.0.119",
"serde 1.0.120",
"serde_json",
"tempfile",
"term_size",
@ -3384,7 +3099,7 @@ dependencies = [
"nu-source",
"num-bigint 0.3.1",
"num-traits 0.2.14",
"serde 1.0.119",
"serde 1.0.120",
"serde_json",
"serde_yaml",
"toml",
@ -3417,7 +3132,7 @@ dependencies = [
"nu-test-support",
"num-bigint 0.3.1",
"num-traits 0.2.14",
"serde 1.0.119",
"serde 1.0.120",
"shellexpand",
]
@ -3433,7 +3148,7 @@ dependencies = [
"nu-test-support",
"nu-value-ext",
"num-bigint 0.3.1",
"serde 1.0.119",
"serde 1.0.120",
"serde_json",
]
@ -3453,7 +3168,7 @@ dependencies = [
"num-bigint 0.3.1",
"num-integer",
"num-traits 0.2.14",
"serde 1.0.119",
"serde 1.0.120",
"serde_bytes",
"serde_json",
"serde_yaml",
@ -3467,7 +3182,7 @@ dependencies = [
"derive-new",
"getset",
"pretty",
"serde 1.0.119",
"serde 1.0.120",
"termcolor",
]
@ -3640,12 +3355,12 @@ version = "0.25.2"
dependencies = [
"futures 0.3.12",
"futures-timer",
"heim",
"nu-errors",
"nu-plugin",
"nu-protocol",
"nu-source",
"num-bigint 0.3.1",
"sysinfo",
]
[[package]]
@ -3689,15 +3404,14 @@ dependencies = [
name = "nu_plugin_sys"
version = "0.25.2"
dependencies = [
"battery",
"futures 0.3.12",
"futures-util",
"heim",
"nu-errors",
"nu-plugin",
"nu-protocol",
"nu-source",
"num-bigint 0.3.1",
"sysinfo",
]
[[package]]
@ -3804,7 +3518,7 @@ dependencies = [
"autocfg",
"num-integer",
"num-traits 0.2.14",
"serde 1.0.119",
"serde 1.0.120",
]
[[package]]
@ -4020,15 +3734,6 @@ dependencies = [
"num-traits 0.2.14",
]
[[package]]
name = "ordered-float"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dacdec97876ef3ede8c50efc429220641a0b11ba0048b4b0c357bccbc47c5204"
dependencies = [
"num-traits 0.2.14",
]
[[package]]
name = "parking"
version = "2.0.0"
@ -4259,12 +3964,6 @@ version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c"
[[package]]
name = "platforms"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc77a3fc329982cbf3ea772aa265b742a550998bad65747c630406ee52dac425"
[[package]]
name = "plist"
version = "1.0.0"
@ -4275,7 +3974,7 @@ dependencies = [
"chrono",
"indexmap",
"line-wrap",
"serde 1.0.119",
"serde 1.0.120",
"xml-rs",
]
@ -4409,7 +4108,7 @@ dependencies = [
"config",
"directories",
"petgraph",
"serde 1.0.119",
"serde 1.0.120",
"serde-value",
"tint",
]
@ -4594,7 +4293,7 @@ version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c026d7df8b298d90ccbbc5190bd04d85e159eaf5576caeacf8741da93ccbd2e5"
dependencies = [
"getrandom 0.2.1",
"getrandom 0.2.2",
]
[[package]]
@ -4708,7 +4407,7 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64"
dependencies = [
"getrandom 0.2.1",
"getrandom 0.2.2",
"redox_syscall 0.2.4",
]
@ -4803,7 +4502,7 @@ dependencies = [
"native-tls",
"percent-encoding 2.1.0",
"pin-project-lite 0.2.4",
"serde 1.0.119",
"serde 1.0.120",
"serde_urlencoded 0.7.0",
"tokio 0.2.24",
"tokio-tls",
@ -4917,7 +4616,7 @@ dependencies = [
"byteorder",
"lazy_static 1.4.0",
"num",
"serde 1.0.119",
"serde 1.0.120",
]
[[package]]
@ -4952,7 +4651,7 @@ dependencies = [
"libc",
"log 0.4.13",
"memchr",
"nix 0.18.0",
"nix",
"scopeguard",
"unicode-segmentation",
"unicode-width",
@ -4989,7 +4688,7 @@ dependencies = [
"reqwest",
"rust-crypto",
"rustc-serialize",
"serde 1.0.119",
"serde 1.0.120",
"serde_derive",
"serde_json",
"sha2 0.6.0",
@ -5046,8 +4745,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1759c2e3c8580017a484a7ac56d3abc5a6c1feadf88db2f3633f12ae4268c69"
dependencies = [
"bitflags",
"core-foundation 0.9.1",
"core-foundation-sys 0.8.2",
"core-foundation",
"core-foundation-sys",
"libc",
"security-framework-sys",
]
@ -5058,7 +4757,7 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f99b9d5e26d2a71633cc4f2ebae7cc9f874044e0c351a27e17892d76dce5678b"
dependencies = [
"core-foundation-sys 0.8.2",
"core-foundation-sys",
"libc",
]
@ -5132,9 +4831,9 @@ checksum = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8"
[[package]]
name = "serde"
version = "1.0.119"
version = "1.0.120"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9bdd36f49e35b61d49efd8aa7fc068fd295961fd2286d0b2ee9a4c7a14e99cc3"
checksum = "166b2349061381baf54a58e4b13c89369feb0ef2eaa57198899e2312aac30aab"
dependencies = [
"serde_derive",
]
@ -5158,8 +4857,8 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a65a7291a8a568adcae4c10a677ebcedbc6c9cec91c054dee2ce40b0e3290eb"
dependencies = [
"ordered-float 1.1.1",
"serde 1.0.119",
"ordered-float",
"serde 1.0.120",
]
[[package]]
@ -5168,14 +4867,14 @@ version = "0.11.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16ae07dd2f88a366f15bd0632ba725227018c69a1c8550a927324f8eb8368bb9"
dependencies = [
"serde 1.0.119",
"serde 1.0.120",
]
[[package]]
name = "serde_derive"
version = "1.0.119"
version = "1.0.120"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "552954ce79a059ddd5fd68c271592374bd15cab2274970380c000118aeffe1cd"
checksum = "0ca2a8cb5805ce9e3b95435e3765b7b553cecc762d938d409434338386cb5775"
dependencies = [
"proc-macro2",
"quote 1.0.8",
@ -5189,7 +4888,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb236687e2bb073a7521c021949be944641e671b8505a94069ca37b656c81139"
dependencies = [
"result",
"serde 1.0.119",
"serde 1.0.120",
"void",
]
@ -5202,7 +4901,7 @@ dependencies = [
"indexmap",
"itoa",
"ryu",
"serde 1.0.119",
"serde 1.0.120",
]
[[package]]
@ -5222,7 +4921,7 @@ checksum = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97"
dependencies = [
"dtoa",
"itoa",
"serde 1.0.119",
"serde 1.0.120",
"url",
]
@ -5235,7 +4934,7 @@ dependencies = [
"form_urlencoded",
"itoa",
"ryu",
"serde 1.0.119",
"serde 1.0.120",
]
[[package]]
@ -5246,7 +4945,7 @@ checksum = "971be8f6e4d4a47163b405a3df70d14359186f9ab0f3a3ec37df144ca1ce089f"
dependencies = [
"dtoa",
"linked-hash-map 0.5.4",
"serde 1.0.119",
"serde 1.0.120",
"yaml-rust",
]
@ -5387,24 +5086,6 @@ version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e"
[[package]]
name = "smol"
version = "1.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85cf3b5351f3e783c1d79ab5fc604eeed8b8ae9abd36b166e8b87a089efd85e4"
dependencies = [
"async-channel",
"async-executor",
"async-fs",
"async-io",
"async-lock",
"async-net",
"async-process",
"blocking",
"futures-lite",
"once_cell",
]
[[package]]
name = "socket2"
version = "0.3.19"
@ -5450,7 +5131,7 @@ dependencies = [
"new_debug_unreachable",
"phf_shared",
"precomputed-hash",
"serde 1.0.119",
"serde 1.0.120",
]
[[package]]
@ -5493,7 +5174,7 @@ dependencies = [
"log 0.4.13",
"mime",
"mime_guess",
"serde 1.0.119",
"serde 1.0.120",
"serde_json",
"serde_urlencoded 0.6.1",
"url",
@ -5582,13 +5263,30 @@ dependencies = [
"onig",
"plist",
"regex-syntax 0.6.22",
"serde 1.0.119",
"serde 1.0.120",
"serde_derive",
"serde_json",
"walkdir",
"yaml-rust",
]
[[package]]
name = "sysinfo"
version = "0.15.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de94457a09609f33fec5e7fceaf907488967c6c7c75d64da6a7ce6ffdb8b5abd"
dependencies = [
"cc",
"cfg-if 1.0.0",
"core-foundation-sys",
"doc-comment",
"libc",
"ntapi",
"once_cell",
"rayon",
"winapi 0.3.9",
]
[[package]]
name = "take"
version = "0.1.0"
@ -5651,9 +5349,9 @@ dependencies = [
[[package]]
name = "terminal_size"
version = "0.1.15"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bd2d183bd3fac5f5fe38ddbeb4dc9aec4a39a9d7d59e7491d900302da01cbe1"
checksum = "86ca8ced750734db02076f44132d802af0b33b09942331f4459dde8636fd2406"
dependencies = [
"libc",
"winapi 0.3.9",
@ -6044,7 +5742,7 @@ version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa"
dependencies = [
"serde 1.0.119",
"serde 1.0.120",
]
[[package]]
@ -6199,17 +5897,6 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "uom"
version = "0.30.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e76503e636584f1e10b9b3b9498538279561adcef5412927ba00c2b32c4ce5ed"
dependencies = [
"num-rational 0.3.2",
"num-traits 0.2.14",
"typenum",
]
[[package]]
name = "url"
version = "2.2.0"
@ -6278,7 +5965,7 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
dependencies = [
"getrandom 0.2.1",
"getrandom 0.2.2",
]
[[package]]
@ -6377,7 +6064,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3cd364751395ca0f68cafb17666eee36b63077fb5ecd972bbcd74c90c4bf736e"
dependencies = [
"cfg-if 1.0.0",
"serde 1.0.119",
"serde 1.0.120",
"serde_json",
"wasm-bindgen-macro",
]
@ -6489,12 +6176,6 @@ dependencies = [
"thiserror",
]
[[package]]
name = "widestring"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c"
[[package]]
name = "wild"
version = "2.0.4"

View file

@ -66,7 +66,6 @@ nu-test-support = {version = "0.25.2", path = "./crates/nu-test-support"}
ctrlc-support = ["nu-cli/ctrlc", "nu-command/ctrlc"]
directories-support = ["nu-cli/directories", "nu-cli/dirs", "nu-command/directories", "nu-command/dirs", "nu-data/directories", "nu-data/dirs", "nu-engine/dirs"]
ptree-support = ["nu-cli/ptree", "nu-command/ptree"]
rich-benchmark = ["nu-cli/rich-benchmark", "nu-command/rich-benchmark"]
rustyline-support = ["nu-cli/rustyline-support", "nu-command/rustyline-support"]
term-support = ["nu-cli/term", "nu-command/term"]
uuid-support = ["nu-cli/uuid_crate", "nu-command/uuid_crate"]
@ -87,7 +86,6 @@ default = [
"match",
"post",
"fetch",
"rich-benchmark",
"zip-support",
]
extra = ["default", "binaryview", "tree", "clipboard-cli", "trash-support", "start", "bson", "sqlite", "s3", "chart", "xpath", "selector"]

View file

@ -55,7 +55,6 @@ futures-util = "0.3.8"
futures_codec = "0.4.1"
getset = "0.1.1"
glob = "0.3.0"
heim = { version = "0.1.0-rc.1", optional = true }
htmlescape = "0.3.1"
ical = "0.7.0"
ichwh = { version = "0.3.4", optional = true }
@ -98,7 +97,6 @@ titlecase = "1.0"
toml = "0.5.6"
trash = { version = "1.2.0", optional = true }
unicode-segmentation = "1.6.0"
uom = { version = "0.30.0", features = ["f64", "try-from"] }
url = "2.1.1"
uuid_crate = { package = "uuid", version = "0.8.1", features = ["v4"], optional = true }
which = { version = "4.0.2", optional = true }
@ -130,7 +128,6 @@ quickcheck_macros = "0.9.1"
[features]
default = ["shadow-rs"]
clipboard-cli = ["arboard"]
rich-benchmark = ["heim"]
rustyline-support = ["rustyline", "nu-engine/rustyline-support"]
stable = []
trash-support = ["trash"]

View file

@ -54,7 +54,6 @@ futures-util = "0.3.8"
futures_codec = "0.4.1"
getset = "0.1.1"
glob = "0.3.0"
heim = { version = "0.1.0-rc.1", optional = true }
htmlescape = "0.3.1"
ical = "0.7.0"
ichwh = { version = "0.3.4", optional = true }
@ -97,7 +96,6 @@ titlecase = "1.0"
toml = "0.5.6"
trash = { version = "1.2.0", optional = true }
unicode-segmentation = "1.6.0"
uom = { version = "0.30.0", features = ["f64", "try-from"] }
url = "2.1.1"
uuid_crate = { package = "uuid", version = "0.8.1", features = ["v4"], optional = true }
which = { version = "4.0.2", optional = true }
@ -127,7 +125,6 @@ quickcheck_macros = "0.9.1"
[features]
clipboard-cli = ["arboard"]
rich-benchmark = ["heim"]
rustyline-support = ["rustyline"]
stable = []
trash-support = ["trash"]

View file

@ -1,6 +1,6 @@
use crate::prelude::*;
#[cfg(feature = "rich-benchmark")]
use heim::cpu::time;
// #[cfg(feature = "rich-benchmark")]
// use heim::cpu::time;
use nu_engine::run_block;
use nu_engine::WholeStreamCommand;
use nu_errors::ShellError;
@ -81,22 +81,22 @@ async fn benchmark(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
let start_time = Instant::now();
#[cfg(feature = "rich-benchmark")]
let start = time().await;
// #[cfg(feature = "rich-benchmark")]
// let start = time().await;
context.scope.enter_scope();
let result = run_block(&block.block, &context, input).await;
context.scope.exit_scope();
let output = result?.into_vec().await;
#[cfg(feature = "rich-benchmark")]
let end = time().await;
// #[cfg(feature = "rich-benchmark")]
// let end = time().await;
let end_time = Instant::now();
context.clear_errors();
// return basic runtime
#[cfg(not(feature = "rich-benchmark"))]
//#[cfg(not(feature = "rich-benchmark"))]
{
let mut indexmap = IndexMap::with_capacity(1);
@ -105,28 +105,28 @@ async fn benchmark(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
benchmark_output(indexmap, output, passthrough, &tag, &mut context).await
}
// return advanced stats
#[cfg(feature = "rich-benchmark")]
if let (Ok(start), Ok(end)) = (start, end) {
let mut indexmap = IndexMap::with_capacity(4);
// #[cfg(feature = "rich-benchmark")]
// if let (Ok(start), Ok(end)) = (start, end) {
// let mut indexmap = IndexMap::with_capacity(4);
let real_time = into_big_int(end_time - start_time);
indexmap.insert("real time".to_string(), real_time);
// let real_time = into_big_int(end_time - start_time);
// indexmap.insert("real time".to_string(), real_time);
let user_time = into_big_int(end.user() - start.user());
indexmap.insert("user time".to_string(), user_time);
// let user_time = into_big_int(end.user() - start.user());
// indexmap.insert("user time".to_string(), user_time);
let system_time = into_big_int(end.system() - start.system());
indexmap.insert("system time".to_string(), system_time);
// let system_time = into_big_int(end.system() - start.system());
// indexmap.insert("system time".to_string(), system_time);
let idle_time = into_big_int(end.idle() - start.idle());
indexmap.insert("idle time".to_string(), idle_time);
// let idle_time = into_big_int(end.idle() - start.idle());
// indexmap.insert("idle time".to_string(), idle_time);
benchmark_output(indexmap, output, passthrough, &tag, &mut context).await
} else {
Err(ShellError::untagged_runtime_error(
"Could not retrieve CPU time",
))
}
// benchmark_output(indexmap, output, passthrough, &tag, &mut context).await
// } else {
// Err(ShellError::untagged_runtime_error(
// "Could not retrieve CPU time",
// ))
// }
}
async fn benchmark_output<T, Output>(

View file

@ -170,10 +170,10 @@ fn features_enabled() -> Vec<String> {
names.push("ptree".to_string());
}
#[cfg(feature = "rich-benchmark")]
{
names.push("rich-benchmark".to_string());
}
// #[cfg(feature = "rich-benchmark")]
// {
// names.push("rich-benchmark".to_string());
// }
#[cfg(feature = "rustyline-support")]
{

View file

@ -1,5 +1,6 @@
use nu_protocol::{outln, CallInfo, Value};
use nu_protocol::{CallInfo, Value};
use serde::{Deserialize, Serialize};
use std::io::Write;
#[derive(Debug, Serialize, Deserialize)]
pub struct JsonRpc<T> {
@ -22,10 +23,16 @@ pub fn send_response<T: Serialize>(result: T) {
let response = JsonRpc::new("response", result);
let response_raw = serde_json::to_string(&response);
let mut stdout = std::io::stdout();
match response_raw {
Ok(response) => outln!("{}", response),
Err(err) => outln!("{}", err),
}
Ok(response) => {
let _ = writeln!(stdout, "{}", response);
}
Err(err) => {
let _ = writeln!(stdout, "{}", err);
}
};
}
#[derive(Debug, Serialize, Deserialize)]

View file

@ -19,10 +19,6 @@ num-bigint = "0.3.0"
futures = {version = "0.3.5", features = ["compat", "io-compat"]}
futures-timer = "3.0.2"
[dependencies.heim]
default-features = false
features = ["process"]
version = "0.1.0-rc.1"
sysinfo = "0.15.9"
[build-dependencies]

View file

@ -1,15 +1,7 @@
use futures::{StreamExt, TryStreamExt};
use heim::process::{self as process, Process, ProcessResult};
use heim::units::{information, ratio, time, Ratio};
use std::usize;
use nu_errors::ShellError;
use nu_protocol::{TaggedDictBuilder, UntaggedValue, Value};
use nu_source::Tag;
use num_bigint::BigInt;
use std::time::Duration;
use sysinfo::{ProcessExt, System, SystemExt};
#[derive(Default)]
pub struct Ps;
@ -20,88 +12,41 @@ impl Ps {
}
}
async fn usage(process: Process) -> ProcessResult<(process::Process, Ratio, process::Memory)> {
let usage_1 = process.cpu_usage().await?;
futures_timer::Delay::new(Duration::from_millis(100)).await;
let usage_2 = process.cpu_usage().await?;
let memory = process.memory().await?;
Ok((process, usage_2 - usage_1, memory))
}
pub async fn ps(tag: Tag, long: bool) -> Result<Vec<Value>, ShellError> {
let processes = process::processes()
.await
.map_err(|_| {
ShellError::labeled_error(
"Unable to get process list",
"could not load process list",
tag.span,
)
})?
.map_ok(|process| {
// Note that there is no `.await` here,
// as we want to pass the returned future
// into the `.try_buffer_unordered`.
usage(process)
})
.try_buffer_unordered(usize::MAX);
futures::pin_mut!(processes);
let mut sys = System::new_all();
sys.refresh_all();
let duration = std::time::Duration::from_millis(500);
std::thread::sleep(duration);
sys.refresh_all();
let mut output = vec![];
while let Some(res) = processes.next().await {
if let Ok((process, usage, memory)) = res {
let mut dict = TaggedDictBuilder::new(&tag);
dict.insert_untagged("pid", UntaggedValue::int(process.pid()));
if let Ok(name) = process.name().await {
dict.insert_untagged("name", UntaggedValue::string(name));
}
if let Ok(status) = process.status().await {
dict.insert_untagged("status", UntaggedValue::string(format!("{:?}", status)));
}
dict.insert_untagged(
"cpu",
UntaggedValue::decimal_from_float(usage.get::<ratio::percent>() as f64, tag.span),
);
dict.insert_untagged(
"mem",
UntaggedValue::filesize(memory.rss().get::<information::byte>()),
);
dict.insert_untagged(
"virtual",
UntaggedValue::filesize(memory.vms().get::<information::byte>()),
);
if long {
if let Ok(cpu_time) = process.cpu_time().await {
let user_time = cpu_time.user().get::<time::nanosecond>().round() as i64;
let system_time = cpu_time.system().get::<time::nanosecond>().round() as i64;
dict.insert_untagged(
"cpu_time",
UntaggedValue::duration(BigInt::from(user_time + system_time)),
)
}
if let Ok(parent_pid) = process.parent_pid().await {
dict.insert_untagged("parent", UntaggedValue::int(parent_pid))
}
let result = sys.get_processes();
if let Ok(exe) = process.exe().await {
dict.insert_untagged("exe", UntaggedValue::string(exe.to_string_lossy()))
}
for (pid, process) in result.iter() {
let mut dict = TaggedDictBuilder::new(&tag);
dict.insert_untagged("pid", UntaggedValue::int(*pid));
dict.insert_untagged("name", UntaggedValue::string(process.name()));
dict.insert_untagged(
"status",
UntaggedValue::string(format!("{:?}", process.status())),
);
dict.insert_untagged(
"cpu",
UntaggedValue::decimal_from_float(process.cpu_usage() as f64, tag.span),
);
dict.insert_untagged("mem", UntaggedValue::filesize(process.memory()));
dict.insert_untagged("virtual", UntaggedValue::filesize(process.virtual_memory()));
#[cfg(not(windows))]
{
if let Ok(command) = process.command().await {
dict.insert_untagged(
"command",
UntaggedValue::string(command.to_os_string().to_string_lossy()),
);
}
}
if long {
if let Some(parent) = process.parent() {
dict.insert_untagged("parent", UntaggedValue::int(parent));
}
output.push(dict.into_value());
dict.insert_untagged("exe", UntaggedValue::filepath(process.exe()));
dict.insert_untagged("command", UntaggedValue::string(process.cmd().join(" ")));
}
output.push(dict.into_value());
}
Ok(output)

View file

@ -15,15 +15,9 @@ nu-plugin = {path = "../nu-plugin", version = "0.25.2"}
nu-protocol = {path = "../nu-protocol", version = "0.25.2"}
nu-source = {path = "../nu-source", version = "0.25.2"}
battery = "0.7.6"
futures = {version = "0.3.5", features = ["compat", "io-compat"]}
futures-util = "0.3.5"
num-bigint = "0.3.0"
[dependencies.heim]
default-features = false
version = "0.1.0-beta.3"
features = ["host", "cpu", "memory", "disk", "net", "sensors"]
sysinfo = "0.15.9"
[build-dependencies]

View file

@ -1,11 +1,6 @@
use futures_util::StreamExt;
use heim::units::{frequency, information, thermodynamic_temperature, time};
use heim::{disk, host, memory, net, sensors};
use nu_errors::ShellError;
use nu_protocol::{TaggedDictBuilder, UntaggedValue, Value};
use nu_source::Tag;
use num_bigint::BigInt;
use std::ffi::OsStr;
use sysinfo::{ComponentExt, DiskExt, NetworkExt, ProcessorExt, System, SystemExt, UserExt};
#[derive(Default)]
pub struct Sys;
@ -16,225 +11,25 @@ impl Sys {
}
}
async fn cpu(tag: Tag) -> Option<Value> {
let span = tag.span;
match futures::future::try_join(heim::cpu::logical_count(), heim::cpu::frequency()).await {
Ok((num_cpu, cpu_speed)) => {
let mut cpu_idx = TaggedDictBuilder::with_capacity(tag, 4);
cpu_idx.insert_untagged("cores", UntaggedValue::int(num_cpu));
pub fn disks(sys: &mut System, tag: Tag) -> Option<UntaggedValue> {
sys.refresh_disks();
let current_speed =
(cpu_speed.current().get::<frequency::hertz>() as f64 / 1_000_000_000.0 * 100.0)
.round()
/ 100.0;
cpu_idx.insert_untagged(
"current ghz",
UntaggedValue::decimal_from_float(current_speed, span),
);
if let Some(min_speed) = cpu_speed.min() {
let min_speed =
(min_speed.get::<frequency::hertz>() as f64 / 1_000_000_000.0 * 100.0).round()
/ 100.0;
cpu_idx.insert_untagged(
"min ghz",
UntaggedValue::decimal_from_float(min_speed, span),
);
}
if let Some(max_speed) = cpu_speed.max() {
let max_speed =
(max_speed.get::<frequency::hertz>() as f64 / 1_000_000_000.0 * 100.0).round()
/ 100.0;
cpu_idx.insert_untagged(
"max ghz",
UntaggedValue::decimal_from_float(max_speed, span),
);
}
Some(cpu_idx.into_value())
}
Err(_) => None,
}
}
async fn mem(tag: Tag) -> Value {
let mut dict = TaggedDictBuilder::with_capacity(tag, 4);
let (memory_result, swap_result) =
futures::future::join(memory::memory(), memory::swap()).await;
if let Ok(memory) = memory_result {
dict.insert_untagged(
"total",
UntaggedValue::filesize(memory.total().get::<information::byte>()),
);
dict.insert_untagged(
"free",
UntaggedValue::filesize(memory.free().get::<information::byte>()),
);
}
if let Ok(swap) = swap_result {
dict.insert_untagged(
"swap total",
UntaggedValue::filesize(swap.total().get::<information::byte>()),
);
dict.insert_untagged(
"swap free",
UntaggedValue::filesize(swap.free().get::<information::byte>()),
);
}
dict.into_value()
}
async fn host(tag: Tag) -> Result<Value, ShellError> {
let mut dict = TaggedDictBuilder::with_capacity(&tag, 6);
let (platform_result, uptime_result) =
futures::future::join(host::platform(), host::uptime()).await;
// OS
if let Ok(platform) = platform_result {
dict.insert_untagged("name", UntaggedValue::string(platform.system()));
dict.insert_untagged("release", UntaggedValue::string(platform.release()));
dict.insert_untagged("version", UntaggedValue::string(platform.version()));
dict.insert_untagged("hostname", UntaggedValue::string(platform.hostname()));
dict.insert_untagged(
"arch",
UntaggedValue::string(platform.architecture().as_str()),
);
}
// Uptime
if let Ok(uptime) = uptime_result {
let uptime = uptime.get::<time::nanosecond>().round() as i64;
dict.insert_untagged("uptime", UntaggedValue::duration(BigInt::from(uptime)));
}
// Sessions
// note: the heim host module has nomenclature "users"
let users = host::users().await.map_err(|_| {
ShellError::labeled_error("Unable to get users", "could not load users", tag.span)
})?;
futures::pin_mut!(users);
let mut user_vec = vec![];
while let Some(user) = users.next().await {
if let Ok(user) = user {
user_vec.push(Value {
value: UntaggedValue::string(user.username()),
tag: tag.clone(),
});
}
}
let user_list = UntaggedValue::Table(user_vec);
dict.insert_untagged("sessions", user_list);
Ok(dict.into_value())
}
async fn disks(tag: Tag) -> Result<Option<UntaggedValue>, ShellError> {
let mut output = vec![];
let partitions = disk::partitions_physical().await.map_err(|_| {
ShellError::labeled_error(
"Unable to get disk list",
"could not load disk list",
tag.span,
)
})?;
futures::pin_mut!(partitions);
while let Some(part) = partitions.next().await {
if let Ok(part) = part {
let mut dict = TaggedDictBuilder::with_capacity(&tag, 6);
dict.insert_untagged(
"device",
UntaggedValue::string(
part.device()
.unwrap_or_else(|| OsStr::new("N/A"))
.to_string_lossy(),
),
);
dict.insert_untagged("type", UntaggedValue::string(part.file_system().as_str()));
dict.insert_untagged(
"mount",
UntaggedValue::string(part.mount_point().to_string_lossy()),
);
if let Ok(usage) = disk::usage(part.mount_point().to_path_buf()).await {
dict.insert_untagged(
"total",
UntaggedValue::filesize(usage.total().get::<information::byte>()),
);
dict.insert_untagged(
"used",
UntaggedValue::filesize(usage.used().get::<information::byte>()),
);
dict.insert_untagged(
"free",
UntaggedValue::filesize(usage.free().get::<information::byte>()),
);
}
output.push(dict.into_value());
}
for disk in sys.get_disks() {
let mut dict = TaggedDictBuilder::new(&tag);
dict.insert_untagged(
"device",
UntaggedValue::string(disk.get_name().to_string_lossy()),
);
dict.insert_untagged(
"type",
UntaggedValue::string(String::from_utf8_lossy(disk.get_file_system())),
);
dict.insert_untagged("mount", UntaggedValue::filepath(disk.get_mount_point()));
dict.insert_untagged("total", UntaggedValue::filesize(disk.get_total_space()));
dict.insert_untagged("free", UntaggedValue::filesize(disk.get_available_space()));
output.push(dict.into_value());
}
if !output.is_empty() {
Ok(Some(UntaggedValue::Table(output)))
} else {
Ok(None)
}
}
async fn battery(tag: Tag) -> Option<UntaggedValue> {
let mut output = vec![];
let span = tag.span;
if let Ok(manager) = battery::Manager::new() {
if let Ok(batteries) = manager.batteries() {
for battery in batteries {
if let Ok(battery) = battery {
let mut dict = TaggedDictBuilder::new(&tag);
if let Some(vendor) = battery.vendor() {
dict.insert_untagged("vendor", UntaggedValue::string(vendor));
}
if let Some(model) = battery.model() {
dict.insert_untagged("model", UntaggedValue::string(model));
}
if let Some(cycles) = battery.cycle_count() {
dict.insert_untagged("cycles", UntaggedValue::int(cycles));
}
if let Some(time_to_full) = battery.time_to_full() {
dict.insert_untagged(
"mins to full",
UntaggedValue::decimal_from_float(
time_to_full.get::<battery::units::time::minute>() as f64,
span,
),
);
}
if let Some(time_to_empty) = battery.time_to_empty() {
dict.insert_untagged(
"mins to empty",
UntaggedValue::decimal_from_float(
time_to_empty.get::<battery::units::time::minute>() as f64,
span,
),
);
}
output.push(dict.into_value());
}
}
}
}
if !output.is_empty() {
Some(UntaggedValue::Table(output))
} else {
@ -242,54 +37,21 @@ async fn battery(tag: Tag) -> Option<UntaggedValue> {
}
}
async fn temp(tag: Tag) -> Option<UntaggedValue> {
pub fn net(sys: &mut System, tag: Tag) -> Option<UntaggedValue> {
sys.refresh_networks();
let mut output = vec![];
let span = tag.span;
for (iface, data) in sys.get_networks() {
let mut dict = TaggedDictBuilder::new(&tag);
dict.insert_untagged("name", UntaggedValue::string(iface));
dict.insert_untagged(
"sent",
UntaggedValue::filesize(data.get_total_transmitted()),
);
dict.insert_untagged("recv", UntaggedValue::filesize(data.get_total_received()));
let sensors = sensors::temperatures();
futures::pin_mut!(sensors);
while let Some(sensor) = sensors.next().await {
if let Ok(sensor) = sensor {
let mut dict = TaggedDictBuilder::new(&tag);
dict.insert_untagged("unit", UntaggedValue::string(sensor.unit()));
if let Some(label) = sensor.label() {
dict.insert_untagged("label", UntaggedValue::string(label));
}
dict.insert_untagged(
"temp",
UntaggedValue::decimal_from_float(
sensor
.current()
.get::<thermodynamic_temperature::degree_celsius>()
as f64,
span,
),
);
if let Some(high) = sensor.high() {
dict.insert_untagged(
"high",
UntaggedValue::decimal_from_float(
high.get::<thermodynamic_temperature::degree_celsius>() as f64,
span,
),
);
}
if let Some(critical) = sensor.critical() {
dict.insert_untagged(
"critical",
UntaggedValue::decimal_from_float(
critical.get::<thermodynamic_temperature::degree_celsius>() as f64,
span,
),
);
}
output.push(dict.into_value());
}
output.push(dict.into_value());
}
if !output.is_empty() {
Some(UntaggedValue::Table(output))
} else {
@ -297,71 +59,136 @@ async fn temp(tag: Tag) -> Option<UntaggedValue> {
}
}
async fn net(tag: Tag) -> Result<Option<UntaggedValue>, ShellError> {
pub fn cpu(sys: &mut System, tag: Tag) -> Option<UntaggedValue> {
sys.refresh_cpu();
let mut output = vec![];
let io_counters = net::io_counters().await.map_err(|_| {
ShellError::labeled_error(
"Unable to get network device list",
"could not load network device list",
tag.span,
)
})?;
for cpu in sys.get_processors() {
let mut dict = TaggedDictBuilder::new(&tag);
dict.insert_untagged("name", UntaggedValue::string(cpu.get_name()));
dict.insert_untagged("brand", UntaggedValue::string(cpu.get_brand()));
dict.insert_untagged("freq", UntaggedValue::int(cpu.get_frequency()));
futures::pin_mut!(io_counters);
while let Some(nic) = io_counters.next().await {
if let Ok(nic) = nic {
let mut network_idx = TaggedDictBuilder::with_capacity(&tag, 3);
network_idx.insert_untagged("name", UntaggedValue::string(nic.interface()));
network_idx.insert_untagged(
"sent",
UntaggedValue::filesize(nic.bytes_sent().get::<information::byte>()),
);
network_idx.insert_untagged(
"recv",
UntaggedValue::filesize(nic.bytes_recv().get::<information::byte>()),
);
output.push(network_idx.into_value());
}
output.push(dict.into_value());
}
if !output.is_empty() {
Ok(Some(UntaggedValue::Table(output)))
Some(UntaggedValue::Table(output))
} else {
Ok(None)
None
}
}
pub fn mem(sys: &mut System, tag: Tag) -> Option<UntaggedValue> {
sys.refresh_memory();
let mut dict = TaggedDictBuilder::new(tag);
let total_mem = sys.get_total_memory();
let free_mem = sys.get_free_memory();
let total_swap = sys.get_total_swap();
let free_swap = sys.get_free_swap();
dict.insert_untagged("total", UntaggedValue::filesize(total_mem));
dict.insert_untagged("free", UntaggedValue::filesize(free_mem));
dict.insert_untagged("swap total", UntaggedValue::filesize(total_swap));
dict.insert_untagged("swap free", UntaggedValue::filesize(free_swap));
Some(dict.into_untagged_value())
}
pub fn host(sys: &mut System, tag: Tag) -> Option<UntaggedValue> {
sys.refresh_users_list();
let mut dict = TaggedDictBuilder::new(&tag);
if let Some(name) = sys.get_name() {
dict.insert_untagged("name", UntaggedValue::string(name));
}
if let Some(version) = sys.get_version() {
dict.insert_untagged("version", UntaggedValue::string(version));
}
if let Some(hostname) = sys.get_host_name() {
dict.insert_untagged("hostname", UntaggedValue::string(hostname));
}
dict.insert_untagged(
"uptime",
UntaggedValue::duration(1000000000 * sys.get_uptime()),
);
let mut users = vec![];
for user in sys.get_users() {
let mut user_dict = TaggedDictBuilder::new(&tag);
user_dict.insert_untagged("name", UntaggedValue::string(user.get_name()));
let mut groups = vec![];
for group in user.get_groups() {
groups.push(UntaggedValue::string(group).into_value(&tag));
}
user_dict.insert_untagged("groups", UntaggedValue::Table(groups));
users.push(user_dict.into_value());
}
if !users.is_empty() {
dict.insert_untagged("sessions", UntaggedValue::Table(users));
}
Some(dict.into_untagged_value())
}
pub fn temp(sys: &mut System, tag: Tag) -> Option<UntaggedValue> {
sys.refresh_components();
sys.refresh_components_list();
let mut output = vec![];
for component in sys.get_components() {
let mut dict = TaggedDictBuilder::new(&tag);
dict.insert_untagged("unit", UntaggedValue::string(component.get_label()));
dict.insert_untagged(
"temp",
UntaggedValue::decimal_from_float(component.get_temperature() as f64, tag.span),
);
dict.insert_untagged(
"high",
UntaggedValue::decimal_from_float(component.get_max() as f64, tag.span),
);
if let Some(critical) = component.get_critical() {
dict.insert_untagged(
"critical",
UntaggedValue::decimal_from_float(critical as f64, tag.span),
);
}
output.push(dict.into_value());
}
if !output.is_empty() {
Some(UntaggedValue::Table(output))
} else {
None
}
}
pub async fn sysinfo(tag: Tag) -> Vec<Value> {
let mut sysinfo = TaggedDictBuilder::with_capacity(&tag, 7);
let mut sys = System::new_all();
let (host, cpu, disks, memory, temp) = futures::future::join5(
host(tag.clone()),
cpu(tag.clone()),
disks(tag.clone()),
mem(tag.clone()),
temp(tag.clone()),
)
.await;
let (net, battery) = futures::future::join(net(tag.clone()), battery(tag.clone())).await;
let mut sysinfo = TaggedDictBuilder::with_capacity(&tag, 6);
if let Ok(host) = host {
if let Some(host) = host(&mut sys, tag.clone()) {
sysinfo.insert_value("host", host);
}
if let Some(cpu) = cpu {
sysinfo.insert_value("cpu", cpu);
if let Some(cpus) = cpu(&mut sys, tag.clone()) {
sysinfo.insert_value("cpu", cpus);
}
if let Ok(Some(disks)) = disks {
sysinfo.insert_untagged("disks", disks);
if let Some(disks) = disks(&mut sys, tag.clone()) {
sysinfo.insert_value("disks", disks);
}
sysinfo.insert_value("mem", memory);
if let Some(temp) = temp {
sysinfo.insert_untagged("temp", temp);
if let Some(mem) = mem(&mut sys, tag.clone()) {
sysinfo.insert_value("mem", mem);
}
if let Ok(Some(net)) = net {
sysinfo.insert_untagged("net", net);
if let Some(temp) = temp(&mut sys, tag.clone()) {
sysinfo.insert_value("temp", temp);
}
if let Some(battery) = battery {
sysinfo.insert_untagged("battery", battery);
if let Some(net) = net(&mut sys, tag) {
sysinfo.insert_value("net", net);
}
vec![sysinfo.into_value()]