update some dependencies (#6009)

* update some dependencies

* there may be some bugs here but it seems to compile and run

* clippy
This commit is contained in:
Darren Schroeder 2022-07-11 11:18:06 -05:00 committed by GitHub
parent 9e3c64aa84
commit 9b6b817276
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 288 additions and 115 deletions

237
Cargo.lock generated
View file

@ -269,6 +269,25 @@ version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
[[package]]
name = "bindgen"
version = "0.59.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bd2a9a458e8f4304c52c43ebb0cfbd520289f8379a52e329a38afda99bf8eb8"
dependencies = [
"bitflags",
"cexpr",
"clang-sys",
"lazy_static",
"lazycell",
"peeking_take_while",
"proc-macro2",
"quote",
"regex",
"rustc-hash",
"shlex",
]
[[package]]
name = "bit_field"
version = "0.10.1"
@ -337,9 +356,9 @@ dependencies = [
[[package]]
name = "brownstone"
version = "1.1.0"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "030ea61398f34f1395ccbeb046fb68c87b631d1f34567fed0f0f11fa35d18d8d"
checksum = "c5839ee4f953e811bfdcf223f509cb2c6a3e1447959b0bff459405575bc17f22"
dependencies = [
"arrayvec 0.7.2",
]
@ -445,6 +464,15 @@ dependencies = [
"jobserver",
]
[[package]]
name = "cexpr"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
dependencies = [
"nom 7.1.1",
]
[[package]]
name = "cfg-if"
version = "0.1.10"
@ -512,6 +540,17 @@ dependencies = [
"phf_codegen 0.10.0",
]
[[package]]
name = "clang-sys"
version = "1.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a050e2153c5be08febd6734e29298e844fdb0fa21aeddd63b4eb7baa106c69b"
dependencies = [
"glob",
"libc",
"libloading",
]
[[package]]
name = "codepage"
version = "0.1.1"
@ -543,7 +582,7 @@ dependencies = [
"libc",
"once_cell",
"regex",
"terminal_size",
"terminal_size 0.1.17",
"unicode-width",
"winapi 0.3.9",
]
@ -1090,7 +1129,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46e245f4c8ec30c6415c56cb132c07e69e74f1942f6b4a4061da748b49f486ca"
dependencies = [
"cfg-if 1.0.0",
"rustix",
"rustix 0.34.8",
"windows-sys 0.30.0",
]
@ -1284,6 +1323,12 @@ version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a"
[[package]]
name = "futures-timer"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c"
[[package]]
name = "futures-util"
version = "0.3.21"
@ -1720,9 +1765,9 @@ dependencies = [
[[package]]
name = "inventory"
version = "0.2.3"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84344c6e0b90a9e2b6f3f9abe5cc74402684e348df7b32adca28747e0cef091a"
checksum = "e0257e268c91daba296499206db5dd5a058875936bec3d8429b5f3e20ec9dc9a"
dependencies = [
"ctor",
"ghost",
@ -1734,6 +1779,12 @@ version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9448015e586b611e5d322f6703812bbca2f1e709d5773ecd38ddb4e3bb649504"
[[package]]
name = "io-lifetimes"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24c3f4eff5495aee4c0399d7b6a0dc2b6e81be84242ffbfcf253ebacccc1d0cb"
[[package]]
name = "iovec"
version = "0.1.4"
@ -1946,6 +1997,16 @@ dependencies = [
"pkg-config",
]
[[package]]
name = "libloading"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd"
dependencies = [
"cfg-if 1.0.0",
"winapi 0.3.9",
]
[[package]]
name = "libm"
version = "0.2.2"
@ -1954,10 +2015,11 @@ checksum = "33a33a362ce288760ec6a508b94caaec573ae7d3bbbd91b87aa0bad4456839db"
[[package]]
name = "libproc"
version = "0.10.0"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6466fc1f834276563fbbd4be1c24236ef92bb9efdbd4691e07f1cf85a0b407f0"
checksum = "0b799ad155d75ce914c467ee5627b62247c20d4aedbd446f821484cebf3cded7"
dependencies = [
"bindgen",
"errno",
"libc",
]
@ -2036,9 +2098,9 @@ dependencies = [
[[package]]
name = "lscolors"
version = "0.9.0"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e9323b3525d4efad2dead1837a105e313253bfdbad1d470994038eededa4d62"
checksum = "88e4434edeec6cd16a7e8e13569af4568a66fcd6d79abd8696db22dd95f920e6"
dependencies = [
"ansi_term",
"crossterm",
@ -2144,13 +2206,14 @@ dependencies = [
[[package]]
name = "miette"
version = "3.3.0"
version = "4.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd2adcfcced5d625bf90a958a82ae5b93231f57f3df1383fee28c9b5096d35ed"
checksum = "1c90329e44f9208b55f45711f9558cec15d7ef8295cc65ecd6d4188ae8edc58c"
dependencies = [
"miette-derive 3.3.0",
"miette-derive 4.7.1",
"once_cell",
"thiserror",
"unicode-width",
]
[[package]]
@ -2167,7 +2230,7 @@ dependencies = [
"supports-color",
"supports-hyperlinks",
"supports-unicode",
"terminal_size",
"terminal_size 0.1.17",
"textwrap",
"thiserror",
"unicode-width",
@ -2175,9 +2238,9 @@ dependencies = [
[[package]]
name = "miette-derive"
version = "3.3.0"
version = "4.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c01a8b61312d367ce87956bb686731f87e4c6dd5dbc550e8f06e3c24fb1f67f"
checksum = "6b5bc45b761bcf1b5e6e6c4128cd93b84c218721a8d9b894aa0aff4ed180174c"
dependencies = [
"proc-macro2",
"quote",
@ -2376,9 +2439,9 @@ dependencies = [
[[package]]
name = "nom-supreme"
version = "0.6.0"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aadc66631948f6b65da03be4c4cd8bd104d481697ecbb9bbd65719b1ec60bc9f"
checksum = "2bd3ae6c901f1959588759ff51c95d24b491ecb9ff91aa9c2ef4acc5b1dcab27"
dependencies = [
"brownstone",
"indent_write",
@ -2448,7 +2511,7 @@ dependencies = [
"pretty_env_logger",
"rayon",
"reedline",
"rstest",
"rstest 0.12.0",
"serial_test",
"signal-hook",
"tempfile",
@ -2485,7 +2548,7 @@ dependencies = [
"nu-test-support",
"nu-utils",
"reedline",
"sysinfo 0.24.1",
"sysinfo",
"thiserror",
]
@ -2555,7 +2618,7 @@ dependencies = [
"pathdiff",
"polars",
"powierza-coefficient",
"quick-xml 0.22.0",
"quick-xml 0.23.0",
"quickcheck",
"quickcheck_macros",
"rand 0.8.5",
@ -2564,7 +2627,7 @@ dependencies = [
"regex",
"reqwest",
"roxmltree",
"rstest",
"rstest 0.15.0",
"rusqlite",
"rust-embed",
"serde",
@ -2575,8 +2638,8 @@ dependencies = [
"shadow-rs",
"sqlparser",
"strip-ansi-escapes",
"sysinfo 0.23.13",
"terminal_size",
"sysinfo",
"terminal_size 0.2.1",
"thiserror",
"titlecase",
"toml",
@ -2600,7 +2663,7 @@ dependencies = [
"nu-path",
"nu-protocol",
"nu-utils",
"sysinfo 0.23.13",
"sysinfo",
]
[[package]]
@ -3137,6 +3200,12 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd"
[[package]]
name = "peeking_take_while"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
[[package]]
name = "percent-encoding"
version = "2.1.0"
@ -3528,9 +3597,9 @@ dependencies = [
[[package]]
name = "procfs"
version = "0.12.0"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0941606b9934e2d98a3677759a971756eb821f75764d0e0d26946d08e74d9104"
checksum = "57928c5e4262566636d405e7c6a5a4f59bcb61a04a65dea57cf26b0dc3de6423"
dependencies = [
"bitflags",
"byteorder",
@ -3538,7 +3607,7 @@ dependencies = [
"flate2",
"hex",
"lazy_static",
"libc",
"rustix 0.35.7",
]
[[package]]
@ -3569,9 +3638,9 @@ dependencies = [
[[package]]
name = "quick-xml"
version = "0.22.0"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8533f14c8382aaad0d592c812ac3b826162128b65662331e1127b45c3d18536b"
checksum = "9279fbdacaad3baf559d8cabe0acc3d06e30ea14931af31af79578ac0946decc"
dependencies = [
"memchr",
]
@ -3919,6 +3988,31 @@ dependencies = [
"syn",
]
[[package]]
name = "rstest"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9c9dc66cc29792b663ffb5269be669f1613664e69ad56441fdb895c2347b930"
dependencies = [
"futures",
"futures-timer",
"rstest_macros",
"rustc_version 0.4.0",
]
[[package]]
name = "rstest_macros"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5015e68a0685a95ade3eee617ff7101ab6a3fc689203101ca16ebc16f2b89c66"
dependencies = [
"cfg-if 1.0.0",
"proc-macro2",
"quote",
"rustc_version 0.4.0",
"syn",
]
[[package]]
name = "rusqlite"
version = "0.27.0"
@ -3986,6 +4080,12 @@ version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
[[package]]
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustc_version"
version = "0.2.3"
@ -4012,12 +4112,26 @@ checksum = "2079c267b8394eb529872c3cf92e181c378b41fea36e68130357b52493701d2e"
dependencies = [
"bitflags",
"errno",
"io-lifetimes",
"io-lifetimes 0.6.1",
"libc",
"linux-raw-sys",
"winapi 0.3.9",
]
[[package]]
name = "rustix"
version = "0.35.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d51cc38aa10f6bbb377ed28197aa052aa4e2b762c22be9d3153d01822587e787"
dependencies = [
"bitflags",
"errno",
"io-lifetimes 0.7.2",
"libc",
"linux-raw-sys",
"windows-sys 0.36.1",
]
[[package]]
name = "rustversion"
version = "1.0.6"
@ -4286,15 +4400,21 @@ dependencies = [
[[package]]
name = "shadow-rs"
version = "0.11.0"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f47e98e36909e951f4da3908f4475f969bec92a41734dd92e883aaa11c10294b"
checksum = "ed1b83da0a4e48d8dcc13ad177b64f2fc40097974f9bf176c2bcb702cabadff3"
dependencies = [
"chrono",
"const_format",
"is_debug",
]
[[package]]
name = "shlex"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3"
[[package]]
name = "signal-hook"
version = "0.3.14"
@ -4583,24 +4703,9 @@ dependencies = [
[[package]]
name = "sysinfo"
version = "0.23.13"
version = "0.24.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3977ec2e0520829be45c8a2df70db2bf364714d8a748316a10c3c35d4d2b01c9"
dependencies = [
"cfg-if 1.0.0",
"core-foundation-sys",
"libc",
"ntapi",
"once_cell",
"rayon",
"winapi 0.3.9",
]
[[package]]
name = "sysinfo"
version = "0.24.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6a8e71535da31837213ac114531d31def75d7aebd133264e420a3451fa7f703"
checksum = "0b6e19da72a8d75be4d40e4dd4686afca31507f26c3ffdf6bd3073278d9de0a0"
dependencies = [
"cfg-if 1.0.0",
"core-foundation-sys",
@ -4688,6 +4793,16 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "terminal_size"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8440c860cf79def6164e4a0a983bcc2305d82419177a0e0c71930d049e3ac5a1"
dependencies = [
"rustix 0.35.7",
"windows-sys 0.36.1",
]
[[package]]
name = "termtree"
version = "0.2.4"
@ -4768,9 +4883,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "titlecase"
version = "1.1.0"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f565e410cfc24c2f2a89960b023ca192689d7f77d3f8d4f4af50c2d8affe1117"
checksum = "ea7a2f1a76e892e6c07c275e6e851400257304a6e34c0e4e32ebbd3871808802"
dependencies = [
"lazy_static",
"regex",
@ -4888,9 +5003,9 @@ checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
[[package]]
name = "typetag"
version = "0.1.8"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4080564c5b2241b5bff53ab610082234e0c57b0417f4bd10596f183001505b8a"
checksum = "62a3f3e32f68a8a611e8b98a14e058954f1b81d6eb6af50e2349bf322ae4062b"
dependencies = [
"erased-serde",
"inventory",
@ -4901,9 +5016,9 @@ dependencies = [
[[package]]
name = "typetag-impl"
version = "0.1.8"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e60147782cc30833c05fba3bab1d9b5771b2685a2557672ac96fa5d154099c0e"
checksum = "762400b16d1815702b6a22e71764f5936ef5d2c4dcff95497f874c53594d59fd"
dependencies = [
"proc-macro2",
"quote",
@ -5031,9 +5146,9 @@ checksum = "936e4b492acfd135421d8dca4b1aa80a7bfc26e702ef3af710e0752684df5372"
[[package]]
name = "uuid"
version = "0.8.2"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
checksum = "dd6469f4314d5f1ffec476e05f17cc9a78bc7a27a6a857842170bdf8d6f98d2f"
dependencies = [
"getrandom 0.2.6",
]
@ -5214,14 +5329,14 @@ checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744"
[[package]]
name = "wax"
version = "0.4.0"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97a4ecdf7da7e42385f844503bac3e9a2a066838e3cb66c5f28ce03bafb2f90d"
checksum = "06c7a3bac6110ac062b7b422a442b7ee23e07209e2784a036654cab1e71bbafc"
dependencies = [
"bstr",
"const_format",
"itertools",
"miette 3.3.0",
"miette 4.7.1",
"nom 7.1.1",
"nom-supreme",
"pori",

View file

@ -52,7 +52,7 @@ is-root = "0.1.2"
itertools = "0.10.0"
lazy_static = "1.4.0"
log = "0.4.14"
lscolors = { version = "0.9.0", features = ["crossterm"]}
lscolors = { version = "0.10.0", features = ["crossterm"]}
md5 = { package = "md-5", version = "0.10.0" }
meval = "0.2.0"
mime = "0.3.16"
@ -60,7 +60,7 @@ notify = "4.0.17"
num = { version = "0.4.0", optional = true }
pathdiff = "0.2.1"
powierza-coefficient = "1.0"
quick-xml = "0.22"
quick-xml = "0.23.0"
rand = "0.8"
rayon = "1.5.1"
regex = "1.5.4"
@ -73,19 +73,19 @@ serde_urlencoded = "0.7.0"
serde_yaml = "0.8.16"
sha2 = "0.10.0"
# Disable default features b/c the default features build Git (very slow to compile)
shadow-rs = { version = "0.11.0", default-features = false }
shadow-rs = { version = "0.12.0", default-features = false }
strip-ansi-escapes = "0.1.1"
sysinfo = "0.23.5"
terminal_size = "0.1.17"
sysinfo = "0.24.6"
terminal_size = "0.2.1"
thiserror = "1.0.31"
titlecase = "1.1.0"
titlecase = "2.0.0"
toml = "0.5.8"
unicode-segmentation = "1.8.0"
url = "2.2.1"
uuid = { version = "0.8.2", features = ["v4"] }
uuid = { version = "1.1.2", features = ["v4"] }
which = { version = "4.2.2", optional = true }
reedline = { version = "0.8.0", features = ["bashisms", "sqlite"]}
wax = { version = "0.4.0", features = ["diagnostics"] }
wax = { version = "0.5.0", features = ["diagnostics"] }
rusqlite = { version = "0.27.0", features = ["bundled"], optional = true }
sqlparser = { version = "0.16.0", features = ["serde"], optional = true }
@ -126,11 +126,11 @@ dataframe = ["polars", "num"]
database = ["sqlparser", "rusqlite"]
[build-dependencies]
shadow-rs = { version = "0.11.0", default-features = false }
shadow-rs = { version = "0.12.0", default-features = false }
[dev-dependencies]
hamcrest2 = "0.3.0"
dirs-next = "2.0.0"
quickcheck = "1.0.3"
quickcheck_macros = "1.0.0"
rstest = "0.12.0"
rstest = "0.15.0"

View file

@ -6,7 +6,7 @@ use nu_protocol::{
Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Spanned,
SyntaxShape, Value,
};
use wax::Glob as WaxGlob;
use wax::{Glob as WaxGlob, WalkBehavior};
#[derive(Clone)]
pub struct Glob;
@ -120,7 +120,13 @@ impl Command for Glob {
#[allow(clippy::needless_collect)]
let glob_results: Vec<Value> = glob
.walk(path, folder_depth)
.walk_with_behavior(
path,
WalkBehavior {
depth: folder_depth,
..Default::default()
},
)
.flatten()
.map(|entry| Value::String {
val: entry.into_path().to_string_lossy().to_string(),

View file

@ -40,7 +40,7 @@ impl Command for SubCommand {
fn uuid(call: &Call) -> Result<PipelineData, ShellError> {
let span = call.head;
let uuid_4 = Uuid::new_v4().to_hyphenated().to_string();
let uuid_4 = Uuid::new_v4().hyphenated().to_string();
Ok(PipelineData::Value(
Value::String { val: uuid_4, span },

View file

@ -6,7 +6,7 @@ use nu_protocol::{
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Value,
};
use std::time::{Duration, UNIX_EPOCH};
use sysinfo::{ComponentExt, DiskExt, NetworkExt, ProcessorExt, System, SystemExt, UserExt};
use sysinfo::{ComponentExt, CpuExt, DiskExt, NetworkExt, System, SystemExt, UserExt};
#[derive(Clone)]
pub struct Sys;
@ -199,7 +199,7 @@ pub fn cpu(sys: &mut System, span: Span) -> Option<Value> {
sys.refresh_cpu();
let mut output = vec![];
for cpu in sys.processors() {
for cpu in sys.cpus() {
let mut cols = vec![];
let mut vals = vec![];

View file

@ -13,7 +13,7 @@ nu-glob = { path = "../nu-glob", version = "0.65.1" }
nu-utils = { path = "../nu-utils", version = "0.65.1" }
chrono = { version="0.4.19", features=["serde"] }
sysinfo = "0.23.10"
sysinfo = "0.24.6"
[features]
plugin = []

View file

@ -19,7 +19,7 @@ chrono-humanize = "0.2.1"
byte-unit = "4.0.9"
serde_json = { version = "1.0", optional = true }
nu-json = { path = "../nu-json", version = "0.65.1" }
typetag = "0.1.8"
typetag = "0.2.1"
num-format = "0.4.0"
sys-locale = "0.2.0"
regex = "1.5.4"

View file

@ -16,10 +16,10 @@ path = "src/main.rs"
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
procfs = "0.12.0"
procfs = "0.13.0"
[target.'cfg(target_os = "macos")'.dependencies]
libproc = "0.10"
libproc = "0.12.0"
errno = "0.2"
libc = "0.2"

View file

@ -6,14 +6,17 @@ use std::time::{Duration, Instant};
pub enum ProcessTask {
Process(Process),
Task { stat: Stat, owner: u32 },
Task { stat: Box<Stat>, owner: u32 },
}
impl ProcessTask {
pub fn stat(&self) -> &Stat {
pub fn stat(&self) -> Result<Stat, ProcError> {
match self {
ProcessTask::Process(x) => &x.stat,
ProcessTask::Task { stat: x, owner: _ } => x,
ProcessTask::Process(x) => match x.stat() {
Ok(it) => Ok(it),
Err(err) => Err(err),
},
ProcessTask::Task { stat: x, owner: _ } => Ok(*x.clone()),
}
}
@ -33,7 +36,13 @@ impl ProcessTask {
pub fn fd(&self) -> Result<Vec<FDInfo>, ProcError> {
match self {
ProcessTask::Process(x) => x.fd(),
ProcessTask::Process(x) => {
let fds = match x.fd() {
Ok(f) => f,
Err(e) => return Err(e),
};
fds.collect()
}
_ => Err(ProcError::Other("not supported".to_string())),
}
}
@ -47,7 +56,7 @@ impl ProcessTask {
pub fn owner(&self) -> u32 {
match self {
ProcessTask::Process(x) => x.owner,
ProcessTask::Process(x) => x.uid().unwrap_or(0),
ProcessTask::Task { stat: _, owner: x } => *x,
}
}
@ -77,32 +86,54 @@ pub fn collect_proc(interval: Duration, with_thread: bool) -> Vec<ProcessInfo> {
let mut ret = Vec::new();
if let Ok(all_proc) = procfs::process::all_processes() {
for proc in all_proc {
for proc in all_proc.flatten() {
let io = proc.io().ok();
let time = Instant::now();
if with_thread {
if let Ok(iter) = proc.tasks() {
collect_task(iter, &mut base_tasks);
}
base_procs.push((proc.pid(), proc, io, time));
}
base_procs.push((proc.pid(), proc, io, time));
// match proc {
// Ok(p) => {
// let io = p.io().ok();
// let time = Instant::now();
// if with_thread {
// if let Ok(iter) = p.tasks() {
// collect_task(iter, &mut base_tasks);
// }
// }
// base_procs.push((p.pid(), p, io, time));
// }
// Err(_) => {}
// }
}
}
thread::sleep(interval);
for (pid, prev_proc, prev_io, prev_time) in base_procs {
let curr_proc = if let Ok(proc) = Process::new(pid) {
proc
} else {
prev_proc.clone()
let curr_proc_pid = pid;
let prev_proc_pid = prev_proc.pid();
let curr_proc = match Process::new(curr_proc_pid) {
Ok(p) => p,
Err(_) => return Vec::<ProcessInfo>::new(),
};
let prev_proc = match Process::new(prev_proc_pid) {
Ok(p) => p,
Err(_) => return Vec::<ProcessInfo>::new(),
};
let curr_io = curr_proc.io().ok();
let curr_status = curr_proc.status().ok();
let curr_time = Instant::now();
let interval = curr_time - prev_time;
let ppid = curr_proc.stat.ppid;
let owner = curr_proc.owner;
let ppid = match curr_proc.stat() {
Ok(p) => p.ppid,
Err(_) => 0,
};
let owner = curr_proc.uid().unwrap_or(0);
let mut curr_tasks = HashMap::new();
if with_thread {
@ -133,11 +164,11 @@ pub fn collect_proc(interval: Duration, with_thread: bool) -> Vec<ProcessInfo> {
pid: tid,
ppid: pid,
curr_proc: ProcessTask::Task {
stat: curr_stat,
stat: Box::new(curr_stat),
owner,
},
prev_proc: ProcessTask::Task {
stat: prev_stat,
stat: Box::new(prev_stat),
owner,
},
curr_io,
@ -196,35 +227,50 @@ impl ProcessInfo {
if !cmd.is_empty() {
cmd.join(" ").replace('\n', " ").replace('\t', " ")
} else {
self.curr_proc.stat().comm.clone()
match self.curr_proc.stat() {
Ok(p) => p.comm,
Err(_) => "".to_string(),
}
}
} else {
self.curr_proc.stat().comm.clone()
match self.curr_proc.stat() {
Ok(p) => p.comm,
Err(_) => "".to_string(),
}
}
}
/// Get the status of the process
pub fn status(&self) -> String {
match self.curr_proc.stat().state {
'S' => "Sleeping".into(),
'R' => "Running".into(),
'D' => "Disk sleep".into(),
'Z' => "Zombie".into(),
'T' => "Stopped".into(),
't' => "Tracing".into(),
'X' => "Dead".into(),
'x' => "Dead".into(),
'K' => "Wakekill".into(),
'W' => "Waking".into(),
'P' => "Parked".into(),
_ => "Unknown".into(),
match self.curr_proc.stat() {
Ok(p) => match p.state {
'S' => "Sleeping".into(),
'R' => "Running".into(),
'D' => "Disk sleep".into(),
'Z' => "Zombie".into(),
'T' => "Stopped".into(),
't' => "Tracing".into(),
'X' => "Dead".into(),
'x' => "Dead".into(),
'K' => "Wakekill".into(),
'W' => "Waking".into(),
'P' => "Parked".into(),
_ => "Unknown".into(),
},
Err(_) => "Unknown".into(),
}
}
/// CPU usage as a percent of total
pub fn cpu_usage(&self) -> f64 {
let curr_time = self.curr_proc.stat().utime + self.curr_proc.stat().stime;
let prev_time = self.prev_proc.stat().utime + self.prev_proc.stat().stime;
let curr_time = match self.curr_proc.stat() {
Ok(c) => c.utime + c.stime,
Err(_) => 0,
};
let prev_time = match self.prev_proc.stat() {
Ok(c) => c.utime + c.stime,
Err(_) => 0,
};
let usage_ms =
(curr_time - prev_time) * 1000 / procfs::ticks_per_second().unwrap_or(100) as u64;
let interval_ms = self.interval.as_secs() * 1000 + u64::from(self.interval.subsec_millis());
@ -233,11 +279,17 @@ impl ProcessInfo {
/// Memory size in number of bytes
pub fn mem_size(&self) -> u64 {
self.curr_proc.stat().rss_bytes().unwrap_or(0) as u64
match self.curr_proc.stat() {
Ok(p) => p.rss_bytes().unwrap_or(0),
Err(_) => 0,
}
}
/// Virtual memory size in bytes
pub fn virtual_size(&self) -> u64 {
self.curr_proc.stat().vsize
match self.curr_proc.stat() {
Ok(p) => p.vsize,
Err(_) => 0u64,
}
}
}